Bläddra i källkod

bugfix: do not save thread description update when both label and description keep the same

Damien ACCORSI 10 år sedan
förälder
incheckning
61469c92bd

+ 6 - 0
tracim/tracim/controllers/__init__.py Visa fil

@@ -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 Visa fil

@@ -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 Visa fil

@@ -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

+ 3 - 0
tracim/tracim/lib/utils.py Visa fil

@@ -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