Exemple #1
0
    def getTerm(self, value, brain=None):
        # Contacts
        if ActorLookup(value).is_contact() and brain is None:
            catalog = api.portal.get_tool('portal_catalog')
            brain = catalog.unrestrictedSearchResults(
                portal_type=CONTACT_TYPE,
                contactid=value)[0]

        if brain and ActorLookup(value).is_contact():
            actor = Actor.contact(brain.contactid, contact=brain)
            token = value
            title = actor.get_label()
            return SimpleTerm(value, token, title)

        # Inboxes
        if ActorLookup(value).is_inbox():
            orgunit_id = value.split(':', 1)[1]
            orgunit = OrgUnit.query.filter(OrgUnit.unit_id == orgunit_id).one()

            value = token = orgunit.inbox().id()
            title = translate(_(u'inbox_label',
                                default=u'Inbox: ${client}',
                                mapping=dict(client=orgunit.label())),
                              context=getRequest())

            return SimpleTerm(value, token, title)

        user = self.base_query.filter(User.userid == value).one()

        token = value
        title = u'{} ({})'.format(user.fullname(),
                                  user.userid)
        return SimpleTerm(value, token, title)
Exemple #2
0
    def get_label(self, with_principal=None):
        # we need to instantly translate, because otherwise
        # stuff like the autocomplete widget will not work
        # properly.
        label = _(u'inbox_label',
                  default=u'Inbox: ${client}',
                  mapping=dict(client=self.org_unit.label()))

        return translate(label, context=getRequest())
Exemple #3
0
    def get_label(self, with_principal=None):
        # we need to instantly translate, because otherwise
        # stuff like the autocomplete widget will not work
        # properly.
        label = _(u'inbox_label',
                  default=u'Inbox: ${client}',
                  mapping=dict(client=self.org_unit.label()))

        return translate(label, context=getRequest())
class ITeam(model.Schema):

    title = schema.TextLine(title=_(u"label_title", default=u"Title"),
                            required=True,
                            max_length=UNIT_TITLE_LENGTH)

    active = schema.Bool(title=_(u"label_active", default=u"Active"),
                         required=True,
                         default=True)

    form.widget('groupid', KeywordFieldWidget, async=True)
    groupid = schema.Choice(title=_('label_group', default=u'Group'),
                            source=AllGroupsSourceBinder(),
                            required=True)

    form.widget('org_unit_id', KeywordFieldWidget, async=True)
    org_unit_id = schema.Choice(title=_('label_org_unit', default=u'Org Unit'),
                                source=AllOrgUnitsSourceBinder(),
                                required=True)
Exemple #5
0
    def getTerm(self, value):

        data = value.split(':', 1)
        if len(data) == 2:
            orgunit_id, userid = data
        else:
            userid = value
            orgunit_id = self.client_id

        # Handle special case - Inboxes: in form "inbox:unit_id"
        if ActorLookup(value).is_inbox():
            orgunit_id = userid
            query = OrgUnit.query

            if self.only_current_inbox:
                orgunit = query.filter(OrgUnit.unit_id == self.client_id) \
                               .filter(OrgUnit.unit_id == orgunit_id) \
                               .one()
            else:
                orgunit = query.filter(OrgUnit.unit_id == orgunit_id) \
                               .one()

            value = token = orgunit.inbox().id()
            title = translate(_(u'inbox_label',
                                default=u'Inbox: ${client}',
                                mapping=dict(client=orgunit.label())),
                              context=getRequest())

            return SimpleTerm(value, token, title)

        if ActorLookup(value).is_team():
            if not self.include_teams:
                raise LookupError

            team = Team.query.get_by_actor_id(value)
            return SimpleTerm(team.actor_id(), team.actor_id(), team.label())

        user, orgunit = self.base_query.filter(OrgUnit.unit_id == orgunit_id) \
                                       .filter(User.userid == userid).one()

        token = u'{}:{}'.format(orgunit_id, userid)
        title = u'{}: {} ({})'.format(orgunit.title,
                                      user.fullname(),
                                      user.userid)
        return SimpleTerm(value, token, title)
Exemple #6
0
    def getTerm(self, value):

        data = value.split(':', 1)
        if len(data) == 2:
            orgunit_id, userid = data
        else:
            userid = value
            orgunit_id = self.client_id

        # Handle special case - Inboxes: in form "inbox:unit_id"
        if ActorLookup(value).is_inbox():
            orgunit_id = userid
            query = OrgUnit.query

            if self.only_current_inbox:
                orgunit = query.filter(OrgUnit.unit_id == self.client_id) \
                               .filter(OrgUnit.unit_id == orgunit_id) \
                               .one()
            else:
                orgunit = query.filter(OrgUnit.unit_id == orgunit_id) \
                               .one()

            value = token = orgunit.inbox().id()
            title = translate(_(u'inbox_label',
                                default=u'Inbox: ${client}',
                                mapping=dict(client=orgunit.label())),
                              context=getRequest())

            return SimpleTerm(value, token, title)

        if ActorLookup(value).is_team():
            if not self.include_teams:
                raise LookupError

            team = Team.query.get_by_actor_id(value)
            return SimpleTerm(team.actor_id(), team.actor_id(), team.label())

        user, orgunit = self.base_query.filter(OrgUnit.unit_id == orgunit_id) \
                                       .filter(User.userid == userid).one()

        token = u'{}:{}'.format(orgunit_id, userid)
        title = u'{}: {} ({})'.format(orgunit.title,
                                      user.fullname(),
                                      user.userid)
        return SimpleTerm(value, token, title)
