示例#1
0
    def post(self, request, *args, **kw):
        'for handling post request of signin service'
        response = {}
        response_data = {}
        email = request.data.get('email', None)
        password = request.data.get('password', None)
        device_id, device_token, device_type = FizzUtility.get_device_keys_from_request(request)

        if User.objects.filter(Q(email__iexact=email) & Q(is_superuser=False)).exists():
            user = authenticate(email=email, password=password)
            response = AppUtility.check_user_create_outh_token(
                user, device_id, device_type, request)

            res = response.get('response', None)
            if res:
                token = res.get('access_token', None)
                access_token = AccessToken.objects.filter(
                        token=token)
                if len(access_token) > 0:
                    AppUtility.add_device_detail(
                        device_type, device_id, user, device_token)

            return Response(response, status=status.HTTP_200_OK)
        else:
            response = {settings.MESSAGE_KEY: Messages.INVALID_USER_PASSWORD}
            response_data = FizzUtility.data_wrapper(
                response, settings.HTTP_USER_ERROR)
            return Response(response_data, status=status.HTTP_200_OK)
示例#2
0
    def get(self, request, *args, **kwargs):
        'for handling get request of view profile'
        response_data = {}
        if request.user:
            user_serializer = UserSerializer(request.user)

            response_data['user'] = user_serializer.data
            response = FizzUtility.data_wrapper(response_data)
            return Response(response, status=status.HTTP_200_OK)
        else:
            response = {settings.MESSAGE_KEY: Messages.NOT_FOUND}
            response_data = FizzUtility.data_wrapper(
                response, settings.HTTP_USER_ERROR)
            return Response(response_data, status=status.HTTP_200_OK)
示例#3
0
    def get(self, request, category_id):
        response_data = {}
        serializer_data = []
        
        cursor = connection.cursor()

        cursor.execute("Select product_id FROM public.product_product_category WHERE productcategory_id = %s", [category_id])
    
        category_product = cursor.fetchall()
         
        for productCat in category_product:
            product_data = Product.objects.filter(id = productCat[0], is_active=True)
            serializer = serializers.ProductSerializer(product_data, many=True)
             
            for product in serializer.data:
                product_images = ProductImages.objects.filter(product_id = product.get('id'), is_active=True).order_by('sort_order')[:5]
                serializer_image = serializers.ProductImagesSerializer(product_images, many=True)
                product_data = product
                product_data['images'] = serializer_image.data
             
            serializer_data.append(product_data)
        
        if len(category_product) > 0:
            status_code = status.HTTP_200_OK
        else:
            status_code = settings.HTTP_USER_ERROR
             
        response_data['products'] = serializer_data
        response = FizzUtility.data_wrapper(response_data, status_code=status_code)
        return Response(response, status=status.HTTP_200_OK)
示例#4
0
 def get(self, request, *args, **kwargs):
     'for handling get request for countries'
     countries = self.list(request, *args, **kwargs)
     response_data = {}
     response_data['countries'] = countries.data
     response = FizzUtility.data_wrapper(response_data)
     return Response(response, status=status.HTTP_200_OK)
示例#5
0
    def post(self, request, *args, **kwargs):
        exception = self.create(request, *args, **kwargs)
        exception = FrontLog.objects.get(id=exception.data.get('id', None))

        exception_serializer = serializers.FrontLogSerializer(exception)
        response_data = {}
        response_data['exception'] = exception_serializer.data
        response = FizzUtility.data_wrapper(response_data)
        return Response(response, status=status.HTTP_200_OK)
示例#6
0
    def check_user_create_outh_token(user,
                                     device_id=None,
                                     device_type=None,
                                     request=None):
        '''
        check user and create auth token
        '''
        response = {}
        response_data = {}

        if user:
            if user.is_active:
                # User is valid, active and authenticated
                if len(
                        User.objects.filter(id=user.id)
                ) > 0 and request is not None and device_type is not None:
                    obj_acces_token = AppUtility.create_oauth_token(
                        user, request, settings.APPLICATION_NAME)
                    response_data['access_token'] = obj_acces_token.token

                user_serializer = UserSerializer(user)
                response_data['user'] = user_serializer.data
                response["status_code"] = status.HTTP_200_OK
                response['response'] = response_data
                return response

            else:
                # The password is valid, but the account has been disabled!
                response = {
                    settings.MESSAGE_KEY:
                    Messages.PASSWORD_MATCHED_ACCOUNT_DISABLED %
                    settings.ADMIN_EMAIL
                }
                response_data = FizzUtility.data_wrapper(
                    response, settings.HTTP_USER_ERROR)
                return response_data
        else:
            response = {settings.MESSAGE_KEY: Messages.INVALID_USER_PASSWORD}
            response_data = FizzUtility.data_wrapper(response,
                                                     settings.HTTP_USER_ERROR)
            return response_data
示例#7
0
    def put(self, request, *args, **kw):
        'for handling post request of signout service'
        token = request.META['HTTP_AUTHORIZATION']
        lst_token = token.split(' ')
        access_token = get_object_or_404(AccessToken, token=lst_token[1])
        access_token.expires = timezone.now()
        access_token.save()
 
        response = {settings.MESSAGE_KEY: Messages.ACCESS_TOKEN_EXPIRED}
        response_data = FizzUtility.data_wrapper(
            response, status.HTTP_200_OK)
        return Response(response_data, status=status.HTTP_200_OK)
