summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks2011-10-25 00:17:19 +0200
committerÉtienne Loks2011-10-25 00:17:19 +0200
commite41e52768085a81b1b5d48f5f0583b6449179fa8 (patch)
treeda836b2f6390b6490fb3f8acfaea3aaa4a2ad7d5
parent2a50c79d3b9de35937c07c838205e25ad058b3e1 (diff)
Correct hard link in templates and views (closes #309)
-rw-r--r--papillon/polls/feeds.py2
-rw-r--r--papillon/polls/views.py41
-rw-r--r--papillon/templates/base.html4
-rw-r--r--papillon/templates/category.html2
-rw-r--r--papillon/templates/create.html2
-rw-r--r--papillon/templates/edit.html14
-rw-r--r--papillon/templates/editChoices.html2
-rw-r--r--papillon/templates/editChoicesAdmin.html10
-rw-r--r--papillon/templates/editChoicesUser.html8
-rw-r--r--papillon/templates/main.html6
-rw-r--r--papillon/templates/vote.html14
-rw-r--r--papillon/urls.py33
12 files changed, 70 insertions, 68 deletions
diff --git a/papillon/polls/feeds.py b/papillon/polls/feeds.py
index 2d52dc7..5c11b9c 100644
--- a/papillon/polls/feeds.py
+++ b/papillon/polls/feeds.py
@@ -52,4 +52,4 @@ class PollLatestEntries(Feed):
def items(self, obj):
voters = Voter.objects.filter(poll__id=obj.id).\
order_by('-modification_date')[:10]
- return voters \ No newline at end of file
+ return voters
diff --git a/papillon/polls/views.py b/papillon/polls/views.py
index 300b313..75823be 100644
--- a/papillon/polls/views.py
+++ b/papillon/polls/views.py
@@ -26,11 +26,12 @@ import string
import time
from datetime import datetime
-from django.utils.translation import gettext_lazy as _
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
+from django.conf import settings
+from django.utils.translation import gettext_lazy as _
+from django.core.urlresolvers import reverse
-from papillon.settings import LANGUAGES, BASE_SITE
from papillon.polls.models import Poll, PollUser, Choice, Voter, Vote, \
Category, Comment
from papillon.polls.forms import CreatePollForm, AdminPollForm, ChoiceForm, \
@@ -40,16 +41,17 @@ def getBaseResponse(request):
"""Manage basic fields for the template
If not null the second argument returned is a redirection.
"""
- url = BASE_SITE
# setting the current language and available languages
if 'language' in request.GET:
- if request.GET['language'] in [language[0] for language in LANGUAGES]:
+ if request.GET['language'] in \
+ [language[0] for language in settings.LANGUAGES]:
request.session['django_language'] = request.GET['language']
return None, HttpResponseRedirect(request.path)
languages = []
- for language_code, language_label in LANGUAGES:
+ for language_code, language_label in settings.LANGUAGES:
languages.append((language_code, language_label))
- return {'root_url':url, 'languages':languages}, None
+ return {'media_url':settings.MEDIA_URL, 'languages':languages,
+ 'admin_url':settings.ADMIN_MEDIA_PREFIX,}, None
def index(request):
"Main page"
@@ -99,8 +101,8 @@ def create(request):
poll.admin_url = genRandomURL()
poll.base_url = genRandomURL()
poll.save()
- return HttpResponseRedirect('%seditChoicesAdmin/%s/' % (
- response_dct['root_url'], poll.admin_url))
+ return HttpResponseRedirect(reverse('edit_choices_admin',
+ args=[poll.admin_url]))
else:
form = CreatePollForm()
response_dct['form'] = form
@@ -116,17 +118,15 @@ def edit(request, admin_url):
poll = Poll.objects.filter(admin_url=admin_url)[0]
except IndexError:
# if the poll don't exist redirect to the creation page
- url = response_dct['root_url']
- return HttpResponseRedirect('%screate' % (
- response_dct['root_url']))
+ return HttpResponseRedirect(reverse('create'))
Form = AdminPollForm
if request.method == 'POST':
form = Form(request.POST, instance=poll)
if form.is_valid():
poll = form.save()
- return HttpResponseRedirect('%sedit/%s/' % (
- response_dct['root_url'], poll.admin_url))
+ return HttpResponseRedirect(reverse('edit',
+ args=[poll.admin_url]))
else:
form = Form(instance=poll)
response_dct['form'] = form
@@ -141,8 +141,7 @@ def editChoicesAdmin(request, admin_url):
poll = Poll.objects.filter(admin_url=admin_url)[0]
except IndexError:
# if the poll don't exist redirect to the main page
- url = "/".join(request.path.split('/')[:-2])
- return response_dct, HttpResponseRedirect(url)
+ return HttpResponseRedirect(reverse('index'))
response_dct['poll'] = poll
return editChoices(request, response_dct, admin=True)
@@ -156,8 +155,7 @@ def editChoicesUser(request, poll_url):
poll = None
if not poll or not poll.opened_admin:
# if the poll don't exist redirect to the main page
- url = "/".join(request.path.split('/')[:-2])
- return HttpResponseRedirect(url)
+ return HttpResponseRedirect(reverse('index'))
response_dct['poll'] = poll
return editChoices(request, response_dct)
@@ -215,7 +213,10 @@ def editChoices(request, response_dct, admin=False):
if admin and request.method == 'GET':
for key in request.GET:
try:
- current_url = request.path.split('?')[0]
+ current_url = reverse('edit_choices_admin',
+ args=[poll.admin_url]) if admin else \
+ reverse('edit_choices_user',
+ args=[poll.poll_url])
if 'up_choice' in key:
choice = Choice.objects.get(id=int(request.GET[key]))
if choice.poll != poll:
@@ -411,9 +412,7 @@ def poll(request, poll_url):
# if the poll don't exist or if it has no choices the user is
# redirected to the main page
if not choices or not poll:
- url = "/".join(request.path.split('/')[:-3])
- url += "/?bad_poll=1"
- return HttpResponseRedirect(url)
+ return HttpResponseRedirect(reverse('index'))
# a vote is submitted
if 'author_name' in request.POST and poll.open:
diff --git a/papillon/templates/base.html b/papillon/templates/base.html
index b673f24..5da20fb 100644
--- a/papillon/templates/base.html
+++ b/papillon/templates/base.html
@@ -2,7 +2,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
- <link rel="stylesheet" href="{{root_url}}static/styles.css" />
+ <link rel="stylesheet" href="{{media_url}}styles.css" />
<title>{% block title %}Papillon{% endblock %}</title>
{% block fullscript %}{% endblock %}
</head>
@@ -13,7 +13,7 @@
<span id='languages'>{% for language in languages%}<a href='?language={{language.0}}'>{{language.1}}</a>{% endfor %}</span>
</div>
<div id="top">
- <h1><a href='{{root_url}}'>Papillon</a></h1>
+ <h1><a href='{% url index %}'>Papillon</a></h1>
</div>
<div id="content">
{% block content %}{% endblock %}
diff --git a/papillon/templates/category.html b/papillon/templates/category.html
index 55aa084..f38743a 100644
--- a/papillon/templates/category.html
+++ b/papillon/templates/category.html
@@ -8,7 +8,7 @@
{% if polls %}<h2>{%trans "Polls"%}</h2>{%endif%}
{% for poll in polls %}
<div class='poll-description'>
- <p><a href='{{root_url}}poll/{{poll.base_url}}'>{{poll.name}}</a></p>
+ <p><a href='{% url poll poll.base_url%}'>{{poll.name}}</a></p>
<p>{{poll.description|safe}}</p>
</div>
{% endfor %}
diff --git a/papillon/templates/create.html b/papillon/templates/create.html
index 7c3d2b3..224ae78 100644
--- a/papillon/templates/create.html
+++ b/papillon/templates/create.html
@@ -9,7 +9,7 @@
{% block content %}
<h2>{% trans "New poll" %}</h2>
-<form action="" method="post">
+<form action="." method="post">
<table class='new_poll'>
{% for field in form %}
{% if field.is_hidden %}
diff --git a/papillon/templates/edit.html b/papillon/templates/edit.html
index 7ef4f14..b2b38a5 100644
--- a/papillon/templates/edit.html
+++ b/papillon/templates/edit.html
@@ -3,20 +3,20 @@
{% load i18n %}
{% block fullscript %}
-<script type="text/javascript" src="{{root_url}}admin/jsi18n/"></script>
-<script type="text/javascript" src="{{root_url}}media/js/core.js"></script>
-<script type="text/javascript" src="{{root_url}}media/js/admin/RelatedObjectLookups.js"></script>
+<script type="text/javascript" src="{%url admin_i18n%}"></script>
+<script type="text/javascript" src="{{admin_url}}js/core.js"></script>
+<script type="text/javascript" src="{{admin_url}}js/admin/RelatedObjectLookups.js"></script>
{{ form.media }}
{% endblock %}
{% block content %}
<h2>{% trans "Edit poll" %}</h2>
-<form action="" method="post">
+<form action="." method="post">
<table class='new_poll'>
<tr>
<td><label>{% trans "Poll url" %}</label></td>
<td>
-<a href='{{root_url}}poll/{{poll.base_url}}'>{{root_url}}poll/{{poll.base_url}}</a>
+<a href='{% url poll poll.base_url%}'>{% url poll poll.base_url%}</a>
</td>
<td class='form_description'><p>
{% trans "Copy this address and send it to voters who want to participate to this poll" %}
@@ -25,7 +25,7 @@
<tr>
<td><label>{% trans "Administration url" %}</label></td>
<td>
-<a href='{{root_url}}edit/{{poll.admin_url}}'>{{root_url}}edit/{{poll.admin_url}}</a>
+<a href='{% url edit poll.admin_url %}'>{% url edit poll.admin_url %}</a>
</td>
<td class='form_description'><p>
{% trans "Address to modify the current poll" %}
@@ -34,7 +34,7 @@
<tr>
<td><label>{% trans "Choices administration url" %}</label></td>
<td>
-<a href='{{root_url}}editChoicesAdmin/{{poll.admin_url}}'>{{root_url}}editChoicesAdmin/{{poll.admin_url}}</a>
+<a href='{% url edit_choices_admin poll.admin_url %}'>{% url edit_choices_admin poll.admin_url %}</a>
</td>
<td class='form_description'><p>
{% trans "Address to modify choices of the current poll." %}
diff --git a/papillon/templates/editChoices.html b/papillon/templates/editChoices.html
index 1082d30..7e059a8 100644
--- a/papillon/templates/editChoices.html
+++ b/papillon/templates/editChoices.html
@@ -3,7 +3,7 @@
<h2>{% trans "New choice" %}</h2>
{%if form_new_choice.errors %} <p class='error'>{{form_new_choice.errors}}</p>{%endif%}
-<form action="{{admin_url}}" method="post">
+<form action="." method="post">
{{form_new_choice.poll}}
{{form_new_choice.order}}
<table class='new_poll'>
diff --git a/papillon/templates/editChoicesAdmin.html b/papillon/templates/editChoicesAdmin.html
index b04b0ec..6510dcc 100644
--- a/papillon/templates/editChoicesAdmin.html
+++ b/papillon/templates/editChoicesAdmin.html
@@ -3,9 +3,9 @@
{% load i18n %}
{% block fullscript %}
-<script type="text/javascript" src="{{root_url}}admin/jsi18n/"></script>
-<script type="text/javascript" src="{{root_url}}media/js/core.js"></script>
-<script type="text/javascript" src="{{root_url}}media/js/admin/RelatedObjectLookups.js"></script>
+<script type="text/javascript" src="{%url admin_i18n%}"></script>
+<script type="text/javascript" src="{{admin_url}}js/core.js"></script>
+<script type="text/javascript" src="{{admin_url}}js/admin/RelatedObjectLookups.js"></script>
{{ form_new_choice.media }}
{% endblock %}
@@ -14,7 +14,7 @@
{% blocktrans %}As long as no options were added to the poll, it will not be available.{% endblocktrans %}
</p>{% else %}
<h2>{% trans "Complete/Finalise the poll" %}</h2>
-<p><a href='{{root_url}}edit/{{poll.admin_url}}'><button>{% trans "Next"%}</button></a></p>
+<p><a href='{% url edit poll.admin_url%}'><button>{% trans "Next"%}</button></a></p>
{% endif %}
{% include 'editChoices.html' %}
{% if choices %}
@@ -27,7 +27,7 @@
<th>{% trans "Delete?"%}</th>
</tr>
{% for choice in choices %}
- <form action="" method="post">
+ <form action="." method="post">
{{choice.form.poll}}{{choice.form.order}}<tr>
{%if not poll.dated_choices%}<td><a href='?up_choice={{choice.id}}' class='arrow'>+</a>
/ <a href='?down_choice={{choice.id}}' class='arrow'>-</a></td>{%endif%}
diff --git a/papillon/templates/editChoicesUser.html b/papillon/templates/editChoicesUser.html
index 0d2b2c1..47d6a52 100644
--- a/papillon/templates/editChoicesUser.html
+++ b/papillon/templates/editChoicesUser.html
@@ -3,14 +3,14 @@
{% load i18n %}
{% block fullscript %}
-<script type="text/javascript" src="{{root_url}}admin/jsi18n/"></script>
-<script type="text/javascript" src="{{root_url}}media/js/core.js"></script>
-<script type="text/javascript" src="{{root_url}}media/js/admin/RelatedObjectLookups.js"></script>
+<script type="text/javascript" src="{%url admin_i18n%}"></script>
+<script type="text/javascript" src="{{admin_url}}js/core.js"></script>
+<script type="text/javascript" src="{{admin_url}}js/admin/RelatedObjectLookups.js"></script>
{{ form_new_choice.media }}
{% endblock %}
{% block content %}
- <p><a href="{{root_url}}poll/{{poll.base_url}}/">{%trans "Return to the poll"%}</a></p>
+ <p><a href="{% url poll poll.base_url %}">{%trans "Return to the poll"%}</a></p>
<h2>{% trans "Choices" %}</h2>
{% if choices %}<table class='new_poll'>
<tr>
diff --git a/papillon/templates/main.html b/papillon/templates/main.html
index 49088f0..f27a97b 100644
--- a/papillon/templates/main.html
+++ b/papillon/templates/main.html
@@ -3,20 +3,20 @@
{% block content %}
{% if error %}<p class='error'>{{error}}</p>{%endif%}
-<h2><a href='create'>{%trans "Create a poll"%}</a></h2>
+<h2><a href='{% url create%}'>{%trans "Create a poll"%}</a></h2>
<p>{% trans "Create a new sondage for take a decision, find a date for a meeting, etc." %} <a href='create'>{% trans "It's here!" %}</a></p>
{% if polls %}<h2>{%trans "Public polls"%}</h2>{%endif%}
{% for poll in polls %}
<div class='poll-description'>
- <p><a href='poll/{{poll.base_url}}'>{{poll.name}}</a></p>
+ <p><a href='{% url poll poll.base_url%}'>{{poll.name}}</a></p>
<p>{{poll.description|safe}}</p>
</div>
{% endfor %}
{% if categories %}<h2>{%trans "Categories"%}</h2>{% endif %}
{% for category in categories %}
-<h3><a href='category/{{category.id}}'>{{category.name}}</a></h3>
+<h3><a href='{% url category category.id%}'>{{category.name}}</a></h3>
{% endfor %}
{% endblock %}
diff --git a/papillon/templates/vote.html b/papillon/templates/vote.html
index 94d1898..dc384f5 100644
--- a/papillon/templates/vote.html
+++ b/papillon/templates/vote.html
@@ -3,9 +3,9 @@
{% load get_range %}
{% block fullscript %}
-<script type="text/javascript" src="{{root_url}}admin/jsi18n/"></script>
-<script type="text/javascript" src="{{root_url}}media/js/core.js"></script>
-<script type="text/javascript" src="{{root_url}}media/js/admin/RelatedObjectLookups.js"></script>
+<script type="text/javascript" src="{%url admin_i18n%}"></script>
+<script type="text/javascript" src="{{admin_url}}js/core.js"></script>
+<script type="text/javascript" src="{{admin_url}}js/admin/RelatedObjectLookups.js"></script>
{{ form_comment.media }}
{% endblock %}
@@ -14,7 +14,7 @@
{% if error %}<p class='alert'>{{ error }}</p>{% endif %}
{% if not poll.open %}<p class='alert'>{% trans "The current poll is closed."%}</p>{% endif %}
<p>{{ poll.description|safe }}</p>
- <form method='post' action='{{base_url}}'>
+ <form method='post' action='.'>
<div id='poll_table'>
<table id='poll'>
<tr>
@@ -119,15 +119,15 @@
<hr class='spacer'/>
</form>
{%if poll.opened_admin%}
- <p><a href="{{root_url}}editChoicesUser/{{poll.base_url}}/">{%trans "Add a new choice to this poll?"%}</a></p>{%endif%}
+ <p><a href="{% url edit_choices_user poll.base_url %}">{%trans "Add a new choice to this poll?"%}</a></p>{%endif%}
<div class='footnote'>
{%if hide_vote%}<p>{% trans "You have already vote? You are enough wise not to be influenced by other votes? You can display result by clicking" %} <a href='?display_result=1'>{% trans "here" %}</a>.</p>{%else%}
- <p>{% trans "Remain informed of poll evolution:" %} <a href="{{root_url}}feeds/poll/{{poll.base_url}}/">{%trans "syndication"%}</a></p>{%endif%}
+ <p>{% trans "Remain informed of poll evolution:" %} <a href="../../feeds/poll/{{poll.base_url}}">{%trans "syndication"%}</a></p>{%endif%}
</div>
{%if not hide_vote%}
<h3>{%trans "Comments"%}</h3>
<div class='comments'>
- {%if poll.open%}<form method='post' action='{{base_url}}'>
+ {%if poll.open%}<form method='post' action='.'>
<table class='comment'>
<tr>
<td><label for='comment_author'>{% trans "Author name" %}</label></td>
diff --git a/papillon/urls.py b/papillon/urls.py
index 9d1d8a3..30f95be 100644
--- a/papillon/urls.py
+++ b/papillon/urls.py
@@ -35,22 +35,25 @@ if not base.endswith('/'):
urlpatterns = patterns('',
(base + r'admin/doc/', include('django.contrib.admindocs.urls')),
- (base + r'admin/jsi18n/$', 'django.views.i18n.javascript_catalog'),
+ url(base + r'admin/jsi18n/$', 'django.views.i18n.javascript_catalog',
+ name='admin_i18n'),
(base + r'admin/(.*)', admin.site.root),
- (base + r'$', 'papillon.polls.views.index'),
- (base + r'create$', 'papillon.polls.views.create'),
- (base + r'edit/(?P<admin_url>\w+)/$',
- 'papillon.polls.views.edit'),
- (base + r'editChoicesAdmin/(?P<admin_url>\w+)/$',
- 'papillon.polls.views.editChoicesAdmin'),
- (base + r'editChoicesUser/(?P<poll_url>\w+)/$',
- 'papillon.polls.views.editChoicesUser'),
- (base + r'category/(?P<category_id>\w+)/$',
- 'papillon.polls.views.category'),
- (base + r'poll/(?P<poll_url>\w+)/$', 'papillon.polls.views.poll'),
- (base + r'poll/(?P<poll_url>\w+)/vote$', 'papillon.polls.views.poll'),
- (base + r'feeds/(?P<url>.*)$',
- 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
+ url(base + r'$', 'papillon.polls.views.index', name='index'),
+ url(base + r'create/$', 'papillon.polls.views.create', name='create'),
+ url(base + r'edit/(?P<admin_url>\w+)/$',
+ 'papillon.polls.views.edit', name='edit'),
+ url(base + r'editChoicesAdmin/(?P<admin_url>\w+)/$',
+ 'papillon.polls.views.editChoicesAdmin', name='edit_choices_admin'),
+ url(base + r'editChoicesUser/(?P<poll_url>\w+)/$',
+ 'papillon.polls.views.editChoicesUser', name='edit_choices_user'),
+ url(base + r'category/(?P<category_id>\w+)/$',
+ 'papillon.polls.views.category', name='category'),
+ url(base + r'poll/(?P<poll_url>\w+)/$', 'papillon.polls.views.poll',
+ name='poll'),
+ url(base + r'poll/(?P<poll_url>\w+)/vote/$', 'papillon.polls.views.poll',
+ name='vote'),
+ url(base + r'feeds/(?P<url>.*)$', 'django.contrib.syndication.views.feed',
+ {'feed_dict': feeds}, name='feed'),
(base + r'static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.PROJECT_PATH + '/static'}),
(base + r'media/(?P<path>.*)$', 'django.views.static.serve',