class ITaskContent(model.Schema): """ Interface for task content type """ title = schema.TextLine(title=_PMF(u'label_title', default=u'Title'), required=True) parents_assigned_groups = LocalRolesField( title=_(u"Parents assigned groups"), required=False, value_type=schema.Choice(vocabulary=u'collective.task.AssignedGroups')) # must change widget to hide it, because default widget (orderedselect) doesn't have hidden widget template directives.widget('parents_assigned_groups', SelectFieldWidget, multiple='multiple', size=10) directives.mode(parents_assigned_groups='hidden') parents_enquirers = LocalRolesField( title=_(u"Parents enquirers"), required=False, value_type=schema.Choice(vocabulary=u'collective.task.Enquirer')) # must change widget to hide it, because default widget (orderedselect) doesn't have hidden widget template directives.widget('parents_enquirers', SelectFieldWidget, multiple='multiple', size=10) directives.mode(parents_enquirers='hidden')
class IParentsFieldSchema(Interface): fieldname = schema.TextLine(title=_("Parents field name"), required=True) attribute = schema.TextLine(title=_("Parent attribute"), required=True) attribute_prefix = schema.TextLine( title=_("Attribute prefix (without dot)"), required=False) provided_interface = schema.TextLine(title=_("Parent interface"), required=True)
def updateWidgets(self): super(TaskItemView, self).updateWidgets() if not self.context.assigned_user \ and api.content.get_state(obj=self.context) == 'to_assign': self.widgets['ITask.assigned_user'].field = copy.copy(self.widgets['ITask.assigned_user'].field) self.widgets['ITask.assigned_user'].field.description = \ _(u'You must select an assigned user before continuing !')
def updateWidgets(self): super(TaskItemView, self).updateWidgets() if not self.context.assigned_user \ and api.content.get_state(obj=self.context) == 'to_assign': self.widgets['ITask.assigned_user'].field = copy.copy( self.widgets['ITask.assigned_user'].field) self.widgets['ITask.assigned_user'].field.description = \ _(u'You must select an assigned user before continuing !')
class TasksListViewlet(base.ViewletBase): """Tasks list for current task container object.""" label = _(u"Tasks list") noresult_message = _(u"There is no task for this content.") __table__ = TasksTable def update(self): self.table = self.__table__(self.context, self.request) self.table.viewlet = self catalog = api.portal.get_tool('portal_catalog') container_path = '/'.join(self.context.getPhysicalPath()) brains = catalog.searchResults( object_provides=ITask.__identifier__, path={'query': container_path, 'depth': 1}) self.table.results = [b.getObject() for b in brains] self.table.update()
def _update(self): self.do_apply = is_permitted(self.brains) self.fields += Fields(schema.Choice( __name__='assigned_group', title=_(u"Assigned group"), description=(not self.do_apply and cannot_modify_field_msg or u''), required=(self.do_apply), vocabulary=self.do_apply and u'collective.task.AssignedGroups' or SimpleVocabulary([]), ))
def _update(self): self.voc = self.get_available_assigneduser_voc() self.do_apply = is_permitted(self.brains) self.fields += Fields(schema.Choice( __name__='assigned_user', title=_(u'Assigned user'), vocabulary=self.do_apply and self.voc or SimpleVocabulary([]), description=((len(self.voc) <= 1 and self.err_msg) or (not self.do_apply and cannot_modify_field_msg) or u''), required=self.do_apply))
class AssignedGroupColumn(Column): """Column that displays assigned group.""" header = _("Assigned group") weight = 30 def renderCell(self, value): if value.assigned_group: group = api.group.get(value.assigned_group).getGroup() return group.getProperty('title').decode('utf-8') return ""
def _update(self): self.do_apply = is_permitted(self.brains) self.fields += Fields( schema.Choice( __name__='assigned_group', title=_(u"Assigned group"), description=(not self.do_apply and cannot_modify_field_msg or u''), required=(self.do_apply), vocabulary=self.do_apply and u'collective.task.AssignedGroups' or SimpleVocabulary([]), ))
def _update(self): self.voc = self.get_available_assigneduser_voc() self.do_apply = is_permitted(self.brains) self.fields += Fields( schema.Choice( __name__='assigned_user', title=_(u'Assigned user'), vocabulary=self.do_apply and self.voc or SimpleVocabulary([]), description=((len(self.voc) <= 1 and self.err_msg) or (not self.do_apply and cannot_modify_field_msg) or u''), required=self.do_apply))
class ITask(model.Schema): """ITask behavior.""" task_description = RichText( title=_(u"Task description"), required=False, description=_(u"What is to do and/or what is done"), ) assigned_group = LocalRoleMasterSelectField( title=_(u"Assigned group"), required=False, vocabulary="collective.task.AssignedGroups", slave_fields=({ 'name': 'ITask.assigned_user', 'slaveID': '#form-widgets-ITask-assigned_user', 'action': 'vocabulary', 'vocab_method': get_users_vocabulary, 'control_param': 'group', 'initial_trigger': True }, ), defaultFactory=get_parent_assigned_group) assigned_user = LocalRoleField(title=_(u"Assigned user"), required=False, vocabulary="plone.principalsource.Users") due_date = schema.Date( title=_(u"Due date"), required=False, ) enquirer = LocalRoleField(title=_(u"Enquirer"), required=False, vocabulary="collective.task.Enquirer")
class ITaskWithFieldset(ITask): """ITask behavior with fieldset.""" fieldset('task', label=_(u'Task'), fields=( 'assigned_group', 'assigned_user', 'enquirer', 'due_date', )) assigned_group = LocalRoleMasterSelectField( title=_(u"Assigned group"), required=False, vocabulary="plone.principalsource.Groups", slave_fields=({ 'name': 'ITaskWithFieldset.assigned_user', 'slaveID': '#form-widgets-ITaskWithFieldset-assigned_user', 'action': 'vocabulary', 'vocab_method': get_users_vocabulary, 'control_param': 'group', 'initial_trigger': True }, ))
class DueDateColumn(Column): """Column that displays due date.""" header = _("Due date") weight = 50 long_format = False time_only = False def renderCell(self, value): if value.due_date: return api.portal.get_localized_time(datetime=value.due_date, long_format=self.long_format, time_only=self.time_only) return ""
def validate(self, value): # we go out if assigned user is empty if value is None: return # check if we are editing a task if isinstance(self.view, DefaultEditForm) and self.context.portal_type == 'task': # check if assigned_group is changed and assigned_user is no more in if (self.context.assigned_group is not None and self.context.assigned_user is not None and self.request.form['form.widgets.ITask.assigned_group'] and self.request.form['form.widgets.ITask.assigned_group'][0] != self.context.assigned_group): try: users = api.user.get_users(groupname=self.request.form['form.widgets.ITask.assigned_group'][0]) except api.exc.GroupNotFoundError: return if value not in [mb.getUserName() for mb in users]: raise Invalid(_(u"The assigned user is not in the selected assigned group !"))
def validate(self, value): # we go out if assigned user is empty if value is None: return # check if we are editing a task if isinstance(self.view, DefaultEditForm) and self.context.portal_type == 'task': # check if assigned_group is changed and assigned_user is no more in if (self.context.assigned_group is not None and self.context.assigned_user is not None and self.request.form['form.widgets.ITask.assigned_group'] and self.request.form['form.widgets.ITask.assigned_group'][0] != self.context.assigned_group): try: users = api.user.get_users( groupname=self.request. form['form.widgets.ITask.assigned_group'][0]) except api.exc.GroupNotFoundError: return if value not in [mb.getUserName() for mb in users]: raise Invalid( _(u"The assigned user is not in the selected assigned group !" ))
class ICollectiveTaskConfig(model.Schema): parents_fields = schema.List(title=_(u'Parents fields'), value_type=DictRow( title=_("Parents field"), schema=IParentsFieldSchema))
class EnquirerColumn(UserColumn): """Column that displays enquirer.""" header = _("Enquirer") weight = 20 field = 'enquirer'
class AssignedUserColumn(UserColumn): """Column that displays assigned user.""" header = _("Assigned user") weight = 40 field = 'assigned_user'