diff --git a/news/SUP-41619.feature b/news/SUP-41619.feature new file mode 100644 index 000000000..3eccacff5 --- /dev/null +++ b/news/SUP-41619.feature @@ -0,0 +1,2 @@ +Add utility view to fix task_config_UID on task +[jchandelle] \ No newline at end of file diff --git a/src/Products/urban/browser/configure.zcml b/src/Products/urban/browser/configure.zcml index b8fea785d..dbcbc22f2 100644 --- a/src/Products/urban/browser/configure.zcml +++ b/src/Products/urban/browser/configure.zcml @@ -10,6 +10,7 @@ + + + + + diff --git a/src/Products/urban/browser/view_utils/fix_task_uid_error.py b/src/Products/urban/browser/view_utils/fix_task_uid_error.py new file mode 100644 index 000000000..488d593c6 --- /dev/null +++ b/src/Products/urban/browser/view_utils/fix_task_uid_error.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +from Products.Five import BrowserView +from eea.facetednavigation.widgets import ViewPageTemplateFile +from imio.schedule.interfaces import TaskConfigNotFound +from imio.schedule.utils import get_container_tasks +from plone import api + +import logging +import transaction + + +logger = logging.getLogger("Fix task uid error") + + +def check_if_task_error(task): + try: + task.get_task_config() + except TaskConfigNotFound: + return True + return False + + +class FixTaskUidError(BrowserView): + """View used to fix wrong config uid attach to task.""" + + template = ViewPageTemplateFile("templates/fix_task_uid_error.pt") + + def __call__(self): + if not self.request.form.get("form.submitted", False): + return self.template() + + self.fix_task() + return self.template() + + def get_tasks(self): + tasks = get_container_tasks(self.context) + task_in_error = [task for task in tasks if check_if_task_error(task)] + return task_in_error + + def fix_task(self): + form = self.request.form + del form["form.submitted"] + del form["submit"] + for task, new_uid in form.items(): + task_uid = task.split("-")[0] + task_to_fix = api.content.get(UID=task_uid) + task_to_fix.task_config_UID = new_uid + transaction.commit() diff --git a/src/Products/urban/browser/view_utils/templates/fix_task_uid_error.pt b/src/Products/urban/browser/view_utils/templates/fix_task_uid_error.pt new file mode 100644 index 000000000..0c277ad68 --- /dev/null +++ b/src/Products/urban/browser/view_utils/templates/fix_task_uid_error.pt @@ -0,0 +1,44 @@ + + +
+ + + +

+ Fix task uid error +

+
+
    + +
  • + + +
    + +
    + +
    +
    +
  • +
+ +
+ + + + +
+ +
+ +
+ + \ No newline at end of file