def get_ttw_fields(obj):
    """Returns names of the fields that were added to obj through the web"""
    fti = getUtility(IDexterityFTI, name=obj.portal_type)
    full_schema = fti.lookupSchema()
    all_fields = schema.getFieldsInOrder(full_schema)

    schema_policy = getUtility(ISchemaPolicy, name=fti.schema_policy)
    original_schema = schema_policy.bases(None, None)[0]
    original_fields = schema.getFieldsInOrder(original_schema)
    new_fields = [field[0] for field in all_fields
                  if field[0] not in dict(original_fields).keys()]

    for behavior_id in fti.behaviors:
        behavior = getUtility(IBehavior, behavior_id).interface
        if behavior == IContactDetails or not IFormFieldProvider.providedBy(behavior):
            continue

        try:
            default_fieldset_fields = non_fieldset_fields(behavior)
            behavior_name = behavior_id.split('.')[-1]
            # @TODO: get generic method to get widget id
            new_fields.extend(['%s.%s' % (behavior_name, field_name)
                               for field_name in default_fieldset_fields])
        except:
            pass

    return new_fields
Example #2
0
def get_ttw_fields(obj):
    """Returns names of the fields that were added to obj through the web"""
    fti = getUtility(IDexterityFTI, name=obj.portal_type)
    full_schema = fti.lookupSchema()
    all_fields = schema.getFieldsInOrder(full_schema)

    schema_policy = getUtility(ISchemaPolicy, name=fti.schema_policy)
    original_schema = schema_policy.bases(None, None)[0]
    original_fields = schema.getFieldsInOrder(original_schema)
    new_fields = [
        field[0] for field in all_fields
        if field[0] not in dict(original_fields).keys()
    ]

    for behavior_id in fti.behaviors:
        behavior = getUtility(IBehavior, behavior_id).interface
        if behavior in IGNORED_BEHAVIORS or not IFormFieldProvider.providedBy(
                behavior):
            continue

        try:
            default_fieldset_fields = non_fieldset_fields(behavior)
            behavior_name = behavior_id.split('.')[-1]
            # @TODO: get generic method to get widget id
            new_fields.extend([
                '%s.%s' % (behavior_name, field_name)
                for field_name in default_fieldset_fields
            ])
        except:
            pass

    return new_fields
def get_fields(fti):
    schema = fti.lookupSchema()
    fields = getFields(schema)
    for behavior_id in fti.behaviors:
        schema = getUtility(IBehavior, behavior_id).interface
        if not IFormFieldProvider.providedBy(schema):
            continue
        fields.update(getFields(schema))

    return fields
def get_fields(fti):
    schema = fti.lookupSchema()
    fields = getFields(schema)
    for behavior_id in fti.behaviors:
        schema = getUtility(IBehavior, behavior_id).interface
        if not IFormFieldProvider.providedBy(schema):
            continue
        fields.update(getFields(schema))

    return fields
    def is_field(self, attr_name):
        ttool = api.portal.get_tool('portal_types')
        fti = ttool[self.context.portal_type]
        is_field = bool(fti.lookupSchema().get(attr_name))
        if not is_field:
            # check if it is a behavior field
            for behavior_id in fti.behaviors:
                schema = getUtility(IBehavior, behavior_id).interface
                if not IFormFieldProvider.providedBy(schema):
                    continue

                is_field = bool(schema.get(attr_name))

        return is_field
Example #6
0
def get_ordered_fields(fti):
    """ return fields in fieldset order """
    # NOTE: code extracted from collective.excelexport. Original comments
    # preserved

    # this code is much complicated because we have to get sure
    # we get the fields in the order of the fieldsets
    # the order of the fields in the fieldsets can differ
    # of the getFieldsInOrder(schema) order...
    # that's because fields from different schemas
    # can take place in the same fieldset
    schema = fti.lookupSchema()
    fieldset_fields = {}
    ordered_fieldsets = ['default']

    for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
        ordered_fieldsets.append(fieldset.__name__)
        fieldset_fields[fieldset.__name__] = fieldset.fields

    if fieldset_fields.get('default', []):
        fieldset_fields['default'] += non_fieldset_fields(schema)
    else:
        fieldset_fields['default'] = non_fieldset_fields(schema)

    # Get the behavior fields
    fields = getFieldsInOrder(schema)

    for behavior_id in fti.behaviors:
        schema = getUtility(IBehavior, behavior_id).interface

        if not IFormFieldProvider.providedBy(schema):
            continue

        fields.extend(getFieldsInOrder(schema))

        for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
            fieldset_fields.setdefault(
                fieldset.__name__, []).extend(fieldset.fields)
            ordered_fieldsets.append(fieldset.__name__)

        fieldset_fields['default'].extend(non_fieldset_fields(schema))

    ordered_fields = []

    for fieldset in ordered_fieldsets:
        ordered_fields.extend(fieldset_fields[fieldset])

    fields.sort(key=lambda field: ordered_fields.index(field[0]))

    return fields
    def is_field(self, attr_name):
        ttool = api.portal.get_tool('portal_types')
        fti = ttool[self.context.portal_type]
        is_field = bool(fti.lookupSchema().get(attr_name))
        if not is_field:
            # check if it is a behavior field
            for behavior_id in fti.behaviors:
                schema = getUtility(IBehavior, behavior_id).interface
                if not IFormFieldProvider.providedBy(schema):
                    continue

                is_field = bool(schema.get(attr_name))

        return is_field
