Example #1
0
def upgrade_to_ttw(context):
    # the new default schema only contains fullname and email fields
    # so we put the missing ones (home_page, description, location, portrait)
    # into the ttw schema
    if schemaeditor.get_schema() == '':
        finalizeSchemas(IEmpty)
        current_ttw = IEditableSchema(IEmpty)
    else:
        current_ttw = IEditableSchema(schemaeditor.load_ttw_schema())

    attrs = copySchemaAttrs(current_ttw.schema)
    current_fields = current_ttw.schema.names()
    pm = getToolByName(context, "portal_memberdata")
    existing = pm.propertyIds()

    if 'home_page' in existing and 'home_page' not in current_fields:
        attrs.update(copySchemaAttrs(IHomePageSchema))

    if 'description' in existing and 'description' not in current_fields:
        attrs.update(copySchemaAttrs(IDescriptionSchema))

    if 'location' in existing and 'location' not in current_fields:
        attrs.update(copySchemaAttrs(ILocationSchema))

    if 'portrait' in existing and 'portrait' not in current_fields:
        attrs.update(copySchemaAttrs(IPortraitSchema))

    sch = SchemaClass(schemaeditor.SCHEMATA_KEY,
                      bases=(current_ttw.schema, ),
                      attrs=attrs)
    finalizeSchemas(sch)

    xml_model = schemaeditor.serialize_ttw_schema(sch)
    schemaeditor.set_schema(xml_model)
    log.info('Old member fields migrated into TTW schema')
Example #2
0
    def move(self, pos, fieldset_index):
        """ AJAX method to change field position within its schema.
        The position is relative to the fieldset.
        """
        schema = IEditableSchema(self.schema)
        fieldname = self.field.__name__
        pos = int(pos)
        fieldset_index = int(fieldset_index)
        fieldset_index -= 1  # index 0 is default fieldset

        fieldsets = self.schema.queryTaggedValue(FIELDSETS_KEY, [])
        new_fieldset = fieldset_index >= 0 and fieldsets[
            fieldset_index] or None
        schema.changeFieldFieldset(fieldname, new_fieldset)

        ordered_field_ids = [info[0] for info in sortedFields(self.schema)]
        if new_fieldset:
            old_field_of_position = new_fieldset.fields[pos]
            new_absolute_position = ordered_field_ids.index(
                old_field_of_position)
        else:
            new_absolute_position = pos

        # if fieldset changed, update fieldsets
        schema.moveField(fieldname, new_absolute_position)

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.__parent__.__parent__))
Example #3
0
    def move(self, pos):
        """ AJAX method to change field position within its schema.
        The position is relative to the fieldset.
        """
        schema = IEditableSchema(self.schema)
        fieldname = self.field.__name__
        pos = int(pos)


        ordered_field_ids = [name for (name, field) in sortedFields(self.schema)]
        for fieldset in self.schema.getTaggedValue(FIELDSETS_KEY):
            # if we are in a fieldset, pos is the position relative to the fieldset
            if fieldname in fieldset.fields:
                old_field_of_position = fieldset.fields[pos]
                absolute_position = ordered_field_ids.index(old_field_of_position)
                break
        else:
            # in default fieldset, the relative position == the absolute position
            fieldset = None
            absolute_position = pos

        schema.moveField(fieldname, absolute_position)
        # if field is in a fieldset, also reorder fieldset tagged value
        ordered_field_ids = [name for (name, field) in sortedFields(self.schema)]
        if fieldset is not None:
            fieldset.fields = sorted(fieldset.fields,
                                     key=lambda x: ordered_field_ids.index(x))

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
Example #4
0
    def move(self, pos):
        """ AJAX method to change field position within its schema.
        The position is relative to the fieldset.
        """
        schema = IEditableSchema(self.schema)
        fieldname = self.field.__name__
        pos = int(pos)

        ordered_field_ids = [
            name for (name, field) in sortedFields(self.schema)
        ]
        for fieldset in self.schema.getTaggedValue(FIELDSETS_KEY):
            # if we are in a fieldset, pos is the position relative to the fieldset
            if fieldname in fieldset.fields:
                old_field_of_position = fieldset.fields[pos]
                absolute_position = ordered_field_ids.index(
                    old_field_of_position)
                break
        else:
            # in default fieldset, the relative position == the absolute position
            fieldset = None
            absolute_position = pos

        schema.moveField(fieldname, absolute_position)
        # if field is in a fieldset, also reorder fieldset tagged value
        ordered_field_ids = [
            name for (name, field) in sortedFields(self.schema)
        ]
        if fieldset is not None:
            fieldset.fields = sorted(fieldset.fields,
                                     key=lambda x: ordered_field_ids.index(x))

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
Example #5
0
 def delete(self):
     """
     AJAX method to delete a field
     """
     schema = IEditableSchema(self.schema)
     schema.removeField(self.field.getName())
     notify(ObjectRemovedEvent(self.field, self.schema))
     notify(FieldRemovedEvent(self.aq_parent.aq_parent, self.field))
     self.request.response.setHeader('Content-Type', 'application/json')
