Ejemplo n.º 1
0
    def publishTraverse(self, request, name):
        view = queryMultiAdapter((self.context, request), name=name)
        if view is not None:
            return view

        ct = queryUtility(IContentType, name)
        if ct is not None:
            schema = IContentSchema(ct, None)
            if schema is not None:
                schema.__name__ = name
                schema.__parent__ = self.context
                return schema

        raise NotFound(self, name, request)
Ejemplo n.º 2
0
class ContentSchemaView(PageletDisplayForm):

    @property
    def fields(self):
        schema = self.schema
        data = schema.getSchemaData()

        fields = []
        for name, field in IOrder(schema).items():
            if data.get(name, field.missing_value) is not field.missing_value:
                fields.append(field)

        return Fields(*fields)

    def update(self):
        self.schema = IContentSchema(self.context)

        if self.schema is not None:
            super(ContentSchemaView, self).update()

    def getContent(self):
        return self.schema.getSchemaData()

    def render(self):
        if self.schema is None or not self.fields:
            return u''

        return super(ContentSchemaView, self).render()
Ejemplo n.º 3
0
 def applyChanges(self, data):
     self.schema = IContentSchema(self.parentForm._addedObject)
     changes = self.schema.setSchemaData(data)
     if changes:
         return {IContentSchema: changes}
     else:
         return {}
Ejemplo n.º 4
0
class ContentSchemaAdd(PageletAddSubForm):

    schema = None
    prefix = 'content.schema'
    label = _('Custom fields')

    @property
    def fields(self):
        return Fields(*list(IOrder(self.schema).values()))

    def getContent(self):
        return {}

    def update(self):
        schema = IContentSchema(self.context, None)

        if schema is not None:
            self.schema = schema
            super(ContentSchemaAdd, self).update()

    def isAvailable(self):
        return self.schema is not None and len(self.schema)

    def applyChanges(self, data):
        self.schema = IContentSchema(self.parentForm._addedObject)
        changes = self.schema.setSchemaData(data)
        if changes:
            return {IContentSchema: changes}
        else:
            return {}
Ejemplo n.º 5
0
    def update(self):
        self.schema = IContentSchema(self.context)

        if self.schema is not None:
            super(ContentSchemaView, self).update()