src/pyams_utils/zmi/zeo.py
changeset 50 f4e90f45ebb3
parent 29 4bbddbc10590
child 60 cde349864894
equal deleted inserted replaced
49:01eaa997a5f4 50:f4e90f45ebb3
    17 
    17 
    18 # import interfaces
    18 # import interfaces
    19 from pyams_skin.interfaces.container import ITableElementName
    19 from pyams_skin.interfaces.container import ITableElementName
    20 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
    20 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
    21 from pyams_skin.layer import IPyAMSLayer
    21 from pyams_skin.layer import IPyAMSLayer
       
    22 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
    22 from pyams_utils.interfaces.zeo import IZEOConnection
    23 from pyams_utils.interfaces.zeo import IZEOConnection
    23 from pyams_zmi.layer import IAdminLayer
    24 from pyams_zmi.layer import IAdminLayer
    24 from z3c.form.interfaces import IDataExtractedEvent, DISPLAY_MODE
    25 from z3c.form.interfaces import IDataExtractedEvent, DISPLAY_MODE
    25 from zope.component.interfaces import ISite
    26 from zope.component.interfaces import ISite
    26 
    27 
    52         translate = self.request.localizer.translate
    53         translate = self.request.localizer.translate
    53         return translate(_("ZEO: {0}")).format(self.context.name)
    54         return translate(_("ZEO: {0}")).format(self.context.name)
    54 
    55 
    55 
    56 
    56 @viewlet_config(name='add-zeo-connection.menu', context=ISite, layer=IAdminLayer,
    57 @viewlet_config(name='add-zeo-connection.menu', context=ISite, layer=IAdminLayer,
    57                 view=UtilitiesTable, manager=IToolbarAddingMenu, permission='system.manage')
    58                 view=UtilitiesTable, manager=IToolbarAddingMenu, permission=MANAGE_SYSTEM_PERMISSION)
    58 class ZEOConnectionAddMenu(ToolbarMenuItem):
    59 class ZEOConnectionAddMenu(ToolbarMenuItem):
    59     """ZEO connection add menu"""
    60     """ZEO connection add menu"""
    60 
    61 
    61     label = _("Add ZEO connection...")
    62     label = _("Add ZEO connection...")
    62     label_css_class = 'fa fa-fw fa-database'
    63     label_css_class = 'fa fa-fw fa-database'
    63     url = 'add-zeo-connection.html'
    64     url = 'add-zeo-connection.html'
    64     modal_target = True
    65     modal_target = True
    65 
    66 
    66 
    67 
    67 @pagelet_config(name='add-zeo-connection.html', context=ISite, layer=IPyAMSLayer, permission='system.manage')
    68 @pagelet_config(name='add-zeo-connection.html', context=ISite, layer=IPyAMSLayer, permission=MANAGE_SYSTEM_PERMISSION)
    68 class ZEOConnectionAddForm(AdminDialogAddForm):
    69 class ZEOConnectionAddForm(AdminDialogAddForm):
    69     """ZEO connection add form"""
    70     """ZEO connection add form"""
    70 
    71 
    71     title = _("Utilities")
    72     title = _("Utilities")
    72     legend = _("Add ZEO connection")
    73     legend = _("Add ZEO connection")
    99     if connection is not None:
   100     if connection is not None:
   100         event.form.widgets.errors += (Invalid(_("A ZEO connection is already registered with this name!")), )
   101         event.form.widgets.errors += (Invalid(_("A ZEO connection is already registered with this name!")), )
   101 
   102 
   102 
   103 
   103 @view_config(name='add-zeo-connection.json', context=ISite, request_type=IPyAMSLayer,
   104 @view_config(name='add-zeo-connection.json', context=ISite, request_type=IPyAMSLayer,
   104              permission='system.manage', renderer='json', xhr=True)
   105              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   105 class ZEOConnectionAJAXAddForm(AJAXAddForm, ZEOConnectionAddForm):
   106 class ZEOConnectionAJAXAddForm(AJAXAddForm, ZEOConnectionAddForm):
   106     """ZEO connection add form, AJAX view"""
   107     """ZEO connection add form, AJAX view"""
   107 
   108 
   108 
   109 
   109 @pagelet_config(name='properties.html', context=IZEOConnection, layer=IPyAMSLayer, permission='system.view')
   110 @pagelet_config(name='properties.html', context=IZEOConnection, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   110 class ZEOConnectionPropertiesEditForm(AdminDialogEditForm):
   111 class ZEOConnectionPropertiesEditForm(AdminDialogEditForm):
   111     """ZEO connection properties edit form"""
   112     """ZEO connection properties edit form"""
   112 
   113 
   113     @property
   114     @property
   114     def title(self):
   115     def title(self):
   119     icon_css_class = 'fa fa-fw fa-database'
   120     icon_css_class = 'fa fa-fw fa-database'
   120 
   121 
   121     fields = field.Fields(IZEOConnection)
   122     fields = field.Fields(IZEOConnection)
   122     autocomplete = 'off'
   123     autocomplete = 'off'
   123     ajax_handler = 'properties.json'
   124     ajax_handler = 'properties.json'
   124     edit_permission = 'system.manage'
   125     edit_permission = MANAGE_SYSTEM_PERMISSION
   125 
   126 
   126     def updateWidgets(self, prefix=None):
   127     def updateWidgets(self, prefix=None):
   127         super(ZEOConnectionPropertiesEditForm, self).updateWidgets(prefix)
   128         super(ZEOConnectionPropertiesEditForm, self).updateWidgets(prefix)
   128         self.widgets['name'].mode = DISPLAY_MODE
   129         self.widgets['name'].mode = DISPLAY_MODE
   129 
   130 
   130 
   131 
   131 @view_config(name='properties.json', context=IZEOConnection, request_type=IPyAMSLayer,
   132 @view_config(name='properties.json', context=IZEOConnection, request_type=IPyAMSLayer,
   132              permission='system.manage', renderer='json', xhr=True)
   133              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   133 class ZEOConnectionPropertiesAJAXEditForm(AJAXEditForm, ZEOConnectionPropertiesEditForm):
   134 class ZEOConnectionPropertiesAJAXEditForm(AJAXEditForm, ZEOConnectionPropertiesEditForm):
   134     """ZEO connection properties edit form, AJAX view"""
   135     """ZEO connection properties edit form, AJAX view"""