Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
django-url-follower
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikolaos S. Papaspyrou
django-url-follower
Commits
f5461e76
Commit
f5461e76
authored
Jun 15, 2015
by
Nikolaos S. Papaspyrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for new URLs
parent
153b80c1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
0 deletions
+33
-0
base.html
urlforward/templates/base.html
+1
-0
new.html
urlforward/templates/new.html
+16
-0
urls.py
urlforward/urls.py
+2
-0
views.py
urlforward/views.py
+14
-0
No files found.
urlforward/templates/base.html
View file @
f5461e76
...
...
@@ -18,6 +18,7 @@
</div>
<ul
class=
"nav navbar-nav navbar-right"
>
{% if user.is_authenticated %}
<li><a
href=
"{% url 'new' %}"
>
New
</a></li>
<li><a
href=
"{% url 'logout' %}"
>
Logout
</a></li>
{% endif %}
</ul>
...
...
urlforward/templates/new.html
0 → 100644
View file @
f5461e76
{% extends "base.html" %}
{% block content %}
<h1>
Add new URL
</h1>
{% if error_message %}
<p><strong>
{{ error_message }}
</strong></p>
{% endif %}
<form
action=
"{% url 'generate' %}"
method=
"post"
>
{% csrf_token %}
<label
for=
"target"
>
Target:
</label><br
/>
<input
type=
"text"
name=
"target"
id=
"target"
/>
<input
type=
"submit"
value=
"Generate"
/>
</form>
{% endblock %}
urlforward/urls.py
View file @
f5461e76
...
...
@@ -6,4 +6,6 @@ urlpatterns = [
url
(
r'^$'
,
views
.
index
,
name
=
'index'
),
url
(
r'^(?P<url_id>[0-9]+)$'
,
views
.
redir
,
name
=
'redir'
),
url
(
r'^url=(?P<url_id>[0-9]+)$'
,
views
.
details
,
name
=
'details'
),
url
(
r'^new$'
,
views
.
new
,
name
=
'new'
),
url
(
r'^generate$'
,
views
.
generate
,
name
=
'generate'
),
]
urlforward/views.py
View file @
f5461e76
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
HttpResponseRedirect
from
django.core.urlresolvers
import
reverse
from
.models
import
Url
# Create your views here.
...
...
@@ -24,3 +27,14 @@ def details(request, url_id):
'url'
:
get_object_or_404
(
Url
,
id
=
url_id
)
}
return
render
(
request
,
'details.html'
,
context
)
@
login_required
def
new
(
request
):
context
=
{}
return
render
(
request
,
'new.html'
,
context
)
@
login_required
def
generate
(
request
):
u
=
Url
(
target
=
request
.
POST
[
'target'
],
user
=
request
.
user
)
u
.
save
()
return
HttpResponseRedirect
(
reverse
(
'index'
))
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