Project

General

Profile

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

root / extra / modules / backoffice.ptl @ ee316ad8

1
import os
2

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

    
6
from qommon.publisher import get_publisher_class
7

    
8
import wcs.backoffice.root
9
import wcs.root
10
from wcs.admin.menu import *
11
from wcs.categories import Category
12
from wcs.formdef import FormDef
13

    
14
from qommon import get_cfg
15
from qommon.form import *
16

    
17
class BackofficeRootDirectory(wcs.backoffice.root.RootDirectory):
18
    def __init__(self):
19
        wcs.backoffice.root.RootDirectory.__init__(self)
20
        self._q_exports = wcs.backoffice.root.RootDirectory._q_exports
21

    
22
    def _q_index [html] (self):
23
        from wcs.backoffice.menu import html_top
24
        html_top('/')
25
        '<p>'
26
        _('Welcome on Au Quotidien back office interface')
27
        '</p>'
28

    
29
        user = get_request().user
30

    
31
        def append_form_entry(formdef):
32
            all_forms = formdef.data_class().select()
33
            if formdef.workflow:
34
                not_endpoint_status = formdef.workflow.get_not_endpoint_status()
35
                not_endpoint_status_ids = ['wf-%s' % x.id for x in not_endpoint_status]
36
            else:
37
                not_endpoint_status_ids = ['new', 'accepted']
38
            pending_forms = [x for x in all_forms if x.status in not_endpoint_status_ids]
39
            if len(pending_forms) == 0:
40
                return
41
            l.append((formdef, len(pending_forms), len(all_forms)))
42

    
43
        l = []
44
        if user:
45
            for formdef in FormDef.select(order_by='name', ignore_errors=True):
46
                if formdef.disabled:
47
                    continue
48
                if user.is_admin or formdef.receiver_id in (user.roles or []):
49
                    append_form_entry(formdef)
50

    
51
        if l:
52
            '<div class="bo-block">'
53
            '<h2>%s</h2>' % _('Forms in your care')
54
            '<ul>'
55
            cats = Category.select(order_by = 'name')
56
            one = False
57
            for c in cats:
58
                l2 = [x for x in l if x[0].category_id == c.id]
59
                if not l2:
60
                    continue
61
                '<li>%s</li>' % c.name
62
                '<ul>'
63
                for formdef, no_pending, no_total in l2:
64
                    '<li><a href="%s/pending">%s</a>' % (formdef.url_name, formdef.name)
65
                    _(': %s open on %s') % (no_pending, no_total)
66
                    '</li>'
67
                    one = True
68
                '</ul>'
69

    
70
            l2 = [x for x in l if not x[0].category_id]
71
            if l2:
72
                if one:
73
                    '<li>%s</li>' % _('Misc: ')
74
                    '<ul>'
75
                for formdef, no_pending, no_total in l2:
76
                    '<li><a href="%s/pending">%s</a>' % (formdef.url_name, formdef.name)
77
                    _(': %s open on %s') % (no_pending, no_total)
78
                    '</li>'
79
                if one:
80
                    '</ul>'
81
            '</ul>'
82
            '</div>'
83

    
84
get_publisher_class().backoffice_directory_class = BackofficeRootDirectory
85

    
(6-6/16)