widgets_viewport.py 4.97 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
schemaNode = dbui.Panel(autoLoad=URL('default', 'schema'))
versionNode = dbui.Panel(autoLoad=URL('default', 'versions'))
73 74 75 76 77 78 79 80 81 82 83 84

helpNode = dbui.Node(T('Help'))
helpNode.add_child(T('versions'), versionNode)

if session.role == 'admin':
    helpNode.add_child(T('database schema'), schemaNode)
    
helpNode.sort_children()

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

LE GAC Renaud's avatar
LE GAC Renaud committed
89 90
metricNode = dbui.to_panelWithUrlSelector(virtdb.metric_selector, 
                                          baseUrl=URL('metrics', 'index'))
91 92 93 94 95 96 97 98 99 100

reportNode = dbui.Node(T('Reports'))
reportNode.add_child(T('lists'), listNode)
reportNode.add_child(T('metrics'), metricNode)

reportNode.sort_children()

#
# wizard node
#
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
if session.role in ('admin', 'user'):
    authorNode = dbui.to_panelWithUrlSelector(virtdb.authors_selector, 
                                              baseUrl=URL('wizards', 'extract_authors'))
    
    freeNode = dbui.to_panelWithUrlSelector(virtdb.free_harvester_selector, 
                                            baseUrl=URL('harvest', 'free_run'),
                                            timeout=3600)
    
    checkNode = dbui.to_panelWithUrlSelector(virtdb.check_selector, 
                                             baseUrl=URL('wizards', 'check_validate'))
    
    harvesterNode = dbui.to_panelWithUrlSelector(virtdb.harvester_selector, 
                                                 baseUrl=URL('harvest', 'run'),
                                                 timeout=3600)
    
    marc12Node = dbui.to_panelWithUrlSelector(virtdb.marc12_selector, 
                                              baseUrl=URL('harvest', 'insert_marcxml')) 
    
    runAllNode = dbui.to_panelWithUrlSelector(virtdb.run_all_harvesters_selector, 
                                              baseUrl=URL('harvest', 'run_all'),
                                              timeout=3600)
    
    wizardNode = dbui.Node(T('Wizards'))
    
    wizardNode.add_child(T('insert MARCXML'), marc12Node)
126
    wizardNode.add_child(T('run a free harvester'), freeNode)
127
    
128 129 130 131 132 133 134
    if session.role == 'admin':
        wizardNode.add_child(T('check and validate'), checkNode)
        wizardNode.add_child(T('extract authors'), authorNode)
        wizardNode.add_child(T('run a harvester'), harvesterNode)
        wizardNode.add_child(T('run all harvester'), runAllNode)

    wizardNode.sort_children()
135 136 137 138 139 140 141 142 143

#
# 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':
144
    viewportModifier.add_node(helpNode, casNode, wizardNode, confNode, gridNode, reportNode)
145 146
    viewportModifier.configure(logged=True)

147
elif session.role == 'user':
148
    viewportModifier.add_node(helpNode, wizardNode, gridNode, reportNode)
149
    viewportModifier.configure(logged=False)
150 151 152 153
    
else:
    viewportModifier.add_node(helpNode, reportNode)
    viewportModifier.configure(logged=False)
154