Compare commits
5 Commits
master
...
wip/multi-
Author | SHA1 | Date |
---|---|---|
Frédéric Péters | d89c17f62f | |
Frédéric Péters | bb36a04855 | |
Frédéric Péters | 3912aee4be | |
Frédéric Péters | 4cb740b2eb | |
Frédéric Péters | 102ee9e564 |
|
@ -0,0 +1,66 @@
|
|||
from copy import deepcopy
|
||||
import z3c.form
|
||||
from z3c.form import button
|
||||
|
||||
import zope.event
|
||||
from zope.i18nmessageid.message import MessageFactory
|
||||
|
||||
from plone import api
|
||||
from plone.dexterity.browser.add import DefaultAddForm
|
||||
from plone.dexterity.utils import createContentInContainer
|
||||
from plone.stringinterp.adapters import _recursiveGetMembersFromIds
|
||||
|
||||
from collective.task import _
|
||||
|
||||
|
||||
class AddInformation(DefaultAddForm):
|
||||
"""Custom add information view"""
|
||||
|
||||
portal_type = "information"
|
||||
|
||||
@property
|
||||
def action(self):
|
||||
return self.request.getURL() + '?documents=' + self.request.documents
|
||||
|
||||
@button.buttonAndHandler(_('Add'), name='add')
|
||||
def handleAdd(self, action):
|
||||
data, errors = self.extractData()
|
||||
if errors:
|
||||
self.status = self.formErrorsMessage
|
||||
return
|
||||
|
||||
for document_id in self.request.documents.split(','):
|
||||
base_document = api.content.get(str(document_id))
|
||||
self.add_info(base_document, data)
|
||||
|
||||
self._finishedAdd = True
|
||||
return
|
||||
|
||||
def add_info(self, base_document, data):
|
||||
portal = api.portal.get()
|
||||
objs = []
|
||||
seen = {}
|
||||
for responsible in data['responsible']:
|
||||
group = api.group.get(responsible)
|
||||
if group is not None:
|
||||
# responsible is a group, create an Information by user in this group
|
||||
groupname = group.getId()
|
||||
users = _recursiveGetMembersFromIds(portal, [groupname])
|
||||
for user in users:
|
||||
username = user.getId()
|
||||
if username in seen:
|
||||
continue
|
||||
_data = deepcopy(data)
|
||||
_data['responsible'] = [username]
|
||||
createContentInContainer(base_document, 'information', **_data)
|
||||
seen[username] = True
|
||||
else:
|
||||
# responsible is a user
|
||||
if responsible in seen:
|
||||
continue
|
||||
_data = deepcopy(data)
|
||||
_data['responsible'] = [responsible]
|
||||
createContentInContainer(base_document, 'information', **_data)
|
||||
seen[responsible] = True
|
||||
|
||||
print 'seen:', seen
|
|
@ -57,6 +57,20 @@
|
|||
permission="zope2.View"
|
||||
/>
|
||||
|
||||
<browser:page
|
||||
name="add_multi_information"
|
||||
for="*"
|
||||
class=".add_multi_information.AddInformation"
|
||||
permission="cmf.AddPortalContent"
|
||||
/>
|
||||
|
||||
<browser:page
|
||||
name="multi_attribute_task"
|
||||
for="*"
|
||||
class=".multi_attribute_task.AttributeTasks"
|
||||
permission="cmf.AddPortalContent"
|
||||
/>
|
||||
|
||||
<!-- Custom comments viewlet for IBaseTask -->
|
||||
<browser:viewlet
|
||||
name="plone.comments"
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from copy import deepcopy
|
||||
import z3c.form
|
||||
from z3c.form import button
|
||||
|
||||
import zope.event
|
||||
from zope.i18nmessageid.message import MessageFactory
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
|
||||
from plone import api
|
||||
from plone.dexterity.browser.add import DefaultAddForm
|
||||
from plone.dexterity.utils import createContentInContainer
|
||||
from plone.stringinterp.adapters import _recursiveGetMembersFromIds
|
||||
|
||||
from collective.task import _
|
||||
from collective.task.browser.attribute_task import find_nontask
|
||||
|
||||
|
||||
class AttributeTasks(DefaultAddForm):
|
||||
"Attribute multiple tasks"
|
||||
|
||||
portal_type = "task"
|
||||
|
||||
@property
|
||||
def label(self):
|
||||
return u"Attribuer les tâches"
|
||||
|
||||
@property
|
||||
def action(self):
|
||||
return self.request.getURL() + '?documents=' + self.request.documents
|
||||
|
||||
def updateWidgets(self):
|
||||
"""Update widgets then add workflow_action value to workflow_action field"""
|
||||
super(AttributeTasks, self).updateWidgets()
|
||||
for task_id in self.request.documents.split(','):
|
||||
base_task = api.content.get(str(task_id))
|
||||
self.widgets['title'].value = base_task.title
|
||||
break
|
||||
|
||||
@button.buttonAndHandler(_('Add'), name='add')
|
||||
def handleAdd(self, action):
|
||||
data, errors = self.extractData()
|
||||
if errors:
|
||||
self.status = self.formErrorsMessage
|
||||
return
|
||||
|
||||
for task_id in self.request.documents.split(','):
|
||||
base_task = api.content.get(str(task_id))
|
||||
self.attribute_task(base_task, data)
|
||||
|
||||
self._finishedAdd = True
|
||||
return
|
||||
|
||||
def attribute_task(self, base_task, data):
|
||||
seen = {}
|
||||
nontask = find_nontask(base_task)
|
||||
portal_workflow = getToolByName(nontask, 'portal_workflow')
|
||||
transitions = portal_workflow.getTransitionsFor(nontask)
|
||||
transition_ids = [t['id'] for t in transitions]
|
||||
|
||||
for responsible in data['responsible']:
|
||||
if responsible in seen:
|
||||
continue
|
||||
_data = deepcopy(data)
|
||||
_data['responsible'] = [responsible]
|
||||
new_task = createContentInContainer(base_task, 'task', **_data)
|
||||
seen[responsible] = True
|
||||
|
||||
for responsible in data['responsible']:
|
||||
nontask.manage_addLocalRoles(responsible, ['Editor',])
|
||||
nontask.reindexObjectSecurity()
|
||||
if 'attribute' in transition_ids:
|
||||
portal_workflow.doActionFor(nontask, 'attribute')
|
|
@ -80,14 +80,20 @@ class DocumentTitleColumn(column.TitleColumn):
|
|||
grok.adapts(Interface, Interface, TasksTable)
|
||||
|
||||
def getLinkContent(self, item):
|
||||
if item.document_title is Missing.Value:
|
||||
try:
|
||||
if item.document_title is Missing.Value:
|
||||
return super(DocumentTitleColumn, self).getLinkContent(item)
|
||||
except AttributeError:
|
||||
return super(DocumentTitleColumn, self).getLinkContent(item)
|
||||
|
||||
return item.document_title.decode('utf8') + ' / ' + \
|
||||
column.get_value(item, 'Title').decode('utf8')
|
||||
|
||||
def getLinkURL(self, item):
|
||||
if item.document_title is Missing.Value:
|
||||
try:
|
||||
if item.document_title is Missing.Value:
|
||||
return super(DocumentTitleColumn, self).getLinkURL(item)
|
||||
except AttributeError:
|
||||
return super(DocumentTitleColumn, self).getLinkURL(item)
|
||||
|
||||
return self.request.physicalPathToURL(item.document_path)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
</div>
|
||||
|
||||
<script>
|
||||
$.querywidget.updateSearch = function () {
|
||||
$.querywidget.updateSearch = function (stay_on_page) {
|
||||
var context_url = (function() {
|
||||
var baseUrl, pieces;
|
||||
baseUrl = $('base').attr('href');
|
||||
|
@ -51,6 +51,9 @@ $.querywidget.updateSearch = function () {
|
|||
if ($('#sort_order:checked').length > 0) {
|
||||
query += '&sort_order=reverse';
|
||||
}
|
||||
/*if (stay_on_page && $('a.batch-link.current').length) {
|
||||
query += '&' + $('a.batch-link.current').data('query');
|
||||
}*/
|
||||
$.querywidget.runQuery(query);
|
||||
};
|
||||
|
||||
|
|
|
@ -114,9 +114,10 @@ def incoming_mail_attributed(context, comment):
|
|||
treating_groups = list(frozenset(list(context.treating_groups or []) + list(context.treated_by or [])))
|
||||
treating_dm = LocalRolesToPrincipalsDataManager(context, IDmsIncomingMail['treating_groups'])
|
||||
treating_dm.set(treating_groups)
|
||||
recipient_groups = list(frozenset(list(context.recipient_groups or []) + list(context.in_copy or [])))
|
||||
recipient_dm = LocalRolesToPrincipalsDataManager(context, IDmsIncomingMail['recipient_groups'])
|
||||
recipient_dm.set(recipient_groups)
|
||||
if hasattr(context, 'in_copy'):
|
||||
recipient_groups = list(frozenset(list(context.recipient_groups or []) + list(context.in_copy or [])))
|
||||
recipient_dm = LocalRolesToPrincipalsDataManager(context, IDmsIncomingMail['recipient_groups'])
|
||||
recipient_dm.set(recipient_groups)
|
||||
context.reindexObjectSecurity()
|
||||
|
||||
already_in_charge = []
|
||||
|
|
Reference in New Issue