Example #8
0
def get_ordered_fields(fti):
    """ return fields in fieldset order """
    # NOTE: code extracted from collective.excelexport. Original comments
    # preserved

    # this code is much complicated because we have to get sure
    # we get the fields in the order of the fieldsets
    # the order of the fields in the fieldsets can differ
    # of the getFieldsInOrder(schema) order...
    # that's because fields from different schemas
    # can take place in the same fieldset
    schema = fti.lookupSchema()
    fieldset_fields = {}
    ordered_fieldsets = ['default']

    for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
        ordered_fieldsets.append(fieldset.__name__)
        fieldset_fields[fieldset.__name__] = fieldset.fields

    if fieldset_fields.get('default', []):
        fieldset_fields['default'] += non_fieldset_fields(schema)
    else:
        fieldset_fields['default'] = non_fieldset_fields(schema)

    # Get the behavior fields
    fields = getFieldsInOrder(schema)

    for behavior_id in fti.behaviors:
        schema = getUtility(IBehavior, behavior_id).interface

        if not IFormFieldProvider.providedBy(schema):
            continue

        fields.extend(getFieldsInOrder(schema))

        for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
            fieldset_fields.setdefault(
                fieldset.__name__, []).extend(fieldset.fields)
            ordered_fieldsets.append(fieldset.__name__)

        fieldset_fields['default'].extend(non_fieldset_fields(schema))

    ordered_fields = []

    for fieldset in ordered_fieldsets:
        ordered_fields.extend(fieldset_fields[fieldset])

    fields.sort(key=lambda field: ordered_fields.index(field[0]))

    return fields
Example #9
0
def get_ordered_fields(fti):
    # this code is much complicated because we have to get sure
    # we get the fields in the order of the fieldsets
    # the order of the fields in the fieldsets can differ
    # of the getFieldsInOrder(schema) order...
    # that's because fields from different schemas
    # can take place in the same fieldset
    schema = fti.lookupSchema()
    fieldset_fields = {}
    ordered_fieldsets = ['default']
    labels = {'default': u'Default'}
    for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
        ordered_fieldsets.append(fieldset.__name__)
        labels[fieldset.__name__] = fieldset.label
        fieldset_fields[fieldset.__name__] = fieldset.fields

    fieldset_fields['default'] = non_fieldset_fields(schema)

    # Get the behavior fields
    fields = getFieldsInOrder(schema)
    for behavior_id in fti.behaviors:
        schema = getUtility(IBehavior, behavior_id).interface
        if not IFormFieldProvider.providedBy(schema):
            continue

        fields.extend(getFieldsInOrder(schema))
        for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
            fieldset_fields.setdefault(fieldset.__name__, []).extend(
                fieldset.fields)
            if fieldset.__name__ not in ordered_fieldsets:
                ordered_fieldsets.append(fieldset.__name__)
                labels[fieldset.__name__] = fieldset.label

        fieldset_fields['default'].extend(non_fieldset_fields(schema))

    ordered_fields = []
    for fieldset in ordered_fieldsets:
        ordered_fields.extend(fieldset_fields[fieldset])

    ordered_fieldsets_fields = [{
        'id': fieldset,
        'fields': fieldset_fields[fieldset],
        'title': labels[fieldset],
    } for fieldset in ordered_fieldsets]

    fields.sort(key=lambda field: ordered_fields.index(field[0]))
    return (fields, ordered_fieldsets_fields)
