Simplify sending types behavior and vocabulary
This commit is contained in:
parent
49a9b553bb
commit
7f22bc3463
|
@ -1,26 +1,28 @@
|
|||
from z3c.form.browser.radio import RadioFieldWidget
|
||||
from zope.interface import alsoProvides
|
||||
from zope.schema import Choice
|
||||
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
|
||||
|
||||
from plone.autoform.interfaces import IFormFieldProvider
|
||||
from plone.autoform import directives as form
|
||||
from plone.directives.form import default_value
|
||||
from plone.supermodel import model
|
||||
|
||||
from collective.dms.mailcontent import _
|
||||
|
||||
|
||||
sending_types = SimpleVocabulary([
|
||||
SimpleTerm(value='normal', title=_(u'Normal')),
|
||||
SimpleTerm(value='registered', title=_(u'Registered')),
|
||||
])
|
||||
|
||||
|
||||
class ISendingType(model.Schema):
|
||||
"""Sending type behavior"""
|
||||
sending_type = Choice(title=_(u"Sending type"),
|
||||
vocabulary='SendingTypes',
|
||||
vocabulary=sending_types,
|
||||
default='normal',
|
||||
required=False)
|
||||
form.widget(sending_type=RadioFieldWidget)
|
||||
|
||||
|
||||
@default_value(field=ISendingType['sending_type'])
|
||||
def sending_type_default_value(data):
|
||||
return "normal"
|
||||
|
||||
|
||||
alsoProvides(ISendingType, IFormFieldProvider)
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
from five import grok
|
||||
|
||||
from zope.schema.vocabulary import SimpleVocabulary
|
||||
from zope.schema.interfaces import IVocabularyFactory
|
||||
|
||||
from . import _
|
||||
|
||||
|
||||
class SendingTypes(grok.GlobalUtility):
|
||||
grok.name("SendingTypes")
|
||||
grok.implements(IVocabularyFactory)
|
||||
|
||||
def __call__(self, context):
|
||||
terms = []
|
||||
types = [('normal', _("Normal")),
|
||||
('registered', _("Registered"))]
|
||||
for (token, value) in types:
|
||||
term = SimpleVocabulary.createTerm(token, token, value)
|
||||
terms.append(term)
|
||||
return SimpleVocabulary(terms)
|
Reference in New Issue