[Oi-commits] r1477 - in trunk: forum templates/forum
oi-commits at pardus.org.tr
oi-commits at pardus.org.tr
Tue Jun 17 18:20:43 EEST 2008
Author: jnmbk
Date: Tue Jun 17 18:20:42 2008
New Revision: 1477
Added:
trunk/templates/forum/change_poll.html
- copied, changed from r1476, trunk/templates/forum/create_poll.html
Modified:
trunk/forum/forms.py
trunk/forum/models.py
trunk/forum/urls.py
trunk/forum/views.py
trunk/templates/forum/topic.html
Log:
change poll
Modified: trunk/forum/forms.py
=================================================================
--- trunk/forum/forms.py (original)
+++ trunk/forum/forms.py Tue Jun 17 18:20:42 2008
@@ -59,14 +59,14 @@
reason = XssField(label='Şikayet Sebebi', widget=forms.Textarea(attrs={'rows': 7, 'cols': 45}), required=True, help_text="(en fazla 512 karakter olabilir)", max_length=512)
class PollForm(forms.ModelForm):
- option1 = forms.CharField(label='1. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
- option2 = forms.CharField(label='2. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
- option3 = forms.CharField(label='3. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
- option4 = forms.CharField(label='4. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
- option5 = forms.CharField(label='5. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
- option6 = forms.CharField(label='6. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
- option7 = forms.CharField(label='7. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
- option8 = forms.CharField(label='8. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
+ option0 = forms.CharField(label='1. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
+ option1 = forms.CharField(label='2. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
+ option2 = forms.CharField(label='3. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
+ option3 = forms.CharField(label='4. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
+ option4 = forms.CharField(label='5. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
+ option5 = forms.CharField(label='6. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
+ option6 = forms.CharField(label='7. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
+ option7 = forms.CharField(label='8. Seçenek', required=False, max_length=128, widget=forms.TextInput(attrs={'size': '40',}))
class Meta:
model = Poll
Modified: trunk/forum/models.py
=================================================================
--- trunk/forum/models.py (original)
+++ trunk/forum/models.py Tue Jun 17 18:20:42 2008
@@ -200,6 +200,9 @@
def get_create_poll_url(self):
return '/forum/%s/%s/poll/create/' % (self.forum.slug, self.id)
+ def get_change_poll_url(self):
+ return '/forum/%s/%s/poll/change/' % (self.forum.slug, self.id)
+
def get_email_id(self):
return '<%s.%s@%s>' % (md5.new(self.title).hexdigest(), self.id, FORUM_FROM_EMAIL.split('@')[1])
Modified: trunk/forum/urls.py
=================================================================
--- trunk/forum/urls.py (original)
+++ trunk/forum/urls.py Tue Jun 17 18:20:42 2008
@@ -45,6 +45,7 @@
(r'^(?P<forum_slug>.*)/(?P<topic_id>\d+)/move/$', 'oi.forum.views.move'),
(r'^(?P<forum_slug>.*)/(?P<topic_id>\d+)/edit/$', 'oi.forum.views.edit_topic'),
(r'^(?P<forum_slug>.*)/(?P<topic_id>\d+)/poll/create/$', 'oi.forum.views.create_poll'),
+ (r'^(?P<forum_slug>.*)/(?P<topic_id>\d+)/poll/change/$', 'oi.forum.views.change_poll'),
(r'^(?P<forum_slug>.*)/(?P<topic_id>\d+)/$', 'oi.forum.views.topic'),
(r'^(?P<forum_slug>.*)/$', 'oi.forum.views.forum'),
)
Modified: trunk/forum/views.py
=================================================================
--- trunk/forum/views.py (original)
+++ trunk/forum/views.py Tue Jun 17 18:20:42 2008
@@ -709,7 +709,7 @@
topic = get_object_or_404(Topic, pk=topic_id)
forum = topic.forum
if forum.slug != forum_slug:
- return HttpResponseRedirect(topic.get_absolute_url())
+ return HttpResponseRedirect(topic.get_create_poll_url())
# Check locks
if forum.locked or topic.locked:
@@ -735,7 +735,7 @@
poll.save()
# create poll options
- for i in range(1, 9):
+ for i in range(8):
if form.cleaned_data["option%d" % i]:
option = PollOption(
poll = poll,
@@ -752,3 +752,74 @@
form = PollForm()
return render_response(request, "forum/create_poll.html", locals())
+
+ at permission_required("forum.can_change_poll", login_url="/kullanici/giris/")
+def change_poll(request, forum_slug, topic_id):
+ topic = get_object_or_404(Topic, pk=topic_id)
+ forum = topic.forum
+ if forum.slug != forum_slug:
+ return HttpResponseRedirect(topic.get_change_poll_url())
+
+ # check poll
+ try:
+ poll = topic.poll
+ except: #DoesNotExist
+ return HttpResponseRedirect(topic.get_create_poll_url())
+
+ # Check locks
+ if forum.locked or topic.locked:
+ return HttpResponse('Forum or topic is locked')
+
+ if request.method == 'POST':
+ form = PollForm(request.POST.copy())
+ if form.is_valid():
+ # change the poll
+ poll.question = form.cleaned_data["question"]
+ poll.allow_changing_vote = form.cleaned_data["allow_changing_vote"]
+ poll.date_limit = form.cleaned_data["date_limit"]
+ poll.end_date = form.cleaned_data["end_date"]
+ poll.save()
+
+ # change options, this is tricky
+ options = poll.polloption_set.all()
+ j = options.count()
+
+ # existing options may be deleted or changed, so let's do it
+ tobedeleted = []
+ for i in range(j):
+ if form.cleaned_data["option%d" % i]:
+ option = options[i]
+ option.text = form.cleaned_data["option%d" % i]
+ option.save()
+ else:
+ tobedeleted.append(options[i])
+ # now delete them
+ for option in tobedeleted:
+ option.delete()
+
+ # create non-existing options
+ for i in range(j, 8):
+ if form.cleaned_data["option%d" % i]:
+ option = PollOption(
+ poll = poll,
+ text = form.cleaned_data["option%d" % i],
+ )
+ option.save()
+
+ return HttpResponseRedirect(topic.get_absolute_url())
+ else:
+ initial = {
+ "question": poll.question,
+ "allow_changing_vote": poll.allow_changing_vote,
+ "date_limit": poll.date_limit,
+ "end_date": poll.end_date,
+ }
+
+ # add options to initial data
+ i = 0
+ for option in poll.polloption_set.all():
+ initial["option%d" % i] = option.text
+ i += 1
+ form = PollForm(initial=initial)
+
+ return render_response(request, "forum/change_poll.html", locals())
Copied: trunk/templates/forum/change_poll.html (from r1476, trunk/templates/forum/create_poll.html)
=================================================================
--- trunk/templates/forum/create_poll.html (original)
+++ trunk/templates/forum/change_poll.html Tue Jun 17 18:20:42 2008
@@ -2,10 +2,10 @@
{% block content %}
<div class="forum_address">
- <div class="current_topic"><a href="/">Ana Sayfa</a> > <a href="/forum/">Forum</a> > <a href="{{ forum.get_absolute_url }}">{{ forum.name }}</a> > <a href="{{ topic.get_absolute_url }}">{{ topic.title }}</a> > Anket Ekle</div>
+ <div class="current_topic"><a href="/">Ana Sayfa</a> > <a href="/forum/">Forum</a> > <a href="{{ forum.get_absolute_url }}">{{ forum.name }}</a> > <a href="{{ topic.get_absolute_url }}">{{ topic.title }}</a> > Anketi Değiştir</div>
</div>
{% if form.errors %}
-<font color="red">Anket oluşturulamadı, lütfen aşağıdaki hataları düzeltin</font><br />
+<font color="red">Anket değiştirilemedi, lütfen aşağıdaki hataları düzeltin</font><br />
{% endif %}
<form action="" method="post">
@@ -17,6 +17,6 @@
{% if field.errors %}<dd class="myerrors" style="font-color: red">{{ field.errors }}</dd>{% endif %}
{% endfor %}
</dl>
-<input type="submit" value="Anket Oluştur">
+<input type="submit" value="Anketi Değiştir">
</form>
{% endblock %}
Modified: trunk/templates/forum/topic.html
=================================================================
--- trunk/templates/forum/topic.html (original)
+++ trunk/templates/forum/topic.html Tue Jun 17 18:20:42 2008
@@ -26,7 +26,7 @@
{% for option in topic.poll.polloption_set.all %}
{{ option.text }}<br />
{% endfor %}
-{% if perms.forum.can_change_poll %}change - delete{% endif %}
+{% if perms.forum.can_change_poll %}<a href="{{ topic.get_change_poll_url }}">change</a> - delete{% endif %}
{% endif %}
{% for post in post_list %}
More information about the Oi-commits
mailing list