Browse Source

Enhance code lisibility for Button 'mark everything as read'

Alexis CLEMENT 8 years ago
parent
commit
7bd3b5aae5

+ 3 - 6
tracim/tracim/controllers/read.py View File

@@ -6,7 +6,7 @@ from tracim.lib.content import ContentApi
6 6
 from tracim.model.data import ContentType
7 7
 
8 8
 
9
-class ReadController(StandardController):
9
+class ContentController(StandardController):
10 10
 
11 11
     @classmethod
12 12
     def current_item_id_key_in_context(cls) -> str:
@@ -18,13 +18,10 @@ class ReadController(StandardController):
18 18
 
19 19
     @require(predicates.not_anonymous())
20 20
     @tg.expose()
21
-    def all(self):
22
-        print("read all")
21
+    def mark_all_read(self):
23 22
         user = tg.tmpl_context.current_user
24 23
         content_api = ContentApi(user)
25
-        itemset = content_api.get_last_unread(None, ContentType.Any, None)
26
-        for item in itemset:
27
-            content_api.mark_read(item)
24
+        content_api.mark_read__all()
28 25
 
29 26
         tg.redirect("/home")
30 27
 

+ 2 - 2
tracim/tracim/controllers/root.py View File

@@ -12,7 +12,7 @@ from tg import url
12 12
 
13 13
 from tg.i18n import ugettext as _
14 14
 from tracim.controllers.api import APIController
15
-from tracim.controllers.tools import ToolsController
15
+from tracim.controllers.read import ContentController
16 16
 
17 17
 from tracim.lib import CST
18 18
 from tracim.lib.base import logger
@@ -63,7 +63,7 @@ class RootController(StandardController):
63 63
     workspaces = UserWorkspaceRestController()
64 64
     user = UserRestController()
65 65
 
66
-    tools = ToolsController()
66
+    content = ContentController()
67 67
 
68 68
     # api
69 69
     api = APIController()

+ 11 - 0
tracim/tracim/lib/content.py View File

@@ -872,6 +872,17 @@ class ContentApi(object):
872 872
         content.is_deleted = False
873 873
         content.revision_type = ActionDescription.UNDELETION
874 874
 
875
+    def mark_read__all(self,
876
+                  read_datetime: datetime=None,
877
+                  do_flush: bool=True, recursive: bool=True):
878
+
879
+        if not read_datetime:
880
+            read_datetime = datetime.datetime.now()
881
+
882
+        itemset = self.get_last_unread(None, ContentType.Any, None)
883
+        for item in itemset:
884
+            self.mark_read(item, read_datetime, do_flush, recursive)
885
+
875 886
     def mark_read(self, content: Content,
876 887
                   read_datetime: datetime=None,
877 888
                   do_flush: bool=True, recursive: bool=True) -> Content:

+ 1 - 1
tracim/tracim/templates/home.mak View File

@@ -96,7 +96,7 @@
96 96
                 % if fake_api.last_unread.nb <= 0:
97 97
                     ${P.EMPTY_CONTENT(_('No new content.'))}
98 98
                 % else:
99
-                    <a href="/tools/read/all" class="btn btn-default"> Mark everything as read </a>
99
+                    <a href="${tg.url('/content/mark_all_read')}" class="btn btn-default"> ${_('Mark everything as read')} </a>
100 100
                     <table class="table table-hover">
101 101
                         % for item in fake_api.last_unread.contents:
102 102
                             <tr>