Exemplo n.º 1
0
 def _process_field_moves(self, rules):
     """move fields according to the rules
     """
     for name, rule in rules.items():
         if name == '__all__':
             continue
         prefix = None
         if '.' in name:
             prefix, name = name.split('.', 1)
         else:
             prefix = ''
         if not rule.get('stub', False):
             after = rule['target'] if rule['dir'] == 'after' else None
             before = rule['target'] if rule['dir'] == 'before' else None
             if not (before or after):
                 raise ValueError(
                     'Direction of a field move must be before or '
                     'after, but got {0}.'.format(rule['direction'])
                 )
             try:
                 move(self, name, before=before, after=after, prefix=prefix)
             except KeyError:
                 # The relative_to field doesn't exist
                 logger.exception(
                     'No field move possible for non-existing field named '
                     '{0} with target {1}'.format(
                         prefix + '.' + name,
                         before or after
                     )
                 )
         self._process_field_moves(rule.get('with', {}))
Exemplo n.º 2
0
def processFieldMoves(form, schema, prefix=''):
    """Process all field moves stored under ORDER_KEY in the schema tagged
    value. This should be run after all schemata have been processed with
    processFields().
    """

    # (name, 'before'/'after', other name)
    order = mergedTaggedValueList(schema, ORDER_KEY)
    for field_name, direction, relative_to in order:

        # Handle shortcut: leading . means 'in this schema'. May be useful
        # if you want to move a field relative to one in the current
        # schema or (more likely) a base schema of the current schema, without
        # having to repeat the full prefix of this schema.

        if relative_to.startswith('.'):
            relative_to = relative_to[1:]
            if prefix:
                relative_to = expandPrefix(prefix) + relative_to

        try:
            if direction == 'before':
                move(form, field_name, before=relative_to, prefix=prefix)
            elif direction == 'after':
                move(form, field_name, after=relative_to, prefix=prefix)
        except KeyError:
            # The relative_to field doesn't exist
            pass
Exemplo n.º 3
0
 def _process_field_moves(self, rules):
     """move fields according to the rules
     """
     for name, rule in rules.items():
         if name == '__all__':
             continue
         prefix = None
         if '.' in name:
             prefix, name = name.split('.', 1)
         else:
             prefix = ''
         if not rule.get('stub', False):
             after = rule['target'] if rule['dir'] == 'after' else None
             before = rule['target'] if rule['dir'] == 'before' else None
             if not (before or after):
                 raise ValueError(
                     'Direction of a field move must be before or '
                     'after, but got {0}.'.format(rule['direction']))
             try:
                 move(self, name, before=before, after=after, prefix=prefix)
             except KeyError as e:
                 if (e.message.startswith('Field ')
                         and e.message.endswith(' not found')):
                     # The relative_to field doesn't exist
                     logger.warning('Field move to non-existing: '
                                    'field name: {0}, rule: {1}'.format(
                                        prefix + '.' + name, str(rule)))
                 else:
                     raise
         self._process_field_moves(rule.get('with', {}))
Exemplo n.º 4
0
 def updateFields(self):
     try:
         return super(ProposalAddForm, self).updateFields()
     finally:
         if self.schema is IAddProposal:
             move(self, 'proposal_template', after='committee')
         move(self, 'title', before='*')
Exemplo n.º 5
0
def processFieldMoves(form, schema, prefix=''):
    """Process all field moves stored under ORDER_KEY in the schema tagged
    value. This should be run after all schemata have been processed with
    processFields().
    """

    # (name, 'before'/'after', other name)
    order = mergedTaggedValueList(schema, ORDER_KEY)
    for field_name, direction, relative_to in order:

        # Handle shortcut: leading . means 'in this schema'. May be useful
        # if you want to move a field relative to one in the current
        # schema or (more likely) a base schema of the current schema, without
        # having to repeat the full prefix of this schema.

        if relative_to.startswith('.'):
            relative_to = relative_to[1:]
            if prefix:
                relative_to = expandPrefix(prefix) + relative_to

        try:
            if direction == 'before':
                move(form, field_name, before=relative_to, prefix=prefix)
            elif direction == 'after':
                move(form, field_name, after=relative_to, prefix=prefix)
        except KeyError:
            # The relative_to field doesn't exist
            pass
Exemplo n.º 6
0
 def updateFields(self):
     try:
         return super(ProposalAddForm, self).updateFields()
     finally:
         if self.schema is IAddProposal:
             move(self, 'proposal_template', after='committee')
         move(self, 'title', before='*')
