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

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

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

26
main_tables = ['publications']
27

28 29 30 31 32 33 34 35 36 37 38 39
#
# CAS node
#
if session.role == 'admin':
    
    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) 
40 41

#
42
# configuration tables node
43 44 45 46 47 48 49
#
if session.role == 'admin':
    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) 
50 51

#
52
# core tables node
53
#
54

55
if session.role in ('admin', 'user'):
56
    
57 58 59 60 61 62 63 64 65 66
    if session.role == 'admin':
        hidden_tables = list(auth_tables)
        hidden_tables.extend(configuration_tools_tables)
        
    elif session.role == 'user':
        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) 
67 68

#
69
# help node
70
#
LE GAC Renaud's avatar
LE GAC Renaud committed
71 72 73
aboutLeaf = dbui.Panel(autoLoad=URL('default', 'about'), autoScroll=True)
schemaLeaf = dbui.Panel(autoLoad=URL('default', 'schema'), autoScroll=True)
versionLeaf = dbui.Panel(autoLoad=URL('default', 'versions'))
74 75

helpNode = dbui.Node(T('Help'))
LE GAC Renaud's avatar
LE GAC Renaud committed
76 77
helpNode.add_child(T('about'), aboutLeaf)
helpNode.add_child(T('versions'), versionLeaf)
78 79

if session.role == 'admin':
LE GAC Renaud's avatar
LE GAC Renaud committed
80
    helpNode.add_child(T('database schema'), schemaLeaf)
81 82 83 84 85 86
    
helpNode.sort_children()

#
# report node
#
LE GAC Renaud's avatar
LE GAC Renaud committed
87
listLeaf = dbui.to_panelWithUrlSelector(virtdb.list_selector, 
LE GAC Renaud's avatar
LE GAC Renaud committed
88
                                        baseUrl=URL('lists', 'index'), 
89
                                        isMathJax=dbui.is_mathjax())
90

LE GAC Renaud's avatar
LE GAC Renaud committed
91
metricLeaf = dbui.to_panelWithUrlSelector(virtdb.metric_selector, 
LE GAC Renaud's avatar
LE GAC Renaud committed
92
                                          baseUrl=URL('metrics', 'index'))
93 94

reportNode = dbui.Node(T('Reports'))
LE GAC Renaud's avatar
LE GAC Renaud committed
95 96
reportNode.add_child(T('lists'), listLeaf)
reportNode.add_child(T('metrics'), metricLeaf)
97 98 99 100 101 102

reportNode.sort_children()

#
# wizard node
#
103
if session.role in ('admin', 'user'):
LE GAC Renaud's avatar
LE GAC Renaud committed
104
    authorLeaf = dbui.to_panelWithUrlSelector(virtdb.authors_selector, 
105 106
                                              baseUrl=URL('wizards', 'extract_authors'))
    
LE GAC Renaud's avatar
LE GAC Renaud committed
107
    freeLeaf = dbui.to_panelWithUrlSelector(virtdb.free_harvester_selector, 
108
                                            baseUrl=URL('harvest', 'free_run'),
109
                                            selectorTitle='Fill all fields',
110 111
                                            timeout=3600)
    
LE GAC Renaud's avatar
LE GAC Renaud committed
112
    checkLeaf = dbui.to_panelWithUrlSelector(virtdb.check_selector, 
113 114
                                             baseUrl=URL('wizards', 'check_validate'))
    
LE GAC Renaud's avatar
LE GAC Renaud committed
115
    harvesterLeaf = dbui.to_panelWithUrlSelector(virtdb.harvester_selector, 
116 117 118
                                                 baseUrl=URL('harvest', 'run'),
                                                 timeout=3600)
    
LE GAC Renaud's avatar
LE GAC Renaud committed
119
    marc12Leaf = dbui.to_panelWithUrlSelector(virtdb.marc12_selector, 
120
                                              selectorTitle='Fill all fields',
121 122
                                              baseUrl=URL('harvest', 'insert_marcxml')) 
    
LE GAC Renaud's avatar
LE GAC Renaud committed
123
    runAllLeaf = dbui.to_panelWithUrlSelector(virtdb.run_all_harvesters_selector, 
124 125 126 127 128
                                              baseUrl=URL('harvest', 'run_all'),
                                              timeout=3600)
    
    wizardNode = dbui.Node(T('Wizards'))
    
LE GAC Renaud's avatar
LE GAC Renaud committed
129 130
    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
131 132 133
    wizardNode.add_child(T('extract authors'), authorLeaf)
    wizardNode.add_child(T('run a harvester'), harvesterLeaf)
    wizardNode.add_child(T('run all harvesters'), runAllLeaf)
134
    
135
    if session.role == 'admin':
LE GAC Renaud's avatar
LE GAC Renaud committed
136
        wizardNode.add_child(T('check and validate'), checkLeaf)
137 138

    wizardNode.sort_children()
139 140 141 142 143 144 145 146 147

#
# The viewport with its navigation tree
# the list of node depends on the user role
#
viewportModifier = dbui.ViewportModifier()
viewportModifier.append_plugins('pViewportLogin')

if session.role == 'admin':
148
    viewportModifier.add_node(helpNode, casNode, wizardNode, confNode, gridNode, reportNode)
149 150
    viewportModifier.configure(logged=True)

151
elif session.role == 'user':
152
    viewportModifier.add_node(helpNode, wizardNode, gridNode, reportNode)
LE GAC Renaud's avatar
LE GAC Renaud committed
153
    viewportModifier.configure(logged=True)
154 155 156 157
    
else:
    viewportModifier.add_node(helpNode, reportNode)
    viewportModifier.configure(logged=False)
158