Sfoglia il codice sorgente

Merge pull request #18 from lebouquetin/master

Tracim 10 anni fa
parent
commit
07ac3640f3

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

@@ -422,7 +422,7 @@ class Content(DeclarativeBase):
422 422
     def get_child_nb(self, content_type: ContentType, content_status = ''):
423 423
         child_nb = 0
424 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 426
                 if not content_status:
427 427
                     child_nb = child_nb+1
428 428
                 elif content_status==child.status:

+ 6 - 2
tracim/tracim/model/serializers.py Vedi File

@@ -283,11 +283,15 @@ def serialize_content_for_menu_api(content: Content, context: Context):
283 283
     content_id = content.content_id
284 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 290
     result = DictLikeClass(
287 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 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 295
         li_attr = { 'title': content.get_label(), 'class': 'tracim-tree-item-is-a-folder' },
292 296
         type = content.type,
293 297
         state = { 'opened': True if ContentType.Folder!=content.type else False, 'selected': False }

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

@@ -8,6 +8,8 @@ from sqlalchemy.orm.exc import NoResultFound
8 8
 
9 9
 import transaction
10 10
 
11
+from tracim.model import DBSession
12
+
11 13
 from tg.util import LazyString
12 14
 from tracim.model.data import Content
13 15
 from tracim.model.data import ContentType
@@ -206,8 +208,6 @@ class TestSerializers(TestStandard):
206 208
 
207 209
         s2 = Context(CTX.DEFAULT).toDict(mylist, 'subitems', 'subitems_nb')
208 210
 
209
-        print('----------------->  ---> ', s2)
210
-        print('----------------->  ', s2.items)
211 211
         ok_('subitems' in s2.keys(), s2)
212 212
 
213 213
         ok_('name' in s2.subitems[0].keys())
@@ -222,6 +222,39 @@ class TestSerializers(TestStandard):
222 222
         eq_(3, s2.subitems_nb)
223 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'])