Example #6
0
 def delete(self):
     """
     AJAX method to delete a field
     """
     schema = IEditableSchema(self.schema)
     schema.removeField(self.field.getName())
     notify(ObjectRemovedEvent(self.field, self.schema))
     notify(FieldRemovedEvent(self.__parent__.__parent__, self.field))
     self.request.response.setHeader('Content-Type', 'application/json')
Example #7
0
 def delete(self):
     """
     AJAX method to delete a field
     """
     schema = IEditableSchema(self.schema)
     schema.removeField(self.field.getName())
     notify(ObjectRemovedEvent(self.field, self.schema))
     notify(FieldRemovedEvent(self.aq_parent.aq_parent, self.field))
     self.request.response.setHeader('Content-Type', 'text/html')
Example #8
0
 def move(self, pos):
     """ AJAX method to change field position within its schema.
     """
     
     schema = IEditableSchema(self.schema)
     fieldname = self.field.__name__
     schema.moveField(fieldname, int(pos))
     notifyContainerModified(self.schema)
     notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
    def change(self, fieldset_index):
        """ AJAX method to change the fieldset of a field
        """
        fieldset_index = int(fieldset_index)
        fieldsets = self.schema.getTaggedValue(FIELDSETS_KEY)
        field_name = self.field.__name__

        # get current fieldset
        fieldset_fields = []
        current_fieldset = None
        for fieldset in fieldsets:
            if field_name in fieldset.fields:
                current_fieldset = fieldset

            fieldset_fields.extend(fieldset.fields)

        # get future fieldset
        if len(sortedFields(self.schema)) != len(fieldset_fields):
            # we have a default fieldset
            fieldset_index -= 1

        if fieldset_index >= 0:
            # the field has not been moved into default
            next_fieldset = fieldsets[fieldset_index]
        else:
            next_fieldset = None

        # computing new Position, which is the last position of the new fieldset
        ordered_field_ids = [
            name for (name, field) in sortedFields(self.schema)
        ]
        if next_fieldset is None:
            # if this is the default,
            new_position = ordered_field_ids.index(fieldset_fields[0])
        else:
            # first we get the first of the fieldsets after the new one
            new_position = None
            for fieldset in fieldsets[fieldsets.index(next_fieldset) + 1:]:
                if len(fieldset.fields) > 0:
                    new_position = ordered_field_ids.index(
                        fieldset.fields[0]) - 1
                    break
            else:
                new_position = len(ordered_field_ids) - 1

        schema = IEditableSchema(self.schema)
        schema.moveField(field_name, new_position)

        # move field
        if next_fieldset is not None:
            next_fieldset.fields.append(field_name)

        if current_fieldset is not None:
            current_fieldset.fields.remove(field_name)

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
    def change(self, fieldset_index):
        """ AJAX method to change the fieldset of a field
        """
        fieldset_index = int(fieldset_index)
        fieldsets = self.schema.getTaggedValue(FIELDSETS_KEY)
        field_name = self.field.__name__

        # get current fieldset
        fieldset_fields = []
        current_fieldset = None
        for fieldset in fieldsets:
            if field_name in fieldset.fields:
                current_fieldset = fieldset

            fieldset_fields.extend(fieldset.fields)

        # get future fieldset
        if len(sortedFields(self.schema)) != len(fieldset_fields):
            # we have a default fieldset
            fieldset_index -= 1

        if fieldset_index >= 0:
            # the field has not been moved into default
            next_fieldset = fieldsets[fieldset_index]
        else:
            next_fieldset = None

        # computing new Position, which is the last position of the new fieldset
        ordered_field_ids = [name for (name, field) in sortedFields(self.schema)]
        if next_fieldset is None:
            # if this is the default,
            new_position = ordered_field_ids.index(fieldset_fields[0])
        else:
            # first we get the first of the fieldsets after the new one
            new_position = None
            for fieldset in fieldsets[fieldsets.index(next_fieldset)+1:]:
                if len(fieldset.fields) > 0:
                    new_position = ordered_field_ids.index(fieldset.fields[0]) - 1
                    break
            else:
                new_position = len(ordered_field_ids) - 1

        schema = IEditableSchema(self.schema)
        schema.moveField(field_name, new_position)

        # move field
        if next_fieldset is not None:
            next_fieldset.fields.append(field_name)

        if current_fieldset is not None:
            current_fieldset.fields.remove(field_name)

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
Example #11
0
    def move(self, pos, fieldset_index):
        """ AJAX method to change field position within its schema.
        The position is relative to the fieldset.
        """
        schema = IEditableSchema(self.schema)
        fieldname = self.field.__name__
        pos = int(pos)
        fieldset_index = int(fieldset_index)
        fieldset_index -= 1  # index 0 is default fieldset

        fieldsets = self.schema.queryTaggedValue(FIELDSETS_KEY, [])
        new_fieldset = fieldset_index >= 0 and fieldsets[fieldset_index] or None
        schema.changeFieldFieldset(fieldname, new_fieldset)

        ordered_field_ids = [info[0] for info in sortedFields(self.schema)]
        if new_fieldset:
            old_field_of_position = new_fieldset.fields[pos]
            new_absolute_position = ordered_field_ids.index(
                old_field_of_position)
        else:
            new_absolute_position = pos

        # if fieldset changed, update fieldsets
        schema.moveField(fieldname, new_absolute_position)

        notifyContainerModified(self.schema)
        notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
