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,7 +10,7 @@ class ContentController(StandardController):
10 10
 
11 11
     @classmethod
12 12
     def current_item_id_key_in_context(cls) -> str:
13
-        pass
13
+        return''
14 14
 
15 15
     @tg.expose()
16 16
     def index(self):

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

@@ -9,6 +9,7 @@ from tracim.config.app_cfg import CFG
9 9
 
10 10
 from tracim.controllers import TIMRestController
11 11
 from tracim.controllers.content import UserWorkspaceFolderRestController
12
+from tracim.controllers.read import ContentController
12 13
 
13 14
 from tracim.lib.helpers import convert_id_into_instances
14 15
 from tracim.lib.content import ContentApi
@@ -42,6 +43,19 @@ class UserWorkspaceRestController(TIMRestController):
42 43
     def get_all(self, *args, **kw):
43 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 59
     @tg.expose('tracim.templates.workspace.getone')
46 60
     def get_one(self, workspace_id, **kwargs):
47 61
         """
@@ -56,6 +70,13 @@ class UserWorkspaceRestController(TIMRestController):
56 70
         user = tmpl_context.current_user
57 71
 
58 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 80
         current_user_content.roles.sort(key=lambda role: role.workspace.name)
60 81
 
61 82
         workspace_api = WorkspaceApi(user)
@@ -64,6 +85,9 @@ class UserWorkspaceRestController(TIMRestController):
64 85
         dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
65 86
         dictified_folders = self.folders.get_all_fake(workspace).result
66 87
         fake_api = DictLikeClass(
88
+            last_unread=Context(CTX.CONTENT_LIST).toDict(unread_contents,
89
+                                                         'contents',
90
+                                                         'nb'),
67 91
             current_user=dictified_current_user,
68 92
             current_workspace_folders=dictified_folders,
69 93
             current_user_workspace_role=workspace.get_user_role(user)

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

@@ -878,7 +878,20 @@ class ContentApi(object):
878 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 895
         for item in itemset:
883 896
             self.mark_read(item, read_datetime, do_flush, recursive)
884 897
 

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

@@ -3,6 +3,7 @@ import logging
3 3
 
4 4
 import os
5 5
 
6
+import tg
6 7
 import transaction
7 8
 import re
8 9
 from datetime import datetime

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

@@ -54,6 +54,12 @@
54 54
 
55 55
 
56 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 63
     ${TITLE.H3(_('Detail'), 'fa-align-justify', 'workspace-members')}
58 64
     % if result.workspace.description:
59 65
         <p>${result.workspace.description}</p>

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

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