Project

General

Profile

Download (11.9 KB) Statistics
| Branch: | Tag: | Revision:

root / extra / modules / admin.ptl @ 2750dbae

1
import os
2

    
3
from quixote import get_publisher, redirect
4
from quixote.directory import Directory
5

    
6
import wcs.admin.root
7
import wcs.root
8
from wcs.admin.menu import *
9
from wcs.roles import get_user_roles
10

    
11
from qommon import get_cfg
12
from qommon.form import *
13

    
14
from wcs.formdef import FormDef
15
from wcs.categories import Category
16

    
17
from events import get_default_event_tags
18
import re
19

    
20
class AdminRootDirectory(wcs.admin.root.RootDirectory):
21
    def __init__(self):
22
        self._q_exports = wcs.admin.root.RootDirectory._q_exports
23

    
24
    def _q_index [html] (self):
25
        self.menu_items[-1] = ('/', N_('Au Quotidien'))
26
        from wcs.admin.menu import html_top
27
        html_top('/')
28
        '<p>'
29
        _('Welcome on Au Quotidien administration interface')
30
        '</p>'
31
        # XXX: add links to documentation, "this is based on w.c.s., a free
32
        # software project", etc.
33

    
34
class PanelDirectory(Directory):
35
    _q_exports = ['', 'update', 'announces', 'permissions', 'event_keywords',
36
            'announce_themes', 'drupal', 'ezldap', 'strongbox']
37
    label = N_('Control Panel')
38

    
39
    def _q_index [html] (self):
40
        html_top('panel', _('Control Panel'))
41
        get_response().breadcrumb.append(('panel', _('Control Panel')))
42

    
43
        '<ul>'
44
        '<li><a href="announces">%s</a></li>' % _('Announces Options')
45
        '<li><a href="permissions">%s</a></li>' % _('Permissions')
46
        '<li><a href="event_keywords">%s</a></li>' % _('Event Keywords')
47
        '<li><a href="announce_themes">%s</a></li>' % _('Announce Themes')
48
        '<li><a href="drupal">%s</a></li>' % _('Drupal Integration')
49
        '<li><a href="ezldap">%s</a></li>' % _('eZ publish / LDAP Integration')
50
        '<li><a href="strongbox">%s</a></li>' % _('Strongbox Support')
51
        '</ul>'
52

    
53
    def _verify_mask(self, form):
54
        if form.is_submitted():
55
            if not re.match("[0-9Xx]*$", form.get('mobile_mask') or ''):
56
                form.set_error('mobile_mask', _('Invalid value'))
57
            else:
58
                string_value = form.get_widget('mobile_mask').value
59
                if string_value:
60
                    form.get_widget('mobile_mask').value = string_value.upper()
61

    
62
    def announces [html] (self):
63
        announces_cfg = get_cfg('announces', {})
64
        sms_cfg = get_cfg('sms', {})
65
        form = Form(enctype='multipart/form-data')
66
        hint = ""
67
        if sms_cfg.get('mode','') in ("none",""):
68
            hint = htmltext(_('You must also <a href="%s">configure your SMS provider</a>') % "../settings/sms")
69

    
70
        form.add(CheckboxWidget, 'sms_support', title = _('SMS support'),
71
                hint = hint, value = announces_cfg.get('sms_support', 0))
72
        form.add(StringWidget, 'mobile_mask', title = _('Mask for mobile numbers'),
73
                hint = _('example: 06XXXXXXXX'),
74
                value = announces_cfg.get('mobile_mask',''))
75
        form.add_submit('submit', _('Submit'))
76
        form.add_submit('cancel', _('Cancel'))
77

    
78
        self._verify_mask(form)
79

    
80
        if form.get_widget('cancel').parse():
81
            return redirect('.')
82

    
83
        if not form.is_submitted() or form.has_errors():
84
            get_response().breadcrumb.append(('panel', _('Control Panel')))
85
            get_response().breadcrumb.append(('announces', _('Announces Options')))
86
            html_top('panel', _('Announces Options'))
87
            '<h2>%s</h2>' % _('Announces Options')
88
            form.render()
89
        else:
90
            from wcs.admin.settings import cfg_submit
91
            cfg_submit(form, 'announces', ('sms_support','mobile_mask'))
92
            return redirect('.')
93

    
94
    def permissions [html] (self):
95
        permissions_cfg = get_cfg('aq-permissions', {})
96
        form = Form(enctype='multipart/form-data')
97
        form.add(SingleSelectWidget, 'forms', title = _('Admin role for forms'),
98
                value = permissions_cfg.get('forms', None),
99
                options = [(None, _('Nobody'))] + get_user_roles())
