initial commit
This commit is contained in:
commit
22e8a10bf9
|
@ -0,0 +1 @@
|
||||||
|
*.pyc
|
|
@ -0,0 +1,26 @@
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
import sys, os
|
||||||
|
|
||||||
|
version = '0.1'
|
||||||
|
|
||||||
|
setup(name='themis.fields',
|
||||||
|
version=version,
|
||||||
|
description="",
|
||||||
|
long_description="""\
|
||||||
|
""",
|
||||||
|
classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
|
||||||
|
keywords='',
|
||||||
|
author="Entr'ouvert",
|
||||||
|
author_email='',
|
||||||
|
url='',
|
||||||
|
license='AGPL',
|
||||||
|
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
|
||||||
|
include_package_data=True,
|
||||||
|
zip_safe=False,
|
||||||
|
install_requires=[
|
||||||
|
# -*- Extra requirements: -*-
|
||||||
|
],
|
||||||
|
entry_points="""
|
||||||
|
# -*- Entry points: -*-
|
||||||
|
""",
|
||||||
|
)
|
|
@ -0,0 +1,10 @@
|
||||||
|
Metadata-Version: 1.0
|
||||||
|
Name: themis.fields
|
||||||
|
Version: 0.1dev
|
||||||
|
Summary: UNKNOWN
|
||||||
|
Home-page: UNKNOWN
|
||||||
|
Author: Entr'ouvert
|
||||||
|
Author-email: UNKNOWN
|
||||||
|
License: AGPL
|
||||||
|
Description: UNKNOWN
|
||||||
|
Platform: UNKNOWN
|
|
@ -0,0 +1,14 @@
|
||||||
|
setup.cfg
|
||||||
|
setup.py
|
||||||
|
themis.fields.egg-info/PKG-INFO
|
||||||
|
themis.fields.egg-info/SOURCES.txt
|
||||||
|
themis.fields.egg-info/dependency_links.txt
|
||||||
|
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/interfaces.py
|
||||||
|
themisfields/value.py
|
||||||
|
themisfields/widget.py
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
# -*- Entry points: -*-
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
themisfields
|
|
@ -0,0 +1,35 @@
|
||||||
|
from zope.interface import implements
|
||||||
|
from zope.schema import Choice, Field
|
||||||
|
|
||||||
|
from zope.schema.interfaces import IFromUnicode
|
||||||
|
from zope.schema.interfaces import WrongType
|
||||||
|
|
||||||
|
from themisfields.interfaces import ICommission
|
||||||
|
from themisfields.vocabs import CommissionsSource
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<configure
|
||||||
|
xmlns="http://namespaces.zope.org/zope"
|
||||||
|
xmlns:zcml="http://namespaces.zope.org/zcml"
|
||||||
|
i18n_domain="themisfields">
|
||||||
|
|
||||||
|
<!-- Configure plone.supermodel support if available -->
|
||||||
|
<include zcml:condition="installed plone.supermodel"
|
||||||
|
file="handlers.zcml"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Configure z3c.form widget if z3c.form is installed -->
|
||||||
|
<include zcml:condition="installed z3c.form"
|
||||||
|
file="widgets.zcml"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Configure plone.schemaeditor field factory if installed -->
|
||||||
|
<include zcml:condition="installed plone.schemaeditor"
|
||||||
|
file="editors.zcml"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<utility component=".vocabs.CommissionsVocabularyFactory"
|
||||||
|
name="themisfields.vocabulary.Commissions"/>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<adapter
|
||||||
|
for=".vocabs.CommissionsSource
|
||||||
|
zope.publisher.interfaces.browser.IBrowserRequest"
|
||||||
|
factory=".vocabs.CommissionsSourceQueryView"
|
||||||
|
provides="zope.browser.interfaces.ITerms"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<adapter
|
||||||
|
for=".vocabs.CommissionsSource
|
||||||
|
zope.publisher.interfaces.browser.IBrowserRequest"
|
||||||
|
factory=".vocabs.CommissionsSourceQueryView"
|
||||||
|
provides="zope.app.form.browser.interfaces.ISourceQueryView"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</configure>
|
|
@ -0,0 +1,10 @@
|
||||||
|
from zope.schema import interfaces as schema_ifaces
|
||||||
|
|
||||||
|
from themisfields import interfaces
|
||||||
|
from themisfields import Commission
|
||||||
|
from plone.schemaeditor.fields import FieldFactory
|
||||||
|
|
||||||
|
class ICommission(interfaces.ICommission, schema_ifaces.IFromUnicode):
|
||||||
|
pass
|
||||||
|
|
||||||
|
CommissionFactory = FieldFactory(Commission, u'Commission')
|
|
@ -0,0 +1,10 @@
|
||||||
|
<configure
|
||||||
|
xmlns="http://namespaces.zope.org/zope"
|
||||||
|
i18n_domain="themisfields">
|
||||||
|
|
||||||
|
<utility
|
||||||
|
name="themisfields.Commission"
|
||||||
|
component=".editors.CommissionFactory"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</configure>
|
|
@ -0,0 +1,18 @@
|
||||||
|
try:
|
||||||
|
from plone.supermodel.exportimport import BaseHandler, ChoiceHandler
|
||||||
|
HAVE_SUPERMODEL = True
|
||||||
|
except ImportError:
|
||||||
|
HAVE_SUPERMODEL = False
|
||||||
|
|
||||||
|
if HAVE_SUPERMODEL:
|
||||||
|
|
||||||
|
from zope.interface import implements
|
||||||
|
from zope.component import adapts
|
||||||
|
from themisfields import Commission
|
||||||
|
from plone.supermodel.interfaces import IToUnicode
|
||||||
|
from themisfields.interfaces import ICommission
|
||||||
|
|
||||||
|
class CommissionHandler_(BaseHandler):
|
||||||
|
pass
|
||||||
|
|
||||||
|
CommissionHandler = CommissionHandler_(Commission)
|
|
@ -0,0 +1,12 @@
|
||||||
|
<configure
|
||||||
|
xmlns="http://namespaces.zope.org/zope"
|
||||||
|
i18n_domain="themisfields">
|
||||||
|
|
||||||
|
<!-- plone.supermodel configuration -->
|
||||||
|
|
||||||
|
<utility
|
||||||
|
component=".handlers.CommissionHandler"
|
||||||
|
name="themisfields.Commission"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</configure>
|
|
@ -0,0 +1,8 @@
|
||||||
|
from zope.interface import Interface
|
||||||
|
|
||||||
|
from zope.schema.interfaces import IChoice, IField
|
||||||
|
from zope import schema
|
||||||
|
|
||||||
|
class ICommission(IField):
|
||||||
|
'''Field containing a unicode string without newlines that is a commission.'''
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
from zope.browser.interfaces import ITerms
|
||||||
|
from zope.interface import implements, classProvides
|
||||||
|
from zope.schema.interfaces import ISource, IContextSourceBinder
|
||||||
|
|
||||||
|
from zope.app.form.browser.interfaces import ISourceQueryView
|
||||||
|
|
||||||
|
from zope.schema.interfaces import IVocabularyFactory
|
||||||
|
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
|
||||||
|
|
||||||
|
class CommissionsSource(object):
|
||||||
|
implements(ISource)
|
||||||
|
classProvides(IContextSourceBinder)
|
||||||
|
|
||||||
|
def __init__(self, context=None):
|
||||||
|
self.terms = ['pomme', 'poire', 'peche', 'abricot']
|
||||||
|
|
||||||
|
def __contains__(self, value):
|
||||||
|
if self.get(value) is None:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def search(self, query):
|
||||||
|
return [SimpleTerm(x, x, x) for x in self.terms if x.startswith(query)]
|
||||||
|
|
||||||
|
def get(self, value):
|
||||||
|
if value in self.terms:
|
||||||
|
return value
|
||||||
|
return None
|
||||||
|
|
||||||
|
class CommissionsSourceQueryView(object):
|
||||||
|
implements(ITerms, ISourceQueryView)
|
||||||
|
|
||||||
|
def __init__(self, context, request):
|
||||||
|
self.context = context
|
||||||
|
self.request = request
|
||||||
|
|
||||||
|
def getTerm(self, value):
|
||||||
|
commission = self.context.get(value)
|
||||||
|
token = value
|
||||||
|
title = value
|
||||||
|
return SimpleTerm(value, token=user, title=user)
|
||||||
|
|
||||||
|
def getValue(self, token):
|
||||||
|
if token not in self.context:
|
||||||
|
raise LookupError(token)
|
||||||
|
return token
|
||||||
|
|
||||||
|
def render(self, name):
|
||||||
|
return name
|
||||||
|
|
||||||
|
def results(self, name):
|
||||||
|
# check whether the normal search button was pressed
|
||||||
|
if name+".search" in self.request.form:
|
||||||
|
query_fieldname = name+".query"
|
||||||
|
if query_fieldname in self.request.form:
|
||||||
|
query = self.request.form[query_fieldname]
|
||||||
|
if query != '':
|
||||||
|
return self.context.search(query)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#class CommissionsVocabulary(object):
|
||||||
|
# implements(IVocabularyFactory)
|
||||||
|
#
|
||||||
|
# def __call__(self, context):
|
||||||
|
# terms = [SimpleVocabulary.createTerm(x, x, x) for x in ['pomme', 'poire', 'peche', 'abricot']]
|
||||||
|
# return SimpleVocabulary(terms)
|
||||||
|
#
|
||||||
|
#CommissionsVocabularyFactory = CommissionsVocabulary()
|
|
@ -0,0 +1,28 @@
|
||||||
|
from Acquisition import ImplicitAcquisitionWrapper
|
||||||
|
|
||||||
|
from zope.interface import implementsOnly, implementer
|
||||||
|
from zope.component import adapts, adapter
|
||||||
|
|
||||||
|
from z3c.form.interfaces import IFormLayer, IFieldWidget
|
||||||
|
from z3c.form.widget import FieldWidget
|
||||||
|
|
||||||
|
from themisfields.interfaces import ICommission
|
||||||
|
|
||||||
|
from plone.formwidget.autocomplete.interfaces import IAutocompleteWidget
|
||||||
|
from plone.formwidget.autocomplete.widget import AutocompleteSelectionWidget
|
||||||
|
from plone.formwidget.autocomplete import AutocompleteFieldWidget
|
||||||
|
|
||||||
|
class ICommissionWidget(IAutocompleteWidget):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class CommissionWidget(AutocompleteSelectionWidget):
|
||||||
|
implementsOnly(ICommissionWidget)
|
||||||
|
klass = u'commissionWidget'
|
||||||
|
|
||||||
|
|
||||||
|
@adapter(ICommission, IFormLayer)
|
||||||
|
@implementer(IFieldWidget)
|
||||||
|
def CommissionFieldWidget(field, request):
|
||||||
|
"""IFieldWidget factory for CommissionWidget."""
|
||||||
|
return FieldWidget(field, AutocompleteSelectionWidget(request))
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<configure
|
||||||
|
xmlns="http://namespaces.zope.org/zope"
|
||||||
|
xmlns:z3c="http://namespaces.zope.org/z3c"
|
||||||
|
xmlns:browser="http://namespaces.zope.org/browser"
|
||||||
|
i18n_domain="themisfields">
|
||||||
|
|
||||||
|
<include package="z3c.form" file="meta.zcml" />
|
||||||
|
<include package="z3c.form" />
|
||||||
|
|
||||||
|
<adapter factory=".widgets.CommissionFieldWidget"/>
|
||||||
|
|
||||||
|
</configure>
|
Reference in New Issue