示例#1
0
文件: thread.py 项目: ar3s3ru/uChan3
        def routine(user: User, thread: Thread):
            """
            Creates new Post table object and returns it as JSON representation.
            Image posting is totally optional (but if chosen, it needs both 'image' and 'image_name' fields.

            :param user:   User object
            :param thread: Thread object
            :return: New Post Object as JSON object
            """
            try:
                self.check_args()
                self.validate_args()

                anon  = str_to_bool(self.args['anon'])
                image = self.media_processing() if self.args['image'] is not None and \
                                                   self.args['image_name'] is not None else None

                post = Post((user.id == thread.author), anon, self.args['text'], thread.id, user.id, thread.board,
                            self.args['reply'], image)

                # Add new Post table to database
                uchan.add_to_db(post)

                # Add new ThreadUser link
                if thread.get_authid(user.id) is None:
                    uchan.add_to_db(ThreadUser(thread.id, user.id))

                # Increments thread counter
                thread.incr_replies((image is not None))
                uchan.commit()

                return responses.successful(201, JSONRepresentation.post(thread.get_last_post(), thread, user))
            except ValueError as msg:
                return responses.client_error(400, '{}'.format(msg))
示例#2
0
文件: thread.py 项目: ar3s3ru/uChan3
        def routine(user: User, thread: Thread):
            """
            Returns Thread's Posts list in JSON object representation.

            :param user:   Requesting User object
            :param thread: Thread ID
            :return: Thread's Posts list in JSON
            """
            return responses.successful(200, [JSONRepresentation.post(post, thread, user)
                                              for post in thread.get_posts(page)])