74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
from zope.interface import implements
|
|
from zope.schema import Choice, Field, List, Date
|
|
|
|
from zope.schema.interfaces import IFromUnicode
|
|
from zope.schema.interfaces import WrongType
|
|
|
|
from themisfields.interfaces import ICommission
|
|
from themisfields.vocabs import CommissionsSource
|
|
|
|
from themisfields.interfaces import IAuthor
|
|
from themisfields.vocabs import AuthorsSource
|
|
|
|
from themisfields.interfaces import IAuthors
|
|
|
|
|
|
class Commission(Field):
|
|
implements(ICommission, IFromUnicode)
|
|
|
|
def __init__(self, **kw):
|
|
self.vocabulary = CommissionsSource
|
|
super(Commission, self).__init__(**kw)
|
|
|
|
source = property(lambda self: self.vocabulary)
|
|
|
|
def bind(self, object):
|
|
"""See zope.schema._bootstrapinterfaces.IField."""
|
|
clone = super(Commission, self).bind(object)
|
|
clone.vocabulary = self.vocabulary(object)
|
|
return clone
|
|
|
|
def _validate(self, value):
|
|
super(Commission, self)._validate(value)
|
|
vocabulary = self.vocabulary
|
|
if value not in vocabulary:
|
|
raise ConstraintNotSatisfied(value)
|
|
|
|
def fromUnicode(self, str):
|
|
self.validate(str)
|
|
return str
|
|
|
|
class Author(Field):
|
|
implements(IAuthor, IFromUnicode)
|
|
|
|
def __init__(self, **kw):
|
|
self.vocabulary = AuthorsSource
|
|
super(Author, self).__init__(**kw)
|
|
|
|
source = property(lambda self: self.vocabulary)
|
|
|
|
def bind(self, object):
|
|
"""See zope.schema._bootstrapinterfaces.IField."""
|
|
clone = super(Author, self).bind(object)
|
|
clone.vocabulary = self.vocabulary(object)
|
|
return clone
|
|
|
|
def _validate(self, value):
|
|
super(Author, self)._validate(value)
|
|
vocabulary = self.vocabulary
|
|
if value not in vocabulary:
|
|
raise ConstraintNotSatisfied(value)
|
|
|
|
def fromUnicode(self, str):
|
|
self.validate(str)
|
|
return str
|
|
|
|
class Authors(List):
|
|
implements(IAuthors)
|
|
|
|
def __init__(self, **kw):
|
|
kw['value_type'] = Author(title=u'Author')
|
|
kw['unique'] = False
|
|
super(Authors, self).__init__(**kw)
|
|
|