[Oi-commits] r1476 - in trunk: forum templates/forum

oi-commits at pardus.org.tr oi-commits at pardus.org.tr
Tue Jun 17 17:12:32 EEST 2008


Author: jnmbk
Date: Tue Jun 17 17:12:31 2008
New Revision: 1476

Added:
   trunk/templates/forum/create_poll.html   (contents, props changed)
      - copied, changed from r1422, trunk/templates/forum/new_topic.html
Modified:
   trunk/forum/forms.py
   trunk/forum/models.py
   trunk/forum/urls.py
   trunk/forum/views.py
   trunk/templates/forum/topic.html
Log:
create poll

Modified: trunk/forum/forms.py
=================================================================
--- trunk/forum/forms.py	(original)
+++ trunk/forum/forms.py	Tue Jun 17 17:12:31 2008
@@ -5,9 +5,12 @@
 # Licensed under the GNU General Public License, version 3.
 # See the file http://www.gnu.org/copyleft/gpl.txt.
 
+from datetime import date
+
 from django import newforms as forms
 from oi.forum.models import AbuseReport, Topic, Forum, WatchList
 from oi.st.models import Tag
+from oi.poll.models import Poll
 
 from oi.st.forms import XssField
 
@@ -54,3 +57,25 @@
 
 class AbuseForm(forms.Form):
     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',}))
+
+    class Meta:
+        model = Poll
+
+    def clean_end_date(self):
+        field_data = self.cleaned_data['end_date']
+
+        # it must be bigger than today
+        if field_data != None and field_data <= date.today():
+            raise forms.ValidationError("Oylama bitiş tarihi bugünden küçük olamaz.")
+
+        return field_data

Modified: trunk/forum/models.py
=================================================================
--- trunk/forum/models.py	(original)
+++ trunk/forum/models.py	Tue Jun 17 17:12:31 2008
@@ -12,6 +12,7 @@
 
 from oi.middleware import threadlocals
 from oi.st.models import Tag
+from oi.poll.models import Poll
 
 from oi.forum.settings import FORUM_FROM_EMAIL
 
@@ -159,6 +160,7 @@
     views = models.IntegerField(default=0, verbose_name='Görüntülenme sayısı')
     topic_latest_post = models.ForeignKey(Post, blank=True, null=True, related_name='topic_latest_post', verbose_name='Son ileti')
     tags = models.ManyToManyField(Tag, verbose_name='Etiketler')
+    poll = models.ForeignKey(Poll, blank=True, verbose_name="Anket")
 
     def __str__(self):
         return self.title
@@ -195,6 +197,9 @@
     def get_hide_url(self):
         return '/forum/%s/%s/hide/' % (self.forum.slug, self.id)
 
+    def get_create_poll_url(self):
+        return '/forum/%s/%s/poll/create/' % (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])
 
@@ -213,6 +218,8 @@
                        ("can_see_hidden_topics", "Can see hidden topics"),
                        ("can_merge_topic", "Can merge topic"),
                        ("can_move_topic", "Can move topic"),
+                       ("can_create_poll", "Can create poll"),
+                       ("can_change_poll", "Can change poll"),
                       )
 
     def save(self):

Modified: trunk/forum/urls.py
=================================================================
--- trunk/forum/urls.py	(original)
+++ trunk/forum/urls.py	Tue Jun 17 17:12:31 2008
@@ -44,6 +44,7 @@
     (r'^(?P<forum_slug>.*)/(?P<topic_id>\d+)/merge/$', 'oi.forum.views.merge'),
     (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+)/$', '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 17:12:31 2008
@@ -25,6 +25,7 @@
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.mail import send_mail
 from oi.st.models import Tag, News
+from oi.poll.models import Poll, PollOption
 
 # import our function for sending e-mails and setting
 from oi.st.wrappers import send_mail_with_header
@@ -702,3 +703,52 @@
         else:
             abuse_list = AbuseReport.objects.all()
             return render_response(request, 'forum/abuse_list.html', {'abuse_list': abuse_list, "abuse_count":abuse_count})
