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
ded1a6f3
Commit
ded1a6f3
authored
Jun 15, 2015
by
Nikolaos S. Papaspyrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for new URLs
parent
fd473073
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
0 deletions
+47
-0
README.md
README.md
+5
-0
base.html
urlapp/templates/base.html
+1
-0
new.html
urlapp/templates/new.html
+16
-0
urls.py
urlapp/urls.py
+2
-0
views.py
urlapp/views.py
+23
-0
No files found.
README.md
View file @
ded1a6f3
...
...
@@ -117,3 +117,8 @@ Part 5
------
Require user authentication.
Part 6
------
Add new URLs.
urlapp/templates/base.html
View file @
ded1a6f3
...
...
@@ -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>
...
...
urlapp/templates/new.html
0 → 100644
View file @
ded1a6f3
{% 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 %}
urlapp/urls.py
View file @
ded1a6f3
...
...
@@ -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
.
url
,
name
=
'url'
),
url
(
r'^new/$'
,
views
.
new
,
name
=
'new'
),
url
(
r'^generate/$'
,
views
.
generate
,
name
=
'generate'
),
]
urlapp/views.py
View file @
ded1a6f3
from
django.shortcuts
import
render
,
get_object_or_404
,
redirect
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
HttpResponseRedirect
,
HttpResponse
from
django.core.urlresolvers
import
reverse
from
.models
import
Url
# Create your views here.
...
...
@@ -24,3 +27,23 @@ def url(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
):
try
:
u
=
Url
(
target
=
request
.
POST
[
'target'
])
request
.
user
.
url_set
.
add
(
u
)
except
:
# Redisplay the question voting form.
return
render
(
request
,
'new.html'
,
{
'error_message'
:
"Something went wrong."
,
})
else
:
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