Browse Source

#185 Button to read workspaces

Alexis CLEMENT 8 years ago
parent
commit
866f0f2984

+ 1 - 1
tracim/tracim/controllers/read.py View File

10
 
10
 
11
     @classmethod
11
     @classmethod
12
     def current_item_id_key_in_context(cls) -> str:
12
     def current_item_id_key_in_context(cls) -> str:
13
-        pass
13
+        return''
14
 
14
 
15
     @tg.expose()
15
     @tg.expose()
16
     def index(self):
16
     def index(self):

+ 24 - 0
tracim/tracim/controllers/workspace.py View File

9
 
9
 
10
 from tracim.controllers import TIMRestController
10
 from tracim.controllers import TIMRestController
11
 from tracim.controllers.content import UserWorkspaceFolderRestController
11
 from tracim.controllers.content import UserWorkspaceFolderRestController
12
+from tracim.controllers.read import ContentController
12
 
13
 
13
 from tracim.lib.helpers import convert_id_into_instances
14
 from tracim.lib.helpers import convert_id_into_instances
14
 from tracim.lib.content import ContentApi
15
 from tracim.lib.content import ContentApi
42
     def get_all(self, *args, **kw):
43
     def get_all(self, *args, **kw):
43
         tg.redirect(tg.url('/home'))
44
         tg.redirect(tg.url('/home'))
44
 
45
 
46
+    @tg.expose()
47
+    def mark_read(self, workspace_id, **kwargs):
48
+
49
+        user = tmpl_context.current_user
50
+        workspace_api = WorkspaceApi(user)
51
+        workspace = workspace_api.get_one(workspace_id)
52
+
53
+        content_api = ContentApi(user)
54
+        content_api.mark_read__workspace(workspace)
55
+
56
+        tg.redirect('/workspaces/{}'.format(workspace_id))
57
+        return DictLikeClass(fake_api=fake_api)
58
+
45
     @tg.expose('tracim.templates.workspace.getone')
59
     @tg.expose('tracim.templates.workspace.getone')
46
     def get_one(self, workspace_id, **kwargs):
60
     def get_one(self, workspace_id, **kwargs):
47
         """
61
         """
56
         user = tmpl_context.current_user
70
         user = tmpl_context.current_user
57
 
71
 
58
         current_user_content = Context(CTX.CURRENT_USER).toDict(user)
72
         current_user_content = Context(CTX.CURRENT_USER).toDict(user)
73
+        fake_api = Context(CTX.CURRENT_USER).toDict({
74
+            'current_user': current_user_content})
75
+
76
+        unread_contents = ContentApi(user).get_last_unread(None,
77
+                                                           ContentType.Any,
78
+                                                           None)
79
+        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
59
         current_user_content.roles.sort(key=lambda role: role.workspace.name)
80
         current_user_content.roles.sort(key=lambda role: role.workspace.name)
60
 
81
 
61
         workspace_api = WorkspaceApi(user)
82
         workspace_api = WorkspaceApi(user)
64
         dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
85
         dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
65
         dictified_folders = self.folders.get_all_fake(workspace).result
86
         dictified_folders = self.folders.get_all_fake(workspace).result
66
         fake_api = DictLikeClass(
87
         fake_api = DictLikeClass(
88
+            last_unread=Context(CTX.CONTENT_LIST).toDict(unread_contents,
89
+                                                         'contents',
90
+                                                         'nb'),
67
             current_user=dictified_current_user,
91
             current_user=dictified_current_user,
68
             current_workspace_folders=dictified_folders,
92
             current_workspace_folders=dictified_folders,
69
             current_user_workspace_role=workspace.get_user_role(user)
93
             current_user_workspace_role=workspace.get_user_role(user)

+ 14 - 1
tracim/tracim/lib/content.py View File

878
                        recursive: bool=True
878
                        recursive: bool=True
879
                        ):
879
                        ):
880
 
880
 
881
-        itemset = self.get_last_unread(None, ContentType.Any, None)
881
+        itemset = self.get_last_unread(None, ContentType.Any)
882
+
883
+        for item in itemset:
884
+            self.mark_read(item, read_datetime, do_flush, recursive)
885
+
886
+    def mark_read__workspace(self,
887
+                       workspace : Workspace,
888
+                       read_datetime: datetime=None,
889
+                       do_flush: bool=True,
890
+                       recursive: bool=True
891
+                       ):
892
+
893
+        itemset = self.get_last_unread(None, ContentType.Any, workspace)
894
+
882
         for item in itemset:
895
         for item in itemset:
883
             self.mark_read(item, read_datetime, do_flush, recursive)
896
             self.mark_read(item, read_datetime, do_flush, recursive)
884
 
897
 

+ 1 - 0
tracim/tracim/lib/webdav/sql_resources.py View File

3
 
3
 
4
 import os
4
 import os
5
 
5
 
6
+import tg
6
 import transaction
7
 import transaction
7
 import re
8
 import re
8
 from datetime import datetime
9
 from datetime import datetime

+ 6 - 0
tracim/tracim/templates/workspace/getone.mak View File

54
 
54
 
55
 
55
 
56
 <div class="workspace__detail__wrapper">
56
 <div class="workspace__detail__wrapper">
57
+     %if fake_api.last_unread.nb > 0:
58
+         <% workspace_id = result.workspace.id %>
59
+         <a href="${tg.url('/workspaces/{ws_id}/mark_read'.format(ws_id = workspace_id))}" class="btn btn-default"> ${_('Mark this workspace as read')} </a>
60
+
61
+     %endif
62
+
57
     ${TITLE.H3(_('Detail'), 'fa-align-justify', 'workspace-members')}
63
     ${TITLE.H3(_('Detail'), 'fa-align-justify', 'workspace-members')}
58
     % if result.workspace.description:
64
     % if result.workspace.description:
59
         <p>${result.workspace.description}</p>
65
         <p>${result.workspace.description}</p>

+ 1 - 0
tracim/tracim/tests/library/test_content_api.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
+import datetime
2
 
3
 
3
 from nose.tools import eq_, ok_
4
 from nose.tools import eq_, ok_
4
 from nose.tools import raises
5
 from nose.tools import raises