Explorar el Código

bugfix: set childre: False in treeview json api for documents

Damien ACCORSI hace 10 años
padre
commit
f8790b2b93

+ 1 - 1
tracim/tracim/model/data.py Ver fichero

422
     def get_child_nb(self, content_type: ContentType, content_status = ''):
422
     def get_child_nb(self, content_type: ContentType, content_status = ''):
423
         child_nb = 0
423
         child_nb = 0
424
         for child in self.valid_children:
424
         for child in self.valid_children:
425
-            if child.type==content_type:
425
+            if child.type == content_type or content_type == ContentType.Any:
426
                 if not content_status:
426
                 if not content_status:
427
                     child_nb = child_nb+1
427
                     child_nb = child_nb+1
428
                 elif content_status==child.status:
428
                 elif content_status==child.status:

+ 6 - 2
tracim/tracim/model/serializers.py Ver fichero

283
     content_id = content.content_id
283
     content_id = content.content_id
284
     workspace_id = content.workspace_id
284
     workspace_id = content.workspace_id
285
 
285
 
286
+    has_children = False
287
+    if content.type == ContentType.Folder:
288
+        has_children = content.get_child_nb(ContentType.Any) > 0
289
+
286
     result = DictLikeClass(
290
     result = DictLikeClass(
287
         id = CST.TREEVIEW_MENU.ID_TEMPLATE__FULL.format(workspace_id, content_id),
291
         id = CST.TREEVIEW_MENU.ID_TEMPLATE__FULL.format(workspace_id, content_id),
288
-        children = True, # TODO: make this dynamic
292
+        children = has_children,
289
         text = content.get_label(),
293
         text = content.get_label(),
290
-        a_attr = { 'href' : context.url(ContentType.fill_url(content)) },
294
+        a_attr = { 'href' : context.url(ContentType.fill_url(content))},
291
         li_attr = { 'title': content.get_label(), 'class': 'tracim-tree-item-is-a-folder' },
295
         li_attr = { 'title': content.get_label(), 'class': 'tracim-tree-item-is-a-folder' },
292
         type = content.type,
296
         type = content.type,
293
         state = { 'opened': True if ContentType.Folder!=content.type else False, 'selected': False }
297
         state = { 'opened': True if ContentType.Folder!=content.type else False, 'selected': False }

+ 37 - 1
tracim/tracim/tests/library/test_serializers.py Ver fichero

8
 
8
 
9
 import transaction
9
 import transaction
10
 
10
 
11
+from tracim.model import DBSession
12
+
11
 from tg.util import LazyString
13
 from tg.util import LazyString
12
 from tracim.model.data import Content
14
 from tracim.model.data import Content
13
 from tracim.model.data import ContentType
15
 from tracim.model.data import ContentType
222
         eq_(3, s2.subitems_nb)
224
         eq_(3, s2.subitems_nb)
223
         eq_(3, len(s2.subitems))
225
         eq_(3, len(s2.subitems))
224
 
226
 
227
+        eq_(2, len(s2))
225
 
228
 
226
 
229
 
227
-        eq_(2, len(s2))
230
+    def test_serializer_content__menui_api_context__children(self):
231
+        self.app.get('/_test_vars')  # Allow to create fake context
232
+
233
+        folder_without_child = Content()
234
+        folder_without_child.type = ContentType.Folder
235
+        res = Context(CTX.MENU_API).toDict(folder_without_child)
236
+        eq_(False, res['children'])
237
+
238
+        folder_with_child = Content()
239
+        folder_with_child.type = ContentType.Folder
240
+        folder_without_child.parent = folder_with_child
241
+        DBSession.add(folder_with_child)
242
+        DBSession.add(folder_without_child)
243
+        DBSession.flush()
244
+
245
+        res = Context(CTX.MENU_API).toDict(folder_with_child)
246
+        eq_(True, res['children'])
247
+
248
+        for curtype in ContentType.all():
249
+            print( 'iteration: ', curtype)
250
+            if curtype not in (ContentType.Folder, ContentType.Comment):
251
+                item = Content()
252
+                item.type = curtype
253
+
254
+                fake_child = Content()
255
+                fake_child.type = curtype
256
+                fake_child.parent = item
257
+
258
+                DBSession.add(item)
259
+                DBSession.add(fake_child)
260
+                DBSession.flush()
261
+
262
+                res = Context(CTX.MENU_API).toDict(item)
263
+                eq_(False, res['children'])