Started view for dmsthesaurus (pair work with Fred)
This commit is contained in:
parent
0518dda031
commit
74ff838ee8
|
@ -28,4 +28,13 @@
|
|||
permission="zope2.View"
|
||||
/>
|
||||
|
||||
<browser:page
|
||||
name="view"
|
||||
for="collective.dms.thesaurus.dmsthesaurus.IDmsThesaurus"
|
||||
layer="plone.app.z3cform.interfaces.IPloneFormLayer"
|
||||
class="collective.dms.thesaurus.browser.thesaurusview.DmsThesaurusView"
|
||||
template="dmsthesaurus_view.pt"
|
||||
permission="zope2.View"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
xmlns:metal="http://xml.zope.org/namespaces/metal"
|
||||
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
|
||||
lang="en"
|
||||
metal:use-macro="context/main_template/macros/master"
|
||||
i18n:domain="plone.app.dexterity">
|
||||
<body>
|
||||
|
||||
<metal:main fill-slot="main">
|
||||
|
||||
<h1 class="documentFirstHeading" tal:content="context/Title" />
|
||||
<div tal:replace="structure provider:plone.belowcontenttitle" />
|
||||
|
||||
<form id="thesaurus-search-form"
|
||||
tal:content="structure view/renderForm"
|
||||
onsubmit="window.location=window.location+'/'+document.forms['thesaurus-search-form']['form-widgets-keyword_search'].value; return false" />
|
||||
|
||||
<ul>
|
||||
<tal:elems repeat="ep view/context/entry_points">
|
||||
<li tal:content="ep" />
|
||||
</tal:elems>
|
||||
</ul>
|
||||
|
||||
</metal:main>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
xmlns:metal="http://xml.zope.org/namespaces/metal">
|
||||
<body>
|
||||
<metal:use use-macro="context/@@ploneform-macros/fields" />
|
||||
<metal:use use-macro="context/@@ploneform-macros/actions" />
|
||||
</body>
|
||||
</html>
|
|
@ -1,16 +1,41 @@
|
|||
from zope.component import getUtility
|
||||
from zope import schema
|
||||
from zope.interface import Interface
|
||||
|
||||
from zope.app.intid.interfaces import IIntIds
|
||||
from z3c.form import form, button, field
|
||||
from plone.z3cform import layout
|
||||
from plone.formwidget.autocomplete.widget import AutocompleteFieldWidget
|
||||
|
||||
from zc.relation.interfaces import ICatalog
|
||||
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
|
||||
|
||||
from plone.dexterity.browser.view import DefaultView
|
||||
from Products.Five.browser import BrowserView
|
||||
|
||||
#from plone.dexterity.interfaces import IDexterityFTI
|
||||
#from plone.dexterity.utils import getAdditionalSchemata
|
||||
|
||||
from collective.dms.thesaurus.dmsthesaurus import GlobalThesaurusSource
|
||||
|
||||
class DmsThesaurusView(DefaultView):
|
||||
"""The default view for DMSThesaurus.
|
||||
"""
|
||||
|
||||
class IThesaurusForm(Interface):
|
||||
keyword_search = schema.Choice(title=u"Search for keyword",
|
||||
source=GlobalThesaurusSource(), required=False)
|
||||
|
||||
|
||||
class DmsThesaurusForm(form.Form):
|
||||
fields = field.Fields(IThesaurusForm)
|
||||
#fields['keyword_search'].widgetFactory = AutocompleteFieldWidget
|
||||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('thesaurus_form.pt')
|
||||
|
||||
@button.buttonAndHandler(u'Ok')
|
||||
def handle_ok(self, action):
|
||||
data, errors = self.extractData()
|
||||
print data, errors
|
||||
|
||||
class DmsThesaurusView(BrowserView):
|
||||
|
||||
def renderForm(self):
|
||||
form = DmsThesaurusForm(self.context, self.request)
|
||||
form.update()
|
||||
return form.render()
|
||||
|
|
@ -1,16 +1,27 @@
|
|||
#import datetime
|
||||
#from zope import schema
|
||||
from zope import schema
|
||||
#from zope.component import adapts
|
||||
from zope.interface import implements
|
||||
from zope.component import adapter
|
||||
from zope.interface import implementer
|
||||
from z3c.form.widget import FieldWidget, SequenceWidget
|
||||
|
||||
#from plone.dexterity.content import Container
|
||||
from plone.dexterity.schema import DexteritySchemaPolicy
|
||||
from plone.dexterity.content import Container
|
||||
|
||||
from zope.schema.interfaces import ISet
|
||||
from zope.schema.interfaces import IFromUnicode
|
||||
from z3c.form.interfaces import IFormLayer, IFieldWidget, ISequenceWidget
|
||||
|
||||
from plone.formwidget.autocomplete.widget import AutocompleteMultiSelectionWidget
|
||||
|
||||
from plone.supermodel import model
|
||||
|
||||
from . import _
|
||||
|
||||
from vocabulary import GlobalThesaurusSource
|
||||
|
||||
#from plone.autoform import directives as form
|
||||
#from plone.directives.form import default_value
|
||||
|
||||
|
@ -18,9 +29,28 @@ class NoThesaurusFound(Exception):
|
|||
"""No thesaurus found"""
|
||||
|
||||
|
||||
class IEntryPoints(ISet):
|
||||
pass
|
||||
|
||||
class EntryPoints(schema.Set):
|
||||
implements(IEntryPoints, IFromUnicode)
|
||||
|
||||
|
||||
@adapter(IEntryPoints, IFormLayer)
|
||||
@implementer(IFieldWidget)
|
||||
def EntryPointsFieldWidget(field, request):
|
||||
return FieldWidget(field, AutocompleteMultiSelectionWidget(request))
|
||||
|
||||
|
||||
class IDmsThesaurus(model.Schema):
|
||||
""" """
|
||||
|
||||
entry_points = EntryPoints(
|
||||
title=_(u"Entry Points"),
|
||||
value_type=schema.Choice(source=GlobalThesaurusSource())
|
||||
)
|
||||
|
||||
|
||||
class DmsThesaurus(Container):
|
||||
""" """
|
||||
implements(IDmsThesaurus)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
from zope.interface import Interface
|
||||
#from zope.interface import implements
|
||||
from zope.interface import implements
|
||||
from five import grok
|
||||
|
||||
from zope.schema.interfaces import IContextSourceBinder
|
||||
|
||||
#from zope.component import queryUtility
|
||||
from zope.schema.interfaces import IVocabularyFactory
|
||||
#from zope.schema.interfaces import ISource, IContextSourceBinder
|
||||
|
@ -14,9 +16,14 @@ class IMainThesaurus(Interface):
|
|||
""" Marker interface for main thesaurus container
|
||||
"""
|
||||
|
||||
class ThesaurusVocabulary(SimpleVocabulary):
|
||||
|
||||
def search(self, query_string):
|
||||
q = query_string.lower()
|
||||
return [kw for kw in self._terms if q in kw.title.lower()]
|
||||
|
||||
class GlobalThesaurusSource(object):
|
||||
grok.implements(IVocabularyFactory)
|
||||
implements(IContextSourceBinder)
|
||||
|
||||
def __call__(self, context):
|
||||
catalog = getToolByName(context, 'portal_catalog')
|
||||
|
@ -25,18 +32,18 @@ class GlobalThesaurusSource(object):
|
|||
def cmp_keyword(x, y):
|
||||
return cmp(x.title, y.title)
|
||||
keywords.sort(cmp_keyword)
|
||||
keyword_ids = [x.id for x in keywords]
|
||||
#keyword_ids = [x.id for x in keywords]
|
||||
keyword_terms = [SimpleVocabulary.createTerm(
|
||||
x.id, x.id, x.title) for x in keywords]
|
||||
return SimpleVocabulary(keyword_terms)
|
||||
return ThesaurusVocabulary(keyword_terms)
|
||||
|
||||
def __iter__(self):
|
||||
# hack to let schema editor handle the field
|
||||
yield u'DO NOT TOUCH'
|
||||
|
||||
|
||||
grok.global_utility(GlobalThesaurusSource,
|
||||
name=u'dms.thesaurus.global')
|
||||
#grok.global_utility(GlobalThesaurusSource,
|
||||
# name=u'dms.thesaurus.global')
|
||||
|
||||
class KeywordFromSameThesaurusSource(object):
|
||||
"""
|
||||
|
|
|
@ -28,5 +28,6 @@
|
|||
template="thesaurus-keyword-equivs-display.pt"
|
||||
/>
|
||||
|
||||
<!-- adapter factory=".dmsthesaurus.EntryPointsFieldWidget"/-->
|
||||
|
||||
</configure>
|
||||
|
|
Reference in New Issue