Example #10
0
def get_ordered_fields(fti):
    # this code is much complicated because we have to get sure
    # we get the fields in the order of the fieldsets
    # the order of the fields in the fieldsets can differ
    # of the getFieldsInOrder(schema) order...
    # that's because fields from different schemas
    # can take place in the same fieldset
    schema = fti.lookupSchema()
    fieldset_fields = {}
    ordered_fieldsets = ['default']
    labels = {'default': u'Default'}
    for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
        ordered_fieldsets.append(fieldset.__name__)
        labels[fieldset.__name__] = fieldset.label
        fieldset_fields[fieldset.__name__] = fieldset.fields

    fieldset_fields['default'] = non_fieldset_fields(schema)

    # Get the behavior fields
    fields = getFieldsInOrder(schema)
    for behavior_id in fti.behaviors:
        schema = getUtility(IBehavior, behavior_id).interface
        if not IFormFieldProvider.providedBy(schema):
            continue

        fields.extend(getFieldsInOrder(schema))
        for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
            fieldset_fields.setdefault(fieldset.__name__, []).extend(
                fieldset.fields)
            if fieldset.__name__ not in ordered_fieldsets:
                ordered_fieldsets.append(fieldset.__name__)
                labels[fieldset.__name__] = fieldset.label

        fieldset_fields['default'].extend(non_fieldset_fields(schema))

    ordered_fields = []
    for fieldset in ordered_fieldsets:
        ordered_fields.extend(fieldset_fields[fieldset])

    ordered_fieldsets_fields = [{
        'id': fieldset,
        'fields': fieldset_fields[fieldset],
        'title': labels[fieldset],
    } for fieldset in ordered_fieldsets]

    fields.sort(key=lambda field: ordered_fields.index(field[0]))
    return (fields, ordered_fieldsets_fields)
 def test_behaviors_installation(self):
     contact_details_behavior = getUtility(IBehavior,
             name='collective.contact.core.behaviors.IContactDetails')
     global_positioning_behavior = getUtility(IBehavior,
             name='collective.contact.core.behaviors.IGlobalPositioning')
     birthday_behavior = getUtility(IBehavior,
             name='collective.contact.core.behaviors.IBirthday')
     self.assertEqual(contact_details_behavior.interface, IContactDetails)
     self.assertEqual(global_positioning_behavior.interface,
                      IGlobalPositioning)
     self.assertEqual(birthday_behavior.interface, IBirthday)
     IFormFieldProvider.providedBy(contact_details_behavior.interface)
     IFormFieldProvider.providedBy(global_positioning_behavior.interface)
     IFormFieldProvider.providedBy(birthday_behavior.interface)
 def test_behaviors_installation(self):
     contact_details_behavior = getUtility(
         IBehavior,
         name='collective.contact.core.behaviors.IContactDetails')
     global_positioning_behavior = getUtility(
         IBehavior,
         name='collective.contact.core.behaviors.IGlobalPositioning')
     birthday_behavior = getUtility(
         IBehavior, name='collective.contact.core.behaviors.IBirthday')
     self.assertEqual(contact_details_behavior.interface, IContactDetails)
     self.assertEqual(global_positioning_behavior.interface,
                      IGlobalPositioning)
     self.assertEqual(birthday_behavior.interface, IBirthday)
     IFormFieldProvider.providedBy(contact_details_behavior.interface)
     IFormFieldProvider.providedBy(global_positioning_behavior.interface)
     IFormFieldProvider.providedBy(birthday_behavior.interface)
def get_ordered_fields(fti, context):
    # this code is much complicated because we have to get sure
    # we get the fields in the order of the fieldsets
    # the order of the fields in the fieldsets can differ
    # of the getFieldsInOrder(schema) order...
    # that's because fields from different schemas
    # can take place in the same fieldset
    schema = fti.lookupSchema()
    fieldset_fields = {}
    ordered_fieldsets = ['default']
    for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
        ordered_fieldsets.append(fieldset.__name__)
        fieldset_fields[fieldset.__name__] = fieldset.fields

    fieldset_fields['default'] = non_fieldset_fields(schema, context)

    # Get the behavior fields
    fields = get_fields_in_order_with_permission(schema, context)
    for behavior_id in fti.behaviors:
        schema = getUtility(IBehavior, behavior_id).interface
        if not IFormFieldProvider.providedBy(schema):
            continue

        fields.extend(get_fields_in_order_with_permission(schema, context))
        for fieldset in schema.queryTaggedValue(FIELDSETS_KEY, []):
            fieldset_fields.setdefault(fieldset.__name__, []).extend(fieldset.fields)
            ordered_fieldsets.append(fieldset.__name__)

        fieldset_fields['default'].extend(non_fieldset_fields(schema, context))

    ordered_fields = []
    for fieldset in ordered_fieldsets:
        ordered_fields.extend(fieldset_fields[fieldset])

    fields.sort(key=lambda field: ordered_fields.index(field[0]))
    return fields
 def test_behaviors_installation(self):
     sending_type_behavior = getUtility(IBehavior,
                                        name='collective.dms.mailcontent.behaviors.ISendingType')
     self.assertEqual(sending_type_behavior.interface, ISendingType)
     IFormFieldProvider.providedBy(sending_type_behavior.interface)
 def test_alsoProvides(self):
     from plone.autoform.interfaces import IFormFieldProvider
     from collective.behavior.price.behavior import IPrice
     self.assertTrue(IFormFieldProvider.providedBy(IPrice))