Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
common-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
protokollsystem
common-web
Commits
3dfc2b71
Commit
3dfc2b71
authored
7 years ago
by
Robin Sonnabend
Browse files
Options
Downloads
Patches
Plain Diff
Add back.py to common web modules
parent
f9dbd00f
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
back.py
+35
-0
35 additions, 0 deletions
back.py
with
35 additions
and
0 deletions
back.py
0 → 100644
+
35
−
0
View file @
3dfc2b71
# This snippet is in public domain.
# However, please retain this link in your sources:
# http://flask.pocoo.org/snippets/120/
# Danya Alexeyevsky
import
functools
from
flask
import
session
,
request
,
redirect
as
flask_redirect
,
url_for
import
config
cookie
=
getattr
(
config
,
"
REDIRECT_BACK_COOKIE
"
,
"
back
"
)
default_view
=
getattr
(
config
,
"
REDIRECT_BACK_DEFAULT
"
,
"
index
"
)
def
anchor
(
func
,
cookie
=
cookie
):
@functools.wraps
(
func
)
def
result
(
*
args
,
**
kwargs
):
session
[
cookie
]
=
request
.
url
return
func
(
*
args
,
**
kwargs
)
return
result
def
default_url
(
default
,
**
url_args
):
return
url_for
(
default
,
**
url_args
)
def
url
(
default
=
default_view
,
cookie
=
cookie
,
**
url_args
):
return
session
.
get
(
cookie
,
default_url
(
default
,
**
url_args
))
def
redirect
(
default
=
default_view
,
cookie
=
cookie
,
**
url_args
):
print
(
request
.
url
,
request
.
url_rule
,
default
,
session
.
get
(
cookie
))
target
=
url
(
default
,
cookie
,
**
url_args
)
if
target
==
request
.
url
:
target
=
default_url
(
default
,
**
url_args
)
return
flask_redirect
(
target
)
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