Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUP-41619 Add view to fix task_config_UID on task #311

Open
wants to merge 2 commits into
base: urban2.7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/SUP-41619.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add utility view to fix task_config_UID on task
[jchandelle]
1 change: 1 addition & 0 deletions src/Products/urban/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<include package=".table" />
<include package=".warnings" />
<include package=".exportimport" />
<include package=".view_utils" />
<include file="portlets.zcml" />

<browser:resourceDirectory
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions src/Products/urban/browser/view_utils/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="urban">

<browser:page
for="Products.urban.interfaces.IGenericLicence"
name="fix-task-uid-error"
class=".fix_task_uid_error.FixTaskUidError"
permission="cmf.ManagePortal"
/>

</configure>
49 changes: 49 additions & 0 deletions src/Products/urban/browser/view_utils/fix_task_uid_error.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:tal="http://xml.zope.org/namespaces/tal">

<div>



<h1 class="documentFirstHeading" >
Fix task uid error
</h1>
<form action="@@fix-task-uid-error" method="post">
<ul>

<li tal:repeat="task view/get_tasks">
<label tal:attributes="for python:'{}-new_uid'.format(task.UID())" ><span tal:content="task/title">Title</span>
(<span tal:content="python:'/'.join(task.getPhysicalPath())">id</span>)
Current task_config_UID: <span tal:content="task/task_config_UID">current UID</span></label>

<div class="field">
<label tal:attributes="for python:'{}-new_uid'.format(task.UID())">New task_config_UID</label>
<div class="widget">
<input type="text" value=""
tal:attributes="id python:'{}-new_uid'.format(task.UID());
name python:'{}-new_uid'.format(task.UID());">
</div>
</div>
</li>
</ul>

<div class="formControls" class="form-group">
<input type="hidden" name="form.submitted" value="1"/>

<button class="btn btn-primary submit-widget button-field context"
type="submit" name="submit" value="fix">Fix Task
</button>

</div>

</form>

</div>

</html>