+# -*- coding: utf-8 -*-
+from django.core.exceptions import ObjectDoesNotExist
import pybb.views
import pybb.forms
pybb_post = self.object
pybb_topic = pybb_post.topic
- topic, topic_created = Topic.objects.get_or_create(pybb_topic = pybb_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']
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