half working authorS field
This commit is contained in:
parent
e9a424c5c9
commit
45a577d394
|
@ -1,5 +1,5 @@
|
|||
from zope.interface import implements
|
||||
from zope.schema import Choice, Field
|
||||
from zope.schema import Choice, Field, List
|
||||
|
||||
from zope.schema.interfaces import IFromUnicode
|
||||
from zope.schema.interfaces import WrongType
|
||||
|
@ -10,6 +10,8 @@ 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)
|
||||
|
@ -61,3 +63,11 @@ class Author(Field):
|
|||
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)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ from zope.schema import interfaces as schema_ifaces
|
|||
from themisfields import interfaces
|
||||
from themisfields import Commission
|
||||
from themisfields import Author
|
||||
from themisfields import Authors
|
||||
from plone.schemaeditor.fields import FieldFactory
|
||||
|
||||
class ICommission(interfaces.ICommission, schema_ifaces.IFromUnicode):
|
||||
|
@ -15,3 +16,9 @@ class IAuthor(interfaces.IAuthor, schema_ifaces.IFromUnicode):
|
|||
pass
|
||||
|
||||
AuthorFactory = FieldFactory(Author, u'Author')
|
||||
|
||||
|
||||
class IAuthors(interfaces.IAuthors, schema_ifaces.IList):
|
||||
pass
|
||||
|
||||
AuthorsFactory = FieldFactory(Authors, u'Author(s)')
|
||||
|
|
|
@ -12,4 +12,9 @@
|
|||
component=".editors.AuthorFactory"
|
||||
/>
|
||||
|
||||
<utility
|
||||
name="themisfields.Authors"
|
||||
component=".editors.AuthorsFactory"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
try:
|
||||
from plone.supermodel.exportimport import BaseHandler, ChoiceHandler
|
||||
from plone.supermodel.fields import ListHandler
|
||||
HAVE_SUPERMODEL = True
|
||||
except ImportError:
|
||||
HAVE_SUPERMODEL = False
|
||||
|
@ -16,6 +17,9 @@ if HAVE_SUPERMODEL:
|
|||
from themisfields import Author
|
||||
from themisfields.interfaces import IAuthor
|
||||
|
||||
from themisfields import Authors
|
||||
from themisfields.interfaces import IAuthors
|
||||
|
||||
class CommissionHandler_(BaseHandler):
|
||||
pass
|
||||
|
||||
|
@ -25,3 +29,8 @@ if HAVE_SUPERMODEL:
|
|||
pass
|
||||
|
||||
AuthorHandler = AuthorHandler_(Author)
|
||||
|
||||
class AuthorsHandler_(BaseHandler):
|
||||
pass
|
||||
|
||||
AuthorsHandler = AuthorsHandler_(Authors)
|
||||
|
|
|
@ -14,4 +14,9 @@
|
|||
name="themisfields.Author"
|
||||
/>
|
||||
|
||||
<utility
|
||||
component=".handlers.AuthorsHandler"
|
||||
name="themisfields.Authors"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from zope.interface import Interface
|
||||
|
||||
from zope.schema.interfaces import IChoice, IField
|
||||
from zope.schema.interfaces import IChoice, IField, IList
|
||||
from zope import schema
|
||||
|
||||
class ICommission(IField):
|
||||
|
@ -9,3 +9,5 @@ class ICommission(IField):
|
|||
class IAuthor(IField):
|
||||
'''Field containing a unicode string without newlines that is an author.'''
|
||||
|
||||
class IAuthors(IList):
|
||||
'''Field containing a list of authors'''
|
||||
|
|
Reference in New Issue