# HG changeset patch # User Thierry Florac # Date 1531230450 -7200 # Node ID 3f568439009174b4efc02ed9ec1a3cc415913f4b # Parent 5a56ac57d94e17d7731b76d55b31f3eb4177f3c0 Use new thesaurus terms tree widget to display themes and tags diff -r 5a56ac57d94e -r 3f5684390091 src/pyams_content/component/theme/zmi/__init__.py --- a/src/pyams_content/component/theme/zmi/__init__.py Tue Jul 10 14:19:56 2018 +0200 +++ b/src/pyams_content/component/theme/zmi/__init__.py Tue Jul 10 15:47:30 2018 +0200 @@ -9,7 +9,6 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # -from pyams_content.component.theme import ITagsTarget, ITagsInfo, ITagsManagerTarget, ITagsManager __docformat__ = 'restructuredtext' @@ -17,10 +16,11 @@ # import standard library # import interfaces -from pyams_content.component.theme.interfaces import IThemesTarget, IThemesInfo, IThemesManagerTarget, IThemesManager +from pyams_content.component.theme import ITagsTarget, ITagsInfo, ITagsManager, IThemesTarget, IThemesInfo, \ + IThemesManagerTarget, IThemesManager from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION from pyams_form.interfaces.form import IWidgetForm -from pyams_skin.interfaces import IInnerPage, IPageHeader +from pyams_skin.interfaces import IInnerPage, IPageHeader, IDialog from pyams_skin.layer import IPyAMSLayer from pyams_thesaurus.interfaces.thesaurus import IThesaurus from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION @@ -29,15 +29,15 @@ # import packages from pyams_content.shared.common.zmi import WfSharedContentHeaderAdapter -from pyams_form.form import ajax_config +from pyams_form.form import ajax_config, AJAXEditForm, EditForm from pyams_pagelet.pagelet import pagelet_config from pyams_skin.viewlet.menu import MenuItem -from pyams_template.template import template_config +from pyams_thesaurus.widget import ThesaurusTermsTreeFieldWidget from pyams_utils.adapter import adapter_config from pyams_utils.registry import query_utility from pyams_utils.traversing import get_parent from pyams_viewlet.viewlet import viewlet_config -from pyams_zmi.form import AdminEditForm +from pyams_zmi.form import AdminEditForm, AdminDialogEditForm from z3c.form import field from zope.interface import implementer @@ -59,7 +59,6 @@ @pagelet_config(name='tags.html', context=ITagsTarget, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) -@template_config(template='templates/themes-info.pt', layer=IPyAMSLayer) @ajax_config(name='tags.json', context=ITagsTarget, layer=IPyAMSLayer, permission=MANAGE_CONTENT_PERMISSION) @implementer(IWidgetForm, IInnerPage) class TagsEditForm(AdminEditForm): @@ -67,8 +66,11 @@ legend = _("Content tags") + label_css_class = 'control-label hidden' + input_css_class = 'col-md-12' + fields = field.Fields(ITagsInfo) - fieldname = 'tags' + fields['tags'].widgetFactory = ThesaurusTermsTreeFieldWidget def __init__(self, context, request): super(TagsEditForm, self).__init__(context, request) @@ -120,50 +122,47 @@ url = '#themes.html' -@pagelet_config(name='themes.html', context=IThemesTarget, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) -@template_config(template='templates/themes-info.pt', layer=IPyAMSLayer) -@ajax_config(name='themes.json', context=IThemesTarget, layer=IPyAMSLayer, permission=MANAGE_CONTENT_PERMISSION) -@implementer(IWidgetForm, IInnerPage) -class ThemesEditForm(AdminEditForm): - """Themes edit form""" +class BaseThemesEditForm(EditForm): + """Base themes edit form""" legend = _("Content themes") - fields = field.Fields(IThemesInfo) - fieldname = 'themes' + label_css_class = 'control-label hidden' + input_css_class = 'col-md-12' - def __init__(self, context, request): - super(ThemesEditForm, self).__init__(context, request) - target = get_parent(self.context, IThemesManagerTarget) - manager = IThemesManager(target) - self.thesaurus_name = manager.thesaurus_name - self.extract_name = manager.extract_name + fields = field.Fields(IThemesInfo) + fields['themes'].widgetFactory = ThesaurusTermsTreeFieldWidget + + edit_permission = MANAGE_CONTENT_PERMISSION def updateWidgets(self, prefix=None): - super(ThemesEditForm, self).updateWidgets(prefix) - widget = self.widgets['themes'] - widget.thesaurus_name = self.thesaurus_name - widget.extract_name = self.extract_name - - @property - def top_terms(self): - thesaurus = query_utility(IThesaurus, name=self.thesaurus_name) - if thesaurus is not None: - return sorted(thesaurus.get_top_terms(extract=self.extract_name), - key=lambda x: x.label) - else: - return () - - def get_subterms(self, term): - for subterm in term.specifics: - if (not self.extract_name) or (self.extract_name in subterm.extracts): - yield subterm - for another in self.get_subterms(subterm): - yield another + super(BaseThemesEditForm, self).updateWidgets(prefix) + if 'themes' in self.widgets: + widget = self.widgets['themes'] + target = get_parent(self.context, IThemesManagerTarget) + manager = IThemesManager(target) + widget.thesaurus_name = manager.thesaurus_name + widget.extract_name = manager.extract_name -@adapter_config(context=(IThemesTarget, IAdminLayer, ThemesEditForm), provides=IPageHeader) +@adapter_config(context=(IThemesTarget, IAdminLayer, BaseThemesEditForm), provides=IPageHeader) class ThemesHeaderAdapter(WfSharedContentHeaderAdapter): """Shared content themes header adapter""" icon_class = 'fa fa-fw fa-tags' + + +@pagelet_config(name='themes.html', context=IThemesTarget, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) +@ajax_config(name='themes.json', context=IThemesTarget, layer=IPyAMSLayer, base=AJAXEditForm) +@implementer(IWidgetForm, IInnerPage) +class ThemesEditForm(BaseThemesEditForm, AdminEditForm): + """Themes edit form""" + + +@pagelet_config(name='themes-dialog.html', context=IThemesTarget, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) +@ajax_config(name='themes-dialog.json', context=IThemesTarget, layer=IPyAMSLayer, base=AJAXEditForm) +@implementer(IDialog) +class DialogThemesEditForm(BaseThemesEditForm, AdminDialogEditForm): + """Dialog themes edit form""" + + dialog_class = 'modal-large' diff -r 5a56ac57d94e -r 3f5684390091 src/pyams_content/component/theme/zmi/templates/themes-info.pt --- a/src/pyams_content/component/theme/zmi/templates/themes-info.pt Tue Jul 10 14:19:56 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -
-
- - -

- - -
-
-
Form prefix
- -
- -
- -
-
-
Form suffix
-
-