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

"""
5 6 7 8 9 10 11 12
# helper function translating a tablename into the grid configuration
to_grid = lambda tablename: dbui.to_gridPanel(db[tablename]) 

# short cuts
Node = dbui.Node
Panel = dbui.Panel
PanelWithUrlSelector = dbui.to_panelWithUrlSelector

13 14
#-------------------------------------------------------------------------------
#
15
# CAS
16
#
17
#-------------------------------------------------------------------------------
18
casNode = None
LE GAC Renaud's avatar
LE GAC Renaud committed
19
if "auth" in globals() and session.role == ADMIN:
20 21
    
    leaves = ('auth_user', 'auth_group', 'auth_membership')
22

23 24
    casNode = Node(T('CAS'))
    casNode.add_children(leaves, func=to_grid) 
25

26
#-------------------------------------------------------------------------------
27
#
28
# CONFIGURE HARVESTERS
29
#
30
#-------------------------------------------------------------------------------
31 32
confHarvesterNode = None
if session.role in (ADMIN, USER):
33
    
34
    leaves = ('controllers', 'cppm_authors', 'harvesters')
35

36 37 38 39 40
    if session.role == USER:
        leaves = ('cppm_authors', 'harvesters')
        
    confHarvesterNode = Node(T('Configure harvesters'))
    confHarvesterNode.add_children(leaves, func=to_grid)
41

42
#-------------------------------------------------------------------------------
43
#
44
# CONFIGURE RAPPORTS
45
#
46
#-------------------------------------------------------------------------------
47
confRapportNode = None
48
if session.role == ADMIN:
49

50
    leaves = ('axes', 'lists', 'metrics', 'renderers', 'sections')
51

52 53 54
    confRapportNode = Node(T('Configure rapports'))
    confRapportNode.add_children(leaves, func=to_grid)
     
55
#-------------------------------------------------------------------------------
56
#
57
# DATA INSTITUT
58
#
59
#-------------------------------------------------------------------------------
60 61 62 63 64 65 66 67 68 69 70 71 72 73
dataInstituteNode = None
if session.role == ADMIN:

    leaves = ('authors_roles', 'organisation', 'projects', 'teams')

    dataInstituteNode = Node(T('Data institute'))
    dataInstituteNode.add_children(leaves, func=to_grid)
     
#-------------------------------------------------------------------------------
#
# DATA PUBLICATIONS
#
#-------------------------------------------------------------------------------
dataPublicationeNode = None
74
if session.role in (ADMIN, USER):
75

76 77 78 79 80 81
    leaves = ('categories', 
              'collaborations', 
              'countries',
              'publications', 
              'publishers',
              'status')
82

83 84 85 86 87 88
    if session.role == USER:
        leaves = ('publications')
        
    dataPublicationeNode = Node(T('Data publications'))
    dataPublicationeNode.add_children(leaves, func=to_grid)
    
89
#-------------------------------------------------------------------------------
90
#
91
# HELP NODE
92
#
93
#-------------------------------------------------------------------------------
94 95 96 97
aboutLeaf = Panel(autoLoad=URL('default', 'about'), autoScroll=True)
documentationsLeaf = Panel(autoLoad=URL('default', 'documentations'), autoScroll=True)
schemaLeaf = Panel(autoLoad=URL('default', 'schema'), autoScroll=True)
versionLeaf = Panel(autoLoad=URL('default', 'versions'))
98

99
helpNode = Node(T('Help'))
LE GAC Renaud's avatar
LE GAC Renaud committed
100 101
helpNode.add_child(T('about'), aboutLeaf)
helpNode.add_child(T('versions'), versionLeaf)
102

103
if session.role == ADMIN:
104
    helpNode.add_child(T('documentations'), documentationsLeaf)
105 106 107
    
helpNode.sort_children()

108
#-------------------------------------------------------------------------------
109
#
110
# REPORT NODE
111
#
112
#-------------------------------------------------------------------------------
113 114 115 116
listLeaf = PanelWithUrlSelector(virtdb.list_selector, 
                                baseUrl=URL('lists', 'index'),
                                extField='format',
                                isMathJax=dbui.is_mathjax())
117

118 119 120
metricLeaf = PanelWithUrlSelector(virtdb.metric_selector, 
                                  baseUrl=URL('metrics', 'index'),
                                  extField='format')
121

122
reportNode = Node(T('Reports'))
LE GAC Renaud's avatar
LE GAC Renaud committed
123 124
reportNode.add_child(T('lists'), listLeaf)
reportNode.add_child(T('metrics'), metricLeaf)
125 126 127

reportNode.sort_children()

128
#-------------------------------------------------------------------------------
129
#
130
# WIZARD NODE
131
#
132
#-------------------------------------------------------------------------------
133
wizardNode = None
134
if session.role in (ADMIN, USER):
135 136
    authorLeaf = PanelWithUrlSelector(virtdb.authors_selector, 
                                      baseUrl=URL('wizards', 'extract_authors'))
137
    
138 139 140 141
    freeLeaf = PanelWithUrlSelector(virtdb.free_harvester_selector, 
                                    baseUrl=URL('harvest', 'free_run'),
                                    selectorTitle='Fill all fields',
                                    timeout=ONE_HOUR)
142
    
143 144 145
    checkLeaf = PanelWithUrlSelector(virtdb.check_selector, 
                                     baseUrl=URL('wizards', 'check_validate'),
                                     extField='format')
146
    
147 148 149 150
    harvesterLeaf = PanelWithUrlSelector(virtdb.harvester_selector, 
                                         baseUrl=URL('harvest', 'run'),
                                         extField='format',
                                         timeout=ONE_HOUR)
151
    
152 153 154
    marc12Leaf = PanelWithUrlSelector(virtdb.marc12_selector, 
                                      selectorTitle='Fill all fields',
                                      baseUrl=URL('harvest', 'insert_marcxml')) 
155
    
156 157 158 159
    runAllLeaf = PanelWithUrlSelector(virtdb.run_all_harvesters_selector, 
                                      baseUrl=URL('harvest', 'run_all'),
                                      extField='format',
                                      timeout=ONE_HOUR)
160
    
161
    wizardNode = Node(T('Wizards'))
LE GAC Renaud's avatar
LE GAC Renaud committed
162 163
    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
164 165 166
    wizardNode.add_child(T('extract authors'), authorLeaf)
    wizardNode.add_child(T('run a harvester'), harvesterLeaf)
    wizardNode.add_child(T('run all harvesters'), runAllLeaf)
167
    
168
    if session.role == ADMIN:
LE GAC Renaud's avatar
LE GAC Renaud committed
169
        wizardNode.add_child(T('check and validate'), checkLeaf)
170 171 172
    else:
        wizardNode.add_child(T('check'), checkLeaf)
    
173
    wizardNode.sort_children()
174

175
#-------------------------------------------------------------------------------
176
#
177
# VIEWPORT
178
#
179
#-------------------------------------------------------------------------------
180 181 182 183 184 185 186 187 188
nodes = [helpNode, 
         casNode, 
         wizardNode, 
         confHarvesterNode, 
         confRapportNode,
         dataInstituteNode,
         dataPublicationeNode, 
         reportNode]

189
viewportModifier = dbui.ViewportModifier()
190
viewportModifier.add_node(*nodes)
191

LE GAC Renaud's avatar
LE GAC Renaud committed
192 193
viewportModifier.configure(tabTitleTpl="{1}")

194 195
# NOTE the session.auth only exit when the user is logged
if "auth" in globals():
LE GAC Renaud's avatar
LE GAC Renaud committed
196 197
    viewportModifier.configure(logged=False, 
                               plugins=['pViewportLogin'])
198
 
199
if session.role in (ADMIN, USER):
LE GAC Renaud's avatar
LE GAC Renaud committed
200
    viewportModifier.configure(logged=True)
201
    viewportModifier.default_node(T('Data publications'), T('publications'))