From 05ce0b5f9bd62d1b369a6718bec1b70e0a4a0fef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 29 Aug 2013 11:01:47 +0200 Subject: [PATCH] First take on connecting lessons to forum topics --- .../catalogue/lesson/lesson_detail.html | 11 ++ edumed/settings.d/30-apps.py | 1 + edumed/urls.py | 1 + forum/__init__.py | 0 forum/forms.py | 10 ++ forum/locale/pl/LC_MESSAGES/django.mo | Bin 0 -> 536 bytes forum/locale/pl/LC_MESSAGES/django.po | 60 +++++++ forum/migrations/0001_initial.py | 164 ++++++++++++++++++ forum/migrations/__init__.py | 0 forum/models.py | 12 ++ .../templates/forum/related_lesson_info.html | 2 + forum/templates/pybb/post_form.html | 36 ++++ forum/templates/pybb/topic.html | 102 +++++++++++ forum/urls.py | 9 + forum/views.py | 52 ++++++ 15 files changed, 460 insertions(+) create mode 100644 forum/__init__.py create mode 100644 forum/forms.py create mode 100644 forum/locale/pl/LC_MESSAGES/django.mo create mode 100644 forum/locale/pl/LC_MESSAGES/django.po create mode 100644 forum/migrations/0001_initial.py create mode 100644 forum/migrations/__init__.py create mode 100644 forum/models.py create mode 100644 forum/templates/forum/related_lesson_info.html create mode 100644 forum/templates/pybb/post_form.html create mode 100644 forum/templates/pybb/topic.html create mode 100644 forum/urls.py create mode 100644 forum/views.py diff --git a/catalogue/templates/catalogue/lesson/lesson_detail.html b/catalogue/templates/catalogue/lesson/lesson_detail.html index c6f726a..adc5dc3 100755 --- a/catalogue/templates/catalogue/lesson/lesson_detail.html +++ b/catalogue/templates/catalogue/lesson/lesson_detail.html @@ -111,6 +111,17 @@

+ + +{% if object.forum_topics.all.count %} +

Na forum

+ +{% endif %} + {% endblock %} diff --git a/edumed/settings.d/30-apps.py b/edumed/settings.d/30-apps.py index 824b44b..670f532 100644 --- a/edumed/settings.d/30-apps.py +++ b/edumed/settings.d/30-apps.py @@ -15,6 +15,7 @@ INSTALLED_APPS = ( 'haystack', 'chunks', 'contact', + 'forum', 'pybb', 'django_libravatar', 'sorl.thumbnail', diff --git a/edumed/urls.py b/edumed/urls.py index 2c31a0c..ff55310 100644 --- a/edumed/urls.py +++ b/edumed/urls.py @@ -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 index 0000000..e69de29 diff --git a/forum/forms.py b/forum/forms.py new file mode 100644 index 0000000..559796b --- /dev/null +++ b/forum/forms.py @@ -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 index 0000000000000000000000000000000000000000..219ea2adca4e809f65b60563be2d7ac8c594cd1f GIT binary patch literal 536 zcmYL^(QeZ)6ovyDT;yUBTyt@5m^KX$C*z{H$ynC9BO+-+nofc%Olv|$W>>bm4YXSx zfk)s?cn+S0lY;1xKKa=G|Ks1kAMgC|uNU z{a?L*QWiU;04iV3jG&@bkQd}{}lIi)p zj~r#$Y1bZU(`+>uHBWQC{az=PV(W)UVJ_}=|i|6%(47R#H z)+cEQR|~ytRl{KLv2}jgt&Ql&M4KziK&>`g8y^qhZyWEcI1bOB*xTE* sQT(EB_xocS1r+Y?Hs`&D9-t>cPk1o&y;9$_zrKGHNPx# literal 0 HcmV?d00001 diff --git a/forum/locale/pl/LC_MESSAGES/django.po b/forum/locale/pl/LC_MESSAGES/django.po new file mode 100644 index 0000000..bc13e50 --- /dev/null +++ b/forum/locale/pl/LC_MESSAGES/django.po @@ -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 , 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 \n" +"Language-Team: LANGUAGE \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 index 0000000..3a80106 --- /dev/null +++ b/forum/migrations/0001_initial.py @@ -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 index 0000000..e69de29 diff --git a/forum/models.py b/forum/models.py new file mode 100644 index 0000000..7a9c359 --- /dev/null +++ b/forum/models.py @@ -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 index 0000000..bbfb686 --- /dev/null +++ b/forum/templates/forum/related_lesson_info.html @@ -0,0 +1,2 @@ +{% load i18n %} +
{% trans 'Related lesson' %}: {{lesson.title}}
\ 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 index 0000000..0ac465b --- /dev/null +++ b/forum/templates/pybb/post_form.html @@ -0,0 +1,36 @@ +{% load url from future %} +{% load i18n pybb_tags %} +
+ {% csrf_token %} +
+ {% 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 %} +
+ {% for smile, url in form.available_smiles.items %} + + {% endfor %} +
+ + {% if form.poll_type %} + {% include "pybb/poll_edit_form.html" %} + {% endif %} + {% include "pybb/attachments_formset.html" %} +

{% include "pybb/_button_submit.html" %}

+
+
diff --git a/forum/templates/pybb/topic.html b/forum/templates/pybb/topic.html new file mode 100644 index 0000000..f11f2cb --- /dev/null +++ b/forum/templates/pybb/topic.html @@ -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" %} + +{% endblock %} + +{% block breadcrumb %} + {% with object=topic %} + {% include "pybb/breadcrumb.html" %} + {% endwith %} +{% endblock %} + +{% block content %} +
+

{{ topic.name }}

+ + {% 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 %} + +
+ {% if first_post %}{% ifnotequal first_post post_list.0 %} + {% with first_post as post %} +
  • {% include "pybb/post_template.html" %}
  • + {% endwith %} + {% endifnotequal %}{% endif %} + {% for post in post_list %} + {% cycle 'odd' 'even' as rowcolors silent %} + {% include "pybb/post_template.html" %} + {% endfor %} +
    +
     
    + {% with _('Posts') as label %} + {% include "pybb/pagination.html" %} + {% endwith %} + + {% if user.is_authenticated %} +
    + {% if user.is_moderator %} + {% if topic.sticky %} + {% trans "Unstick topic" %} / + {% else %} + {% trans "Stick topic" %} / + {% endif %} + + {% if topic.closed %} + {% trans "Open topic" %} / + {% else %} + {% trans "Close topic" %} / + {% endif %} + {% if perms.pybb.change_topic and user.is_staff %} + {% trans 'Admin' %} / + {% endif %} + {% comment %} + {% trans 'Merge topics' %} / + {% endcomment %} + {% endif %} + + {% if user.is_subscribed %} + {% trans "Unsubscribe" %} + {% else %} + {% trans "Subscribe" %} + {% endif %} +
    + {% 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 %} +
    + {% trans "Subscribers" %}: + {% for subscriber in topic.subscribers.all %} + {{ subscriber.username }}, + {% endfor %} +
    + {% endif %} +
    +{% endblock %} diff --git a/forum/urls.py b/forum/urls.py new file mode 100644 index 0000000..a0135fb --- /dev/null +++ b/forum/urls.py @@ -0,0 +1,9 @@ +from django.conf.urls import patterns, include, url + +from .views import AddPostView, EditPostView + + +urlpatterns = patterns('', + url(r'^forum/(?P\d+)/topic/add/$', AddPostView.as_view()), + url(r'^post/(?P\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 index 0000000..7eb412e --- /dev/null +++ b/forum/views.py @@ -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 -- 2.20.1