1 """
2 admin setting and preferences
3 Solo vistas y forms
4
5 @author: Juan Pablo Gimenez
6 @contact: jpg@rcom.com.ar
7 """
8 __author__ = """Juan Pablo Gimenez <jpg@rcom.com.ar>"""
9 __docformat__ = 'plaintext'
10
11 import os
12 from datetime import datetime
13
14 import zope
15 from zope import component
16 from zope.component import getUtility
17 from zope.formlib import form
18 from zope.app.form.browser import MultiSelectSetWidget
19 from zope.app.form.browser.itemswidgets import MultiSelectWidget \
20 as BaseMultiSelectWidget, DropdownWidget, SelectWidget
21 from zope.app.form.browser import FileWidget
22
23 try:
24 from zope.lifecycleevent import ObjectModifiedEvent
25 except:
26 from zope.app.event.objectevent import ObjectModifiedEvent
27
28 from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
29 from Products.Five.browser import BrowserView
30 from Products.Five.formlib import formbase
31
32 from platecom.utils import interfaces
33 from platecom.utils import pkg_home
34 from platecom.utils.i18n import _
35 from base import BaseSettingsForm
36 from widgets import OrderedMultiSelectionWidgetFactory, \
37 MultiSelectionWidgetFactory
38 from zope.app.component.hooks import getSite
39 from platecom.ontoplone.interfaces.IThesaurus import IThesaurus
42 """ overview of entire system
43 """
47
49 fh = open( os.path.join( pkg_home, 'version.txt') )
50 version_string = fh.read()
51 fh.close()
52 return version_string
53
54 -class ContentTypes( BaseSettingsForm ):
55 """ Configlet para elegir los Content Types que tendran la
56 capacidad de hacer fallback de lenguajes
57 """
58 form_name = _(u'Content Types')
59 form_fields = form.Fields( interfaces.IPlatecomManagementContentTypes )
60 form_fields['fallback_types'].custom_widget = MultiSelectionWidgetFactory
61
62 @form.action(_("Apply"), condition=form.haveInputWidgets)
63 - def handle_edit_action(self, action, data):
64 old_types = self.adapters['IPlatecomManagementContentTypes'].fallback_types
65 if form.applyChanges(self.context,
66 self.form_fields,
67 data,
68 self.adapters):
69 ccpatcher = getUtility(interfaces.IContentTypesMultilingualPatcher)
70 for type_name in data['fallback_types']:
71 ccpatcher.patch(type_name, True)
72
73 unpatch_types = [type_name for type_name in old_types \
74 if type_name not in data['fallback_types']]
75 for type_name in unpatch_types:
76 ccpatcher.unpatch(type_name)
77
78 zope.event.notify(
79 ObjectModifiedEvent(self.context)
80 )
81 self.status = _(
82 "Updated on ${date_time}",
83 mapping={'date_time': str(datetime.utcnow())}
84 )
85 else:
86 self.status = _('No changes')
87
89 """ Configlet for upload a thesaurus rdf file.
90 """
91 form_name = _(u'Thesaurus upload')
92 form_fields = form.Fields( interfaces.IPlatecomManagementThesaurusUpload )
93 form_fields['thesaurus_file'].custom_widget = FileWidget
94
95 @form.action(_("Apply"), condition=form.haveInputWidgets)
97 if form.applyChanges(self.context,
98 self.form_fields,
99 data,
100 self.adapters):
101 self.load_thesaurus(data['thesaurus_file'], data['default_language'])
102
103 zope.event.notify(
104 ObjectModifiedEvent(self.context)
105 )
106 self.status = _(
107 "Updated on ${date_time}",
108 mapping={'date_time': str(datetime.utcnow())}
109 )
110 else:
111 self.status = _('No changes')
112
116
118 sm = getSite().getSiteManager()
119 return sm.utilities.queryUtility(IThesaurus)
120