File: ModuleDirlist.py

package info (click to toggle)
cherokee 0.7.2-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,808 kB
  • ctags: 6,577
  • sloc: ansic: 45,071; python: 9,628; sh: 9,468; makefile: 1,639; xml: 61; perl: 32
file content (66 lines) | stat: -rw-r--r-- 2,424 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import validations 

from Form import *
from Table import *
from Module import *
from configured import *

DATA_VALIDATION = [
    ('^vserver!.+?!.+?!.+?!handler!icon_dir',     validations.is_path),
    ('^vserver!.+?!.+?!.+?!handler!notice_files', validations.is_path_list),
]

DEFAULT_THEME = "default"

NOTE_THEME        = "Choose the listing theme."
NOTE_ICON_DIR     = "Web directory where the icon files are located. Default: <i>/icons</i>."
NOTE_NOTICE_FILES = "List of notice files to be inserted."

class ModuleDirlist (Module, FormHelper):
    PROPERTIES = [
        'size', 'date',
        'user', 'group',
        'theme', 'icon_dir',
        'notice_files', 'symlinks'
    ]

    def __init__ (self, cfg, prefix, submit_url):
        Module.__init__ (self, 'dirlist', cfg, prefix, submit_url)
        FormHelper.__init__ (self, 'dirlist', cfg)

    def _op_render (self):
        txt = '<h2>Listing</h2>'
        table = TableProps()
        self.AddPropCheck (table, "Show Size",  "%s!size" %(self._prefix), True,  '')
        self.AddPropCheck (table, "Show Date",  "%s!date" %(self._prefix), True,  '')
        self.AddPropCheck (table, "Show User",  "%s!user" %(self._prefix), False, '')
        self.AddPropCheck (table, "Show Group", "%s!group"%(self._prefix), False, '')
        self.AddPropCheck (table, "Allow symbolic links", "%s!symlinks"%(self._prefix), True, '')
        txt += self.Indent(table)

        txt += '<h2>Theming</h2>'
        table  = TableProps()
        themes = self._get_theme_list()
        self.AddPropOptions (table, 'Theme',        "%s!theme" % (self._prefix), themes, NOTE_THEME)
        self.AddPropEntry   (table, 'Icons dir',    "%s!icon_dir" % (self._prefix), NOTE_ICON_DIR)
        self.AddPropEntry   (table, 'Notice files', "%s!notice_files" % (self._prefix), NOTE_NOTICE_FILES)
        txt += self.Indent(table)

        return txt

    def _op_apply_changes (self, uri, post):
        checkboxes = ['size', 'date', 'user', 'group', 'symlinks']
        self.ApplyChangesPrefix (self._prefix, checkboxes, post, DATA_VALIDATION)

    def _get_theme_list (self):
        themes = []
        for f in os.listdir(CHEROKEE_THEMEDIR):
            full = os.path.join(CHEROKEE_THEMEDIR, f)
            if os.path.isdir (full):
                themes.append((f,f))

        if not themes:
            themes = [(DEFAULT_THEME, DEFAULT_THEME)]

        return themes