def post(self, request): idCategory = request.data['id'] permission = 0 user = None try: user = get_user_from_request(self, request) permission = user.profile.permission except: pass try: category = Category.objects.get(id_category=idCategory) if category.permission > permission: raise Exception('Permission is required') except: # return Response({"msg": 'the category is not exsit'}, status=HTTP_400_BAD_REQUEST) return Response({"msg": 'the category is not exsit'}, status=HTTP_404_NOT_FOUND) jsonResponse = category.getCategory(user) if jsonResponse == -1: return Response({"msg": 'the page not found'}, status=HTTP_404_NOT_FOUND) return Response({"category": jsonResponse}, status=HTTP_200_OK)
def post(self, request): idForum = request.data['id'] page = request.data['page'] permission = 0 user = None try: user = get_user_from_request(self, request) permission = user.profile.permission except: pass try: forum = Forum.objects.get(id_forum=idForum) if forum.permission > permission: raise Exception('Permission is required') except: return Response({"msg": 'the forum is not exsit'}, status=HTTP_400_BAD_REQUEST) jsonResponse = forum.getForum(user, page) if jsonResponse == -1: return Response({"msg": 'the page not found'}, status=HTTP_404_NOT_FOUND) return Response({"forum": jsonResponse}, status=HTTP_200_OK)
def post(self, request): idPost = request.data['id'] page = request.data['page'] permission = 0 user = None try: user = get_user_from_request(self, request) permission = user.profile.permission except: pass try: post = Post.objects.get(id_post=idPost) print('post', post) if post.permission > permission: raise Exception('Permission is required') except: return Response({"msg": 'the post is not exsit'}, status=HTTP_400_BAD_REQUEST) print('b1') jsonResponse = post.getPost(user) print('b2') # return Response({"msg": 'the post is not exsit'}, status=HTTP_400_BAD_REQUEST) if jsonResponse == -1: return Response({"msg": 'the page not found'}, status=HTTP_404_NOT_FOUND) return Response({"post": jsonResponse}, status=HTTP_200_OK)
def post(self, request): data = request.data['data'] title = request.data['title'] forum_ids = request.data['forum_id'] user = get_user_from_request(self, request) try: permission = request.data['permission'] if permission <= user.profile.permission: permission = regular_code except: permission = regular_code try: forum = Forum.objects.get(id_forum=forum_ids) except: return Response({"msg": 'The forum does not exist'}, status=HTTP_400_BAD_REQUEST) post = Post.create(user=user, data=data, permission=permission, forum_id=forum_ids, title=title) post.save() forum.posts.add(post) forum.save() return Response({ "msg": 'The post created', 'id': post.id_post }, status=HTTP_200_OK)
def post(self, request): permission = 100 try: user = get_user_from_request(self, request) permission = user.profile.permission except: pass categories = Category.objects.all() listJsonCategory = [] for category in categories: if category.permission <= permission: listJsonCategory.append(category.getHeadCategory()) return Response({"listCategory": listJsonCategory}, status=HTTP_200_OK)
def post(self, request): data = request.data['data'] post_id = request.data['post_id'] user = get_user_from_request(self, request) if data == None: data = "test" try: permission = request.data['permission'] if permission <= user.profile.permission: permission = regular_code except: permission = regular_code try: post = Post.objects.get(id_post=post_id) except: return Response({"msg": 'The post does not exist'}, status=HTTP_400_BAD_REQUEST) message = Message.create(user=user, data=data, permission=permission, is_quoted=False, post_id=post_id) message.save() post.messages.add(message) post.save() return Response( { "msg": 'The message created', 'id': message.id_message }, status=HTTP_200_OK)