Exemplo n.º 7
0
    def reorder_widgets(self):
        """ Reorders the widgets of the form. Must be called before the parent's
        __init__ method. The field order is a list of fields. Fields present
        in the list are put in the order of the list. Fields not present in the
        list are put at the location of the asterisk (*) which must be present
        in the list.

        Example:
        class ISchema(Interface):
            field1 = Field()
            field2 = Field()
            field3 = Field()
            field4 = Field()
            field5 = Field()

        ISchema.setTaggedValue('seantis.dir.base.order',
            ["field5", "field4", "*", "field1"]

        Will produce this order:
        Field5, Field4, Field2, Field3, Field1

        """
        order = self.field_order
        default = order.index('*')

        # move fields before the star
        for prev, curr, next in utils.previous_and_next(reversed(order[:default])):
            move(self.form, curr, before=prev or '*')

        # move fields after the star
        for prev, curr, next in utils.previous_and_next(order[default + 1:]):
            move(self.form, curr, after=prev or '*')
Exemplo n.º 8
0
    def updateFields(self):
        super(EmailConfirmation, self).updateFields()
        if self.has_captcha and self.isAnon:
            self.fields['captcha'].widgetFactory = ReCaptchaFieldWidget
        else:
            self.fields['captcha'].mode = interfaces.HIDDEN_MODE

        move(self, 'email', before='*')
Exemplo n.º 9
0
    def updateFields(self):
        super(FieldConfigurationMixin, self).updateFields()
        textfields = ('legal_basis', 'initial_position', 'proposed_action',
                      'decision_draft', 'publish_in', 'disclose_to',
                      'copy_for_attention')

        map(self.use_trix, textfields)
        if is_word_meeting_implementation_enabled():
            map(self.omit_field, textfields)
            move(self, 'title', before='*')
Exemplo n.º 10
0
 def updateFields(self):
     super(missionEditForm, self).updateFields()
     if 'IILOOffices.ilo_offices' in self.fields.keys():
         move(self, 'IILOOffices.ilo_offices', after='text')
     if 'IILOTheme.ilo_themes' in self.fields.keys():
         move(self, 'IILOTheme.ilo_themes', after='IILOOffices.ilo_offices')
     if 'IILOTheme.theme_other' in self.fields.keys():
         move(self, 'IILOTheme.theme_other', after='IILOTheme.ilo_themes')
     if 'IILORegions.ilo_regions' in self.fields.keys():
         move(self, 'IILORegions.ilo_regions', after='IILOTheme.theme_other')
     if 'IILOOffices.mission_location_other' in self.fields.keys():
         move(self, 'IILOOffices.mission_location_other', after='IILORegions.ilo_regions')
Exemplo n.º 11
0
    def move(
            self,
            field_name,
            before=None,
            after=None,
            prefix=None,
            relative_prefix=None):
        """Move the field with the given name before or after another field.
        """

        utils.move(self.form, field_name, before=before, after=after,
                   prefix=prefix, relative_prefix=relative_prefix)
Exemplo n.º 12
0
    def move(self,
             field_name,
             before=None,
             after=None,
             prefix=None,
             relative_prefix=None):
        """Move the field with the given name before or after another field.
        """

        utils.move(self.form,
                   field_name,
                   before=before,
                   after=after,
                   prefix=prefix,
                   relative_prefix=relative_prefix)
Exemplo n.º 13
0
 def updateFields(self):
     super(missionEditForm, self).updateFields()
     if 'IILOOffices.ilo_offices' in self.fields.keys():
         move(self, 'IILOOffices.ilo_offices', after='text')
     if 'IILOTheme.ilo_themes' in self.fields.keys():
         move(self, 'IILOTheme.ilo_themes', after='IILOOffices.ilo_offices')
     if 'IILOTheme.theme_other' in self.fields.keys():
         move(self, 'IILOTheme.theme_other', after='IILOTheme.ilo_themes')
     if 'IILORegions.ilo_regions' in self.fields.keys():
         move(self,
              'IILORegions.ilo_regions',
              after='IILOTheme.theme_other')
     if 'IILOOffices.mission_location_other' in self.fields.keys():
         move(self,
              'IILOOffices.mission_location_other',
              after='IILORegions.ilo_regions')
Exemplo n.º 14
0
    def reorder_widgets(self):
        """ Reorders the widgets of the form. Must be called before the
        parent's __init__ method. The field order is a list of fields. Fields
        present in the list are put in the order of the list. Fields not
        present in the list are put at the location of the asterisk (*) which
        must be present in the list.

        Example:
        class ISchema(Interface):
            field1 = Field()
            field2 = Field()
            field3 = Field()
            field4 = Field()
            field5 = Field()

        ISchema.setTaggedValue('seantis.dir.base.order',
            ["field5", "field4", "*", "field1"]

        Will produce this order:
        Field5, Field4, Field2, Field3, Field1

        """

        # The order is defined on the schema, but the this widget manager
        # is instantiated on groupforms as well as normal forms. The moving
        # should only happen on the parentform, not the groupform, as
        # the move function will otherwise not find the fields.
        if self.is_group_form:
            return

        # The move function searches for fields in the groups which fails
        # hard if the groups have not been instantiated yet.
        if self.uninstantiated_groups > 0:
            return

        order = self.field_order
        default = order.index('*')

        previous_and_next = utils.previous_and_next

        # move fields before the star
        for prev, curr, next in previous_and_next(reversed(order[:default])):
            move(self.form, curr, before=prev or '*')

        # move fields after the star
        for prev, curr, next in previous_and_next(order[default + 1:]):
            move(self.form, curr, after=prev or '*')
Exemplo n.º 15
0
    def reorder_widgets(self):
        """ Reorders the widgets of the form. Must be called before the
        parent's __init__ method. The field order is a list of fields. Fields
        present in the list are put in the order of the list. Fields not
        present in the list are put at the location of the asterisk (*) which
        must be present in the list.

        Example:
        class ISchema(Interface):
            field1 = Field()
            field2 = Field()
            field3 = Field()
            field4 = Field()
            field5 = Field()

        ISchema.setTaggedValue('seantis.dir.base.order',
            ["field5", "field4", "*", "field1"]

        Will produce this order:
        Field5, Field4, Field2, Field3, Field1

        """

        # The order is defined on the schema, but the this widget manager
        # is instantiated on groupforms as well as normal forms. The moving
        # should only happen on the parentform, not the groupform, as
        # the move function will otherwise not find the fields.
        if self.is_group_form:
            return

        # The move function searches for fields in the groups which fails
        # hard if the groups have not been instantiated yet.
        if self.uninstantiated_groups > 0:
            return

        order = self.field_order
        default = order.index('*')

        previous_and_next = utils.previous_and_next

        # move fields before the star
        for prev, curr, next in previous_and_next(reversed(order[:default])):
            move(self.form, curr, before=prev or '*')

        # move fields after the star
        for prev, curr, next in previous_and_next(order[default + 1:]):
            move(self.form, curr, after=prev or '*')
    def updateFields(self):
        super(missionReportAddForm, self).updateFields()
        if 'IILOCountries.mission_location' in self.fields.keys():
            move(self, 'IILOCountries.mission_location', after='mission_city')
        
        if 'IILOOffices.ilo_offices' in self.fields.keys():
            move(self, 'IILOOffices.ilo_offices', after='mission_members')

        
            
        
        if 'IILOOffices.mission_location_other' in self.fields.keys():
            move(self, 'IILOOffices.mission_location_other', after='IILOCountries.mission_location')

        if 'IILOTheme.ilo_themes' in self.fields.keys():
            move(self, 'IILOTheme.ilo_themes', after='mission_location_other')
        if 'IILOTheme.theme_other' in self.fields.keys():
            move(self, 'IILOTheme.theme_other', after='IILOTheme.ilo_themes')
    def updateFields(self):
        super(EmailConfirmation, self).updateFields()
        if self.captcha != 'disabled' and self.isAnon:
            # Add a captcha field if captcha is enabled in the registry
            if self.captcha == 'captcha':
                from plone.formwidget.captcha import CaptchaFieldWidget
                self.fields['captcha'].widgetFactory = CaptchaFieldWidget
            elif self.captcha == 'recaptcha':
                from plone.formwidget.recaptcha import ReCaptchaFieldWidget
                self.fields['captcha'].widgetFactory = ReCaptchaFieldWidget
            elif self.captcha == 'norobots':
                from collective.z3cform.norobots import NorobotsFieldWidget
                self.fields['captcha'].widgetFactory = NorobotsFieldWidget
            else:
                self.fields['captcha'].mode = interfaces.HIDDEN_MODE
        else:
            self.fields['captcha'].mode = interfaces.HIDDEN_MODE

        move(self, 'email', before='*')