100
        form.add(SingleSelectWidget, 'events', title = _('Admin role for events'),
101
                value = permissions_cfg.get('events', None),
102
                options = [(None, _('Nobody'))] + get_user_roles())
103
        form.add(SingleSelectWidget, 'links', title = _('Admin role for links'),
104
                value = permissions_cfg.get('links', None),
105
                options = [(None, _('Nobody'))] + get_user_roles())
106
        form.add(SingleSelectWidget, 'announces', title = _('Admin role for announces'),
107
                value = permissions_cfg.get('announces', None),
108
                options = [(None, _('Nobody'))] + get_user_roles())
109
        form.add(SingleSelectWidget, 'payments', title = _('Admin role for payments'),
110
                value = permissions_cfg.get('payments', None),
111
                options = [(None, _('Nobody'))] + get_user_roles())
112
        form.add(SingleSelectWidget, 'strongbox', title = _('Admin role for strongbox'),
113
                value = permissions_cfg.get('strongbox', None),
114
                options = [(None, _('Nobody'))] + get_user_roles())
115
        form.add_submit('submit', _('Submit'))
116
        form.add_submit('cancel', _('Cancel'))
117

    
118
        if form.get_widget('cancel').parse():
119
            return redirect('.')
120

    
121
        if not form.is_submitted() or form.has_errors():
122
            get_response().breadcrumb.append(('panel', _('Control Panel')))
123
            get_response().breadcrumb.append(('permissions', _('Permissions')))
124
            html_top('panel', _('Permissions'))
125
            '<h2>%s</h2>' % _('Permissions')
126
            form.render()
127
        else:
128
            from wcs.admin.settings import cfg_submit
129
            cfg_submit(form, 'aq-permissions',
130
                        ('forms', 'events', 'links', 'announces', 'payments', 'strongbox'))
131
            return redirect('.')
132

    
133

    
134
    def event_keywords [html] (self):
135
        misc_cfg = get_cfg('misc', {})
136
        form = Form(enctype='multipart/form-data')
137
        form.add(WidgetList, 'event_tags', title = _('Event Keywords'),
138
                value = misc_cfg.get('event_tags', get_default_event_tags()),
139
                elemnt_type = StringWidget,
140
                add_element_label = _('Add Keyword'),
141
                element_kwargs = {str('render_br'): False, str('size'): 30})
142

    
143
        form.add_submit('submit', _('Submit'))
144
        form.add_submit('cancel', _('Cancel'))
145

    
146
        if form.get_widget('cancel').parse():
147
            return redirect('.')
148

    
149
        if not form.is_submitted() or form.has_errors():
150
            get_response().breadcrumb.append(('panel', _('Control Panel')))
151
            get_response().breadcrumb.append(('event_keywords', _('Event Keywords')))
152
            html_top('panel', _('Event Keywords'))
153
            '<h2>%s</h2>' % _('Event Keywords')
154
            form.render()
155
        else:
156
            from wcs.admin.settings import cfg_submit
157
            cfg_submit(form, 'misc', ('event_tags',))
158
            return redirect('.')
159

    
160
    def announce_themes [html] (self):
161
        misc_cfg = get_cfg('misc', {})
162
        form = Form(enctype='multipart/form-data')
163
        form.add(WidgetList, 'announce_themes', title = _('Announce Themes'),
164
                value = misc_cfg.get('announce_themes', []),
165
                elemnt_type = StringWidget,
166
                add_element_label = _('Add Theme'),
167
                element_kwargs = {str('render_br'): False, str('size'): 30})
168

    
169
        form.add_submit('submit', _('Submit'))
170
        form.add_submit('cancel', _('Cancel'))
171

    
172
        if form.get_widget('cancel').parse():
173
            return redirect('.')
174

    
175
        if not form.is_submitted() or form.has_errors():
176
            get_response().breadcrumb.append(('panel', _('Control Panel')))
177
            get_response().breadcrumb.append(('announce_themes', _('Announce Themes')))
178
            html_top('panel', _('Announce Themes'))
179
            '<h2>%s</h2>' % _('Announce Themes')
180
            form.render()
181
        else:
182
            from wcs.admin.settings import cfg_submit
183
            cfg_submit(form, 'misc', ('announce_themes',))
184
            return redirect('.')
185

    
186
    def drupal [html] (self):
187
        misc_cfg = get_cfg('misc', {})
188
        form = Form(enctype='multipart/form-data')
