コード例 #1
0
    def _createRemoveOtherSubscriptionsField(self):
        """Create a field with a list of subscribers.

        Return a FormField instance, if subscriptions exist that can
        be removed, else return None.
        """
        teams = set(self.user_teams)
        other_subscriptions = set(
            subscription.subscriber
            for subscription in self.context.bug_subscriptions)

        # Teams and the current user have their own UI elements. Remove
        # them to avoid duplicates.
        other_subscriptions.difference_update(teams)
        other_subscriptions.discard(self.user)

        if not other_subscriptions:
            return None

        other_subscriptions = sorted(other_subscriptions,
                                     key=attrgetter('displayname'))

        terms = [
            SimpleTerm(subscriber, subscriber.name, subscriber.displayname)
            for subscriber in other_subscriptions
        ]

        subscriptions_vocabulary = SimpleVocabulary(terms)
        other_subscriptions_field = List(
            __name__='remove_other_subscriptions',
            title=u'Unsubscribe',
            value_type=Choice(vocabulary=subscriptions_vocabulary),
            required=False)
        return form.FormField(other_subscriptions_field)
コード例 #2
0
 def _createAddOtherSubscriptionsField(self):
     """Create a field for a new subscription."""
     new_subscription_field = Choice(__name__='new_subscription',
                                     title=u'Subscribe someone else',
                                     vocabulary='ValidPersonOrTeam',
                                     required=False)
     return form.FormField(new_subscription_field)
コード例 #3
0
    def setUpFields(self):
        """Setup an extra field with all products using the given bugtracker.

        This extra field is setup only if there is one or more products using
        that bugtracker.
        """
        super(
            BugAlsoAffectsProductWithProductCreationView, self).setUpFields()
        self._loadProductsUsingBugTracker()
        if self.existing_products is None or len(self.existing_products) < 1:
            # No need to setup any extra fields.
            return

        terms = []
        for product in self.existing_products:
            terms.append(SimpleTerm(product, product.name, product.title))
        existing_product = form.FormField(
            Choice(__name__='existing_product',
                   title=_("Existing project"), required=True,
                   vocabulary=SimpleVocabulary(terms)))
        self.form_fields += form.Fields(existing_product)
        if 'field.existing_product' not in self.request.form:
            # This is the first time the form is being submitted, so the
            # request doesn't contain a value for the existing_product
            # widget and thus we'll end up rendering an error message around
            # said widget unless we sneak a value for it in our request.
            self.request.form['field.existing_product'] = terms[0].token
コード例 #4
0
ファイル: new_folder.py プロジェクト: bendavis78/zope
    def __init__(self, *args, **kw):
        super(ContentsView, self).__init__(*args, **kw)
        self.form_fields = form.FormFields()
        self.contents = self.context.contentValues()

        for item in self.contents:
            for n, f in schema.getFieldsInOrder(IFolderItem):
                field = form.FormField(f, n, item.id)
                self.form_fields += form.FormFields(field)
コード例 #5
0
 def member_fields(self):
     """Create content field objects only for batched items
     Also create pseudo-widget for each item
     """
     mtool = getUtility(IMembershipTool)
     f = IMemberItem['select']
     members = []
     fields = form.FormFields()
     for item in self._getBatchObj():
         field = form.FormField(f, 'select', item.getId())
         fields += form.FormFields(field)
         members.append(MemberProxy(item, mtool))
     self.listBatchItems = members
     return fields
コード例 #6
0
    def _createTeamAnswerContactsField(self):
        """Create a list of teams the user is an administrator of."""
        sort_key = attrgetter('displayname')
        terms = []
        for team in sorted(self.administrated_teams, key=sort_key):
            terms.append(SimpleTerm(team, team.name, team.displayname))

        public_person_choice = PublicPersonChoice(
            vocabulary=SimpleVocabulary(terms))
        return form.FormField(
            List(__name__='answer_contact_teams',
                 title=_(
                     "Let the following teams be an answer contact for "
                     "$context",
                     mapping=dict(context=self.context.displayname)),
                 value_type=public_person_choice,
                 required=False))
コード例 #7
0
 def content_fields(self):
     """Create content field objects only for batched items"""
     f = IFolderItem['select']
     contents = []
     b_start = self._getBatchStart()
     key, reverse = self._get_sorting()
     fields = form.FormFields()
     for idx, item in enumerate(self._getBatchObj()):
         field = form.FormField(f, 'select', item.id)
         fields += form.FormFields(field)
         content = ContentProxy(item)
         if key == 'position':
             content.position = b_start + idx + 1
         else:
             content.position = '...'
         contents.append(content)
     self.listBatchItems = contents
     return fields
コード例 #8
0
 def setUpWidgets(self, context=None):
     # We only show those bug tracker types for which there can be
     # multiple instances in the bugtrackertype Choice widget.
     vocab_items = [
         item for item in BugTrackerType.items.items
             if item not in NO_DIRECT_CREATION_TRACKERS]
     fields = []
     for field_name in self.field_names:
         if field_name == 'bugtrackertype':
             fields.append(form.FormField(
                 Choice(__name__='bugtrackertype',
                        title=_('Bug Tracker Type'),
                        values=vocab_items,
                        default=BugTrackerType.BUGZILLA)))
         else:
             fields.append(self.form_fields[field_name])
     self.form_fields = form.Fields(*fields)
     super(BugTrackerAddView, self).setUpWidgets(context=context)
コード例 #9
0
    def _createTeamSubscriptionsField(self):
        """Create field with a list of the teams the user is a member of.

        Return a FormField instance, if the user is a member of at least
        one team, else return None.
        """
        teams = self.user_teams
        if not teams:
            return None
        teams.sort(key=attrgetter('displayname'))
        terms = [
            SimpleTerm(team, team.name, team.displayname) for team in teams
        ]
        team_vocabulary = SimpleVocabulary(terms)
        team_subscriptions_field = List(
            __name__='subscriptions_team',
            title=u'Team subscriptions',
            description=(u'You can subscribe the teams of '
                         'which you are an administrator.'),
            value_type=Choice(vocabulary=team_vocabulary),
            required=False)
        return form.FormField(team_subscriptions_field)
コード例 #10
0
ファイル: folder.py プロジェクト: bendavis78/zope
 def content_fields(self):
     """Create content field objects only for batched items"""
     for item in self._getBatchObj():
         for name, field in schema.getFieldsInOrder(IFolderItem):
             field = form.FormField(field, name, item.id)
             self.form_fields += form.FormFields(field)