Exemple #7
0
    def _extend_terms_with_inboxes(self, text_filters):
        inbox_text = translate(_(u'inbox_label',
                                 default=u'Inbox: ${client}',
                                 mapping=dict(client='')),
                               context=getRequest()).strip().lower()

        text_filters = filter(lambda text: text.lower() not in inbox_text,
                              text_filters)

        query = OrgUnit.query

        if self.only_current_inbox:
            query = query.filter(OrgUnit.unit_id == self.client_id)

        query = extend_query_with_textfilter(
            query,
            [OrgUnit.title, OrgUnit.unit_id],
            text_filters)

        for orgunit in query.all():
            self.terms.insert(0, self.getTerm(orgunit.inbox().id()))
class TeamEditForm(ModelEditForm):

    fields = field.Fields(ITeam)
    model_class = Team

    label = _('label_edit_team', default=u'Edit team')

    fields['groupid'].widgetFactory = ParameterizedWidget(KeywordWidget,
                                                          async=True)

    fields['org_unit_id'].widgetFactory = ParameterizedWidget(KeywordWidget,
                                                              async=True)

    def __init__(self, context, request):
        super(TeamEditForm, self).__init__(context, request, context.model)

    def nextURL(self):
        return get_contactfolder_url()

    def updateWidgets(self):
        super(TeamEditForm, self).updateWidgets()
Exemple #9
0
    def getTerm(self, value=None, brain=None, solr_doc=None):

        if solr_doc is not None:
            value = u'contact:{}'.format(solr_doc[u'id'])
            title = solr_doc[u'Title']
            return SimpleTerm(value, title=title)

        # Contacts
        if ActorLookup(value).is_contact() and brain is None:
            catalog = api.portal.get_tool('portal_catalog')
            brain = catalog.unrestrictedSearchResults(
                portal_type=CONTACT_TYPE,
                contactid=value)[0]

        if brain and ActorLookup(value).is_contact():
            actor = Actor.contact(brain.contactid, contact=brain)
            token = value
            title = actor.get_label()
            return SimpleTerm(value, token, title)

        # Inboxes
        if ActorLookup(value).is_inbox():
            orgunit_id = value.split(':', 1)[1]
            orgunit = OrgUnit.query.filter(OrgUnit.unit_id == orgunit_id).one()

            value = token = orgunit.inbox().id()
            title = translate(_(u'inbox_label',
                                default=u'Inbox: ${client}',
                                mapping=dict(client=orgunit.label())),
                              context=getRequest())

            return SimpleTerm(value, token, title)

        user = self.base_query.filter(User.userid == value).one()

        token = value
        title = u'{} ({})'.format(user.fullname(),
                                  user.userid)
        return SimpleTerm(value, token, title)
Exemple #10
0
    def _extend_terms_with_inboxes(self, text_filters):
        inbox_text = translate(_(u'inbox_label',
                                 default=u'Inbox: ${client}',
                                 mapping=dict(client='')),
                               context=getRequest()).strip().lower()

        text_filters = filter(lambda text: text.lower() not in inbox_text,
                              text_filters)

        query = OrgUnit.query
        query = query.filter(OrgUnit.enabled == True)  # noqa

        if self.only_current_inbox:
            query = query.filter(OrgUnit.unit_id == self.client_id)

        query = extend_query_with_textfilter(
            query,
            [OrgUnit.title, OrgUnit.unit_id],
            text_filters)

        for orgunit in query:
            self.terms.insert(0, self.getTerm(orgunit.inbox().id()))
    def describe(self, principal, with_email=False, with_email2=False,
                 with_principal=True):
        """Represent a user / contact / inbox / ... as string. This usually
        returns the fullname or another label / title.
        `principal` could also be a user object or a contact brain.
        """

        if not principal:
            return ''

        is_string = isinstance(principal, types.StringTypes)
        brain = None
        contact = None
        user = None

        # is principal a brain?
        if not is_string and ICatalogBrain.providedBy(principal):
            brain = principal

        # ok, lets check what we have...

        # string inbox
        if is_string and self.is_inbox(principal):
            # just do it
            client = self.get_client_of_inbox(principal)
            # we need to instantly translate, because otherwise
            # stuff like the autocomplete widget will not work
            # properly.
            label = _(u'inbox_label',
                      default=u'Inbox: ${client}',
                      mapping=dict(client=client.title))

            return translate(label, context=getRequest())

        # string contact
        elif is_string and self.is_contact(principal):
            contact = self.get_contact(principal)

        # string user
        elif is_string and self.is_user(principal):
            user = self.get_user(principal)

        # contact brain
        elif brain and brain_is_contact(brain):
            contact = brain
            principal = contact.contactid

        # user object
        elif IUser.providedBy(principal) or isinstance(principal, UserDict):
            user = principal
            principal = user.userid

        # ok, now lookup the stuff
        if contact:
            if not contact:
                return principal
            elif contact.lastname and contact.firstname:
                name = ' '.join((contact.lastname, contact.firstname))
            elif contact.lastname:
                name = contact.lastname
            elif contact.firstname:
                name = contact.firstname
            elif 'userid' in contact:
                name = contact.userid
            else:
                name = contact.id

            if with_email2 and contact.email2:
                return '%s (%s)' % (name, contact.email2)
            elif with_principal and contact.email:
                return '%s (%s)' % (name, contact.email)
            else:
                return name

        elif user:
            if user.lastname and user.firstname:
                name = ' '.join((user.lastname, user.firstname))
            elif user.lastname:
                name = user.lastname
            elif user.firstname:
                name = user.firstname
            else:
                name = user.userid

            infos = []
            if with_principal:
                infos.append(user.userid)

            if with_email and user.email:
                infos.append(user.email)

            elif with_email2 and user.email2:
                infos.append(user.email2)

            if infos:
                return '%s (%s)' % (name, ', '.join(infos))
            else:
                return name

        elif is_string:
            # fallback for acl_users
            portal = getSite()
            portal_membership = getToolByName(portal, 'portal_membership')
            member = portal_membership.getMemberById(principal)
            if not member:
                if isinstance(principal, str):
                    return principal.decode('utf-8')
                else:
                    return principal
            name = member.getProperty('fullname', principal)
            email = member.getProperty('email', None)

            infos = []
            if with_principal:
                infos.append(principal)

            if with_email and email:
                infos.append(email)

            if infos:
                return '%s (%s)' % (name, ', '.join(infos))
            else:
                return name

        else:
            raise ValueError('Unknown principal type: %s' % str(principal))