Exemplo n.º 18
0
    def updateFields(self):
        super(missionReportEditForm, self).updateFields()

        if 'IILOCountries.mission_location' in self.fields.keys():
            move(self, 'IILOCountries.mission_location', after='mission_city')

        if 'IILOOffices.ilo_offices' in self.fields.keys():
            move(self, 'IILOOffices.ilo_offices', after='mission_members')

        if 'IILOTheme.ilo_themes' in self.fields.keys():
            move(self, 'IILOTheme.ilo_themes', after='mission_location_other')
        if 'IILOTheme.theme_other' in self.fields.keys():
            move(self, 'IILOTheme.theme_other', after='IILOTheme.ilo_themes')
Exemplo n.º 19
0
def _add_edit_update(self):
    # Flatten group fields.
    fields = {}
    for k, v in self.fields.items():
        fields[k] = v

    for group in self.groups:
        for k, v in group.fields.items():
            fields[k] = v

    # Set hidden fields
    fields['IDublinCore.description'].mode = HIDDEN_MODE

    registry = getUtility(IRegistry)
    show_lead_image = registry.forInterface(
        IBlogSettings, check=False).show_lead_image

    if not show_lead_image and 'ILeadImage.image' in fields:
        fields['ILeadImage.image'].mode = HIDDEN_MODE
        fields['ILeadImage.image_caption'].mode = HIDDEN_MODE

    # Move the text field after the title field
    move(self, 'IRichText.text', after='IDublinCore.title')

    # Set restricted fields
    restricted_fields = (
        'IDublinCore.creators',
        'IDublinCore.description',
        'IDublinCore.rights',
        'IAllowDiscussion.allow_discussion',
        'IExcludeFromNavigation.exclude_from_nav',
        'INextPreviousToggle.nextPreviousEnabled',
    )

    for rfield in restricted_fields:
        if rfield in fields:
            fields[rfield].read_permission = 'cmf.ModifyPortalContent'
            fields[rfield].write_permission = 'cmf.ModifyPortalContent'
 def update(self):
     super(AddForm, self).update()
     move(self, 'IRelatedItems.relatedItems', after='duracao')
     super(AddForm, self).update()
     self.widgets['IRelatedItems.relatedItems'].label = label_related
     self.widgets['IRelatedItems.relatedItems'].description = desc_related
Exemplo n.º 21
0
 def update(self):
     move(self, 'text', after='*')
     super(AssignForwardingForm, self).update()
Exemplo n.º 22
0
 def update(self):
     super(AdvancedSearchForm, self).update()
     move(self, 'searchable_filing_no', before='responsible')
Exemplo n.º 23
0
 def update(self):
     move(self, 'text', after='*')
     super(AssignForwardingForm, self).update()
Exemplo n.º 24
0
 def updateFields(self):
     super(ProposalEditForm, self).updateFields()
     move(self, 'description', before='*')
     move(self, 'title', before='*')
Exemplo n.º 25
0
    def updateFields(self):
        try:
            return super(ProposalAddForm, self).updateFields()
        finally:
            if self.schema is IAddProposal:
                move(self, 'proposal_template', after='committee')
                move(self, 'proposal_document_type', before='proposal_template')
                move(self, 'proposal_document', before='proposal_template')
                move(self, 'edit_after_creation', after='proposal_template')
            move(self, 'description', before='*')
            move(self, 'title', before='*')
            move(self, 'issuer', after='description')

            self.fields['proposal_document_type'].widgetFactory[INPUT_MODE] \
                = radio.RadioFieldWidget
Exemplo n.º 26
0
 def update(self):
     super(AdvancedSearchForm, self).update()
     move(self, 'searchable_filing_no', before='responsible')
Exemplo n.º 27
0
 def updateFields(self):
     super(SubmittedProposalEditForm, self).updateFields()
     move(self, 'title', before='*')
Exemplo n.º 28
0
 def move_fields(self):
     move(self, 'searchable_filing_no', before='responsible')
Exemplo n.º 29
0
 def updateFields(self):
     super(SubmittedProposalEditForm, self).updateFields()
     move(self, 'title', before='*')
Exemplo n.º 30
0
 def move_fields(self):
     move(self, 'searchable_filing_no', before='responsible')