示例#8
0
 def get(self, request, category_id):
     template_list = ProductTemplate.objects.filter(category_id = category_id, is_active=True).order_by('sort_order')[:5]
     
     if template_list.count() > 0:
         status_code = status.HTTP_200_OK
     else:
         status_code = settings.HTTP_USER_ERROR
         
     response_data = {}
     serializer = serializers.ProductTemplateSerializer(template_list, many=True)
     response_data['Templates'] = serializer.data
     response = FizzUtility.data_wrapper(response_data, status_code=status_code)
     return Response(response, status=status.HTTP_200_OK)
示例#9
0
 def get(self, request, template_id):
     template = ProductTemplate.objects.filter(id = template_id, is_active=True)
     
     if template:
         status_code = status.HTTP_200_OK
     else:
         status_code = settings.HTTP_USER_ERROR
         
     response_data = {}
     serializer = serializers.ProductTemplateWithDataSerializer(template, many=True)
     response_data['TemplatesData'] = serializer.data
     response = FizzUtility.data_wrapper(response_data, status_code=status_code)
     return Response(response, status=status.HTTP_200_OK)
示例#10
0
    def post(self, request, *args, **kw):
        'for handling post request of signup service'
        response = {}
        response_data = {}
        device_id, device_token, device_type = FizzUtility.get_device_keys_from_request(request)

        user = User.objects.filter(email__iexact=request.data.get('email', None)).first()
        if user:
            response = {settings.MESSAGE_KEY: Messages.ALREADY_REGISTER_USER}
            response_data = FizzUtility.data_wrapper(
                response, settings.HTTP_USER_ERROR)
            return Response(response_data, status=status.HTTP_200_OK)
        else:
            user = self.create(request, *args, **kw)
            token_application_name = settings.APPLICATION_NAME
            user = User.objects.get(id=user.data.get('id', None))
            
            current_site = get_current_site(request)
            domain = current_site.domain

            user.protocol = 'http'
            user.domain = domain
            
            AppCustomMethods.send_email(user, request,
                            'thankyou_after_registration.html',
                            'The ChampagnFizz App - Welcome Email.')

            access_token = AppUtility.create_oauth_token(
                 user, request, token_application_name)\

            AppUtility.add_device_detail(
                device_type, device_id, user, device_token)

            user_serializer = UserSerializer(user)
            response_data['access_token'] = access_token.token
            response_data['user'] = user_serializer.data
            response = FizzUtility.data_wrapper(response_data)
            return Response(response, status=status.HTTP_200_OK)
 def update_user(self, user, data, is_busness_user):
     '''
     update function
     '''
     # comment below 2 lines when testing with device.
     serializer = UpdateSerializer(user, data, partial=True)
     response = {}
     response_data = {}
     if serializer.is_valid():
         user = serializer.save()
         update_serializer = UpdateSerializer(user)
         response = FizzUtility.data_wrapper(response_data)
         return response
     return {}
示例#12
0
 def update_user(self, user, data, is_busness_user):
     '''
     update function
     '''
     # comment below 2 lines when testing with device.
     serializer = UpdateSerializer(user, data, partial=True)
     response = {}
     response_data = {}
     if serializer.is_valid():
         user = serializer.save()
         update_serializer = UpdateSerializer(user)
         response = FizzUtility.data_wrapper(response_data)
         return response
     return {}
示例#13
0
 def post(self, request):
     old_password = self.request.data.get('old_password', None)
     new_password = self.request.data.get('new_password', None)
     user = request.user
     self.check_object_permissions(self.request, user)
     match = user.check_password(old_password)
     response_data = {}
     response = {}
     if match:
         user.set_password(new_password)
         user.save()
         response_data[settings.MESSAGE_KEY] = Messages.PASSWORD_CHANGED_SUCCESSFULLY
     else:
         response_data['error'] = Messages.INVALID_PASSWORD
         response['status_code'] = status.HTTP_406_NOT_ACCEPTABLE
         response['response'] = response_data
         return Response(response)
     response = FizzUtility.data_wrapper(response_data)
     return Response(response)
示例#14
0
    def get(self, request, *args):
#         category_list = ProductCategory.objects.filter(is_active=True).order_by('sort_order', 'occasion_start_date',  'name')
#         cursor = connection.cursor()
   
#         cursor.execute("SELECT *,case when occasion_start_date > now() or now() < occasion_end_date then 1 else 2 end as order_ FROM public.product_productcategory WHERE is_active=True order by order_,occasion_start_date asc")
#         category_list = cursor.fetchall()
        
#         if category_list.count() > 0:
#             status_code = status.HTTP_200_OK
#         else:
#             status_code = settings.HTTP_USER_ERROR
        category_list = ProductCategory.objects.raw("SELECT *,case when occasion_start_date > now() or now() < occasion_end_date then 1 else 2 end as order_ FROM public.product_productcategory WHERE is_active=True order by order_,occasion_start_date asc")
        
        status_code = status.HTTP_200_OK
              
        response_data = {}
        serializer = serializers.ProductCategorySerializer(category_list, many=True)
        response_data['Categories'] = serializer.data
#         response_data['Categories'] = category_list
        response = FizzUtility.data_wrapper(response_data, status_code=status_code)
        return Response(response, status=status.HTTP_200_OK)