nimrud / conex / src / conex / types / browser /

Full commit
from z3c.form import form
from z3c.form import field
from zope.component import getUtility
from conex.types import interfaces
from zope import schema

class DefaultAddForm(form.AddForm):
    """A simple add form for concave content"""
    def fields(self):
        if self.request.get("type") is not None:
            type_name = self.request.get("type")
            type_name = self.request.form[u'form.widgets.type_name']
        factory = getUtility(interfaces.IConcaveTypesFactory, "conex.TypesFactory")
        content_type = factory.known_classes[type_name]
        #TODO: This should be refactored to return something more meaningful
        #than the first schema the class provides -- schemata anyone?
        fields = field.Fields(content_type.schemas[0])
        type_field = field.Fields(schema.TextLine(__name__=str("type_name"),
                                                  title=u"type name",
        return fields + type_field

    def create(self, data):
        factory = getUtility(interfaces.IConcaveTypesFactory, "conex.TypesFactory")
        #XXX: There's probably a saner way to get the typename, but it's late
        new_content = factory.create_object(data.get("type_name"))
        del data["type_name"]
        form.applyChanges(self, new_content, data)
        return new_content

    def add(self, new_content):
        #Todo: This should actually be a name-chooser adapter, and it should 
        #probably handle puntuation and multiple spaces
        #see pp 294 of Web Component Development with Zope 3
        self._name = new_content.title.lower().replace(' ', '-')
        self.context[self._name] = new_content

    def nextURL(self):
        #TODO: When we have a default display, that should be the return value
        return '/'