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)
예제 #3
0
    def create(self, request):
        allow_use_private_threads(request.user)
        if not request.user.acl_cache['can_start_private_threads']:
            raise PermissionDenied(_("You can't start private threads."))

        request.user.lock()

        # Initialize empty instances for new thread
        thread = Thread()
        post = Post(thread=thread)

        # Put them through posting pipeline
        posting = PostingEndpoint(
            request,
            PostingEndpoint.START,
            tree_name=PRIVATE_THREADS_ROOT_NAME,
            thread=thread,
            post=post,
        )

        if posting.is_valid():
            posting.save()

            return Response({
                'id': thread.pk,
                'title': thread.title,
                'url': thread.get_absolute_url(),
            })
        else:
            return Response(posting.errors, status=400)
예제 #4
0
    def find_mode(self, request, *args, **kwargs):
        """
        First step: guess from request what kind of view we are
        """
        is_submit = request.method == 'POST' and 'submit' in request.POST
        if is_submit:
            request.user.lock()

        forum = self.get_forum(request, lock=is_submit, **kwargs)

        thread = None
        post = None

        if 'thread_id' in kwargs:
            thread = self.get_thread(request,
                                     lock=is_submit,
                                     queryset=forum.thread_set,
                                     **kwargs)

        if thread:
            mode = REPLY
        else:
            mode = START
            thread = Thread(forum=forum)

        if not post:
            post = Post(forum=forum, thread=thread)

        return mode, forum, thread, post
예제 #5
0
    def create(self, request):
        # Initialize empty instances for new thread
        thread = Thread()
        post = Post(thread=thread)
        tag = Tag(thread=thread)

        # Put them through posting pipeline
        posting = PostingEndpoint(
            request,
            PostingEndpoint.START,
            tree_name=THREADS_ROOT_NAME,
            thread=thread,
            post=post,
            tag=tag,
        )

        if posting.is_valid():
            posting.save()

            return Response({
                'id': thread.pk,
                'title': thread.title,
                'url': thread.get_absolute_url(),
            })
        else:
            return Response(posting.errors, status=400)
예제 #6
0
파일: posting.py 프로젝트: qhhonx/Misago
    def find_mode(self, request, *args, **kwargs):
        """
        First step: guess from request what kind of view we are
        """
        is_post = request.method == 'POST'

        if 'forum_id' in kwargs:
            mode = START
            user = request.user

            forum = self.get_forum(request, lock=is_post, **kwargs)
            thread = Thread(forum=forum)
            post = Post(forum=forum, thread=thread)
            quote = Post(0)
        elif 'thread_id' in kwargs:
            thread = self.get_thread(request, lock=is_post, **kwargs)
            forum = thread.forum

        return mode, forum, thread, post, quote
예제 #7
0
파일: tasks.py 프로젝트: Time1ess/SIEForum
 def _wraps(self, thread_id, sol_id, *args, **kwargs):
     try:
         thread = Thread.objects.get(id=thread_id)
         poster = get_user_model().objects.get(username='******')
         now = timezone.now()
         reply = _('<h3>Status: Judging</h3>')
         post = Post.objects.filter(category=thread.category,
                                    thread=thread,
                                    poster=poster)
         if post.count() == 0:
             post = Post(category=thread.category,
                         thread=thread,
                         poster=poster,
                         poster_name=settings.OJ_ROBOT_NAME,
                         poster_ip='0.0.0.0',
                         updated_on=now,
                         original=reply,
                         parsed=reply,
                         posted_on=now)
         else:
             post = post[0]
             post.updated_on = now
             post.original = reply
             post.parsed = reply
         post.save()
         update_post_checksum(post)
         post.save()
     except Exception as e:
         logging.error('Posting error:{}'.format(e))
     start_time = time.time()
     try:
         logging.info('Judging started:{}'.format(sol_id))
         solution = Solution.objects.get(id=sol_id)
         result = func(solution, *args, **kwargs)
     except Exception as e:
         logging.error('Judgin failed:{}'.format(e))
         solution.status = SOL_ERROR
         result = -1
     else:
         logging.info('Judging succeed:{}'.format(sol_id))
         solution.status = SOL_FINISHED
     finally:
         solution.save()
         logging.info('Judging finished:{}'.format(sol_id))
     # Reply thread about judgement details
     duration = time.time() - start_time
     status = _('Error') if result < 0 else _('Succeed')
     reply = settings.OJ_REPLY_FORMAT % {
         'status': status,
         'duration': duration,
         'result': result,
         'updated_on': timezone.localtime(now).strftime(
             _('%Y-%m-%d %H:%M:%S')),
     }
     now = timezone.now()
     post.updated_on = now
     post.original = reply
     post.parsed = reply
     post.save()
     update_post_checksum(post)
     post.save()
     return result
예제 #8
0
def create_post(thread, user):
    now = timezone.now()
    post = Post()
    post.forum = thread.forum
    post.thread = thread
    post.date = now
    post.user = user
    post.user_name = user.username
    post.ip = '127.0.0.1'
    post.agent = 'No matter'
    post.post = 'No matter'
    post.post_preparsed = 'No matter'
    post.save(force_insert=True)
    if not thread.start_post:
        thread.start = now
        thread.start_post = post
        thread.start_poster = user
        thread.start_poster_name = user.username
        thread.start_poster_slug = user.username_slug
    thread.last = now
    thread.last_post = post
    thread.last_poster = user
    thread.last_poster_name = user.username
    thread.last_poster_slug = user.username_slug
    thread.save(force_update=True)
    return post