class INamedImageField(interfaces.INamedImageField): default = field.NamedImage( title=interfaces.INamedImageField['default'].title, description=interfaces.INamedImageField[ 'default'].description, required=False) missing_value = field.NamedImage( title=interfaces.INamedImageField['missing_value'].title, description=interfaces.INamedImageField[ 'missing_value'].description, required=False) NamedFileFactory = FieldFactory(field.NamedFile, _(u'File Upload')) NamedImageFactory = FieldFactory(field.NamedImage, _(u'Image')) class INamedBlobFileField(interfaces.INamedBlobFileField): default = field.NamedBlobFile( title=interfaces.INamedBlobFileField['default'].title, description=interfaces.INamedBlobFileField[ 'default'].description, required=False) missing_value = field.NamedBlobFile( title=interfaces.INamedBlobFileField[ 'missing_value'].title, description=interfaces.INamedBlobFileField[
from plone.schemaeditor.fields import FieldFactory from zope import schema from zope.interface import Attribute from zope.schema import interfaces as schema_ifaces try: import plone.app.vocabularies # noqa HAS_VOCABS = True except ImportError: HAS_VOCABS = False class IRichText(interfaces.IRichText, schema_ifaces.IFromUnicode): if HAS_VOCABS: default_mime_type = schema.Choice( title=_(u'Input format'), vocabulary='plone.app.vocabularies.AllowedContentTypes', default='text/html', ) else: default_mime_type = Attribute('') # prevent some settings from being included in the field edit form default = Attribute('') output_mime_type = Attribute('') allowed_mime_types = Attribute('') RichTextFactory = FieldFactory(RichText, _(u'Rich Text'))
################################################################ # XML Binary Content ################################################################ class IXMLBinary(IField): """ Marker for XML fields """ pass class XMLBinary(NamedFileField): zope.interface.implements(IXMLBinary) XMLBinaryFactory = FieldFactory( XMLBinary, _(u'label_xml_binary_field', default=u'XML (binary data)')) XMLBinaryHandler = plone.supermodel.exportimport.BaseHandler(XMLBinary) class XMLBinaryDataManager(AttributeDataManager): """Attribute field.""" zope.component.adapts(zope.interface.Interface, IXMLBinary) suffix = '.bin' return_class = NamedFile @property def storage_key(self): context_id = util.get_storage_key(self.context) if not context_id: context_id = util.new_storage_key(self.context)
@implementer(IFromUnicode, IRichTextLabel) class RichTextLabel(Field): """A rich text field """ text = u'' def __init__(self, text=u'', **kw): self.text = text super(RichTextLabel, self).__init__(**kw) def validate(self, value): pass def fromUnicode(self, s): pass RichTextLabelFactory = FieldFactory(RichTextLabel, _(u'Instruction')) RichTextLabelHandler = BaseHandler(RichTextLabel) configure.utility( name=u'collective.flow.fields.RichTextLabel', component=u'collective.flow.fields.RichTextLabelFactory', ) configure.utility( name=u'collective.flow.fields.RichTextLabel', component=u'collective.flow.fields.RichTextLabelHandler', )
def __init__(self, rich_label=u"", checkbox_label=u"", **kw): if not isinstance(rich_label, RichTextValue): rich_label = RichTextValue(rich_label) self.rich_label = rich_label self.checkbox_label = checkbox_label super(Consent, self).__init__(**kw) def validate(self, value): if self.required: res = isChecked(value) if res: raise Invalid(res) super(Consent, self).validate(value) ConsentFactory = FieldFactory( Consent, _(u"label_consent_field", default=u"Einwilligung") ) ConsentHandler = BaseHandler(Consent) @implementer(IDivider) class Divider(Label): """ A custom label field that uses a different widget template. Intended as an alternative to the use of fieldsets.""" DividerFactory = FieldFactory(Divider, _(u"label_divider_field", default=u"Trenner")) DividerHandler = BaseHandler(Divider)
def query(self, obj): return '1' def set(self, obj, v): pass def fromUnicode(self, str): return '1' class DividerField(DescriptiveText): """Divider field""" DescriptiveTextFactory = FieldFactory( DescriptiveText, u'Descriptive Text Label (read-only)', required=False, ) DescriptiveTextHandler = plone.supermodel.exportimport.BaseHandler( DescriptiveText) DividerFieldFactory = FieldFactory( DividerField, u'Section divider', required=False, ) DividerFieldHandler = plone.supermodel.exportimport.BaseHandler(DividerField)
from plone.schema import _ from plone.schema.email import Email, IEmail from plone.schemaeditor.fields import FieldFactory from zope.interface import Attribute from zope.schema import URI from zope.schema.interfaces import IURI from plone.schema.jsonfield import IJSONField from plone.schema.jsonfield import JSONField class IURI(IURI): # prevent some settings from being included in the field edit form default = Attribute('') class IEmail(IEmail): # prevent some settings from being included in the field edit form default = Attribute('') class IJSON(IJSONField): # prevent some settings from being included in the field edit form default = Attribute('') URIFactory = FieldFactory(URI, _(u'URL')) EmailFactory = FieldFactory(Email, _(u'Email')) JSONFactory = FieldFactory(JSONField, _(u'JSONField'))
# _*_ coding: utf-8 _*_ from plone import api from plone.app.jsonfield import field from plone.app.jsonfield import interfaces from plone.app.jsonfield.compat import _ from plone.schemaeditor.fields import FieldFactory import logging __author__ = 'Md Nazrul Islam<*****@*****.**>' logger = logging.getLogger('plone.app.jsonfield') # Patch: for plone 5.x if api.env.plone_version().startswith('5'): import plone.app.dexterity.browser.types as padbt padbt.ALLOWED_FIELDS.append(u'plone.app.jsonfield.field.JSON') logger.info( 'schemaeditor: patch done! `plone.app.jsonfield.field.JSON` is added in whitelist\n' 'Location: plone.app.dexterity.browser.types.ALLOWED_FIELDS') class IJSON(interfaces.IJSON): """ """ JSONFieldFactory = FieldFactory(field.JSON, _(u'FHIR Resource Field'))
from plone.namedfile import NamedImage from xmldirector.plonecore.i18n import MessageFactory as _ from xmldirector.plonecore.dx.xml_binary import XMLBinaryDataManager ################################################################ # XML Image Content ################################################################ class IXMLImage(IField): """ Marker for XML fields """ pass class XMLImage(NamedImageField): zope.interface.implements(IXMLImage) XMLImageFactory = FieldFactory( XMLImage, _(u'label_xml_Image_field', default=u'XML (image)')) XMLImageHandler = plone.supermodel.exportimport.BaseHandler(XMLImage) class XMLImageDataManager(XMLBinaryDataManager): """Attribute field.""" zope.component.adapts(zope.interface.Interface, IXMLImage) suffix = '.img' return_class = NamedImage
class XMLText(Text): zope.interface.implements(IXMLText) def validate(self, value): """ Perform XML validation """ if value: try: lxml.etree.fromstring(normalize_xml(value)) except lxml.etree.XMLSyntaxError as e: raise zope.interface.Invalid(u'XML syntax error {}'.format(e)) return super(XMLText, self).validate(value) XMLTextFactory = FieldFactory(XMLText, _(u'label_xml_field', default=u'XML (Text)')) XMLTextHandler = plone.supermodel.exportimport.BaseHandler(XMLText) class XMLFieldDataManager(z3c.form.datamanager.AttributeField): """A dedicated manager for XMLText field.""" zope.component.adapts(zope.interface.Interface, IXMLText) def __init__(self, context, field): self.context = context self.field = field @property def storage_key(self): context_id = util.get_storage_key(self.context)
# limit size of the preview for text areas if hasattr(widget, 'rows'): if widget.rows is None or widget.rows > 5: widget.rows = 5 return form.Form.render(self) class SQLTypeFieldsPage(TypeFieldsPage): @property def tabs(self): tabs = super(SQLTypeFieldsPage, self).tabs tabs += ((_('Data'), '@@data'), ) return tabs @property def form(self): if self.context.fti.hasDynamicSchema: return SQLEnhancedSchemaListing else: return ReadOnlySchemaListing TupleFactory = FieldFactory(schema.Tuple, _(u'label_tuple_field', default=u'Tuple')) class ITuple(schema.interfaces.ITuple, schema.interfaces.IFromUnicode): pass
for item in catalog(**query)[:self.field.limit]: terms.append( SimpleVocabulary.createTerm(item.id, item.id, item.Title)) value = SimpleVocabulary(terms) if request is not None: request.environ[cache_key] = value return value # so we can still resolve correctly alsoProvides(QueryChoiceSource, IContextSourceBinder) QueryChoiceFactory = FieldFactory( QueryChoice, _(u'label_query_choice_field', default=u'Query Choice'), source=QueryChoiceSource) class IQueryChoiceFieldSchema(IField): form.widget(query=QueryFieldWidget) query = schema.List( title=u'Query', value_type=schema.Dict(value_type=schema.Field(), key_type=schema.TextLine()), required=False ) sort_on = schema.TextLine( title=u'Sort on', required=False,
return @implementer(IRichLabel) class RichLabel(Label): """A Rich Label field """ rich_label = u"" def __init__(self, rich_label=u"", **kw): self.rich_label = rich_label super(RichLabel, self).__init__(**kw) LabelFactory = FieldFactory(Label, _(u"label_label_field", default=u"Label")) RichLabelFactory = FieldFactory( RichLabel, _(u"label_richlabel_field", default=u"Rich Label")) LabelHandler = BaseHandler(Label) RichLabelHandler = BaseHandler(RichLabel) @implementer(IReCaptcha) class ReCaptcha(TextLine): """A ReCaptcha field """ ReCaptchaFactory = FieldFactory( ReCaptcha, _(u"label_recaptcha_field", default=u"ReCaptcha"))
from StringIO import StringIO from csv import writer as csvwriter from smdu.participacao.browser.field import MapaField from plone.schemaeditor.fields import FieldFactory from smdu.participacao.interfaces import IMapa MapaFactory = FieldFactory(MapaField, 'Mapa') def getSavedFormInputForEdit(self, header=False, delimiter=','): """ returns saved as CSV text """ sbuf = StringIO() writer = csvwriter(sbuf, delimiter=delimiter) names = self.getColumnNames() titles = self.getColumnTitles() if header: encoded_titles = [] for t in titles: if isinstance(t, unicode): t = t.encode('utf-8') encoded_titles.append(t) writer.writerow(encoded_titles) for row in self.getSavedFormInput(): def get_data(row, i): data = row.get(i, '') if self._is_file_data(data): return data.filename elif IMapa.providedBy(data): return (data.latitude, data.longitude)
@property def tabs(self): tabs = super(SQLTypeFieldsPage, self).tabs tabs += ((_('Data'), '@@data'), ) return tabs @property def form(self): if self.context.fti.hasDynamicSchema: return SQLEnhancedSchemaListing else: return ReadOnlySchemaListing TupleFactory = FieldFactory(schema.Tuple, _(u'label_tuple_field', default=u'Tuple'), value_type=schema.Choice(values=[])) class ITuple(schema.interfaces.ITuple, schema.interfaces.IFromUnicode): pass class SQLCollectionTermsVocabulary(CollectionTermsVocabulary): """ITerms adapter for zope.schema.ICollection based implementations using vocabulary.""" zope.component.adapts(ISQLDexterityItem, iz3cform.IFormLayer, zope.interface.Interface, zope.schema.interfaces.ICollection, zope.schema.interfaces.IBaseVocabulary,
""" return class RichLabel(Label): """A Rich Label field """ implements(IRichLabel) rich_label = u'' def __init__(self, rich_label=u'', **kw): self.rich_label = rich_label super(RichLabel, self).__init__(**kw) LabelFactory = FieldFactory(Label, _(u'label_label_field', default=u'Label')) RichLabelFactory = FieldFactory( RichLabel, _(u'label_richlabel_field', default=u'Rich Label')) LabelHandler = BaseHandler(Label) RichLabelHandler = BaseHandler(RichLabel) class ReCaptcha(TextLine): """A ReCaptcha field """ implements(IReCaptcha) ReCaptchaFactory = FieldFactory( ReCaptcha, _(u'label_recaptcha_field', default=u'ReCaptcha'))
from plone.schema import _ from plone.schema.email import Email, IEmail from plone.schemaeditor.fields import FieldFactory from zope.interface import Attribute from zope.schema import URI from zope.schema.interfaces import IURI class IURI(IURI): # prevent some settings from being included in the field edit form default = Attribute('') class IEmail(IEmail): # prevent some settings from being included in the field edit form default = Attribute('') URIFactory = FieldFactory(URI, _(u'URL')) EmailFactory = FieldFactory(Email, _(u'Email'))
zope.interface.implements(IXMLXPath) def validate(self, value): if value: mo = parse_field_expression(value) try: fieldname, xpath_expr = mo except TypeError: raise zope.interface.Invalid( u'Invalid specification ({})'.format(value)) return super(XMLXPath, self).validate(value) XMLXPathFactory = FieldFactory( XMLXPath, _(u'label_xml_xpath_field', default=u'XML (extended XPath expression)')) XMLXPathHandler = plone.supermodel.exportimport.BaseHandler(XMLXPath) from xmldirector.plonecore.dx.xml_field import XMLFieldDataManager class IXPathWidget(IWidget): pass class XPathWidget(text.TextWidget): """ Widget for XPath expressions.""" zope.interface.implementsOnly(IXPathWidget) def xpath_evaluated(self):
raise Invalid(_(u'Invalid email address')) return True class EmailField(schema.TextLine): def __init__(self, *args, **kwargs): super(schema.TextLine, self).__init__(*args, **kwargs) def _validate(self, value): super(schema.TextLine, self)._validate(value) validate_email(value) # referenced by configuration.zcml to register the Email fields from plone.schemaeditor.fields import FieldFactory EmailFieldFactory = FieldFactory(EmailField, _(u'Email')) from plone.supermodel.exportimport import BaseHandler EmailFieldHandler = BaseHandler(EmailField) class IOverview(Interface): """ Views implementing this interface may use the OverviewletManager to display an overview of a list of resources. The OverviewletManager displays viewlets which work with a list of resources in a folderish view. Those resources are not required to actually be stored in that folder. They just need to be defined using this interface. The result may be something like this, with the part on the right side