コード例 #1
0
ファイル: statuses.py プロジェクト: indigos33k3r/anfora
    def on_post(self, req, resp):

        if req.get_param('media_ids'):
            user = req.context['user']

            status = Status(
                caption=req.get_param('status') or '',
                visibility=bool(req.get_param('visibility')), #False if None
                user=user,
                sensitive=bool(req.get_param('sensitive')),
                remote=False,
                story=bool(req.get_param('is_story'))
            )

            if status.sensitive:
                status.spoliet_text=req.get_param('spoiler_text')

            status.save()

            if  req.get_param('media_ids') != None:
                    for image in req.get_param('media_ids').split(','):
                        m = Media.get_or_none(media_name=image)
                        m.status = status
                        m.save()

            #Increment the number of posts uploaded
            UserProfile.update({UserProfile.statuses_count: UserProfile.statuses_count + 1}).where(UserProfile.id == user.id).execute()
            spread_status(status)
            resp.status = falcon.HTTP_200
            resp.body = json.dumps(status.to_json(),default=str)

        elif req.get_param('in_reply_to_id'):

            replying_to = Status.get_or_none(id=req.get_param('in_reply_to_id'))
            if replying_to:
                status = Status(
                    caption = req.get_param('status'),
                    user = user,
                    remote = False,
                    story = False,
                    in_reply_to = replying_to,
                    sensitive = replying_to.sensitive,
                    spoiler_text = req.get_param('spoiler_text') or replying_to.spoiler_text
                )
            else:
                resp.status = falcon.HTTP_500
                resp.body = json.dumps({"Error": "Replying to bad ID"})
        else:
            resp.status = falcon.HTTP_500
            resp.body = json.dumps({"Error": "No photo attached"})
コード例 #2
0
    def create(self,
               user,
               caption,
               sensitive,
               public,
               spoiler=None,
               remote=False,
               story=False,
               media_ids):
        """
            user: UserProfile - User creating the status
            caption: str - Image caption
            sensitive: bool - Content has something sensitive.
            spoiler: str - Content spoiler text
            public: bool - True if yes
            media_ids: list - A list with the media related to the status

            Returns the created status

        """

        status = Status.create(caption=caption,
                               is_public=public,
                               user=user,
                               sensitive=sensitive,
                               spoiler_text=spoiler,
                               remote=remote,
                               is_story=story)

        for image in req.get_param('media_ids').split(','):
            m = Media.get_or_none(media_name=image)
            m.status = status
            m.save()

        UserProfile.update({
            UserProfile.statuses_count:
            UserProfile.statuses_count + 1
        }).where(UserProfile.id == status.user.id).execute()
        spread_status(status)