Просмотр исходного кода

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

Damien ACCORSI 10 лет назад
Родитель
Сommit
61469c92bd

+ 6 - 0
tracim/tracim/controllers/__init__.py Просмотреть файл

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 Просмотреть файл

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 Просмотреть файл

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

+ 3 - 0
tracim/tracim/lib/utils.py Просмотреть файл

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