예제 #1
0
    def post(self, *args, **kwargs):
        circle_id = self.get_arg(MomentKey.ARG_CIRCLE_ID)
        user = self.get_user_info()

        moment_data = self.get_moment_data()
        if not moment_data:
            raise tornado.web.MissingArgumentError('missing args')

        images = ""
        for param in UPLOAD_IMAGE_PARAMS:
            file_name = self.save_image(param)
            if file_name is None:
                break
            # image_id = service.insert_post_image(user['uid'], file_name)
            Image.insert(ts=int(time.time()), path=file_name).execute()
            image = Image.get(Image.path == file_name)

            images += str(image.id)
            images += '|'

        images = images[:-1]

        Moment.insert(
            ts=int(time.time()),
            post_user=user['uid'],
            circle=circle_id,
            content=moment_data[MomentKey.JSON_CONTENT],
            title=moment_data[MomentKey.JSON_TITLE],
            image=images
        ).execute()

        self.write(self.ok_pack())
예제 #2
0
 def get_moment_items(self, index=0):
     rows = Moment.select().paginate(index, 10)
     items = list()
     for row in rows:
         items.append(model_to_dict(row, exclude=get_exclude_field()))
     return items