view for keyword now uses implementation without intIds
This commit is contained in:
parent
7416350c25
commit
0518dda031
|
@ -52,14 +52,21 @@
|
||||||
</dd></dl>
|
</dd></dl>
|
||||||
|
|
||||||
|
|
||||||
<tal:related define="widget python:view.widgets.get('related')">
|
<div class="field" id="dmskeywords-navigation-related-field">
|
||||||
<div id="dmskeywords-navigation-related-field"
|
<label tal:content="string:RT (Related Terms)" />
|
||||||
class="field">
|
<br />
|
||||||
<label tal:content="widget/label" />
|
<tal:list condition="view/related">
|
||||||
<br />
|
<ul id="" class=""
|
||||||
<div tal:content="structure widget/render" />
|
tal:attributes="id string:form-widgets-related;
|
||||||
</div>
|
class string:contenttree-widget relatedthesauruskeywords-field;
|
||||||
</tal:related>
|
"><li tal:repeat="value view/related"
|
||||||
|
><a href="#"
|
||||||
|
tal:content="value/label"
|
||||||
|
tal:attributes="href value/url"
|
||||||
|
/></li
|
||||||
|
></ul></tal:list>
|
||||||
|
<em tal:condition="not:view/related">none</em>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -71,13 +78,12 @@
|
||||||
tal:attributes="id string:form-widgets-children;
|
tal:attributes="id string:form-widgets-children;
|
||||||
class string:contenttree-widget narrowerthesauruskeywords-field;
|
class string:contenttree-widget narrowerthesauruskeywords-field;
|
||||||
"><li tal:repeat="value view/children"
|
"><li tal:repeat="value view/children"
|
||||||
><a class="selected-option"
|
><a href="#"
|
||||||
href="#"
|
|
||||||
tal:content="value/label"
|
tal:content="value/label"
|
||||||
tal:attributes="href value/url"
|
tal:attributes="href value/url"
|
||||||
/></li
|
/></li
|
||||||
></ul></tal:list>
|
></ul></tal:list>
|
||||||
<em tal:condition="not:view/children">(nothing)</em>
|
<em tal:condition="not:view/children">none</em>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
from zope.component import getUtility
|
||||||
|
|
||||||
|
from zope.app.intid.interfaces import IIntIds
|
||||||
|
|
||||||
|
from zc.relation.interfaces import ICatalog
|
||||||
|
|
||||||
|
from plone.dexterity.browser.view import DefaultView
|
||||||
|
|
||||||
|
#from plone.dexterity.interfaces import IDexterityFTI
|
||||||
|
#from plone.dexterity.utils import getAdditionalSchemata
|
||||||
|
|
||||||
|
|
||||||
|
class DmsThesaurusView(DefaultView):
|
||||||
|
"""The default view for DMSThesaurus.
|
||||||
|
"""
|
||||||
|
|
|
@ -1,41 +1,57 @@
|
||||||
from zope.component import getUtility
|
from Products.CMFCore.utils import getToolByName
|
||||||
|
|
||||||
from zope.app.intid.interfaces import IIntIds
|
|
||||||
|
|
||||||
from zc.relation.interfaces import ICatalog
|
|
||||||
|
|
||||||
from plone.dexterity.browser.view import DefaultView
|
from plone.dexterity.browser.view import DefaultView
|
||||||
|
|
||||||
#from plone.dexterity.interfaces import IDexterityFTI
|
|
||||||
#from plone.dexterity.utils import getAdditionalSchemata
|
|
||||||
|
|
||||||
|
|
||||||
class DmsKeywordView(DefaultView):
|
class DmsKeywordView(DefaultView):
|
||||||
"""The default view for DMSKeyword.
|
"""The default view for DMSKeyword.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def children(self):
|
def children(self):
|
||||||
return []
|
|
||||||
"""
|
"""
|
||||||
intids = getUtility(IIntIds)
|
Search in catalog for keywords that have context as broader term.
|
||||||
catalog = getUtility(ICatalog)
|
Query is restricted to same thesaurus.
|
||||||
value = []
|
Returns a list of dicts with ``url`` and ``label`` attributes.
|
||||||
try:
|
"""
|
||||||
doc_intid = intids.getId(self.context)
|
thesaurus_path = '/'.join(self.context.thesaurusPath())
|
||||||
except KeyError:
|
catalog = getToolByName(self.context, 'portal_catalog')
|
||||||
pass
|
brains = catalog.searchResults(portal_type='dmskeyword',
|
||||||
else:
|
path={'query': thesaurus_path,'depth': 1},
|
||||||
for ref in catalog.findRelations(
|
broaderThesaurusKeywords=self.context.id)
|
||||||
{'to_id': doc_intid, 'from_attribute': 'broader'}):
|
refs = []
|
||||||
tp = dict(
|
for ref in brains:
|
||||||
url=ref.from_path,
|
if ref.id != self.context.id:
|
||||||
label=ref.from_object.Title(),
|
refs.append({'url':ref.getPath(), 'label':ref.Title})
|
||||||
hn=ref.from_object.historical_note,
|
def cmp_ref(x, y):
|
||||||
sn=ref.from_object.scope_note
|
return cmp(x['label'], y['label'])
|
||||||
)
|
refs.sort(cmp_ref)
|
||||||
if tp not in value:
|
return refs
|
||||||
value.append(tp)
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def related(self):
|
||||||
"""
|
"""
|
||||||
|
Search in catalog for keywords that have context as broader term.
|
||||||
|
Query is restricted to same thesaurus.
|
||||||
|
Returns a list of dicts with ``url`` and ``label`` attributes.
|
||||||
|
"""
|
||||||
|
refs = []
|
||||||
|
related = self.context.related
|
||||||
|
thesaurus = self.context.thesaurus()
|
||||||
|
thesaurus_path = '/'.join(thesaurus.getPhysicalPath())
|
||||||
|
for ref in related:
|
||||||
|
kw = getattr(thesaurus, ref)
|
||||||
|
refs.append({'url': '/'.join(kw.getPhysicalPath()),
|
||||||
|
'label': kw.Title()})
|
||||||
|
catalog = getToolByName(self.context, 'portal_catalog')
|
||||||
|
brains = catalog.searchResults(
|
||||||
|
portal_type='dmskeyword',
|
||||||
|
path={'query': thesaurus_path,'depth': 1},
|
||||||
|
relatedThesaurusKeywords=self.context.id
|
||||||
|
)
|
||||||
|
for brain in brains:
|
||||||
|
ref = {'url':brain.getPath(), 'label':brain.Title}
|
||||||
|
if brain.id != self.context.id and ref not in refs:
|
||||||
|
refs.append(ref)
|
||||||
|
def cmp_ref(x, y):
|
||||||
|
return cmp(x['label'], y['label'])
|
||||||
|
refs.sort(cmp_ref)
|
||||||
|
return refs
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#import datetime
|
#import datetime
|
||||||
|
from Acquisition import aq_parent
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
|
|
||||||
from zope import schema
|
from zope import schema
|
||||||
|
@ -11,6 +12,7 @@ from plone.supermodel import model
|
||||||
from . import _
|
from . import _
|
||||||
from .keywordsfield import ThesaurusKeywords
|
from .keywordsfield import ThesaurusKeywords
|
||||||
from .equivalencesfield import ThesaurusKeywordEquivalences
|
from .equivalencesfield import ThesaurusKeywordEquivalences
|
||||||
|
from .dmsthesaurus import NoThesaurusFound
|
||||||
|
|
||||||
class IDmsKeyword(model.Schema):
|
class IDmsKeyword(model.Schema):
|
||||||
""" """
|
""" """
|
||||||
|
@ -25,7 +27,7 @@ class IDmsKeyword(model.Schema):
|
||||||
broader = ThesaurusKeywords(
|
broader = ThesaurusKeywords(
|
||||||
title=_(u"BT (Broader Terms)"),
|
title=_(u"BT (Broader Terms)"),
|
||||||
required=False,
|
required=False,
|
||||||
vocabulary=u'dms.thesaurus.samesource'
|
vocabulary=u'dms.thesaurus.internalrefs'
|
||||||
)
|
)
|
||||||
|
|
||||||
# RT: related term
|
# RT: related term
|
||||||
|
@ -33,7 +35,7 @@ class IDmsKeyword(model.Schema):
|
||||||
title=_(u"RT (Related Terms)"),
|
title=_(u"RT (Related Terms)"),
|
||||||
required=False,
|
required=False,
|
||||||
display_backrefs=True,
|
display_backrefs=True,
|
||||||
vocabulary=u'dms.thesaurus.samesource'
|
vocabulary=u'dms.thesaurus.internalrefs'
|
||||||
)
|
)
|
||||||
|
|
||||||
# HN: historical note
|
# HN: historical note
|
||||||
|
@ -48,11 +50,29 @@ class IDmsKeyword(model.Schema):
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def thesaurus():
|
||||||
|
"""get parent thesaurus"""
|
||||||
|
|
||||||
|
def thesaurusPath():
|
||||||
|
"""get parent thesaurus physical path"""
|
||||||
|
|
||||||
|
|
||||||
class DmsKeyword(Item):
|
class DmsKeyword(Item):
|
||||||
""" """
|
""" """
|
||||||
implements(IDmsKeyword)
|
implements(IDmsKeyword)
|
||||||
|
|
||||||
|
def thesaurus(self):
|
||||||
|
thesaurus = self
|
||||||
|
while thesaurus.portal_type != "dmsthesaurus":
|
||||||
|
thesaurus = aq_parent(thesaurus)
|
||||||
|
if not hasattr(thesaurus, 'portal_type') or getattr(thesaurus, 'portal_type', None) is None:
|
||||||
|
raise NoThesaurusFound
|
||||||
|
return thesaurus
|
||||||
|
|
||||||
|
def thesaurusPath(self):
|
||||||
|
return self.thesaurus().getPhysicalPath()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DmsKeywordSchemaPolicy(DexteritySchemaPolicy):
|
class DmsKeywordSchemaPolicy(DexteritySchemaPolicy):
|
||||||
""" """
|
""" """
|
||||||
|
|
|
@ -14,6 +14,10 @@ from . import _
|
||||||
#from plone.autoform import directives as form
|
#from plone.autoform import directives as form
|
||||||
#from plone.directives.form import default_value
|
#from plone.directives.form import default_value
|
||||||
|
|
||||||
|
class NoThesaurusFound(Exception):
|
||||||
|
"""No thesaurus found"""
|
||||||
|
|
||||||
|
|
||||||
class IDmsThesaurus(model.Schema):
|
class IDmsThesaurus(model.Schema):
|
||||||
""" """
|
""" """
|
||||||
|
|
||||||
|
@ -21,6 +25,11 @@ class DmsThesaurus(Container):
|
||||||
""" """
|
""" """
|
||||||
implements(IDmsThesaurus)
|
implements(IDmsThesaurus)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nav_entry_points(self):
|
||||||
|
entry_ids = ["001157243"]
|
||||||
|
return entry_ids
|
||||||
|
|
||||||
|
|
||||||
class DmsThesaurusSchemaPolicy(DexteritySchemaPolicy):
|
class DmsThesaurusSchemaPolicy(DexteritySchemaPolicy):
|
||||||
""" """
|
""" """
|
||||||
|
|
|
@ -5,7 +5,7 @@ from plone.indexer import indexer
|
||||||
|
|
||||||
class IDmsKeywordIndexer(Interface):
|
class IDmsKeywordIndexer(Interface):
|
||||||
"""Dexterity behavior interface for enabling the dynamic SearchableText
|
"""Dexterity behavior interface for enabling the dynamic SearchableText
|
||||||
indexer on Document objecgs."""
|
indexer on Document objects."""
|
||||||
|
|
||||||
|
|
||||||
@indexer(IDmsKeywordIndexer)
|
@indexer(IDmsKeywordIndexer)
|
||||||
|
|
|
@ -13,10 +13,8 @@ from z3c.form.widget import FieldWidget, SequenceWidget
|
||||||
#from z3c.form.widget import Widget
|
#from z3c.form.widget import Widget
|
||||||
#from z3c.form.browser.select import SelectWidget
|
#from z3c.form.browser.select import SelectWidget
|
||||||
|
|
||||||
|
|
||||||
from . import _
|
from . import _
|
||||||
|
|
||||||
|
|
||||||
class IThesaurusKeywords(ISet):
|
class IThesaurusKeywords(ISet):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -35,10 +33,19 @@ class IThesaurusKeywordsWidget(ISequenceWidget):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NoThesaurusFound(Exception):
|
|
||||||
"""No thesaurus found"""
|
|
||||||
|
|
||||||
|
|
||||||
|
JS_TEMPLATE = """
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('a.kw_add_link').prepOverlay({
|
||||||
|
subtype: 'ajax',
|
||||||
|
filter: '#content>*',
|
||||||
|
urlmatch: '.*',
|
||||||
|
urlreplace: '%(thesaurus_url)s'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
"""
|
||||||
|
|
||||||
class ThesaurusKeywordsWidget(SequenceWidget):
|
class ThesaurusKeywordsWidget(SequenceWidget):
|
||||||
implements(IThesaurusKeywordsWidget)
|
implements(IThesaurusKeywordsWidget)
|
||||||
|
|
||||||
|
@ -46,6 +53,13 @@ class ThesaurusKeywordsWidget(SequenceWidget):
|
||||||
self.display_backrefs = display_backrefs
|
self.display_backrefs = display_backrefs
|
||||||
super(ThesaurusKeywordsWidget, self).__init__(request)
|
super(ThesaurusKeywordsWidget, self).__init__(request)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def js(self):
|
||||||
|
thesaurus_path = '/'.join(self.context.thesaurusPath())
|
||||||
|
return JS_TEMPLATE % dict(
|
||||||
|
thesaurus_url=thesaurus_path
|
||||||
|
)
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
value = []
|
value = []
|
||||||
for token in self.value:
|
for token in self.value:
|
||||||
|
@ -59,25 +73,21 @@ class ThesaurusKeywordsWidget(SequenceWidget):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def displayItems(self):
|
def displayItems(self):
|
||||||
thesaurus = self.context
|
thesaurus_path = '/'.join(self.context.thesaurusPath())
|
||||||
|
|
||||||
# XXX attention on remonte a partir d'un document ou d'un kw
|
|
||||||
|
|
||||||
value = []
|
value = []
|
||||||
for token in self.value:
|
for token in self.value:
|
||||||
# Ignore no value entries. They are in the request only.
|
# Ignore no value entries. They are in the request only.
|
||||||
if token == self.noValueToken:
|
if token == self.noValueToken:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
term = self.terms.getTermByToken(token)
|
term = self.terms.getTermByToken(token)
|
||||||
|
|
||||||
value.append(
|
value.append(
|
||||||
{'title': term.title,
|
{'title': term.title,
|
||||||
'href': '#dummy',
|
'href': thesaurus_path + '/' + term.value,
|
||||||
})
|
})
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@adapter(IThesaurusKeywords, IFormLayer)
|
@adapter(IThesaurusKeywords, IFormLayer)
|
||||||
@implementer(IFieldWidget)
|
@implementer(IFieldWidget)
|
||||||
def ThesaurusKeywordsFieldWidget(field, request):
|
def ThesaurusKeywordsFieldWidget(field, request):
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<object name="portal_catalog" meta_type="Plone Catalog Tool">
|
<object name="portal_catalog" meta_type="Plone Catalog Tool">
|
||||||
<column value="historical_note"/>
|
<column value="historical_note" />
|
||||||
<column value="scope_note"/>
|
<column value="scope_note" />
|
||||||
|
<index name="broaderThesaurusKeywords" meta_type="KeywordIndex">
|
||||||
|
<indexed_attr value="broader" />
|
||||||
|
</index>
|
||||||
|
<index name="relatedThesaurusKeywords" meta_type="KeywordIndex">
|
||||||
|
<indexed_attr value="related" />
|
||||||
|
</index>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
@ -26,11 +26,13 @@
|
||||||
><span class="selected-option"
|
><span class="selected-option"
|
||||||
tal:attributes="data-term-id item/value">
|
tal:attributes="data-term-id item/value">
|
||||||
<span tal:content="item/content"
|
<span tal:content="item/content"
|
||||||
/> <span class="remove">×</span></span><tal:block condition="not:repeat/item/end">, </tal:block
|
/> <span class="remove">×</span></span
|
||||||
|
><tal:block condition="not:repeat/item/end">, </tal:block
|
||||||
></tal:block
|
></tal:block
|
||||||
></span>
|
></span>
|
||||||
|
|
||||||
<!--script type="text/javascript" tal:content="structure view/js"></script-->
|
<a href="#" class="kw_add_link">Add keyword</a>
|
||||||
|
<script type="text/javascript" tal:content="structure view/js"></script>
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
span.selected-option {
|
span.selected-option {
|
||||||
|
@ -48,5 +50,4 @@ span.remove {
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<button onclick="return false;">Add</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -30,10 +30,6 @@ class ImportJson(BrowserView):
|
||||||
title=term.get('title'))
|
title=term.get('title'))
|
||||||
object = getattr(self.context, term_id)
|
object = getattr(self.context, term_id)
|
||||||
notify(ObjectAddedEvent(object))
|
notify(ObjectAddedEvent(object))
|
||||||
#try:
|
|
||||||
# term_intids[term_id] = self.intids.getId(object)
|
|
||||||
#except KeyError:
|
|
||||||
# self.intids.register(object)
|
|
||||||
object.title = term.get('title')
|
object.title = term.get('title')
|
||||||
object.historical_note = term.get('historical_note')
|
object.historical_note = term.get('historical_note')
|
||||||
object.scope_note = term.get('scope_note')
|
object.scope_note = term.get('scope_note')
|
||||||
|
|
|
@ -7,7 +7,6 @@ from zope.schema.interfaces import IVocabularyFactory
|
||||||
#from zope.schema.interfaces import ISource, IContextSourceBinder
|
#from zope.schema.interfaces import ISource, IContextSourceBinder
|
||||||
from zope.schema.vocabulary import SimpleVocabulary
|
from zope.schema.vocabulary import SimpleVocabulary
|
||||||
#from zope.schema.vocabulary import SimpleTerm
|
#from zope.schema.vocabulary import SimpleTerm
|
||||||
|
|
||||||
from Products.CMFCore.utils import getToolByName
|
from Products.CMFCore.utils import getToolByName
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,16 +39,23 @@ grok.global_utility(GlobalThesaurusSource,
|
||||||
name=u'dms.thesaurus.global')
|
name=u'dms.thesaurus.global')
|
||||||
|
|
||||||
class KeywordFromSameThesaurusSource(object):
|
class KeywordFromSameThesaurusSource(object):
|
||||||
|
"""
|
||||||
|
This vocabulary is used for keywords that reference one another
|
||||||
|
inside the same thesaurus. It should not be used for referencing
|
||||||
|
keywords from other content types.
|
||||||
|
"""
|
||||||
grok.implements(IVocabularyFactory)
|
grok.implements(IVocabularyFactory)
|
||||||
|
|
||||||
def __call__(self, context):
|
def __call__(self, context):
|
||||||
#XXX: need to add url filter
|
thesaurus_path = '/'.join(context.thesaurusPath())
|
||||||
catalog = getToolByName(context, 'portal_catalog')
|
catalog = getToolByName(context, 'portal_catalog')
|
||||||
results = catalog(portal_type='dmskeyword')
|
results = catalog(portal_type='dmskeyword',
|
||||||
|
path={'query': thesaurus_path,'depth': 1})
|
||||||
keywords = [x.getObject() for x in results]
|
keywords = [x.getObject() for x in results]
|
||||||
def cmp_keyword(x, y):
|
def cmp_keyword(x, y):
|
||||||
return cmp(x.title, y.title)
|
return cmp(x.title, y.title)
|
||||||
keywords.sort(cmp_keyword)
|
keywords.sort(cmp_keyword)
|
||||||
|
|
||||||
keyword_ids = [x.id for x in keywords]
|
keyword_ids = [x.id for x in keywords]
|
||||||
keyword_terms = [SimpleVocabulary.createTerm(
|
keyword_terms = [SimpleVocabulary.createTerm(
|
||||||
x.id, x.id, x.title) for x in keywords]
|
x.id, x.id, x.title) for x in keywords]
|
||||||
|
@ -61,4 +67,4 @@ class KeywordFromSameThesaurusSource(object):
|
||||||
|
|
||||||
|
|
||||||
grok.global_utility(KeywordFromSameThesaurusSource,
|
grok.global_utility(KeywordFromSameThesaurusSource,
|
||||||
name=u'dms.thesaurus.samesource')
|
name=u'dms.thesaurus.internalrefs')
|
||||||
|
|
Reference in New Issue