widgets_viewport.py 5.75 KB
Newer Older
1 2 3 4
# -*- coding: utf-8 -*-
""" widgets viewport

"""
5 6
ONE_HOUR = 3600000

7
#
8 9 10
# list of useful tables 
# To be used to build the list of hidden tables which depend on
# the role and the node
11
#
12 13 14 15 16 17 18
auth_tables = ['auth_cas',
               'auth_event',
               'auth_group',
               'auth_membership',
               'auth_permission',
               'auth_user']

19 20
configuration_tools_tables = ['axes',
                              'controllers',
21
                              'harvesters', 
22
                              'lists',
23
                              'organisation',
24
                              'metrics',
25 26
                              'renderers',
                              'sections']
27

28
main_tables = ['publications']
29

30 31 32
#
# CAS node
#
33 34
casNode = None
if session.auth and session.role == ADMIN:
35 36 37 38 39 40 41 42
    
    hidden_tables = list(db.tables)
    for el in ('auth_user', 'auth_group', 'auth_membership'):
        hidden_tables.remove(el)

    casNode = dbui.Node(T('CAS'))
    configurator = lambda tablename: dbui.to_gridPanel(db[tablename]) 
    casNode.add_children(db.tables, func=configurator, hidden=hidden_tables) 
43 44

#
45
# configuration tables node
46
#
47
confNode = None
48
if session.role == ADMIN:
49 50 51 52 53
    hidden_tables = set(db.tables).difference(configuration_tools_tables) 

    confNode = dbui.Node(T('Configuration'))
    configurator = lambda tablename: dbui.to_gridPanel(db[tablename]) 
    confNode.add_children(db.tables, func=configurator, hidden=hidden_tables) 
54 55

#
56
# core tables node
57
#
58

59
gridNode = None
60
if session.role in (ADMIN, USER):
61
    
62
    if session.role == ADMIN:
63 64 65
        hidden_tables = list(auth_tables)
        hidden_tables.extend(configuration_tools_tables)
        
66
    elif session.role == USER:
67 68 69 70 71
        hidden_tables = set(db.tables).difference(main_tables)

    gridNode = dbui.Node(T('Tables'))
    configurator = lambda tablename: dbui.to_gridPanel(db[tablename]) 
    gridNode.add_children(db.tables, func=configurator, hidden=hidden_tables) 
72 73

#
74
# help node
75
#
LE GAC Renaud's avatar
LE GAC Renaud committed
76
aboutLeaf = dbui.Panel(autoLoad=URL('default', 'about'), autoScroll=True)
77
documentationsLeaf = dbui.Panel(autoLoad=URL('default', 'documentations'), autoScroll=True)
LE GAC Renaud's avatar
LE GAC Renaud committed
78 79
schemaLeaf = dbui.Panel(autoLoad=URL('default', 'schema'), autoScroll=True)
versionLeaf = dbui.Panel(autoLoad=URL('default', 'versions'))
80 81

helpNode = dbui.Node(T('Help'))
LE GAC Renaud's avatar
LE GAC Renaud committed
82 83
helpNode.add_child(T('about'), aboutLeaf)
helpNode.add_child(T('versions'), versionLeaf)
84

85
if session.role == ADMIN:
86
    helpNode.add_child(T('documentations'), documentationsLeaf)
87 88 89 90 91 92
    
helpNode.sort_children()

#
# report node
#
LE GAC Renaud's avatar
LE GAC Renaud committed
93
listLeaf = dbui.to_panelWithUrlSelector(virtdb.list_selector, 
94 95
                                        baseUrl=URL('lists', 'index'),
                                        extField='format',
96
                                        isMathJax=dbui.is_mathjax())
97

LE GAC Renaud's avatar
LE GAC Renaud committed
98
metricLeaf = dbui.to_panelWithUrlSelector(virtdb.metric_selector, 
99 100
                                          baseUrl=URL('metrics', 'index'),
                                          extField='format')
