Explorar el Código

Merge pull request #17 from lebouquetin/master

Tracim hace 10 años
padre
commit
4c209403a6

+ 6 - 0
tracim/tracim/controllers/__init__.py Ver fichero

@@ -23,6 +23,7 @@ from tracim.model.data import Workspace
23 23
 
24 24
 from tracim.lib.content import ContentApi
25 25
 from tracim.lib.user import UserStaticApi
26
+from tracim.lib.utils import SameValueError
26 27
 
27 28
 from tracim.model.serializers import Context
28 29
 from tracim.model.serializers import DictLikeClass
@@ -248,6 +249,11 @@ class TIMWorkspaceContentRestController(TIMRestControllerWithBreadcrumb):
248 249
             tg.flash(msg, CST.STATUS_OK)
249 250
             tg.redirect(self._std_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item.content_id))
250 251
 
252
+        except SameValueError as e:
253
+            msg = _('{} not updated: the content did not change').format(self._item_type_label)
254
+            tg.flash(msg, CST.STATUS_WARNING)
255
+            tg.redirect(self._err_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item_id))
256
+
251 257
         except ValueError as e:
252 258
             msg = _('{} not updated - error: {}').format(self._item_type_label, str(e))
253 259
             tg.flash(msg, CST.STATUS_ERROR)

+ 6 - 0
tracim/tracim/controllers/content.py Ver fichero

@@ -18,6 +18,7 @@ from tracim.controllers import TIMWorkspaceContentRestController
18 18
 from tracim.lib import CST
19 19
 from tracim.lib.base import BaseController
20 20
 from tracim.lib.base import logger
21
+from tracim.lib.utils import SameValueError
21 22
 from tracim.lib.content import ContentApi
22 23
 from tracim.lib.helpers import convert_id_into_instances
23 24
 from tracim.lib.predicates import current_user_is_reader
@@ -426,6 +427,11 @@ class UserWorkspaceFolderPageRestController(TIMWorkspaceContentRestController):
426 427
             tg.flash(msg, CST.STATUS_OK)
427 428
             tg.redirect(self._std_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item.content_id))
428 429
 
430
+        except SameValueError as e:
431
+            msg = _('{} not updated: the content did not change').format(self._item_type_label)
432
+            tg.flash(msg, CST.STATUS_WARNING)
433
+            tg.redirect(self._err_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item_id))
434
+
429 435
         except ValueError as e:
430 436
             msg = _('{} not updated - error: {}').format(self._item_type_label, str(e))
431 437
             tg.flash(msg, CST.STATUS_ERROR)

+ 3 - 0
tracim/tracim/lib/content.py Ver fichero

@@ -15,6 +15,7 @@ from sqlalchemy import not_
15 15
 from sqlalchemy import or_
16 16
 from tracim.lib import cmp_to_key
17 17
 from tracim.lib.notifications import NotifierFactory
18
+from tracim.lib.utils import SameValueError
18 19
 from tracim.model import DBSession
19 20
 from tracim.model.auth import User
20 21
 from tracim.model.data import ActionDescription
@@ -335,6 +336,8 @@ class ContentApi(object):
335 336
 
336 337
 
337 338
     def update_content(self, item: Content, new_label: str, new_content: str=None) -> Content:
339
+        if item.label==new_label and item.description==new_content:
340
+            raise SameValueError(_('The content did not changed'))
338 341
         item.owner = self._user
339 342
         item.label = new_label
340 343
         item.description = new_content if new_content else item.description # TODO: convert urls into links

+ 20 - 14
tracim/tracim/lib/notifications.py Ver fichero

@@ -282,7 +282,7 @@ class EmailNotifier(object):
282 282
 
283 283
         action = content.get_last_action().id
284 284
         if ActionDescription.COMMENT == action:
285
-            content_intro = _('<span id="content-intro-username">{}</span> added a comment:'.format(actor.display_name))
285
+            content_intro = _('<span id="content-intro-username">{}</span> added a comment:').format(actor.display_name)
286 286
             content_text = content.description
287 287
             call_to_action_text = _('Answer')
288 288
 
@@ -332,6 +332,13 @@ class EmailNotifier(object):
332 332
 
