def user_favorite_space_list(request, format=None): token = request.GET.get('token', None) if token is None: raise NotFound('invalid request') data = token_decode(token) if data is None: raise NotFound('invalid request') if request.user.id != data['user_id']: raise PermissionDenied('access denied') result = Favorite.objects.filter(user_id=data['user_id']).order_by('-time_date') serializer = FavoriteSpaceSerializer(result, many=True) return Response(serializer.data)
def update(request): put_data = request.data token = put_data.get('token', None) if token is None: return invalid_request(request) token_data = token_decode(token) user = request.user if user.id != token_data['user_id']: raise PermissionDenied('access permission denied') what = put_data.get('what', None) uid = put_data.get('current', None) space_name = put_data.get('space', None) file = put_data.get('image', None) if file is None: raise NotFound('invalid request') if not ImageHandler.is_valid_format(file.name): raise NotAcceptable('unacceptable type of file') if what is None: raise NotFound('invalid request') what = what.lower() if what == 'banner': if uid is None: raise NotFound('invalid request') if space_name is None: raise NotFound('invalid request') return _update_banner(user, uid, space_name, file) elif what == 'space_logo': if space_name is None: raise NotFound('invalid request') return _update_space_logo(user, space_name, file) elif what == 'product': if uid is None: raise NotFound('invalid request') if space_name is None: raise NotFound('invalid request') return _update_product_media(user, uid, space_name, file) elif what == 'account': return _update_account_thumbnail(user, file)
def product_pinned_request(request, uid, format=None): token = request.GET.get('token', None) req = request.GET.get('req', None) if token is None: raise NotFound('request not found') data = token_decode(token) if data is None: raise None ('invalid request') if request.user.id != data['user_id']: raise PermissionDenied('access denied') req = req.upper() result = activity.handle_pin(request.user, uid, req) if not result: raise NotFound('request not found') return Response({'response': True})
def verify(request, token): data = token_decode(token) if data is None: return views.invalid_request(request) user_id = data['user_id'] email = data['email'] user = Account.objects.get(id=user_id) if user.is_active: return redirect('/account/') if email == user.email: user.is_active = True user.save() return render(request, 'account/auth/confirm.html', {}) return invalid_request(request)
def manager(request, format=None): token = request.GET.get('token', None) if token is None: raise NotFound('invalid request') data = token_decode(token) if data is None: raise NotFound('invalid request') if request.user.id != data['user_id']: raise PermissionDenied('access denied') category = request.GET.get('category', None) query = request.GET.get('query', None) pinned_by = request.GET.get('pinned_by', None) space = request.GET.get('space', None) page = request.GET.get('page', None) page = __clean_value(page) serializer = None if category is not None: serializer = __category_filter(category, page=page) elif query is not None: serializer = __query_filter(query, page=page) elif pinned_by is not None: serializer = __user_pinned_filter(data['user_id'], page=page, request=request) elif space is not None: serializer = __space_product(space, page=page) else: serializer = __all_products(page) if serializer: return Response(serializer.data) raise NotFound('invalid request')
def manager(request, format=None): token = request.GET.get('token', None) query = request.GET.get('query', None) page = request.GET.get('page', None) limit = request.GET.get('limit', None) if token is None: raise NotFound('invalid request') data = token_decode(token) if data is None: raise NotFound('invalid request') if request.user.id != data['user_id']: raise PermissionDenied('access denied') serializer = None page = __clean_value(page) limit = __clean_value(limit) if query is not None: serializer = __query_filter(query, page=page, limit=limit) else: if page is not None: offset = page * SPACE_PAGINATION_SIZE result = Status.objects.all().order_by('-space_id')[offset:offset+SPACE_PAGINATION_SIZE] else: result = Status.objects.all().order_by('-space_id') serializer = SpaceStatusSerializer(result, many=True) if serializer: return Response(serializer.data) raise NotFound('invalid request')
def favorite_request(request, name, format=None): token = request.GET.get('token', None) req = request.GET.get('req', None) if token is None: raise NotFound('invalid request') data = token_decode(token) if data is None: raise NotFound('invalid request') if request.user.id != data['user_id']: raise PermissionDenied('access denied') if req is None: raise NotFound('request not found') result = activity.handle_favorite(request.user, name, req) if not result: raise NotFound('request not found') return Response({'response' : 'space added to favorite list'})
def product_react_request(request, uid, format=None): token = request.GET.get('token', None) what = request.GET.get('react', None) if token is None: raise NotFound('request not found') data = token_decode(token) if data is None: raise None ('invalid request') if request.user.id != data['user_id']: raise PermissionDenied('access denied') if what is None: try: result = Product.objects.get(uid=uid) serializer = ProductSerializerForReact(result) return Response(serializer.data) except ObjectDoesNotExist as e: raise NotFound('request not found') result = activity.handle_react(request.user, uid, what) if result is None: raise NotFound('request not found') serializer = ProductSerializerForReact(result) return Response(serializer.data)