101 102

reportNode = dbui.Node(T('Reports'))
LE GAC Renaud's avatar
LE GAC Renaud committed
103 104
reportNode.add_child(T('lists'), listLeaf)
reportNode.add_child(T('metrics'), metricLeaf)
105 106 107 108 109 110

reportNode.sort_children()

#
# wizard node
#
111
wizardNode = None
112
if session.role in (ADMIN, USER):
LE GAC Renaud's avatar
LE GAC Renaud committed
113
    authorLeaf = dbui.to_panelWithUrlSelector(virtdb.authors_selector, 
114 115
                                              baseUrl=URL('wizards', 'extract_authors'))
    
LE GAC Renaud's avatar
LE GAC Renaud committed
116
    freeLeaf = dbui.to_panelWithUrlSelector(virtdb.free_harvester_selector, 
117
                                            baseUrl=URL('harvest', 'free_run'),
118
                                            selectorTitle='Fill all fields',
119
                                            timeout=ONE_HOUR)
120
    
LE GAC Renaud's avatar
LE GAC Renaud committed
121
    checkLeaf = dbui.to_panelWithUrlSelector(virtdb.check_selector, 
122 123
                                             baseUrl=URL('wizards', 'check_validate'),
                                             extField='format')
124
    
LE GAC Renaud's avatar
LE GAC Renaud committed
125
    harvesterLeaf = dbui.to_panelWithUrlSelector(virtdb.harvester_selector, 
126
                                                 baseUrl=URL('harvest', 'run'),
127 128
                                                 extField='format',
                                                 timeout=ONE_HOUR)
129
    
LE GAC Renaud's avatar
LE GAC Renaud committed
130
    marc12Leaf = dbui.to_panelWithUrlSelector(virtdb.marc12_selector, 
131
                                              selectorTitle='Fill all fields',
132 133
                                              baseUrl=URL('harvest', 'insert_marcxml')) 
    
LE GAC Renaud's avatar
LE GAC Renaud committed
134
    runAllLeaf = dbui.to_panelWithUrlSelector(virtdb.run_all_harvesters_selector, 
135
                                              baseUrl=URL('harvest', 'run_all'),
136 137
                                              extField='format',
                                              timeout=ONE_HOUR)
138 139 140
    
    wizardNode = dbui.Node(T('Wizards'))
    
LE GAC Renaud's avatar
LE GAC Renaud committed
141 142
    wizardNode.add_child(T('insert MARCXML'), marc12Leaf)
    wizardNode.add_child(T('run a free harvester'), freeLeaf)
LE GAC Renaud's avatar
LE GAC Renaud committed
143 144 145
    wizardNode.add_child(T('extract authors'), authorLeaf)
    wizardNode.add_child(T('run a harvester'), harvesterLeaf)
    wizardNode.add_child(T('run all harvesters'), runAllLeaf)
146
    
147
    if session.role == ADMIN:
LE GAC Renaud's avatar
LE GAC Renaud committed
148
        wizardNode.add_child(T('check and validate'), checkLeaf)
149 150 151
    else:
        wizardNode.add_child(T('check'), checkLeaf)
    
152
    wizardNode.sort_children()
153 154 155 156 157 158

#
# The viewport with its navigation tree
# the list of node depends on the user role
#
viewportModifier = dbui.ViewportModifier()
159
viewportModifier.add_node(helpNode, casNode, wizardNode, confNode, gridNode, reportNode)
160

161 162
# NOTE the session.auth only exit when the user is logged
if "auth" in globals():
163 164
    viewportModifier.append_plugins('pViewportLogin')
    viewportModifier.configure(logged=False)
165
 
166
if session.role in (ADMIN, USER):
LE GAC Renaud's avatar
LE GAC Renaud committed
167
    viewportModifier.configure(logged=True)
168
    viewportModifier.default_node(T('Tables'), T('publications'))