def create(self, request, thread_pk): thread = self.get_thread(request, thread_pk).unwrap() allow_reply_thread(request.user, thread) post = Post( thread=thread, category=thread.category, ) # Put them through posting pipeline posting = PostingEndpoint( request, PostingEndpoint.REPLY, thread=thread, post=post, ) if posting.is_valid(): user_posts = request.user.posts posting.save() # setup extra data for serialization post.is_read = False post.is_new = True post.poster.posts = user_posts + 1 make_users_status_aware(request.user, [post.poster]) return Response(PostSerializer(post, context={'user': request.user}).data) else: return Response(posting.errors, status=400)
def create(self, request, thread_pk): thread = self.get_thread(request, thread_pk).unwrap() allow_reply_thread(request.user, thread) post = Post( thread=thread, category=thread.category, ) # Put them through posting pipeline posting = PostingEndpoint( request, PostingEndpoint.REPLY, thread=thread, post=post, ) if posting.is_valid(): user_posts = request.user.posts posting.save() # setup extra data for serialization post.is_read = False post.is_new = True post.poster.posts = user_posts + 1 make_users_status_aware(request.user, [post.poster]) return Response( PostSerializer(post, context={ 'user': request.user }).data) else: return Response(posting.errors, status=400)
def dispatch(self, request, *args, **kwargs): relations = ['forum', 'starter', 'last_poster', 'first_post'] thread = self.fetch_thread(request, select_related=relations, **kwargs) forum = thread.forum self.check_forum_permissions(request, forum) self.check_thread_permissions(request, thread) validate_slug(thread, kwargs['thread_slug']) threadstracker.make_read_aware(request.user, thread) thread_actions = self.ThreadActions(user=request.user, thread=thread) posts_actions = self.PostsActions(user=request.user, thread=thread) if request.method == 'POST': if thread_actions.query_key in request.POST: response = thread_actions.handle_post(request, thread) if response: return response if posts_actions.query_key in request.POST: queryset = self.get_posts_queryset(request.user, forum, thread) response = posts_actions.handle_post(request, queryset) if response: return response page, posts = self.get_posts(request.user, forum, thread, kwargs) make_posts_reports_aware(request.user, thread, posts) threadstracker.make_posts_read_aware(request.user, thread, posts) threadstracker.read_thread(request.user, thread, posts[-1]) try: allow_reply_thread(request.user, thread) thread_reply_message = None except PermissionDenied as e: thread_reply_message = unicode(e) return self.render(request, { 'link_name': request.resolver_match.view_name, 'links_params': { 'thread_id': thread.id, 'thread_slug': thread.slug }, 'forum': forum, 'path': get_forum_path(forum), 'thread': thread, 'thread_actions': thread_actions, 'thread_reply_message': thread_reply_message, 'posts': posts, 'posts_actions': posts_actions, 'selected_posts': posts_actions.get_selected_ids(), 'paginator': page.paginator, 'page': page, })
def dispatch(self, request, *args, **kwargs): relations = ['forum', 'starter', 'last_poster', 'first_post'] thread = self.fetch_thread(request, select_related=relations, **kwargs) forum = thread.forum self.check_forum_permissions(request, forum) self.check_thread_permissions(request, thread) validate_slug(thread, kwargs['thread_slug']) threadstracker.make_read_aware(request.user, thread) thread_actions = self.ThreadActions(user=request.user, thread=thread) posts_actions = self.PostsActions(user=request.user, thread=thread) if request.method == 'POST': if thread_actions.query_key in request.POST: response = thread_actions.handle_post(request, thread) if response: return response if posts_actions.query_key in request.POST: queryset = self.get_posts_queryset(request.user, forum, thread) response = posts_actions.handle_post(request, queryset) if response: return response page, posts = self.get_posts(request.user, forum, thread, kwargs) threadstracker.make_posts_read_aware(request.user, thread, posts) threadstracker.read_thread(request.user, thread, posts[-1]) try: allow_reply_thread(request.user, thread) thread_reply_message = None except PermissionDenied as e: thread_reply_message = unicode(e) return self.render(request, { 'link_name': thread.get_url_name(), 'links_params': { 'thread_id': thread.id, 'thread_slug': thread.slug }, 'forum': forum, 'path': get_forum_path(forum), 'thread': thread, 'thread_actions': thread_actions, 'thread_reply_message': thread_reply_message, 'posts': posts, 'posts_actions': posts_actions, 'selected_posts': posts_actions.get_selected_ids(), 'paginator': page.paginator, 'page': page, })
def reply_editor(self, request, thread_pk): thread = self.get_thread(request, thread_pk).unwrap() allow_reply_thread(request.user, thread) if 'reply' in request.query_params: reply_to = self.get_post(request, thread, request.query_params['reply']).unwrap() if reply_to.is_event: raise PermissionDenied(_("You can't reply to events.")) if reply_to.is_hidden and not reply_to.acl['can_see_hidden']: raise PermissionDenied(_("You can't reply to hidden posts.")) return Response({ 'id': reply_to.pk, 'post': reply_to.original, 'poster': reply_to.poster_name, }) else: return Response({})
def allow_reply(self, user, thread): allow_reply_thread(user, thread)
def allow_reply(self, user, forum, thread): allow_reply_thread(user, thread)
def allow_reply_thread(self, user, thread): allow_reply_thread(user, thread)