def get(self, request): token = request.META.get('HTTP_TOKEN') file_id = request.GET.get('file_id') print(token) print(file_id) user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) f = chk_file_id(file_id) if isinstance(f, Response): return f if len(UserKeptFile.objects.filter(person=u, file=f)) > 0: return Response({ 'info': '你已经收藏过该文档了', 'code': 403, }, status=403) ukf = UserKeptFile.objects.update_or_create(person=u, file=f)[0] print(ukf) return Response( { 'info': 'success', 'code': 200, 'data': UserKeptFileSer(ukf).data }, status=200)
def get(self, request): token = request.META.get('HTTP_TOKEN') file_id = request.GET.get('file_id') print(token) print(file_id) user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) f = chk_file_id(file_id) if isinstance(f, Response): return f ukf = UserKeptFile.objects.filter(person=u, file=f) res = UserKeptFileSer(ukf.get()).data print(ukf) if len(ukf) > 0: # file_id = ukf.get().file_id ukf.get().delete() return Response({ 'info': 'success', 'code': 200, 'data': res }, status=200) return Response({ 'info': '你未收藏过该文档, 无法删除', 'code': 403, }, status=403)
def get(self, request): token = request.META.get('HTTP_TOKEN') team_id = request.GET.get('team_id') print(token) user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) t = Team.objects.filter(pk=team_id) if len(t) <= 0: return Response({'info': '团队不存在', 'code': 403}, status=403) t = t.get() f = File.objects.create(file_content='', type='team', permission='5', team_permission='5', creator=u, team_belong=t) # f = File.objects.filter(pk=f.pk).values() return Response( { 'info': 'success', 'code': 200, 'data': FileSer(f).data }, status=200)
def post(self, request): token = request.META.get('HTTP_TOKEN') file_id = request.POST.get('file_id') comment = request.POST.get('comment') print(token) print(comment) user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) f = chk_file_id(file_id) if isinstance(f, Response): return f c = Comment.objects.create(person=u, file=f, content=comment) # c = Comment.objects.filter(person=u, file=f, content=comment).get(0) print(c) return Response( { 'info': 'success', 'code': 200, 'data': CommentSer(c).data }, status=200)
def post(self, request): token = request.META.get('HTTP_TOKEN') print(token) user_id = chk_token(token) if isinstance(user_id, Response): return user_id pwd = request.POST.get('new_password') email = request.POST.get('email') phone_num = request.POST.get('phone_num') print(pwd) print(email) print(phone_num) if not all([pwd, email, phone_num]): return Response({'info': '参数不完整', 'code': 400}, status=400) u = User.objects.get(pk=user_id) if u.check_pwd(pwd): return Response({'info': '新密码不能与旧密码一样', 'code': 403}, status=403) u.password = make_password(pwd) u.email = email u.phone_num = phone_num u.save() return Response( { 'info': 'success', 'code': 200, 'data': UserInfoSer(u).data }, status=200)
def post(self, request): token = request.META.get('HTTP_TOKEN') file_id = request.GET.get('file_id') is_delete = request.GET.get('is_delete') user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) f = chk_file_id(file_id) if isinstance(f, Response): return f if f: if is_delete == False: f.is_delete = False f.save() else: f.is_delete = True f.save() else: return Response({ 'info': 'not_found_file', 'code': 403, }, status=403) return Response({ 'info': 'success', 'code': 200, }, status=200)
def get(self, request): token = request.META.get('HTTP_TOKEN') team_id = request.GET.get('team_id') if team_id is None: return Response({ 'info': '参数不完整', 'code': 400, }, status=400) user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) t = Team.objects.get(pk=team_id) tm = TeamMember.objects.filter(team=t, member=u) if len(tm) <= 0: return Response({ 'info': '未加入该团队 无法退出', 'code': 403, }, status=403) res = TeamMemberSer(tm.get()).data # t_id = tm.get().team.pk tm.get().delete() return Response({ 'info': 'success', 'code': 200, 'data': res }, status=200)
def get(self, request): token = request.META.get('HTTP_TOKEN') print(token) user_id = chk_token(token) if isinstance(user_id, Response): return user_id res = User.objects.get(pk=user_id) return Response( { 'info': 'success', 'code': 200, 'data': UserInfoSer(res).data }, status=200)
def post(self, request): token = request.META.get('HTTP_TOKEN') print(token) user_id = chk_token(token) if isinstance(user_id, Response): return user_id old_pwd = request.POST.get('old_password') u = User.objects.get(pk=user_id) if u.check_pwd(old_pwd): return Response( { 'info': 'success', 'code': 200, 'data': UserInfoSer(u).data }, status=200) else: return Response({'info': '旧密码错误', 'code': 403}, status=403)
def get(self, request): token = request.META.get('HTTP_TOKEN') print(token) user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) f = File.objects.create(file_content='', type='private', permission='5', creator=u) # f = File.objects.filter(pk=f.pk).values() return Response( { 'info': 'success', 'code': 200, 'data': FileSer(f).data }, status=200)
def post(self, request): token = request.META.get('HTTP_TOKEN') name = request.POST.get('team_name') if name is None: return Response({ 'info': '参数不完整', 'code': 400, }, status=400) print(token) user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) t = Team.objects.create( creator=u, name=name ) return Response({ 'info': 'success', 'code': 200, 'data': TeamSer(t).data }, status=200)
def get(self, request): token = request.META.get('HTTP_TOKEN') file_id = request.GET.get('file_id') print(token) print(file_id) user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) f = chk_file_id(file_id) if isinstance(f, Response): return f UserBrowseFile.objects.update_or_create(person=u, file=f) ubf = UserBrowseFile.objects.filter(person=u, file=f).values() print(ubf) return Response({ 'info': 'success', 'code': 200, 'data': ubf }, status=200)
def get(self, request): token = request.META.get('HTTP_TOKEN') team_id = request.GET.get('team_id') if team_id is None: return Response({ 'info': '参数不完整', 'code': 400, }, status=400) user_id = chk_token(token) if isinstance(user_id, Response): return user_id u = User.objects.get(pk=user_id) t = Team.objects.get(pk=team_id) if TeamMember.objects.filter(team=t, member=u): return Response({ 'info': '你已经加入该团队', 'code': 403, }, status=403) tm = TeamMember.objects.create(team=t, member=u) return Response({ 'info': 'success', 'code': 200, 'data': TeamMemberSer(tm).data }, status=200)