Example #12
0
def upgrade_add_booking_behavior(context):
    portal_types = api.portal.get_tool(name='portal_types')
    event_type = portal_types.get('Event')
    fields = event_type.lookupSchema().names()

    if ('tarifs' not in fields and 'reservation' not in fields):
        # This upgrade step is specific to Liege, where those fields have been
        # added TTW.
        return

    add_behavior('Event', IBooking.__identifier__)
    for brain in api.content.find(portal_type='Event'):
        obj = brain.getObject()
        if getattr(obj, 'tarifs') is not None:
            obj.booking_price = getattr(obj, 'tarifs')
        if getattr(obj, 'reservation') is not None:
            has_booking = getattr(obj, 'reservation')
            if has_booking:
                obj.booking_type = 'mandatory'
            else:
                obj.booking_type = 'no_booking'
    schema = IEditableSchema(event_type.lookupSchema())
    schema.removeField('tarifs')
    schema.removeField('reservation')
Example #13
0
    def change(self, fieldset_index):
        """ AJAX method to change the fieldset of a field
        """
        schema = self.context.field.interface
        field_name = self.context.field.__name__
        fieldset = get_fieldset_from_index(schema, fieldset_index)
        position = new_field_position(schema, fieldset_index)

        editable_schema = IEditableSchema(schema)
        editable_schema.changeFieldFieldset(field_name, fieldset)
        editable_schema.moveField(field_name, position)

        notifyContainerModified(schema)
        notify(SchemaModifiedEvent(self.__parent__.__parent__))
Example #14
0
def upgrade_add_booking_behavior(context):
    portal_types = api.portal.get_tool(name="portal_types")
    event_type = portal_types.get("Event")
    fields = event_type.lookupSchema().names()

    if "tarifs" not in fields and "reservation" not in fields:
        # This upgrade step is specific to Liege, where those fields have been
        # added TTW.
        return

    add_behavior("Event", IBooking.__identifier__)
    for brain in api.content.find(portal_type="Event"):
        obj = brain.getObject()
        if getattr(obj, "tarifs") is not None:
            obj.booking_price = getattr(obj, "tarifs")
        if getattr(obj, "reservation") is not None:
            has_booking = getattr(obj, "reservation")
            if has_booking:
                obj.booking_type = "mandatory"
            else:
                obj.booking_type = "no_booking"
    schema = IEditableSchema(event_type.lookupSchema())
    schema.removeField("tarifs")
    schema.removeField("reservation")