189
        form.add(StringWidget, 'aq-drupal-ip', title=_('IP Address of Drupal'),
190
                value=misc_cfg.get('aq-drupal-ip'), required=False,
191
                hint=_('Empty for disabled authentication'))
192

    
193
        form.add_submit('submit', _('Submit'))
194
        form.add_submit('cancel', _('Cancel'))
195

    
196
        if form.get_widget('cancel').parse():
197
            return redirect('.')
198

    
199
        if not form.is_submitted() or form.has_errors():
200
            get_response().breadcrumb.append(('panel', _('Control Panel')))
201
            get_response().breadcrumb.append(('drupal', _('Drupal Integration')))
202
            html_top('panel', _('Drupal Integration'))
203
            '<h2>%s</h2>' % _('Drupal Integration')
204
            form.render()
205
        else:
206
            from wcs.admin.settings import cfg_submit
207
            cfg_submit(form, 'misc', ('aq-drupal-ip',))
208
            return redirect('.')
209

    
210
    def ezldap [html] (self):
211
        misc_cfg = get_cfg('misc', {})
212
        form = Form(enctype='multipart/form-data')
213
        form.add(StringWidget, 'aq-ezldap-url', title=_('LDAP URL'),
214
                value=misc_cfg.get('aq-ezldap-url'), required=False,
215
                hint=_('Empty to disable eZ/LDAP support'))
216
        form.add(StringWidget, 'aq-ezldap-binddn', title=_('LDAP Admin Bind DN'),
217
                value=misc_cfg.get('aq-ezldap-binddn'), required=False)
218
        form.add(PasswordWidget, 'aq-ezldap-bindpassword', title=_('LDAP Admin Bind Password'),
219
                value=misc_cfg.get('aq-ezldap-bindpassword'), required=False)
220
        form.add(StringWidget, 'aq-ezldap-basedn', title=_('LDAP Base DN'),
221
                value=misc_cfg.get('aq-ezldap-basedn'), required=False)
222
        form.add(StringWidget, 'aq-ezldap-dntemplate', title=_('LDAP DN Template'),
223
                value=misc_cfg.get('aq-ezldap-dntemplate'), required=False)
224
        form.add(StringWidget, 'aq-ezldap-ip', title=_('Use Auth-DN header only from this IP'),
225
                value=misc_cfg.get('aq-ezldap-ip'), required=False,
226
                hint=_('Empty to disable IP filtering'))
227

    
228
        form.add_submit('submit', _('Submit'))
229
        form.add_submit('cancel', _('Cancel'))
230

    
231
        if form.get_widget('cancel').parse():
232
            return redirect('.')
233

    
234
        if not form.is_submitted() or form.has_errors():
235
            get_response().breadcrumb.append(('panel', _('Control Panel')))
236
            get_response().breadcrumb.append(('ezldap', _('eZ publish / LDAP Integration')))
237
            html_top('panel', _('eZ publish / LDAP Integration'))
238
            '<h2>%s</h2>' % _('eZ publish / LDAP Integration')
239
            form.render()
240
        else:
241
            from wcs.admin.settings import cfg_submit
242
            cfg_submit(form, 'misc', ('aq-ezldap-url',
243
                        'aq-ezldap-binddn', 'aq-ezldap-bindpassword',
244
                        'aq-ezldap-basedn', 'aq-ezldap-dntemplate',
245
                        'aq-ezldap-ip'))
246
            return redirect('.')
247

    
248
    def strongbox [html] (self):
249
        misc_cfg = get_cfg('misc', {})
250
        form = Form(enctype='multipart/form-data')
251
        form.add(CheckboxWidget, 'aq-strongbox', title=_('Strongbox Support'),
252
                value=misc_cfg.get('aq-strongbox'), required=False)
253

    
254
        form.add_submit('submit', _('Submit'))
255
        form.add_submit('cancel', _('Cancel'))
256

    
257
        if form.get_widget('cancel').parse():
258
            return redirect('.')
259

    
260
        if not form.is_submitted() or form.has_errors():
261
            get_response().breadcrumb.append(('panel', _('Control Panel')))
262
            get_response().breadcrumb.append(('strongbox', _('Strongbox Support')))
263
            html_top('panel', _('Strongbox Support'))
264
            '<h2>%s</h2>' % _('Strongbox Support')
265
            form.render()
266
        else:
267
            from wcs.admin.settings import cfg_submit
268
            cfg_submit(form, 'misc', ('aq-strongbox',))
269
            return redirect('.')
270

    
271

    
272
AdminRootDirectory.register_page('panel', PanelDirectory())
273

    
274
import categories_admin
275

    
(2-2/26)