class TeamAddForm(ModelAddForm):

    schema = ITeam
    model_class = Team

    label = _('label_add_team', default=u'Add team')
Exemple #13
0
    def describe(self,
                 principal,
                 with_email=False,
                 with_email2=False,
                 with_principal=True):
        """Represent a user / contact / inbox / ... as string. This usually
        returns the fullname or another label / title.
        `principal` could also be a user object or a contact brain.
        """

        if not principal:
            return ''

        is_string = isinstance(principal, types.StringTypes)
        brain = None
        contact = None
        user = None

        # is principal a brain?
        if not is_string and ICatalogBrain.providedBy(principal):
            brain = principal

        # ok, lets check what we have...

        # string inbox
        if is_string and self.is_inbox(principal):
            # just do it
            client = self.get_client_of_inbox(principal)
            # we need to instantly translate, because otherwise
            # stuff like the autocomplete widget will not work
            # properly.
            label = _(u'inbox_label',
                      default=u'Inbox: ${client}',
                      mapping=dict(client=client.title))

            return translate(label, context=getRequest())

        # string contact
        elif is_string and self.is_contact(principal):
            contact = self.get_contact(principal)

        # string user
        elif is_string and self.is_user(principal):
            user = self.get_user(principal)

        # contact brain
        elif brain and brain_is_contact(brain):
            contact = brain
            principal = contact.contactid

        # user object
        elif IUser.providedBy(principal) or isinstance(principal, UserDict):
            user = principal
            principal = user.userid

        # ok, now lookup the stuff
        if contact:
            if not contact:
                return principal
            elif contact.lastname and contact.firstname:
                name = ' '.join((contact.lastname, contact.firstname))
            elif contact.lastname:
                name = contact.lastname
            elif contact.firstname:
                name = contact.firstname
            elif 'userid' in contact:
                name = contact.userid
            else:
                name = contact.id

            if with_email2 and contact.email2:
                return '%s (%s)' % (name, contact.email2)
            elif with_principal and contact.email:
                return '%s (%s)' % (name, contact.email)
            else:
                return name

        elif user:
            if user.lastname and user.firstname:
                name = ' '.join((user.lastname, user.firstname))
            elif user.lastname:
                name = user.lastname
            elif user.firstname:
                name = user.firstname
            else:
                name = user.userid

            infos = []
            if with_principal:
                infos.append(user.userid)

            if with_email and user.email:
                infos.append(user.email)

            elif with_email2 and user.email2:
                infos.append(user.email2)

            if infos:
                return '%s (%s)' % (name, ', '.join(infos))
            else:
                return name

        elif is_string:
            # fallback for acl_users
            portal = getSite()
            portal_membership = getToolByName(portal, 'portal_membership')
            member = portal_membership.getMemberById(principal)
            if not member:
                if isinstance(principal, str):
                    return principal.decode('utf-8')
                else:
                    return principal
            name = member.getProperty('fullname', principal)
            email = member.getProperty('email', None)

            infos = []
            if with_principal:
                infos.append(principal)

            if with_email and email:
                infos.append(email)

            if infos:
                return '%s (%s)' % (name, ', '.join(infos))
            else:
                return name

        else:
            raise ValueError('Unknown principal type: %s' % str(principal))