From 661d3aa0d6d42701bac6731d52e96d5ab7af91a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 13 Jun 2011 21:38:31 +0200 Subject: [PATCH] =?UTF-8?q?Working=20"subjects"=20(mati=C3=A8res)=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themis.fields.egg-info/SOURCES.txt | 8 ++-- themisfields/__init__.py | 24 ++++++++++- themisfields/configure.zcml | 3 ++ themisfields/editors.py | 16 ++++++++ themisfields/editors.zcml | 5 +++ themisfields/handlers.py | 6 +++ themisfields/handlers.zcml | 6 +++ themisfields/interfaces.py | 5 ++- themisfields/vocabs.py | 64 ++++++++++++++++++++++++++++-- themisfields/widgets.py | 20 ++++++++++ themisfields/widgets.zcml | 2 + 11 files changed, 149 insertions(+), 10 deletions(-) diff --git a/themis.fields.egg-info/SOURCES.txt b/themis.fields.egg-info/SOURCES.txt index 3ea6a13..29c16b1 100644 --- a/themis.fields.egg-info/SOURCES.txt +++ b/themis.fields.egg-info/SOURCES.txt @@ -7,8 +7,8 @@ themis.fields.egg-info/entry_points.txt themis.fields.egg-info/not-zip-safe themis.fields.egg-info/top_level.txt themisfields/__init__.py -themisfields/editor.py -themisfields/handler.py +themisfields/editors.py +themisfields/handlers.py themisfields/interfaces.py -themisfields/value.py -themisfields/widget.py \ No newline at end of file +themisfields/vocabs.py +themisfields/widgets.py \ No newline at end of file diff --git a/themisfields/__init__.py b/themisfields/__init__.py index 97e6e28..1e21683 100644 --- a/themisfields/__init__.py +++ b/themisfields/__init__.py @@ -1,4 +1,4 @@ -from zope.interface import implements +from zope.interface import implements, implementsOnly from zope.schema import Choice, Field, List, Date from zope.schema.interfaces import IFromUnicode @@ -12,6 +12,9 @@ from themisfields.vocabs import AuthorsSource from themisfields.interfaces import IAuthors +from themisfields.interfaces import IDate +from themisfields.interfaces import ISubjects, IList + class Commission(Field): implements(ICommission, IFromUnicode) @@ -71,3 +74,22 @@ class Authors(List): kw['unique'] = False super(Authors, self).__init__(**kw) + +from vocabs import SubjectsVocabulary, SubjectsVocabularyFactory +from vocabs import SubjectsSource + +class Subjects(Field): + implements(ISubjects, IList) + _type = list + + def __init__(self, **kw): + self.required = False + self.value_type = Choice(source=SubjectsSource()) + self.unique = True + self.min_length = None + self.max_length = None + + for attr in ('min_length', 'max_length', 'unique', 'value_type'): + if attr in kw: del kw[attr] + super(Subjects, self).__init__(**kw) + diff --git a/themisfields/configure.zcml b/themisfields/configure.zcml index d85d1e7..995bd5b 100644 --- a/themisfields/configure.zcml +++ b/themisfields/configure.zcml @@ -18,6 +18,9 @@ file="editors.zcml" /> + + +