def post(self, request, id): helper.check_parameters( request.data, ['price', 'start_date', 'end_date', 'delivery', "description"]) try: product = Product.objects.get(id=id) except Exception as e: raise helper.exception.NotAcceptable( helper.message.MODULE_NOT_FOUND("product")) agreement = Agreements.objects.create( vendor=request.user, product=product, price=request.data['price'], start_date=request.data['start_date'], end_date=request.data['end_date'], description=request.data['description'], delivery=request.data['delivery'], ) if request.data['attachment']: agreement.attachment = request.FILES['attachment'] agreement.save() return helper.createResponse( helper.message.MODULE_STORE_SUCCESS('Agreement'))
def post(self, request): helper.check_parameters(request.data, ['email', 'password']) helper.verify_recaptcha(request) user = self.get_serializer(data=request.data) user.is_valid(raise_exception=True) user = user.validated_data return helper.createResponse(helper.message.LOGIN_SUCCESS, { "user": user.name, "token": helper.get_token(user) })
def post(self, request): helper.check_parameters(request.data, ['name', 'email', 'password']) if User.objects.filter(email=request.data['email']).count() > 0: raise helper.exception.NotAcceptable( helper.message.USER_EMAIL_EXISTS) user = self.get_serializer(data=request.data) user.is_valid(raise_exception=True) user.save() return helper.createResponse(helper.message.VENDOR_CREATED)
def post(self, request, id): helper.check_parameters(request.data, ['status']) try: user = User.objects.get(id=id, is_superuser=False) except Exception as e: raise helper.exception.ParseError( helper.message.MODULE_NOT_FOUND('User')) user.is_verified = request.data['status'] in ['true', 1] user.save() return helper.createResponse( helper.message.MODULE_STATUS_CHANGE('Vendor status', 'updated'))
def post(self, request, id): helper.check_parameters(request.data, ['price']) try: agreement = Agreements.objects.get(vendor=request.user, id=id, status=3) except Exception as e: raise helper.exception.ParseError( helper.message.MODULE_NOT_FOUND('Agreement')) # 2 = Running/Accept agreement.price = request.data['price'] agreement.save() return helper.createResponse( helper.message.MODULE_STATUS_CHANGE('Agreement', 'updated'))
def post(self, request): helper.check_parameters(request.data, ["old_password", "new_password"]) helper.isEmpty(request.data["old_password"], "old_password") user = authenticate( **{ "email": request.user.email, "password": request.data["old_password"], }) if user != None: user.set_password(request.data["new_password"]) user.save() return helper.createResponse( helper.message.CHANGE_PASSWORD_SUCCESS) else: raise helper.exception.ParseError(helper.message.PASSWORD_MISMATCH)