4 from .forms import PostForm
5 from .models import Topic
8 class PostEditMixin(pybb.views.PostEditMixin):
10 def get_form_class(self):
11 toret = super(PostEditMixin, self).get_form_class()
12 if issubclass(toret, pybb.forms.PostForm):
16 def form_valid(self, form):
17 toret = super(PostEditMixin, self).form_valid(form)
19 pybb_post = self.object
20 pybb_topic = pybb_post.topic
21 topic, topic_created = Topic.objects.get_or_create(pybb_topic = pybb_topic)
23 if pybb_post == pybb_topic.head:
24 topic.lesson = form.cleaned_data['lesson']
30 class AddPostView(PostEditMixin, pybb.views.AddPostView):
31 def get_context_data(self, **kwargs):
32 ctx = super(AddPostView, self).get_context_data(**kwargs)
33 ctx['lesson_editable'] = self._creates_new_topic()
36 def _creates_new_topic(self):
37 return self.forum is not None
40 class EditPostView(PostEditMixin, pybb.views.EditPostView):
41 def get_context_data(self, **kwargs):
42 ctx = super(EditPostView, self).get_context_data(**kwargs)
43 ctx['lesson_editable'] = self._edits_topics_head()
46 def _edits_topics_head(self):
47 return self.object == self.object.topic.head
49 def get_form_kwargs(self):
50 kwargs = super(EditPostView, self).get_form_kwargs()
51 kwargs['initial']['lesson'] = self.object.topic.edumed_topic.lesson