Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jannik Hellenkamp
website
Commits
378701af
Commit
378701af
authored
8 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Use @mod_required to decide if navitem is public
parent
3259f87d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.py
+9
-3
9 additions, 3 deletions
server.py
with
9 additions
and
3 deletions
server.py
+
9
−
3
View file @
378701af
...
@@ -22,6 +22,7 @@ if __name__ == '__main__':
...
@@ -22,6 +22,7 @@ if __name__ == '__main__':
config
[
'
DEBUG
'
]
=
True
config
[
'
DEBUG
'
]
=
True
config
.
from_pyfile
(
'
config.py
'
,
silent
=
True
)
config
.
from_pyfile
(
'
config.py
'
,
silent
=
True
)
app
.
jinja_env
.
globals
[
'
videoprefix
'
]
=
config
[
'
VIDEOPREFIX
'
]
app
.
jinja_env
.
globals
[
'
videoprefix
'
]
=
config
[
'
VIDEOPREFIX
'
]
mod_endpoints
=
[]
if
config
[
'
DB_ENGINE
'
]
==
'
sqlite
'
:
if
config
[
'
DB_ENGINE
'
]
==
'
sqlite
'
:
created
=
not
os
.
path
.
exists
(
config
[
'
SQLITE_DB
'
])
created
=
not
os
.
path
.
exists
(
config
[
'
SQLITE_DB
'
])
...
@@ -127,6 +128,7 @@ def ismod(*args):
...
@@ -127,6 +128,7 @@ def ismod(*args):
app
.
jinja_env
.
globals
[
'
ismod
'
]
=
ismod
app
.
jinja_env
.
globals
[
'
ismod
'
]
=
ismod
def
mod_required
(
func
):
def
mod_required
(
func
):
mod_endpoints
.
append
(
func
.
__name__
)
@wraps
(
func
)
@wraps
(
func
)
def
decorator
(
*
args
,
**
kwargs
):
def
decorator
(
*
args
,
**
kwargs
):
if
not
ismod
():
if
not
ismod
():
...
@@ -134,12 +136,15 @@ def mod_required(func):
...
@@ -134,12 +136,15 @@ def mod_required(func):
return
redirect
(
url_for
(
'
login
'
,
ref
=
request
.
url
))
return
redirect
(
url_for
(
'
login
'
,
ref
=
request
.
url
))
else
:
else
:
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
print
(
decorator
.
__name__
)
return
decorator
return
decorator
app
.
jinja_env
.
globals
[
'
navbar
'
]
=
[]
app
.
jinja_env
.
globals
[
'
navbar
'
]
=
[]
def
register_navbar
(
name
,
icon
=
None
,
visible
=
True
):
def
register_navbar
(
name
,
icon
=
None
):
def
wrapper
(
func
):
def
wrapper
(
func
):
app
.
jinja_env
.
globals
[
'
navbar
'
].
append
((
func
.
__name__
,
name
,
icon
,
visible
))
endpoint
=
func
.
__name__
app
.
jinja_env
.
globals
[
'
navbar
'
].
append
((
endpoint
,
name
,
icon
,
not
endpoint
in
mod_endpoints
))
return
func
return
func
return
wrapper
return
wrapper
...
@@ -297,7 +302,8 @@ def auth(): # For use with nginx auth_request
...
@@ -297,7 +302,8 @@ def auth(): # For use with nginx auth_request
@app.route
(
'
/schedule
'
)
@app.route
(
'
/schedule
'
)
@register_navbar
(
'
Drehplan
'
,
'
calendar
'
,
visible
=
False
)
@register_navbar
(
'
Drehplan
'
,
'
calendar
'
)
@mod_required
def
schedule
():
def
schedule
():
return
render_template
(
'
schedule.html
'
)
return
render_template
(
'
schedule.html
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment