First take on connecting lessons to forum topics
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 29 Aug 2013 09:01:47 +0000 (11:01 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 29 Aug 2013 09:01:47 +0000 (11:01 +0200)
15 files changed:
catalogue/templates/catalogue/lesson/lesson_detail.html
edumed/settings.d/30-apps.py
edumed/urls.py
forum/__init__.py [new file with mode: 0644]
forum/forms.py [new file with mode: 0644]
forum/locale/pl/LC_MESSAGES/django.mo [new file with mode: 0644]
forum/locale/pl/LC_MESSAGES/django.po [new file with mode: 0644]
forum/migrations/0001_initial.py [new file with mode: 0644]
forum/migrations/__init__.py [new file with mode: 0644]
forum/models.py [new file with mode: 0644]
forum/templates/forum/related_lesson_info.html [new file with mode: 0644]
forum/templates/pybb/post_form.html [new file with mode: 0644]
forum/templates/pybb/topic.html [new file with mode: 0644]
forum/urls.py [new file with mode: 0644]
forum/views.py [new file with mode: 0644]

index c6f726a..adc5dc3 100755 (executable)
 </p>
 
 </footer>
+
+
+{% if object.forum_topics.all.count %}
+<h2>Na forum</h2>
+<ul>
+{% for forum_topic in object.forum_topics.all %}
+    <li><a href="{{forum_topic.pybb_topic.get_absolute_url}}">{{forum_topic.pybb_topic.name}}</a></li>
+{% endfor %}
+</ul>
+{% endif %}
+
 </div>
 
 {% endblock %}
index 824b44b..670f532 100644 (file)
@@ -15,6 +15,7 @@ INSTALLED_APPS = (
     'haystack',
     'chunks',
     'contact',
+    'forum',
     'pybb',
     'django_libravatar',
     'sorl.thumbnail',
index 2c31a0c..ff55310 100644 (file)
@@ -13,6 +13,7 @@ urlpatterns = patterns('',
     url(r'^szukaj/', include('haystack.urls')),
     url(r'^zglos/', include('contact.urls')),
     url(r'^forum/profile/edit/$', AvatarlessProfileEditView.as_view(), name='edit_profile'),
+    url(r'^forum/', include('forum.urls')),
     url(r'^forum/', include('pybb.urls', namespace='pybb')),
 )
 
diff --git a/forum/__init__.py b/forum/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/forum/forms.py b/forum/forms.py
new file mode 100644 (file)
index 0000000..559796b
--- /dev/null
@@ -0,0 +1,10 @@
+from django import forms
+from django.utils.translation import ugettext as _
+import pybb.forms
+
+from catalogue.models import Lesson
+
+
+class PostForm(pybb.forms.PostForm):
+    lesson = forms.ModelChoiceField(label = _('Related lesson'), queryset = Lesson.objects.all())
+    
\ No newline at end of file
diff --git a/forum/locale/pl/LC_MESSAGES/django.mo b/forum/locale/pl/LC_MESSAGES/django.mo
new file mode 100644 (file)
index 0000000..219ea2a
Binary files /dev/null and b/forum/locale/pl/LC_MESSAGES/django.mo differ
diff --git a/forum/locale/pl/LC_MESSAGES/django.po b/forum/locale/pl/LC_MESSAGES/django.po
new file mode 100644 (file)
index 0000000..bc13e50
--- /dev/null
@@ -0,0 +1,60 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-08-29 10:00+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
+"|| n%100>=20) ? 1 : 2);\n"
+
+#: forms.py:9 templates/forum/related_lesson_info.html:2
+msgid "Related lesson"
+msgstr "Powiązana lekcja"
+
+#: templates/pybb/topic.html:27 templates/pybb/topic.html.py:47
+msgid "Posts"
+msgstr ""
+
+#: templates/pybb/topic.html:55
+msgid "Unstick topic"
+msgstr ""
+
+#: templates/pybb/topic.html:57
+msgid "Stick topic"
+msgstr ""
+
+#: templates/pybb/topic.html:61
+msgid "Open topic"
+msgstr ""
+
+#: templates/pybb/topic.html:63
+msgid "Close topic"
+msgstr ""
+
+#: templates/pybb/topic.html:66
+msgid "Admin"
+msgstr ""
+
+#: templates/pybb/topic.html:75
+msgid "Unsubscribe"
+msgstr ""
+
+#: templates/pybb/topic.html:77
+msgid "Subscribe"
+msgstr ""
+
+#: templates/pybb/topic.html:96
+msgid "Subscribers"
+msgstr ""
diff --git a/forum/migrations/0001_initial.py b/forum/migrations/0001_initial.py
new file mode 100644 (file)
index 0000000..3a80106
--- /dev/null
@@ -0,0 +1,164 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding model 'Topic'
+        db.create_table(u'forum_topic', (
+            ('pybb_topic', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['pybb.Topic'], unique=True, primary_key=True)),
+            ('lesson', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['catalogue.Lesson'], null=True, blank=True)),
+        ))
+        db.send_create_signal(u'forum', ['Topic'])
+
+
+    def backwards(self, orm):
+        # Deleting model 'Topic'
+        db.delete_table(u'forum_topic')
+
+
+    models = {
+        u'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        u'auth.permission': {
+            'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        u'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        u'catalogue.lesson': {
+            'Meta': {'ordering': "['section', 'level', 'order']", 'object_name': 'Lesson'},
+            'curriculum_courses': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['curriculum.CurriculumCourse']", 'symmetrical': 'False', 'blank': 'True'}),
+            'dc': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}),
+            'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'level': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['curriculum.Level']"}),
+            'order': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
+            'package': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'pdf': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'section': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['catalogue.Section']", 'null': 'True', 'blank': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255'}),
+            'student_package': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'student_pdf': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'type': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+            'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+        },
+        u'catalogue.section': {
+            'Meta': {'ordering': "['order']", 'object_name': 'Section'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+            'order': ('django.db.models.fields.IntegerField', [], {}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255'}),
+            'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+            'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+        },
+        u'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        u'curriculum.curriculumcourse': {
+            'Meta': {'ordering': "['slug']", 'object_name': 'CurriculumCourse'},
+            'accusative': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'slug': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        u'curriculum.level': {
+            'Meta': {'ordering': "['order']", 'object_name': 'Level'},
+            'group': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'order': ('django.db.models.fields.IntegerField', [], {}),
+            'slug': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        u'forum.topic': {
+            'Meta': {'object_name': 'Topic'},
+            'lesson': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['catalogue.Lesson']", 'null': 'True', 'blank': 'True'}),
+            'pybb_topic': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['pybb.Topic']", 'unique': 'True', 'primary_key': 'True'})
+        },
+        u'pybb.category': {
+            'Meta': {'ordering': "['position']", 'object_name': 'Category'},
+            'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+        },
+        u'pybb.forum': {
+            'Meta': {'ordering': "['position']", 'object_name': 'Forum'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'forums'", 'to': u"orm['pybb.Category']"}),
+            'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'headline': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'moderators': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'readed_by': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'readed_forums'", 'symmetrical': 'False', 'through': u"orm['pybb.ForumReadTracker']", 'to': u"orm['auth.User']"}),
+            'topic_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'})
+        },
+        u'pybb.forumreadtracker': {
+            'Meta': {'unique_together': "(('user', 'forum'),)", 'object_name': 'ForumReadTracker'},
+            'forum': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['pybb.Forum']", 'null': 'True', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'time_stamp': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"})
+        },
+        u'pybb.topic': {
+            'Meta': {'ordering': "['-created']", 'object_name': 'Topic'},
+            'closed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+            'forum': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'topics'", 'to': u"orm['pybb.Forum']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'on_moderation': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'poll_question': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'poll_type': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'readed_by': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'readed_topics'", 'symmetrical': 'False', 'through': u"orm['pybb.TopicReadTracker']", 'to': u"orm['auth.User']"}),
+            'sticky': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'subscribers': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'subscriptions'", 'blank': 'True', 'to': u"orm['auth.User']"}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
+            'views': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'})
+        },
+        u'pybb.topicreadtracker': {
+            'Meta': {'unique_together': "(('user', 'topic'),)", 'object_name': 'TopicReadTracker'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'time_stamp': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'topic': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['pybb.Topic']", 'null': 'True', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"})
+        }
+    }
+
+    complete_apps = ['forum']
\ No newline at end of file
diff --git a/forum/migrations/__init__.py b/forum/migrations/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/forum/models.py b/forum/models.py
new file mode 100644 (file)
index 0000000..7a9c359
--- /dev/null
@@ -0,0 +1,12 @@
+from django.db import models
+from django.db.models.signals import post_save
+
+import pybb.models
+
+from catalogue.models import Lesson
+
+
+class Topic(models.Model):
+    pybb_topic = models.OneToOneField(pybb.models.Topic, primary_key = True, related_name = 'edumed_topic')
+    lesson = models.ForeignKey(Lesson, null = True, blank = True, related_name = 'forum_topics')
+    
\ No newline at end of file
diff --git a/forum/templates/forum/related_lesson_info.html b/forum/templates/forum/related_lesson_info.html
new file mode 100644 (file)
index 0000000..bbfb686
--- /dev/null
@@ -0,0 +1,2 @@
+{% load i18n %}
+<h5 style="margin-top: -20px;">{% trans 'Related lesson' %}: <a href="{{lesson.get_absolute_url}}">{{lesson.title}}</a></h4>
\ No newline at end of file
diff --git a/forum/templates/pybb/post_form.html b/forum/templates/pybb/post_form.html
new file mode 100644 (file)
index 0000000..0ac465b
--- /dev/null
@@ -0,0 +1,36 @@
+{% load url from future %}
+{% load i18n pybb_tags %}
+<form class="post-form" action="
+    {% if forum %}
+        {% url 'pybb:add_topic' forum.pk %}
+    {% else %}
+        {% if topic %}
+            {% url 'pybb:add_post' topic.pk %}
+        {% else %}
+            {% url 'pybb:edit_post' pk=object.pk %}
+        {% endif %}
+    {% endif %}" method="post" enctype="multipart/form-data">
+  {% csrf_token %}
+  <fieldset>
+    {% include "pybb/form_errors.html" %}
+    {% if form.name %} {% include "pybb/form_field.html" with field=form.name %} {% endif %}
+
+    {% if lesson_editable %}
+        {% include "pybb/form_field.html" with field=form.lesson %}
+    {% endif %}
+
+    {% if form.login %} {% include "pybb/form_field.html" with field=form.login %}  {% endif %}
+    {% if form.body %} {% include "pybb/form_field.html" with field=form.body %}  {% endif %}
+    <div id='emoticons'>
+      {% for smile, url in form.available_smiles.items %}
+        <a href='#' title='{{ smile|safe }}'><img src='{{ STATIC_URL }}{{ form.smiles_prefix }}{{ url }}'></a>
+      {% endfor %}
+    </div>
+
+    {% if form.poll_type %}
+      {% include "pybb/poll_edit_form.html" %}
+    {% endif %}
+    {% include "pybb/attachments_formset.html" %}
+    <p class="submit">{% include "pybb/_button_submit.html" %}</p>
+  </fieldset>
+</form>
diff --git a/forum/templates/pybb/topic.html b/forum/templates/pybb/topic.html
new file mode 100644 (file)
index 0000000..f11f2cb
--- /dev/null
@@ -0,0 +1,102 @@
+{% extends 'pybb/base.html' %}
+
+{% load url from future %}
+
+{% load pybb_tags i18n %}
+
+{% block title %}{{ topic }}{% endblock %}
+
+{% block extra_script %}
+    {{ block.super }}
+    {% include "pybb/_markitup.html" %}
+    <script type="text/javascript" src="{{ STATIC_URL }}pybb/js/jquery.formset.min.js"></script>
+{% endblock %}
+
+{% block breadcrumb %}
+    {% with object=topic %}
+        {% include "pybb/breadcrumb.html" %}
+    {% endwith %}
+{% endblock %}
+
+{% block content %}
+    <div class="topic">
+        <h1>{{ topic.name }}</h1>
+        
+        {% include 'forum/related_lesson_info.html' with lesson=topic.edumed_topic.lesson %}
+        
+        {% with _('Posts') as label %}
+            {% include "pybb/pagination.html" %}
+        {% endwith %}
+
+        {% if topic.poll_type %}
+            {% include 'pybb/poll.html' %}
+        {% endif %}
+
+        <div class="posts">
+            {% if first_post %}{% ifnotequal first_post post_list.0 %}
+                {% with first_post as post %}
+                    <li class="first_post">{% include "pybb/post_template.html" %}</li>
+                {% endwith %}
+            {% endifnotequal %}{% endif %}
+            {% for post in post_list %}
+                {% cycle 'odd' 'even' as rowcolors silent %}
+                {% include "pybb/post_template.html" %}
+            {% endfor %}
+        </div>
+        <div>&nbsp;</div>
+        {% with _('Posts') as label %}
+            {% include "pybb/pagination.html" %}
+        {% endwith %}
+
+        {% if user.is_authenticated %}
+            <div class="controls">
+                {% if user.is_moderator %}
+                    {% if topic.sticky %}
+                        <a href="{% url 'pybb:unstick_topic' topic.id %}">{% trans "Unstick topic" %}</a> /
+                    {% else %}
+                        <a href="{% url 'pybb:stick_topic' topic.id %}">{% trans "Stick topic" %}</a> /
+                    {% endif %}
+
+                    {% if topic.closed %}
+                        <a href="{% url 'pybb:open_topic' topic.id %}">{% trans "Open topic" %}</a> /
+                    {% else %}
+                        <a href="{% url 'pybb:close_topic' topic.id %}">{% trans "Close topic" %}</a> /
+                    {% endif %}
+                    {% if perms.pybb.change_topic and user.is_staff %}
+                        <a href="{% url 'admin:pybb_topic_change' topic.id %}">{% trans 'Admin' %}</a> /
+                    {% endif %}
+                    {% comment %}
+            <a href="{% url 'pybb:merge_topics' %}?topic={{ topic.id }}">{% trans 'Merge topics' %}</a> /
+            {% endcomment %}
+                {% endif %}
+
+                {% if user.is_subscribed %}
+                    <a href="{% url 'pybb:delete_subscription' topic.id %}?from_topic">{% trans "Unsubscribe" %}</a>
+                {% else %}
+                    <a href="{% url 'pybb:add_subscription' topic.id %}">{% trans "Subscribe" %}</a>
+                {% endif %}
+            </div>
+        {% endif %}
+
+        {% if user.is_authenticated or PYBB_ENABLE_ANONYMOUS_POST %}
+            {% pybb_get_profile user=user as user_profile %}
+
+            {% if not user_profile.is_banned %}
+                {% if not topic.closed %}
+                    {% include "pybb/post_form.html" %}
+                {% endif %}
+            {% endif %}
+        {% else %}
+            {% include 'pybb/_need_to_login_message.html' %}
+        {% endif %}
+
+        {% if user.is_staff %}
+            <div class="subscriber-list">
+                {% trans "Subscribers" %}:
+                {% for subscriber in topic.subscribers.all %}
+                    <a href="{% url 'pybb:user' subscriber.username %}">{{ subscriber.username }}</a>,
+                {% endfor %}
+            </div>
+        {% endif %}
+    </div>
+{% endblock %}
diff --git a/forum/urls.py b/forum/urls.py
new file mode 100644 (file)
index 0000000..a0135fb
--- /dev/null
@@ -0,0 +1,9 @@
+from django.conf.urls import patterns, include, url
+
+from .views import AddPostView, EditPostView
+
+
+urlpatterns = patterns('',
+    url(r'^forum/(?P<forum_id>\d+)/topic/add/$', AddPostView.as_view()),
+    url(r'^post/(?P<pk>\d+)/edit/$', EditPostView.as_view()),
+)
\ No newline at end of file
diff --git a/forum/views.py b/forum/views.py
new file mode 100644 (file)
index 0000000..7eb412e
--- /dev/null
@@ -0,0 +1,52 @@
+import pybb.views
+import pybb.forms
+
+from .forms import PostForm
+from .models import Topic
+
+
+class PostEditMixin(pybb.views.PostEditMixin):
+
+    def get_form_class(self):
+        toret = super(PostEditMixin, self).get_form_class()
+        if issubclass(toret, pybb.forms.PostForm):
+            toret = PostForm
+        return toret
+
+    def form_valid(self, form):
+        toret = super(PostEditMixin, self).form_valid(form)
+
+        pybb_post = self.object
+        pybb_topic = pybb_post.topic
+        topic, topic_created = Topic.objects.get_or_create(pybb_topic = pybb_topic)
+
+        if pybb_post == pybb_topic.head:
+            topic.lesson = form.cleaned_data['lesson']
+            topic.save()
+
+        return toret
+
+
+class AddPostView(PostEditMixin, pybb.views.AddPostView):
+    def get_context_data(self, **kwargs):
+        ctx = super(AddPostView, self).get_context_data(**kwargs)
+        ctx['lesson_editable'] = self._creates_new_topic()
+        return ctx
+
+    def _creates_new_topic(self):
+        return self.forum is not None
+
+
+class EditPostView(PostEditMixin, pybb.views.EditPostView):
+    def get_context_data(self, **kwargs):
+        ctx = super(EditPostView, self).get_context_data(**kwargs)
+        ctx['lesson_editable'] = self._edits_topics_head()
+        return ctx
+
+    def _edits_topics_head(self):
+        return self.object == self.object.topic.head
+
+    def get_form_kwargs(self):
+        kwargs = super(EditPostView, self).get_form_kwargs()
+        kwargs['initial']['lesson'] = self.object.topic.edumed_topic.lesson
+        return kwargs