def create_thread(forum): thread = Thread() thread.forum = forum thread.name = 'Test Thread' thread.slug = 'test-thread' thread.start = timezone.now() thread.last = timezone.now() thread.save(force_insert=True) return thread
def post_action_split(self, ids): for id in ids: if id == self.thread.start_post_id: raise forms.ValidationError(_("You cannot split first post from thread.")) message = None if self.request.POST.get('do') == 'split': form = SplitThreadForm(self.request.POST, request=self.request) if form.is_valid(): new_thread = Thread() new_thread.forum = form.cleaned_data['thread_forum'] new_thread.name = form.cleaned_data['thread_name'] new_thread.slug = slugify(form.cleaned_data['thread_name']) new_thread.start = timezone.now() new_thread.last = timezone.now() new_thread.start_poster_name = 'n' new_thread.start_poster_slug = 'n' new_thread.last_poster_name = 'n' new_thread.last_poster_slug = 'n' new_thread.save(force_insert=True) prev_merge = -1 merge = -1 for post in self.posts: if post.pk in ids: if prev_merge != post.merge: prev_merge = post.merge merge += 1 post.merge = merge post.move_to(new_thread) post.save(force_update=True) new_thread.sync() new_thread.save(force_update=True) self.thread.sync() self.thread.save(force_update=True) self.forum.sync() self.forum.save(force_update=True) if new_thread.forum != self.forum: new_thread.forum.sync() new_thread.forum.save(force_update=True) self.request.messages.set_flash(Message(_("Selected posts have been split to new thread.")), 'success', 'threads') return redirect(reverse('thread', kwargs={'thread': new_thread.pk, 'slug': new_thread.slug})) message = Message(form.non_field_errors()[0], 'error') else: form = SplitThreadForm(request=self.request, initial={ 'thread_name': _('[Split] %s') % self.thread.name, 'thread_forum': self.forum, }) return self.request.theme.render_to_response('threads/split.html', { 'message': message, 'forum': self.forum, 'parents': self.parents, 'thread': self.thread, 'posts': ids, 'form': FormLayout(form), }, context_instance=RequestContext(self.request));