Parcourir la source

Merge pull request #17 from lebouquetin/master

Tracim il y a 10 ans
Parent
révision
4c209403a6

+ 6 - 0
tracim/tracim/controllers/__init__.py Voir le fichier

23
 
23
 
24
 from tracim.lib.content import ContentApi
24
 from tracim.lib.content import ContentApi
25
 from tracim.lib.user import UserStaticApi
25
 from tracim.lib.user import UserStaticApi
26
+from tracim.lib.utils import SameValueError
26
 
27
 
27
 from tracim.model.serializers import Context
28
 from tracim.model.serializers import Context
28
 from tracim.model.serializers import DictLikeClass
29
 from tracim.model.serializers import DictLikeClass
248
             tg.flash(msg, CST.STATUS_OK)
249
             tg.flash(msg, CST.STATUS_OK)
249
             tg.redirect(self._std_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item.content_id))
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
         except ValueError as e:
257
         except ValueError as e:
252
             msg = _('{} not updated - error: {}').format(self._item_type_label, str(e))
258
             msg = _('{} not updated - error: {}').format(self._item_type_label, str(e))
253
             tg.flash(msg, CST.STATUS_ERROR)
259
             tg.flash(msg, CST.STATUS_ERROR)

+ 6 - 0
tracim/tracim/controllers/content.py Voir le fichier

18
 from tracim.lib import CST
18
 from tracim.lib import CST
19
 from tracim.lib.base import BaseController
19
 from tracim.lib.base import BaseController
20
 from tracim.lib.base import logger
20
 from tracim.lib.base import logger
21
+from tracim.lib.utils import SameValueError
21
 from tracim.lib.content import ContentApi
22
 from tracim.lib.content import ContentApi
22
 from tracim.lib.helpers import convert_id_into_instances
23
 from tracim.lib.helpers import convert_id_into_instances
23
 from tracim.lib.predicates import current_user_is_reader
24
 from tracim.lib.predicates import current_user_is_reader
426
             tg.flash(msg, CST.STATUS_OK)
427
             tg.flash(msg, CST.STATUS_OK)
427
             tg.redirect(self._std_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item.content_id))
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
         except ValueError as e:
435
         except ValueError as e:
430
             msg = _('{} not updated - error: {}').format(self._item_type_label, str(e))
436
             msg = _('{} not updated - error: {}').format(self._item_type_label, str(e))
431
             tg.flash(msg, CST.STATUS_ERROR)
437
             tg.flash(msg, CST.STATUS_ERROR)

+ 3 - 0
tracim/tracim/lib/content.py Voir le fichier

15
 from sqlalchemy import or_
15
 from sqlalchemy import or_
16
 from tracim.lib import cmp_to_key
16
 from tracim.lib import cmp_to_key
17
 from tracim.lib.notifications import NotifierFactory
17
 from tracim.lib.notifications import NotifierFactory
18
+from tracim.lib.utils import SameValueError
18
 from tracim.model import DBSession
19
 from tracim.model import DBSession
19
 from tracim.model.auth import User
20
 from tracim.model.auth import User
20
 from tracim.model.data import ActionDescription
21
 from tracim.model.data import ActionDescription
335
 
336
 
336
 
337
 
337
     def update_content(self, item: Content, new_label: str, new_content: str=None) -> Content:
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
         item.owner = self._user
341
         item.owner = self._user
339
         item.label = new_label
342
         item.label = new_label
340
         item.description = new_content if new_content else item.description # TODO: convert urls into links
343
         item.description = new_content if new_content else item.description # TODO: convert urls into links

+ 20 - 14
tracim/tracim/lib/notifications.py Voir le fichier

282
 
282
 
283
         action = content.get_last_action().id
283
         action = content.get_last_action().id
284
         if ActionDescription.COMMENT == action:
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
             content_text = content.description
286
             content_text = content.description
287
             call_to_action_text = _('Answer')
287
             call_to_action_text = _('Answer')
288
 
288
 
332
 
332
 
333
             elif ContentType.Thread == content.type:
333
             elif ContentType.Thread == content.type:
334
                 content_intro = _('<span id="content-intro-username">{}</span> updated the thread description.').format(actor.display_name)
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
             # elif ContentType.Thread == content.type:
343
             # elif ContentType.Thread == content.type:
337
             #     content_intro = _('<span id="content-intro-username">{}</span> updated this page.').format(actor.display_name)
344
             #     content_intro = _('<span id="content-intro-username">{}</span> updated this page.').format(actor.display_name)
359
             )
366
             )
360
             raise ValueError('Unexpected empty notification')
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
         return body_content
382
         return body_content

+ 3 - 0
tracim/tracim/lib/utils.py Voir le fichier

15
         return wrapper_func
15
         return wrapper_func
16
     return decorator_func
16
     return decorator_func
17
 
17
 
18
+
19
+class SameValueError(ValueError):
20
+    pass

+ 2 - 2
tracim/tracim/templates/mail/content_update_body_html.mak Voir le fichier

25
       #content-body del { background-color: #FAA; }
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
       #call-to-action-container { text-align: right; margin-top: 2em; }
29
       #call-to-action-container { text-align: right; margin-top: 2em; }
30
 
30
 
31
       #footer hr { border: 0px solid #CCC; border-top-width: 1px; width: 8em; max-width:25%; margin-left: 0;}
31
       #footer hr { border: 0px solid #CCC; border-top-width: 1px; width: 8em; max-width:25%; margin-left: 0;}
38
     <table style="width: 100%; cell-padding: 0; border-collapse: collapse; margin: 0">
38
     <table style="width: 100%; cell-padding: 0; border-collapse: collapse; margin: 0">
39
       <tr style="background-color: F5F5F5; border-bottom: 1px solid #CCC;" >
39
       <tr style="background-color: F5F5F5; border-bottom: 1px solid #CCC;" >
40
         <td style="background-color: #666;">
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
         </td>
42
         </td>
43
         <td style="padding: 0.5em; background-color: #666; text-align: left;">
43
         <td style="padding: 0.5em; background-color: #666; text-align: left;">
44
           <span style="font-size: 1.3em; color: #FFF; font-weight: bold;">
44
           <span style="font-size: 1.3em; color: #FFF; font-weight: bold;">