From: Aleksander Ɓukasz Date: Thu, 29 Aug 2013 09:24:37 +0000 (+0200) Subject: Forum: related lesson fixes X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/a1247c46b02c89a7d80fed36c89ce8476d0eac79?ds=inline Forum: related lesson fixes - lesson should not be required - handle missing lesson better --- diff --git a/forum/forms.py b/forum/forms.py index 559796b..ec8a3be 100644 --- a/forum/forms.py +++ b/forum/forms.py @@ -6,5 +6,5 @@ from catalogue.models import Lesson class PostForm(pybb.forms.PostForm): - lesson = forms.ModelChoiceField(label = _('Related lesson'), queryset = Lesson.objects.all()) + lesson = forms.ModelChoiceField(label = _('Related lesson'), queryset = Lesson.objects.all(), required = False) \ No newline at end of file diff --git a/forum/templates/forum/related_lesson_info.html b/forum/templates/forum/related_lesson_info.html index bbfb686..1f807f6 100644 --- a/forum/templates/forum/related_lesson_info.html +++ b/forum/templates/forum/related_lesson_info.html @@ -1,2 +1,4 @@ {% load i18n %} -
{% trans 'Related lesson' %}: {{lesson.title}}
\ No newline at end of file +{% if lesson %} +
{% trans 'Related lesson' %}: {{lesson.title}}
+{% endif %} \ No newline at end of file diff --git a/forum/views.py b/forum/views.py index 7eb412e..41b7eb8 100644 --- a/forum/views.py +++ b/forum/views.py @@ -1,6 +1,9 @@ +from django.core.exceptions import ObjectDoesNotExist import pybb.views import pybb.forms +from catalogue.models import Lesson + from .forms import PostForm from .models import Topic @@ -48,5 +51,9 @@ class EditPostView(PostEditMixin, pybb.views.EditPostView): def get_form_kwargs(self): kwargs = super(EditPostView, self).get_form_kwargs() - kwargs['initial']['lesson'] = self.object.topic.edumed_topic.lesson + try: + lesson = self.object.topic.edumed_topic.lesson + except ObjectDoesNotExist: + lesson = None + kwargs['initial']['lesson'] = lesson return kwargs