root/cherokee/trunk/admin/ModuleDirlist.py

Revision 2094, 2.4 kB (checked in by alo, 2 months ago)

--

Line 
1 import os
2 import validations
3
4 from Form import *
5 from Table import *
6 from ModuleHandler import *
7 from configured import *
8
9 DATA_VALIDATION = [
10     ('^vserver!.+?!.+?!.+?!handler!icon_dir',     validations.is_path),
11     ('^vserver!.+?!.+?!.+?!handler!notice_files', validations.is_path_list),
12 ]
13
14 DEFAULT_THEME = "default"
15
16 NOTE_THEME        = "Choose the listing theme."
17 NOTE_ICON_DIR     = "Web directory where the icon files are located. Default: <i>/icons</i>."
18 NOTE_NOTICE_FILES = "List of notice files to be inserted."
19
20 HELPS = [
21     ('modules_handlers_dirlist', "Only listing")
22 ]
23
24 class ModuleDirlist (ModuleHandler):
25     PROPERTIES = [
26         'size', 'date',
27         'user', 'group',
28         'theme', 'icon_dir',
29         'notice_files', 'symlinks'
30     ]
31
32     def __init__ (self, cfg, prefix, submit_url):
33         ModuleHandler.__init__ (self, 'dirlist', cfg, prefix, submit_url)
34
35     def _op_render (self):
36         txt = '<h2>Listing</h2>'
37         table = TableProps()
38         self.AddPropCheck (table, "Show Size",  "%s!size" %(self._prefix), True,  '')
39         self.AddPropCheck (table, "Show Date",  "%s!date" %(self._prefix), True,  '')
40         self.AddPropCheck (table, "Show User",  "%s!user" %(self._prefix), False, '')
41         self.AddPropCheck (table, "Show Group", "%s!group"%(self._prefix), False, '')
42         self.AddPropCheck (table, "Allow symbolic links", "%s!symlinks"%(self._prefix), True, '')
43         txt += self.Indent(table)
44
45         txt += '<h2>Theming</h2>'
46         table  = TableProps()
47         themes = self._get_theme_list()
48         self.AddPropOptions_Reload (table, 'Theme', "%s!theme" % (self._prefix), themes, NOTE_THEME)
49         self.AddPropEntry   (table, 'Icons dir',    "%s!icon_dir" % (self._prefix), NOTE_ICON_DIR)
50         self.AddPropEntry   (table, 'Notice files', "%s!notice_files" % (self._prefix), NOTE_NOTICE_FILES)
51         txt += self.Indent(table)
52
53         return txt
54
55     def _op_apply_changes (self, uri, post):
56         checkboxes = ['size', 'date', 'user', 'group', 'symlinks']
57         self.ApplyChangesPrefix (self._prefix, checkboxes, post, DATA_VALIDATION)
58
59     def _get_theme_list (self):
60         themes = []
61         for f in os.listdir(CHEROKEE_THEMEDIR):
62             full = os.path.join(CHEROKEE_THEMEDIR, f)
63             if os.path.isdir (full):
64                 themes.append((f,f))
65
66         if not themes:
67             themes = [(DEFAULT_THEME, DEFAULT_THEME)]
68
69         return themes
Note: See TracBrowser for help on using the browser.