diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 9845656..eb3e535 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -4,6 +4,12 @@ Changelog 1.0.6 (unreleased) ------------------ +* pep8 + [joka] + +* Fix term title genration to use the brain id if there is not brain title + [joka] + * Added Italian translation. [gborelli] diff --git a/plone/formwidget/contenttree/__init__.py b/plone/formwidget/contenttree/__init__.py index a740ca1..501f596 100644 --- a/plone/formwidget/contenttree/__init__.py +++ b/plone/formwidget/contenttree/__init__.py @@ -4,4 +4,5 @@ MessageFactory = MessageFactory('plone.formwidget.contenttree') from plone.formwidget.contenttree.widget import ContentTreeFieldWidget from plone.formwidget.contenttree.widget import MultiContentTreeFieldWidget -from plone.formwidget.contenttree.source import PathSourceBinder, ObjPathSourceBinder, UUIDSourceBinder +from plone.formwidget.contenttree.source import PathSourceBinder,\ + ObjPathSourceBinder, UUIDSourceBinder diff --git a/plone/formwidget/contenttree/demo.py b/plone/formwidget/contenttree/demo.py index 48d81c2..57b8a81 100644 --- a/plone/formwidget/contenttree/demo.py +++ b/plone/formwidget/contenttree/demo.py @@ -34,12 +34,14 @@ class TestAdapter(object): def _get_buddy(self): return None + def _set_buddy(self, value): print "setting", value buddy = property(_get_buddy, _set_buddy) def _get_friends(self): return [] + def _set_friends(self, value): print "setting", value friends = property(_get_friends, _set_friends) diff --git a/plone/formwidget/contenttree/interfaces.py b/plone/formwidget/contenttree/interfaces.py index 78926a4..b441085 100644 --- a/plone/formwidget/contenttree/interfaces.py +++ b/plone/formwidget/contenttree/interfaces.py @@ -3,6 +3,7 @@ from zope import schema from z3c.formwidget.query.interfaces import IQuerySource + class IContentFilter(Interface): """A filter that specifies what content is addable, where """ @@ -14,19 +15,25 @@ class IContentFilter(Interface): was found from the given index data (a dict), should be included. """ + class IContentSource(IQuerySource): """A source that can specify content. The generated terms should have - tokens that are URLs to the content, since these are used to create links. + tokens that are URLs to the content, since these are used to create + links. """ - navigation_tree_query = Attribute("A dict to pass to portal_catalog when " - "searching for items to display. This dictates " - "how the tree is structured, and also provides an " - "upper bound for items allowed by the source.") + navigation_tree_query = Attribute( + "A dict to pass to portal_catalog when " + "searching for items to display. This dictates " + "how the tree is structured, and also provides an " + "upper bound for items allowed by the source." + ) - selectable_filter = schema.Object(title=u"Filter", - description=u"The filter will be applied to any returned search results", - schema=IContentFilter) + selectable_filter = schema.Object( + title=u"Filter", + description=u"The filter will be applied to any returned search results", + schema=IContentFilter + ) def isBrainSelectable(self, brain): """Return True iff the brain represents a page that can be selected @@ -37,7 +44,7 @@ class IContentSource(IQuerySource): """Given a brain, generate a Term that represents this brain """ + class IContentTreeWidget(Interface): """Marker interface for the content tree widget """ - diff --git a/plone/formwidget/contenttree/navtree.py b/plone/formwidget/contenttree/navtree.py index 100045f..ba8e2fb 100644 --- a/plone/formwidget/contenttree/navtree.py +++ b/plone/formwidget/contenttree/navtree.py @@ -16,8 +16,8 @@ from plone.app.layout.navigation.interfaces import INavigationQueryBuilder from plone.app.layout.navigation.root import getNavigationRoot -from plone.formwidget.contenttree.interfaces import IContentSource -from plone.formwidget.contenttree.interfaces import IContentTreeWidget +from plone.formwidget.contenttree.interfaces import IContentSource +from plone.formwidget.contenttree.interfaces import IContentTreeWidget class QueryBuilder(object): diff --git a/plone/formwidget/contenttree/source.py b/plone/formwidget/contenttree/source.py index 1b0f949..540c847 100644 --- a/plone/formwidget/contenttree/source.py +++ b/plone/formwidget/contenttree/source.py @@ -43,8 +43,8 @@ class CustomFilter(object): def __init__(self, **kw): self.criteria = {} for key, value in kw.items(): - if (not isinstance(value, (list, tuple, set, frozenset)) and - not key == 'path'): + if (not isinstance(value, (list, tuple, set, frozenset)) + and not key == 'path'): self.criteria[key] = [value] elif isinstance(value, (set, frozenset)): self.criteria[key] = list(value) @@ -56,7 +56,7 @@ class CustomFilter(object): test_value = index_data.get(key, None) if test_value is not None: if (not isinstance(test_value, (list, tuple, set, frozenset)) - and not key == 'path'): + and not key == 'path'): test_value = set([test_value]) elif isinstance(value, (list, tuple)): test_value = set(test_value) @@ -84,8 +84,8 @@ class PathSource(object): # Copy path from selectable_filter into the navigation_tree_query # normally it does not make sense to show elements that wouldn't be # selectable anyway and are unneeded to navigate to selectable items - if ('path' not in navigation_tree_query and - 'path' in selectable_filter.criteria): + if ('path' not in navigation_tree_query + and 'path' in selectable_filter.criteria): navigation_tree_query['path'] = selectable_filter.criteria['path'] query.update(navigation_tree_query) @@ -133,7 +133,8 @@ class PathSource(object): if brain is None: return self._placeholderTerm(value) if not self.isBrainSelectable(brain): - raise LookupError('Value "%s" does not match criteria for field' % str(value)) + raise LookupError('Value "%s" does not match criteria for field' + % str(value)) return self.getTermByBrain(brain) # Query API - used to locate content, e.g. in non-JS mode @@ -161,7 +162,8 @@ class PathSource(object): def getTermByBrain(self, brain, real_value=True): value = brain.getPath()[len(self.portal_path):] - return SimpleTerm(value, token=brain.getPath(), title=brain.Title) + return SimpleTerm(value, token=brain.getPath(), title=brain.Title or + brain.id) def tokenToPath(self, token): # token==path for existing sources, but may not be true in future @@ -199,7 +201,8 @@ class ObjPathSource(PathSource): value = brain._unrestrictedGetObject() else: value = brain.getPath()[len(self.portal_path):] - return SimpleTerm(value, token=brain.getPath(), title=brain.Title) + return SimpleTerm(value, token=brain.getPath(), title=brain.Title or + brain.id) class UUIDSource(PathSource): @@ -221,7 +224,8 @@ class UUIDSource(PathSource): logger.warn("Brain in UUIDSource has missing UID value. Maybe you " "need to enable plone.app.referenceablebehavior on " "portal type %s?", brain.portal_type) - return SimpleTerm(value, token=brain.getPath(), title=brain.Title) + return SimpleTerm(value, token=brain.getPath(), title=brain.Title or + brain.id) class PathSourceBinder(object): diff --git a/plone/formwidget/contenttree/tests.py b/plone/formwidget/contenttree/tests.py index cbb9491..a83ad4c 100644 --- a/plone/formwidget/contenttree/tests.py +++ b/plone/formwidget/contenttree/tests.py @@ -5,7 +5,10 @@ from zope.testing import doctest from zope.app.testing.functional import ZCMLLayer testing_zcml_path = os.path.join(os.path.dirname(__file__), 'testing.zcml') -testing_zcml_layer = ZCMLLayer(testing_zcml_path, 'plone.formwidget.contenttree', 'testing_zcml_layer') +testing_zcml_layer = ZCMLLayer(testing_zcml_path, + 'plone.formwidget.contenttree', + 'testing_zcml_layer') + def test_suite(): readme_txt = doctest.DocFileSuite('README.txt') @@ -13,4 +16,4 @@ def test_suite(): return unittest.TestSuite([ readme_txt, - ]) + ]) diff --git a/plone/formwidget/contenttree/widget.py b/plone/formwidget/contenttree/widget.py index ac04b9b..5721a9b 100644 --- a/plone/formwidget/contenttree/widget.py +++ b/plone/formwidget/contenttree/widget.py @@ -17,7 +17,7 @@ from plone.app.layout.navigation.interfaces import INavtreeStrategy from plone.app.layout.navigation.navtree import buildFolderTree from plone.formwidget.autocomplete.widget import \ - AutocompleteSelectionWidget, AutocompleteMultiSelectionWidget + AutocompleteSelectionWidget, AutocompleteMultiSelectionWidget from Products.CMFCore.utils import getToolByName from Products.Five.browser import BrowserView @@ -30,7 +30,7 @@ class Fetch(BrowserView): fragment_template = ViewPageTemplateFile('fragment.pt') recurse_template = ViewPageTemplateFile('input_recurse.pt') - def getTermByBrain(self,brain): + def getTermByBrain(self, brain): # Ask the widget return self.context.getTermByBrain(brain) @@ -94,11 +94,11 @@ class Fetch(BrowserView): children = [] for brain in catalog(navtree_query): - newNode = {'item' : brain, - 'depth' : -1, # not needed here - 'currentItem' : False, - 'currentParent' : False, - 'children' : []} + newNode = {'item': brain, + 'depth': -1, # not needed here + 'currentItem': False, + 'currentParent': False, + 'children': []} if strategy.nodeFilter(newNode): newNode = strategy.decoratorFactory(newNode) children.append(newNode) @@ -115,7 +115,7 @@ class ContentTreeBase(Explicit): input_template = ViewPageTemplateFile('input.pt') hidden_template = ViewPageTemplateFile('hidden.pt') - display_template = None # set by subclass + display_template = None # set by subclass recurse_template = ViewPageTemplateFile('input_recurse.pt') # Parameters passed to the JavaScript function @@ -134,7 +134,7 @@ class ContentTreeBase(Explicit): # are selectable or that are folders. show_all_nodes = False - def getTermByBrain(self,brain): + def getTermByBrain(self, brain): return self.bound_source.getTermByBrain(brain) def render_tree(self): @@ -150,7 +150,8 @@ class ContentTreeBase(Explicit): query=source.navigation_tree_query, strategy=strategy) - return self.recurse_template(children=data.get('children', []), level=1) + return self.recurse_template(children=data.get('children', []), + level=1) def render(self): if self.mode == z3c.form.interfaces.DISPLAY_MODE: @@ -218,6 +219,7 @@ class ContentTreeBase(Explicit): domain='plone.formwidget.contenttree', context=self.request)) + class ContentTreeWidget(ContentTreeBase, AutocompleteSelectionWidget): """ContentTree widget that allows single selection. """