class BannerBoxSchema(ContentSchema): file = colander.SchemaNode( FileData(), title=_(u'File'), widget=FileUploadWidget(tmpstore), validator=validate_file_size_limit, ) link = colander.SchemaNode( colander.String(), title=_('Link'), validator=link_validator, missing=u'', )
class BannerBoxAddForm(ImageAddForm): item_type = _(u"Banner Box") item_class = BannerBox def schema_factory(self): tmpstore = FileUploadTempStore(self.request) return BannerBoxSchema(tmpstore) def save_success(self, appstruct): # overried this method (no filename as title # like images) return AddFormView.save_success(self, appstruct) def add(self, **appstruct): # override (no tags in our form) buf = appstruct['file']['fp'].read() filename = appstruct['file']['filename'] return self.item_class( title=appstruct['title'] or filename, description=appstruct['description'], data=buf, filename=filename, link=appstruct.get('link', u''), mimetype=appstruct['file']['mimetype'], size=len(buf), )
class LeftBoxManagerAddForm(AddFormView): """ Form to add a new instance of BoxManager. """ schema_factory = LeftBoxManagerSchema add = LeftBoxManager item_type = _(u"LeftBoxManager")
def after_bind(self, node, kw): super(BelowContentBoxManagerSchema, self).after_bind(node, kw) node['title'].default = _('BelowContentBoxManager')
def after_bind(self, node, kw): super(AboveFooterBoxManagerSchema, self).after_bind(node, kw) node['title'].default = _('AboveFooterBoxManager')
def after_bind(self, node, kw): super(LeftBoxManagerSchema, self).after_bind(node, kw) node['title'].default = _('LeftBoxManager')
class BelowContentBoxManagerAddForm(AddFormView): """ Form to add a new instance of BoxManager. """ schema_factory = BelowContentBoxManagerSchema add = BelowContentBoxManager item_type = _(u"BelowContentBoxManager")
class AboveFooterBoxManagerAddForm(AddFormView): """ Form to add a new instance of BoxManager. """ schema_factory = AboveFooterBoxManagerSchema add = AboveFooterBoxManager item_type = _(u"AboveFooterBoxManager")
def raise_invalid_url(node, value): raise colander.Invalid(node, _(u"You must provide a valid url."))