def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        status = _(u"Changes saved")

        if self.key:
            membership = self.getContent()
            membership.update(data)
        else:
            # Add new roster member
            membership = self.workspace.add_to_team(**data)
            status = _(u"User added")

        try:
            self.validateInvariants(membership)
        except ActionExecutionError:
            # make sure above changes won't be persisted
            transaction.abort()
            raise

        self._finished = True
        IStatusMessage(self.request).addStatusMessage(status, "info")
def TeamGroupsVocabulary(context):
    workspace = find_workspace(context)
    # Membership in the Members group is implied by
    # inclusion in the roster, so we don't need to show
    # it as an explicit option.
    groups = set(workspace.available_groups.keys()) - set([u'Members'])
    items = []
    for group in groups:
        items.append(SimpleTerm(group, group, _(group)))
    return SimpleVocabulary(items)
 def label(self):
     if self.user_id:
         mtool = getToolByName(self.context, 'portal_membership')
         member = mtool.getMemberById(self.user_id)
         if member is not None:
             return member.getProperty('fullname') or self.user_id
         else:
             return self.user_id
     else:
         return _(u'Add Person to Roster')
Example #4
0
def TeamGroupsVocabulary(context):
    workspace = find_workspace(context)
    # Membership in the auto_groups is determined automatically,
    # so we don't need to show them as explicit options.
    groups = set(workspace.available_groups.keys()) - set(
        workspace.auto_groups.keys())
    items = []
    for group in groups:
        items.append(SimpleTerm(group, group, _(group)))
    return SimpleVocabulary(items)
class ITeamMembership(model.Schema):
    """Schema for one person's membership in a team."""

    user = schema.TextLine(title=_(u"User"), )
    form.widget(
        "user",
        AjaxSelectFieldWidget,
        vocabulary="plone.app.vocabularies.Users",
    )

    position = schema.TextLine(
        title=_(u"Position"),
        required=False,
    )

    form.widget(groups=CheckBoxFieldWidget)
    groups = schema.Set(
        title=_(u"Groups"),
        required=False,
        value_type=schema.Choice(vocabulary="collective.workspace.groups", ),
    )
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            return

        status = _(u'Changes saved')

        if self.user_id:
            membership = self.getContent()
            membership.update(data)
        else:
            # Add new roster member
            membership = self.workspace.add_to_team(**data)
            status = _(u'User added')

        try:
            self.validateInvariants(membership)
        except ActionExecutionError:
            # make sure above changes won't be persisted
            transaction.abort()
            raise

        self._finished = True
        IStatusMessage(self.request).addStatusMessage(status, 'info')
 def label(self):
     return _(u'Roster: ${title}', mapping={'title': self.context.Title()})
 def handleRemove(self, action):
     membership = self.getContent()
     membership.remove_from_team()
     self._finished = True
     IStatusMessage(self.request).addStatusMessage(_(u"User removed"), "info")
class TeamMemberEditForm(AutoExtensibleForm, EditForm):
    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.workspace = IWorkspace(self.context)

    key = None

    def publishTraverse(self, request, name):
        self.key = name
        return self

    @lazy_property
    def schema(self):
        return self.workspace.membership_schema

    def updateFields(self):
        super(TeamMemberEditForm, self).updateFields()
        # don't show the user field if we are editing
        if self.key:
            del self.fields["user"]

    @lazy_property
    def ignoreContext(self):
        return not bool(self.key)

    @lazy_property
    def label(self):
        if self.key:
            return self.getContent()._title
        else:
            return _(u"Add Person to Roster")

    @lazy_property
    def _content(self):
        if not self.key:
            return self.context
        workspace = self.workspace
        memberdata = workspace.members[self.key]
        return workspace.membership_factory(workspace, memberdata)

    def getContent(self):
        return self._content

    def validateInvariants(self, membership):
        pass

    @button.buttonAndHandler(_(u"Save"))
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        status = _(u"Changes saved")

        if self.key:
            membership = self.getContent()
            membership.update(data)
        else:
            # Add new roster member
            membership = self.workspace.add_to_team(**data)
            status = _(u"User added")

        try:
            self.validateInvariants(membership)
        except ActionExecutionError:
            # make sure above changes won't be persisted
            transaction.abort()
            raise

        self._finished = True
        IStatusMessage(self.request).addStatusMessage(status, "info")

    @property
    def can_remove(self):
        return self.key

    @button.buttonAndHandler(_(u"Remove"), condition=lambda self: self.can_remove)
    def handleRemove(self, action):
        membership = self.getContent()
        membership.remove_from_team()
        self._finished = True
        IStatusMessage(self.request).addStatusMessage(_(u"User removed"), "info")

    _finished = False

    def render(self):
        if self._finished:
            return " "
        return super(TeamMemberEditForm, self).render()
 def label(self):
     return _(u"Roster: ${title}", mapping={"title": self.context.Title()})
 def handleRemove(self, action):
     membership = self.getContent()
     membership.remove_from_team()
     self._finished = True
     IStatusMessage(self.request).addStatusMessage(_(u"User removed"), "info")
 def label(self):
     if self.key:
         return self.getContent()._title
     else:
         return _(u"Add Person to Roster")