Browse Source

Merge pull request #18 from lebouquetin/master

Tracim 10 years ago
parent
commit
07ac3640f3

+ 1 - 1
tracim/tracim/model/data.py View File

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 View File

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 }

+ 36 - 3
tracim/tracim/tests/library/test_serializers.py View File

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
206
 
208
 
207
         s2 = Context(CTX.DEFAULT).toDict(mylist, 'subitems', 'subitems_nb')
209
         s2 = Context(CTX.DEFAULT).toDict(mylist, 'subitems', 'subitems_nb')
208
 
210
 
209
-        print('----------------->  ---> ', s2)
210
-        print('----------------->  ', s2.items)
211
         ok_('subitems' in s2.keys(), s2)
211
         ok_('subitems' in s2.keys(), s2)
212
 
212
 
213
         ok_('name' in s2.subitems[0].keys())
213
         ok_('name' in s2.subitems[0].keys())
222
         eq_(3, s2.subitems_nb)
222
         eq_(3, s2.subitems_nb)
223
         eq_(3, len(s2.subitems))
223
         eq_(3, len(s2.subitems))
224
 
224
 
225
+        eq_(2, len(s2))
225
 
226
 
226
 
227
 
227
-        eq_(2, len(s2))
228
+    def test_serializer_content__menui_api_context__children(self):
229
+        self.app.get('/_test_vars')  # Allow to create fake context
230
+
231
+        folder_without_child = Content()
232
+        folder_without_child.type = ContentType.Folder
233
+        res = Context(CTX.MENU_API).toDict(folder_without_child)
234
+        eq_(False, res['children'])
235
+
236
+        folder_with_child = Content()
237
+        folder_with_child.type = ContentType.Folder
238
+        folder_without_child.parent = folder_with_child
239
+        DBSession.add(folder_with_child)
240
+        DBSession.add(folder_without_child)
241
+        DBSession.flush()
242
+
243
+        res = Context(CTX.MENU_API).toDict(folder_with_child)
244
+        eq_(True, res['children'])
245
+
246
+        for curtype in ContentType.all():
247
+            if curtype not in (ContentType.Folder, ContentType.Comment):
248
+                item = Content()
249
+                item.type = curtype
250
+
251
+                fake_child = Content()
252
+                fake_child.type = curtype
253
+                fake_child.parent = item
254
+
255
+                DBSession.add(item)
256
+                DBSession.add(fake_child)
257
+                DBSession.flush()
258
+
259
+                res = Context(CTX.MENU_API).toDict(item)
260
+                eq_(False, res['children'])