src/pyams_thesaurus/zmi/thesaurus.py
changeset 24 e1a86d99c7d4
parent 22 9f1ca1ad2a12
child 29 01a2ab1f4bd8
equal deleted inserted replaced
23:9885b9c88b2e 24:e1a86d99c7d4
    28     IThesaurusExporterConfiguration, IThesaurusExporter
    28     IThesaurusExporterConfiguration, IThesaurusExporter
    29 from pyams_thesaurus.interfaces.thesaurus import IThesaurusInfo, IThesaurus, IThesaurusExtracts
    29 from pyams_thesaurus.interfaces.thesaurus import IThesaurusInfo, IThesaurus, IThesaurusExtracts
    30 from pyams_thesaurus.zmi.interfaces import IThesaurusTermsMenu, IThesaurusView
    30 from pyams_thesaurus.zmi.interfaces import IThesaurusTermsMenu, IThesaurusView
    31 from pyams_utils.interfaces import VIEW_PERMISSION, VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
    31 from pyams_utils.interfaces import VIEW_PERMISSION, VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
    32 from pyams_utils.interfaces.tree import INode, ITree
    32 from pyams_utils.interfaces.tree import INode, ITree
    33 from pyams_zmi.interfaces import IAdminView
       
    34 from pyams_zmi.interfaces.menu import ISiteManagementMenu, IPropertiesMenu
    33 from pyams_zmi.interfaces.menu import ISiteManagementMenu, IPropertiesMenu
    35 from pyams_zmi.layer import IAdminLayer
    34 from pyams_zmi.layer import IAdminLayer
    36 from z3c.form.interfaces import IDataExtractedEvent, DISPLAY_MODE
    35 from z3c.form.interfaces import IDataExtractedEvent, DISPLAY_MODE
    37 
    36 
    38 # import packages
    37 # import packages
    39 from pyams_form.form import AJAXAddForm, AJAXEditForm
    38 from pyams_form.form import AJAXAddForm, AJAXEditForm
    40 from pyams_form.schema import CloseButton
    39 from pyams_form.schema import CloseButton
    41 from pyams_pagelet.pagelet import pagelet_config
    40 from pyams_pagelet.pagelet import pagelet_config
    42 from pyams_skin.layer import IPyAMSLayer
    41 from pyams_skin.layer import IPyAMSLayer
    43 from pyams_skin.page import InnerPage, DefaultPageHeaderAdapter
    42 from pyams_skin.page import DefaultPageHeaderAdapter
    44 from pyams_skin.table import DefaultElementEditorAdapter
    43 from pyams_skin.table import DefaultElementEditorAdapter
    45 from pyams_skin.viewlet.menu import MenuItem
    44 from pyams_skin.viewlet.menu import MenuItem
    46 from pyams_skin.viewlet.toolbar import ToolbarMenuItem
    45 from pyams_skin.viewlet.toolbar import ToolbarMenuItem
    47 from pyams_template.template import template_config
    46 from pyams_template.template import template_config
    48 from pyams_thesaurus.loader.config import ThesaurusUpdaterConfiguration, ThesaurusExporterConfiguration
    47 from pyams_thesaurus.loader.config import ThesaurusUpdaterConfiguration, ThesaurusExporterConfiguration
    55 from pyams_utils.url import absolute_url
    54 from pyams_utils.url import absolute_url
    56 from pyams_viewlet.manager import viewletmanager_config
    55 from pyams_viewlet.manager import viewletmanager_config
    57 from pyams_viewlet.viewlet import viewlet_config
    56 from pyams_viewlet.viewlet import viewlet_config
    58 from pyams_zmi.control_panel import UtilitiesTable
    57 from pyams_zmi.control_panel import UtilitiesTable
    59 from pyams_zmi.form import AdminDialogAddForm, AdminEditForm
    58 from pyams_zmi.form import AdminDialogAddForm, AdminEditForm
       
    59 from pyams_zmi.view import InnerAdminView
    60 from pyramid.events import subscriber
    60 from pyramid.events import subscriber
    61 from pyramid.exceptions import NotFound
    61 from pyramid.exceptions import NotFound
    62 from pyramid.httpexceptions import HTTPBadRequest
    62 from pyramid.httpexceptions import HTTPBadRequest
    63 from pyramid.response import Response
    63 from pyramid.response import Response
    64 from pyramid.url import resource_url
    64 from pyramid.url import resource_url
   104     ajax_handler = 'add-thesaurus.json'
   104     ajax_handler = 'add-thesaurus.json'
   105     edit_permission = None
   105     edit_permission = None
   106 
   106 
   107     def updateWidgets(self, prefix=None):
   107     def updateWidgets(self, prefix=None):
   108         super(ThesaurusAddForm, self).updateWidgets(prefix)
   108         super(ThesaurusAddForm, self).updateWidgets(prefix)
   109         self.widgets['description'].label_css_class = 'input textarea'
   109         if 'description' in self.widgets:
       
   110             self.widgets['description'].widget_css_class = 'input textarea'
   110 
   111 
   111     def create(self, data):
   112     def create(self, data):
   112         return Thesaurus()
   113         return Thesaurus()
   113 
   114 
   114     def add(self, object):
   115     def add(self, object):
   203     ajax_handler = 'properties.json'
   204     ajax_handler = 'properties.json'
   204     edit_permission = MANAGE_SYSTEM_PERMISSION
   205     edit_permission = MANAGE_SYSTEM_PERMISSION
   205 
   206 
   206     def updateWidgets(self, prefix=None):
   207     def updateWidgets(self, prefix=None):
   207         super(ThesaurusPropertiesEditForm, self).updateWidgets(prefix)
   208         super(ThesaurusPropertiesEditForm, self).updateWidgets(prefix)
   208         self.widgets['name'].mode = DISPLAY_MODE
   209         if 'name' in self.widgets:
   209         self.widgets['description'].label_css_class = 'input textarea'
   210             self.widgets['name'].mode = DISPLAY_MODE
       
   211         if 'description' in self.widgets:
       
   212             self.widgets['description'].widget_css_class = 'input textarea'
   210 
   213 
   211 
   214 
   212 @view_config(name='properties.json', context=IThesaurus, request_type=IPyAMSLayer,
   215 @view_config(name='properties.json', context=IThesaurus, request_type=IPyAMSLayer,
   213              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   216              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   214 class ThesaurusPropertiesAJAXEditForm(AJAXEditForm, ThesaurusPropertiesEditForm):
   217 class ThesaurusPropertiesAJAXEditForm(AJAXEditForm, ThesaurusPropertiesEditForm):
   231     url = '#terms.html'
   234     url = '#terms.html'
   232 
   235 
   233 
   236 
   234 @pagelet_config(name='terms.html', context=IThesaurus, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   237 @pagelet_config(name='terms.html', context=IThesaurus, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   235 @template_config(template='templates/terms-tree.pt', layer=IPyAMSLayer)
   238 @template_config(template='templates/terms-tree.pt', layer=IPyAMSLayer)
   236 @implementer(IAdminView, IThesaurusView)
   239 @implementer(IThesaurusView)
   237 class ThesaurusTermsView(InnerPage):
   240 class ThesaurusTermsView(InnerAdminView):
   238     """Thesaurus terms view"""
   241     """Thesaurus terms view"""
   239 
   242 
   240     def __init__(self, context, request):
   243     def __init__(self, context, request):
   241         super(ThesaurusTermsView, self).__init__(context, request)
   244         super(ThesaurusTermsView, self).__init__(context, request)
   242         self.extracts = IThesaurusExtracts(context)
   245         self.extracts = IThesaurusExtracts(context)