Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
e5f55656
Commit
e5f55656
authored
Dec 15, 2013
by
Jean Michel Rouly
Browse files
Added redirection.
parent
21d465e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
go/go/views.py
View file @
e5f55656
from
go.models
import
URL
from
django.http
import
Http404
from
django.contrib.auth.models
import
User
from
django.contrib.auth.decorators
import
login_required
from
django.shortcuts
import
render
,
get_object_or_404
,
redirect
...
...
@@ -45,3 +46,15 @@ def signup(request):
},
)
# Redirection view.
def
redirection
(
request
,
short
):
try
:
url
=
URL
.
objects
.
get
(
short
=
short
)
except
URL
.
DoesNotExist
:
raise
Http404
(
"Target URL not found."
)
target
=
url
.
target
url
.
clicks
=
url
.
clicks
+
1
url
.
save
()
return
redirect
(
target
)
go/settings/urls.py
View file @
e5f55656
...
...
@@ -32,3 +32,8 @@ urlpatterns += patterns('django.contrib.auth.views',
url
(
r
'^logout$'
,
'logout'
,
{
'next_page'
:
'/'
},
name
=
'go_logout'
),
)
urlpatterns
+=
patterns
(
'go.views'
,
# Redirection regex.
url
(
r
'^(?P<short>\w+)$'
,
'redirection'
,
name
=
'redirection'
),
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment