diff --git a/src/collective/dms/thesaurus/browser/dmskeyword_view.pt b/src/collective/dms/thesaurus/browser/dmskeyword_view.pt
index c69716b..bd0d320 100644
--- a/src/collective/dms/thesaurus/browser/dmskeyword_view.pt
+++ b/src/collective/dms/thesaurus/browser/dmskeyword_view.pt
@@ -30,12 +30,8 @@
[]
+ >
+
-
+
diff --git a/src/collective/dms/thesaurus/browser/thesaurusview.py b/src/collective/dms/thesaurus/browser/thesaurusview.py
index 58411a3..515bd3c 100644
--- a/src/collective/dms/thesaurus/browser/thesaurusview.py
+++ b/src/collective/dms/thesaurus/browser/thesaurusview.py
@@ -2,23 +2,23 @@ from zope import schema
from zope.interface import Interface
from z3c.form import form, button, field
-from plone.z3cform import layout
-from plone.formwidget.autocomplete.widget import AutocompleteFieldWidget
+#from plone.z3cform import layout
+#from plone.formwidget.autocomplete.widget import AutocompleteFieldWidget
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
from plone.dexterity.browser.view import DefaultView
-from Products.Five.browser import BrowserView
+#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
+from collective.dms.thesaurus.vocabulary import InternalThesaurusSource
class IThesaurusForm(Interface):
keyword_search = schema.Choice(title=u"Search for keyword",
- source=GlobalThesaurusSource(), required=False)
+ source=InternalThesaurusSource(), required=False)
class DmsThesaurusForm(form.Form):
@@ -32,7 +32,7 @@ class DmsThesaurusForm(form.Form):
data, errors = self.extractData()
print data, errors
-class DmsThesaurusView(BrowserView):
+class DmsThesaurusView(DefaultView):
def renderForm(self):
form = DmsThesaurusForm(self.context, self.request)
diff --git a/src/collective/dms/thesaurus/dmsthesaurus.py b/src/collective/dms/thesaurus/dmsthesaurus.py
index 0a64dd6..150e0e8 100644
--- a/src/collective/dms/thesaurus/dmsthesaurus.py
+++ b/src/collective/dms/thesaurus/dmsthesaurus.py
@@ -1,26 +1,25 @@
#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 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 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 .entrypointsfield import EntryPoints
#from plone.autoform import directives as form
#from plone.directives.form import default_value
@@ -28,38 +27,19 @@ from vocabulary import GlobalThesaurusSource
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())
- )
+ title=_(u"Entry Points"),
+ description=_(u"First level of navigation for this Thesaurus"),
+ required=False)
class DmsThesaurus(Container):
""" """
implements(IDmsThesaurus)
- @property
- def nav_entry_points(self):
- entry_ids = ["001157243"]
- return entry_ids
-
class DmsThesaurusSchemaPolicy(DexteritySchemaPolicy):
""" """
diff --git a/src/collective/dms/thesaurus/entrypoints_display.pt b/src/collective/dms/thesaurus/entrypoints_display.pt
new file mode 100644
index 0000000..43ce052
--- /dev/null
+++ b/src/collective/dms/thesaurus/entrypoints_display.pt
@@ -0,0 +1,9 @@
+
\ No newline at end of file
diff --git a/src/collective/dms/thesaurus/entrypointsfield.py b/src/collective/dms/thesaurus/entrypointsfield.py
new file mode 100644
index 0000000..5595c78
--- /dev/null
+++ b/src/collective/dms/thesaurus/entrypointsfield.py
@@ -0,0 +1,94 @@
+#from Acquisition import aq_parent
+
+from zope.interface import implements, implementer
+from zope.component import adapter
+
+from zope import schema
+from zope.schema.interfaces import IChoice, IContextSourceBinder
+#from zope.schema.interfaces import IVocabularyFactory
+from zope.schema.vocabulary import SimpleVocabulary
+#from zope.schema.vocabulary import SimpleTerm
+#from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from zope.schema.interfaces import ISet
+from zope.schema.interfaces import IFromUnicode
+
+from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
+
+from z3c.form.interfaces import IFormLayer, IFieldWidget
+#from z3c.form.interfaces import IWidget
+from z3c.form.widget import FieldWidget
+#from z3c.form.widget import Widget
+#from z3c.form.browser.select import SelectWidget
+
+from plone.formwidget.autocomplete.interfaces import IAutocompleteWidget
+from plone.formwidget.autocomplete.widget import AutocompleteMultiSelectionWidget
+
+from Products.CMFCore.utils import getToolByName
+
+#from . import _
+
+from collective.dms.thesaurus.vocabulary import InternalThesaurusSource
+
+class IEntryPointChoice(IChoice):
+ """Thesaurus Entry Point Choice Item.
+ """
+
+class EntryPointChoice(schema.Choice):
+ implements(IEntryPointChoice, IFromUnicode)
+
+class IEntryPoints(ISet):
+ """Thesaurus Entry Point List.
+ """
+
+class EntryPoints(schema.Set):
+ implements(IEntryPoints, IFromUnicode)
+
+ def __init__(self, **kw):
+ vt = kw.pop('value_type',
+ #EntryPointChoice(
+ schema.Choice(
+ required=False,
+ source=InternalThesaurusSource())
+ )
+ super(EntryPoints, self).__init__(value_type=vt, **kw)
+
+
+class EntryPointsWidget(AutocompleteMultiSelectionWidget):
+
+ klass = u"entrypoints-widget"
+ display_template = ViewPageTemplateFile('entrypoints_display.pt')
+
+ #def __init__(self, request):
+ # super(EntryPointsWidget, self).__init__(request)
+
+ def items(self):
+ value = []
+ for token in self.value:
+ # Ignore no value entries. They are in the request only.
+ if token == self.noValueToken:
+ continue
+ term = self.terms.getTermByToken(token)
+ value.append({'id': token, 'value': term.value,
+ 'content': term.title, 'selected': True
+ })
+ return value
+
+ def displayItems(self):
+ path = '/'.join(self.context.getPhysicalPath())
+ value = []
+ for token in self.value:
+ # Ignore no value entries. They are in the request only.
+ if token == self.noValueToken:
+ continue
+ term = self.terms.getTermByToken(token)
+ value.append(
+ {'title': term.title,
+ 'href': '/'.join((path, term.value))
+ })
+ return value
+
+@adapter(IEntryPoints, IFormLayer)
+@implementer(IFieldWidget)
+def EntryPointsFieldWidget(field, request):
+ return FieldWidget(field, EntryPointsWidget(request))
+
diff --git a/src/collective/dms/thesaurus/locales/collective.dms.thesaurus.pot b/src/collective/dms/thesaurus/locales/collective.dms.thesaurus.pot
index a3118a2..1f6ebe0 100644
--- a/src/collective/dms/thesaurus/locales/collective.dms.thesaurus.pot
+++ b/src/collective/dms/thesaurus/locales/collective.dms.thesaurus.pot
@@ -17,6 +17,14 @@ msgstr ""
"Preferred-Encodings: utf-8 latin1\n"
"Domain: collective.dms.thesaurus\n"
+#: ./dmsthesaurus.py
+msgid "Entry Points"
+msgstr ""
+
+#: ./dmsthesaurus.py
+msgid "First level of navigation for this Thesaurus"
+msgstr ""
+
#: ./dmskeyword.py
msgid "EQ (Equivalences)"
msgstr ""
diff --git a/src/collective/dms/thesaurus/locales/en/LC_MESSAGES/collective.dms.thesaurus.po b/src/collective/dms/thesaurus/locales/en/LC_MESSAGES/collective.dms.thesaurus.po
index ba5103e..0048d08 100644
--- a/src/collective/dms/thesaurus/locales/en/LC_MESSAGES/collective.dms.thesaurus.po
+++ b/src/collective/dms/thesaurus/locales/en/LC_MESSAGES/collective.dms.thesaurus.po
@@ -15,6 +15,10 @@ msgstr ""
"Domain: plone\n"
"X-is-fallback-for: en-au en-ca en-gb en-us\n"
+#: ./dmsthesaurus.py
+msgid "Entry Points"
+msgstr ""
+
#: ./dmskeyword.py
msgid "EQ (Equivalences)"
msgstr ""
diff --git a/src/collective/dms/thesaurus/locales/fr/LC_MESSAGES/collective.dms.thesaurus.po b/src/collective/dms/thesaurus/locales/fr/LC_MESSAGES/collective.dms.thesaurus.po
index de7376d..ace2d3c 100644
--- a/src/collective/dms/thesaurus/locales/fr/LC_MESSAGES/collective.dms.thesaurus.po
+++ b/src/collective/dms/thesaurus/locales/fr/LC_MESSAGES/collective.dms.thesaurus.po
@@ -15,6 +15,14 @@ msgstr ""
"Domain: plone\n"
"X-is-fallback-for: fr-fr fr-be fr-ca\n"
+#: ./dmsthesaurus.py
+msgid "Entry Points"
+msgstr "Points d'entrée"
+
+#: ./dmsthesaurus.py
+msgid "First level of navigation for this Thesaurus"
+msgstr "Premier niveau de navigation dans ce thésaurus"
+
#: ./dmskeyword.py
msgid "EQ (Equivalences)"
msgstr "Employé pour (équivalences)"
diff --git a/src/collective/dms/thesaurus/thesaurus-keyword-equivs-display.pt b/src/collective/dms/thesaurus/thesaurus-keyword-equivs-display.pt
index 8e029db..cf2f514 100644
--- a/src/collective/dms/thesaurus/thesaurus-keyword-equivs-display.pt
+++ b/src/collective/dms/thesaurus/thesaurus-keyword-equivs-display.pt
@@ -1,20 +1,8 @@
-(nothing)
+[]
+
+(nothing)
diff --git a/src/collective/dms/thesaurus/vocabulary.py b/src/collective/dms/thesaurus/vocabulary.py
index cb217b1..f0637cc 100644
--- a/src/collective/dms/thesaurus/vocabulary.py
+++ b/src/collective/dms/thesaurus/vocabulary.py
@@ -22,6 +22,29 @@ class ThesaurusVocabulary(SimpleVocabulary):
q = query_string.lower()
return [kw for kw in self._terms if q in kw.title.lower()]
+
+class InternalThesaurusSource(object):
+ implements(IContextSourceBinder)
+
+ def __call__(self, context):
+ catalog = getToolByName(context, 'portal_catalog')
+ path = '/'.join(context.getPhysicalPath())
+ results = catalog(portal_type='dmskeyword',
+ path={'query': path,'depth': 1})
+ keywords = [x.getObject() for x in results]
+ def cmp_keyword(x, y):
+ return cmp(x.title, y.title)
+ keywords.sort(cmp_keyword)
+ #keyword_ids = [x.id for x in keywords]
+ _c = SimpleVocabulary.createTerm
+ keyword_terms = [ _c(x.id, x.id, x.title) for x in keywords ]
+ return ThesaurusVocabulary(keyword_terms)
+
+ def __iter__(self):
+ # hack to let schema editor handle the field
+ yield u'DO NOT TOUCH'
+
+
class GlobalThesaurusSource(object):
implements(IContextSourceBinder)
@@ -45,6 +68,7 @@ class GlobalThesaurusSource(object):
#grok.global_utility(GlobalThesaurusSource,
# name=u'dms.thesaurus.global')
+
class KeywordFromSameThesaurusSource(object):
"""
This vocabulary is used for keywords that reference one another
@@ -54,7 +78,10 @@ class KeywordFromSameThesaurusSource(object):
grok.implements(IVocabularyFactory)
def __call__(self, context):
- thesaurus_path = '/'.join(context.thesaurusPath())
+ if context.portal_type == 'dmsthesaurus':
+ thesaurus_path = '/'.join(context.getPhysicalPath())
+ else:
+ thesaurus_path = '/'.join(context.thesaurusPath())
catalog = getToolByName(context, 'portal_catalog')
results = catalog(portal_type='dmskeyword',
path={'query': thesaurus_path,'depth': 1})
diff --git a/src/collective/dms/thesaurus/widgets.zcml b/src/collective/dms/thesaurus/widgets.zcml
index 9f334da..1e97231 100644
--- a/src/collective/dms/thesaurus/widgets.zcml
+++ b/src/collective/dms/thesaurus/widgets.zcml
@@ -28,6 +28,7 @@
template="thesaurus-keyword-equivs-display.pt"
/>
-
+
+