예제 #1
0
파일: user.py 프로젝트: nuannuanwu/weixiao
    def create(self, request):
        '''
        记录设备的唯一标识

        ``POST`` `account/set_device_token/ <http://192.168.1.222:8080/v1/account/set_device_token>`_

        :param token:
            设备令牌.
        '''
        token = request.POST.get("device_token")
        unset = request.POST.get("unset","")
        
        if unset:
            user_id = request.POST.get("user_id","")
            if user_id:
                try:
                    device = Device.objects.get(token=token,user_id=user_id)
                    device.delete()
                except ObjectDoesNotExist:
                    return rc.NOT_HERE
            else:
                try:
                    device = Device.objects.get(token=token,user=request.user)
                    device.delete()
                except ObjectDoesNotExist:
                    return rc.NOT_HERE
        else:
            device,create = Device.objects.get_or_create(user=request.user,defaults={"token":token})
            if not create:
                device.token = token
                device.save()

        return rc.accepted({"result": True})
예제 #2
0
    def delete(self, request):
        """
        删除一条信息

        ``POST`` `messages/destroy/ <http://192.168.1.222:8080/v1/messages/destroy>`_

        :param id:
            该信息的 id
        """
        message_id = request.POST.get("id")
        if not message_id:
            return rc.BAD_REQUEST

        try:
            message = Message.objects.get(pk=message_id)
        except Message.DoesNotExist:
            return rc.NOT_HERE

        now = get_datetime_now()
        if message.sender == request.user:
            message.sender_deleted_at = now
            message.save()

        if request.user in message.recipients.all():
            mr = message.messagerecipient_set.get(user=request.user,
                                                  message=message)
            mr.deleted_at = now
            mr.save()

        return rc.accepted({"result": True})
예제 #3
0
파일: user.py 프로젝트: nuannuanwu/weixiao
    def change_password(self, request):
        '''
        更改用户密码接口.

        ``POST`` `account/change_passwrod/ <http://192.168.1.222:8080/v1/account/change_password>`_

        :param old_password:
            旧密码

        :param new_password:
            新密码
        '''
        user = request.user
        old_password = request.POST.get("old_password")
        new_password = request.POST.get("new_password")

        data = {
            "old_password": old_password,
            "new_password1": new_password,
            "new_password2": new_password,
        }

        form = PasswordChangeForm(user=user, data=data)
        if form.is_valid():
            form.save()
            # Send a signal that the password has changed
            userena_signals.password_complete.send(sender=None,
                                                   user=user)
            return rc.accepted({"result": True})
        # return form.error_messages
        return rc.BAD_REQUEST
예제 #4
0
파일: tile.py 프로젝트: nuannuanwu/weixiao
    def post(self, request):
        """
        喜欢某个瓦片(tile)

        ``POST`` `tiles/like/ <http://192.168.1.222:8080/v1/tiles/like>`_

        :param id:
            某个瓦片的 id

        """
        params = request.POST
        tag = params.get("tag",'')
        d = []
        try:
            t = eval(tag)
        except:
            return rc.not_here("please pass the correct parameters")
        for g in t:
            if g:
                num = TileCreateTag.objects.filter(tag=g).count()
                if num:
                    d.append({"tag":g,"exist": True})
                else:
                    d.append({"tag":g,"exist": False})   
        return rc.accepted(d)
예제 #5
0
파일: tile.py 프로젝트: nuannuanwu/weixiao
    def upload_video(self, request):
        """
        上传视频
        """
        files = {'mugshot': request.FILES['video']}
#         rs = {"result": "http://pyflask-base.stor.sinaapp.com/video/iphone_firefly_green_720_half.mp4"}
        rs = {"result": "http://weixiao178.com/video/iphone_firefly_green_720_half.mp4"}
        # when return rc.deleted, content would be empty
        # no matter what content you pass to it.
        return rc.accepted(rs)
예제 #6
0
    def delete(self, request):
        """
        删除一条内容

        ``POST`` `actives/destroy/ <http://192.168.1.222:8080/api/v1/actives/destroy>`_

        :param id:
            某条活动的 id
        """
        active_id = request.POST.get("id")
        try:
            Activity.objects.get(pk=active_id).delete()
        except Activity.DoesNotExist:
            return rc.NOT_HERE

        return rc.accepted({"result": True})
예제 #7
0
파일: tile.py 프로젝트: nuannuanwu/weixiao
    def delete(self, request):
        """
        删除一条内容

        ``POST`` `tiles/destroy/ <http://192.168.1.222:8080/v1/tiles/types>`_

        :param id:
            某条瓦片的 id
        """
        tile_id = request.POST.get("id")
        try:
            Tile.objects.get(pk=tile_id).delete()
        except Tile.DoesNotExist:
            return rc.NOT_HERE

        # when return rc.deleted, content would be empty
        # no matter what content you pass to it.
        return rc.accepted({"result": True})
예제 #8
0
파일: tile.py 프로젝트: nuannuanwu/weixiao
    def delete(self, request):
        """
        取消喜欢某个瓦片(tile)

        ``POST`` `tiles/like/ <http://192.168.1.222:8080/v1/tiles/like>`_

        :param id:
            某个瓦片的 id

        """

        params = request.POST
        tid = params.get("id")

        try:
            Like.objects.get(user=request.user, object_id=tid).delete()
        except Like.DoesNotExist:
            return rc.NOT_HERE

        return rc.accepted({"result": True})
예제 #9
0
    def delete(self, request):
        """
        删除一条评论

        ``POST`` `comments/destroy <http://192.168.1.222:8080/v1/comments/create>`_

        :param id:
            某条评论的 id.
        """
        comment_id = request.POST.get("id")
        try:
            klass = comments.get_model()
            comment = klass.objects.get(pk=comment_id, site__pk=settings.SITE_ID, is_removed=False)
        except klass.DoesNotExist:
            return rc.NOT_HERE

        if request.user == comment.user:
            perform_delete(request, comment)
            comment.content_object.after_del_comments()
            return rc.accepted({"result": True})
        else:
            return rc.FORBIDDEN