+
+ at permission_required('forum.can_create_poll', login_url="/kullanici/giris/")
+def create_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_absolute_url())
+
+    # Check locks
+    if forum.locked or topic.locked:
+        return HttpResponse('Forum or topic is locked')
+
+    # Check if it already has a poll
+    try:
+        topic.poll
+        return HttpResponse('Bu konuya zaten anket eklenmiş')
+    except: #DoesNotExist
+        pass
+
+    if request.method == 'POST':
+        form = PollForm(request.POST.copy())
+        if form.is_valid():
+            # create the poll
+            poll = Poll(
+                    question = form.cleaned_data["question"],
+                    allow_changing_vote = form.cleaned_data["allow_changing_vote"],
+                    date_limit = form.cleaned_data["date_limit"],
+                    end_date = form.cleaned_data["end_date"],
+                    )
+            poll.save()
+
+            # create poll options
+            for i in range(1, 9):
+                if form.cleaned_data["option%d" % i]:
+                    option = PollOption(
+                            poll = poll,
+                            text = form.cleaned_data["option%d" % i],
+                            )
+                    option.save()
+
+            # now add it to topic
+            topic.poll = poll
+            topic.save()
+
+            return HttpResponseRedirect(topic.get_absolute_url())
+    else:
+        form = PollForm()
+
+    return render_response(request, "forum/create_poll.html", locals())

Copied: trunk/templates/forum/create_poll.html (from r1422, trunk/templates/forum/new_topic.html)
=================================================================
--- trunk/templates/forum/new_topic.html	(original)
+++ trunk/templates/forum/create_poll.html	Tue Jun 17 17:12:31 2008
@@ -1,19 +1,13 @@
 {% extends "forum/forum_base.html" %}
-{% block extrahead %}
-<script language="javascript" type="text/javascript" src="/media/js/tinymce/tiny_mce.js"></script>
-<script language="javascript" type="text/javascript" src="/media/js/tinymce/forum.js"></script>
-{% endblock %}
 
 {% block content %}
-{% if user.is_authenticated %}
 <div class="forum_address">
-    <div class="current_topic"><a href="/">Ana Sayfa</a> &#62; <a href="/forum/">Forum</a> &#62; <a href="{{ forum.get_absolute_url }}">{{ forum.name }}</a> &#62; Yeni Konu</div>
+    <div class="current_topic"><a href="/">Ana Sayfa</a> &#62; <a href="/forum/">Forum</a> &#62; <a href="{{ forum.get_absolute_url }}">{{ forum.name }}</a> &#62; <a href="{{ topic.get_absolute_url }}">{{ topic.title }}</a> &#62; Anket Ekle</div>
 </div>
 {% if form.errors %}
-<font color="red">Başlık açılamadı, lütfen aşağıdaki hataları düzeltin</font><br />
+<font color="red">Anket oluşturulamadı, lütfen aşağıdaki hataları düzeltin</font><br />
 {% endif %}
 
-{% if flood %}<font color="red">Flood koruması aktif, lütfen {{ timeout }} saniye bekleyin.</font>{% endif %}
 <form action="" method="post">
 <dl>
 {% for field in form %}
@@ -23,9 +17,6 @@
     {% if field.errors %}<dd class="myerrors" style="font-color: red">{{ field.errors }}</dd>{% endif %}
 {% endfor %}
 </dl>
-<input type="submit" value="Konu Aç">
+<input type="submit" value="Anket Oluştur">
 </form>
-{% else %}
-<p>Başlık açmak için oturum açmanız gerekiyor.</p>
-{% endif %}
 {% endblock %}

Modified: trunk/templates/forum/topic.html
=================================================================
--- trunk/templates/forum/topic.html	(original)
+++ trunk/templates/forum/topic.html	Tue Jun 17 17:12:31 2008
@@ -15,9 +15,20 @@
     {% if request.user.is_authenticated and not watching %}
     <div class="post_bottom_small"><a href="{{ topic.get_follow_url }}"><img src="/media/dijital/img/forum/watch.gif" alt="izle" title="E-posta ile izle" border="0" /></a></div>
     {% endif %}
+    {% if perms.forum.can_create_poll and not topic.poll %}
+    <div class="post_bottom_small"><a href="{{ topic.get_create_poll_url }}">add_poll</a></div>
+    {% endif %}
 </div>
 <br />
 
+{% if topic.poll %}
+{{ topic.poll.question }}<br />
+{% for option in topic.poll.polloption_set.all %}
+{{ option.text }}<br />
+{% endfor %}
+{% if perms.forum.can_change_poll %}change - delete{% endif %}
+{% endif %}
+
 {% for post in post_list %}
 
 {% if post.hidden and not perms.forum.can_see_hidden_posts %}


More information about the Oi-commits mailing list