333 333
             elif ContentType.Thread == content.type:
334 334
                 content_intro = _('<span id="content-intro-username">{}</span> updated the thread description.').format(actor.display_name)
335
+                previous_revision = content.get_previous_revision()
336
+                title_diff = ''
337
+                if previous_revision.label != content.label:
338
+                    title_diff = htmldiff(previous_revision.label, content.label)
339
+                content_text = _('<p id="content-body-intro">Here is an overview of the changes:</p>')+ \
340
+                    title_diff + \
341
+                    htmldiff(previous_revision.description, content.description)
335 342
 
336 343
             # elif ContentType.Thread == content.type:
337 344
             #     content_intro = _('<span id="content-intro-username">{}</span> updated this page.').format(actor.display_name)
@@ -359,18 +366,17 @@ class EmailNotifier(object):
359 366
             )
360 367
             raise ValueError('Unexpected empty notification')
361 368
 
362
-        # Thread - create
363
-        # logger.debug(self, 'This is a NOT comment <--------------------- {}'.format(content.type))
364
-        body_content = template.render(base_url=self._global_config.WEBSITE_BASE_URL,
365
-                               _=_,
366
-                               h=helpers,
367
-                               user_display_name=role.user.display_name,
368
-                               user_role_label=role.role_as_label(),
369
-                               workspace_label=role.workspace.label,
370
-                               content_intro=content_intro,
371
-                               content_text=content_text,
372
-                               main_title=main_title,
373
-                               call_to_action_text=call_to_action_text,
374
-                               result = DictLikeClass(item=dictified_item, actor=dictified_actor))
369
+        body_content = template.render(
370
+            base_url=self._global_config.WEBSITE_BASE_URL,
371
+            _=_,
372
+            h=helpers,
373
+            user_display_name=role.user.display_name,
374
+            user_role_label=role.role_as_label(),
375
+            workspace_label=role.workspace.label,
376
+            content_intro=content_intro,
377
+            content_text=content_text,
378
+            main_title=main_title,
379
+            call_to_action_text=call_to_action_text,
380
+            result = DictLikeClass(item=dictified_item, actor=dictified_actor))
375 381
 
376 382
         return body_content

+ 3 - 0
tracim/tracim/lib/utils.py Ver fichero

@@ -15,3 +15,6 @@ def exec_time_monitor():
15 15
         return wrapper_func
16 16
     return decorator_func
17 17
 
18
+
19
+class SameValueError(ValueError):
20
+    pass

+ 2 - 2
tracim/tracim/templates/mail/content_update_body_html.mak Ver fichero

@@ -25,7 +25,7 @@
25 25
       #content-body del { background-color: #FAA; }
26 26
 
27 27
 
28
-      #call-to-action-button { background-color: #5CB85C; border: 1px solid #4CAE4C; color: #FFF; text-decoration: none; font-weight: bold; padding: 4px; border-radius: 3px; font-size: 2em; padding-right: 0.5em;}
28
+      #call-to-action-button { background-color: #5CB85C; border: 1px solid #4CAE4C; color: #FFF; text-decoration: none; font-weight: bold; border-radius: 3px; font-size: 2em; padding: 4px 0.3em;}
29 29
       #call-to-action-container { text-align: right; margin-top: 2em; }
30 30
 
31 31
       #footer hr { border: 0px solid #CCC; border-top-width: 1px; width: 8em; max-width:25%; margin-left: 0;}
@@ -38,7 +38,7 @@
38 38
     <table style="width: 100%; cell-padding: 0; border-collapse: collapse; margin: 0">
39 39
       <tr style="background-color: F5F5F5; border-bottom: 1px solid #CCC;" >
40 40
         <td style="background-color: #666;">
41
-          <img src="http://team.trac.im/assets/img/logo.png" style="vertical-align: middle;"/>
41
+          <img src="${base_url+'/assets/img/logo.png'}" style="vertical-align: middle;" alt=""/>
42 42
         </td>
43 43
         <td style="padding: 0.5em; background-color: #666; text-align: left;">
44 44
           <span style="font-size: 1.3em; color: #FFF; font-weight: bold;">