Exemple #1
0
 def get(self, request):
     """Address API GET
     Description:
         return all directions associated to user
     """
     user = get_jwt_user(request)
     req_inf = RequestInfo()
     try:
         if user is not None:
             try:
                 serializer = AddressSerializer(
                     client.addresses.all(),
                     many=True
                 )
                 return Response(serializer.data)
             except ObjectDoesNotExist as e:
                 return req_inf.status_404(e.args[0])
             except Exception as e:
                 return req_inf.status_400(e.args[0])
         else:
             return req_inf.status_401('token invalido')
     except ObjectDoesNotExist as e:
         return req_inf.status_404(e.args[0])
     except Exception as e:
         return req_inf.status_400(e.args[0])
Exemple #2
0
 def put(self, request, pk):
     """DocumentDetailAPIView put
     Description:
         update document information
     """
     req_inf = RequestInfo()
     document_cls = self.get_object(pk)
     if isinstance(document_cls, Document):
         serializer = DocumentInfoSerializer(document_cls,
                                             data=request.data)
         if serializer.is_valid():
             try:
                 serializer.save()
                 log = Log.objects.create(
                     action=Log.NOTIFICATION_TYPE.get_value(
                         'update_document'),
                     user=request.user,
                     description='Modificacion de documento {} - {}'.format(
                         serializer.instance.id, serializer.instance.name))
                 log.save()
                 return req_inf.status_200()
             except Exception as e:
                 return req_inf.status_400(e.args[0])
         return req_inf.status_400(serializer.errors)
     else:
         return req_inf.status_404(document_cls)
Exemple #3
0
 def put(self, request, pk):
     """UserClientDetailAPIView put
     Description:
         update client information
     """
     import pudb
     pudb.set_trace()
     req_inf = RequestInfo()
     user_client = self.get_object(pk)
     if isinstance(user_client, UserClient):
         serializer = ClientSerializer(user_client, data=request.data)
         if serializer.is_valid():
             try:
                 serializer.save()
                 log = Log.objects.create(
                     action=Log.NOTIFICATION_TYPE.get_value(
                         'update_client'),
                     user=request.user,
                     description='Modificacion de cliente {} - {}'.format(
                         serializer.instance.id, serializer.instance.name))
                 log.save()
                 return req_inf.status_200()
             except Exception as e:
                 return req_inf.status_400(e.args[0])
         return req_inf.status_400(serializer.errors)
     else:
         return req_inf.status_404(user_client)
Exemple #4
0
 def get(self, request):
     """User API GET
     Description:
         returns user info
     """
     user = get_jwt_user(request)
     req_inf = RequestInfo()
     if user is not None:
         try:
             serializer = ClientSerializer(user.client)
             return Response(serializer.data)
         except ObjectDoesNotExist as e:
             return req_inf.status_404(e.args[0])
         except Exception as e:
             return req_inf.status_400(e.args[0])
     else:
         return req_inf.status_401('token invalido')
Exemple #5
0
 def patch(self, request):
     """Address API PATCH
     Args:
         country: (str)
         region: (str)
         town: (str)
         neighborhood: (str)
         zip_code: (str)
         street: (str)
         street_number: (str)
         suite_number: (str)
         address_id: (int)
     Description:
         update directions
     """
     user = get_jwt_user(request)
     data = request.data
     req_inf = RequestInfo()
     try:
         if user is not None:
             client = Client.objects.get(user=user)
             address = Address.objects.get(id=data.get('address_id'))
             if 'country' in data:
                 address.country = data.get('country')
             if 'region' in data:
                 address.region = data.get('region')
             if 'town' in data:
                 address.town = data.get('town')
             if 'neighborhood' in data:
                 address.neighborhood = data.get('neighborhood')
             if 'zip_code' in data:
                 address.zip_code = data.get('zip_code')
             if 'street' in data:
                 address.street = data.get('street')
             if 'street_number' in data:
                 address.street_number = data.get('street_number')
             if 'suite_number' in data:
                 address.suite_number = data.get('suite_number')
             address.save()
             return req_inf.status_200('address updated')
         else:
             return req_inf.status_401('token invalido')
     except ObjectDoesNotExist as e:
         return req_inf.status_404(e.args[0])
     except Exception as e:
         return req_inf.status_400(e.args[0])
Exemple #6
0
 def patch(self, request):
     """User API PATCH
     Args:
         username: (str)
         first_name: (str)
         last_name: (str)
         email: (str)
         password: (str)
         phone: (str)
     Description:
         update user info view
     """
     user = get_jwt_user(request)
     data = request.data
     req_inf = RequestInfo()
     try:
         if user is not None:
             user_cls = Client.objects.get(user=user)
             if 'username' in data:
                 if self.validate_data(data.get('username'), user.username):
                     user.username = data.get('username')
             if 'email' in data:
                 if self.validate_data(data.get('email'), user_cls.user.email):
                     user.email = data.get('email')
             if 'password' in data:
                 user.set_password(data.get('password'))
             if 'phone' in data:
                 user_cls.phone = data.get('phone')
             if 'first_name' in data:
                 user.first_name = data.get('first_name')
             if 'last_name' in data:
                 user.last_name = data.get('last_name')
             user.save()
             user_cls.save()
             data_err = {
                 'status': status.HTTP_200_OK,
                 'token': generate_jwt(user, request),
                 'detail': 'user updated'
             }
             return req_inf.return_status(data_err)
         else:
             return req_inf.status_401('token invalido')
     except ObjectDoesNotExist as e:
         return req_inf.status_404(e.args[0])
     except Exception as e:
         return req_inf.status_400(e.args[0])
Exemple #7
0
 def put(self, request, pk=None):
     """FolderClientAPIView put
     Description:
         update client information
     """
     req_inf = RequestInfo()
     folder_client = self.get_object(pk)
     if isinstance(folder_client, FolderClient):
         serializer = FolderSerializer(folder_client, data=request.data)
         if serializer.is_valid():
             serializer.save()
             log = Log.objects.create(
                 action=Log.NOTIFICATION_TYPE.get_value('update_folder'),
                 user=request.user,
                 description='Modificacion de folder {} - {}'.format(
                     serializer.instance.id, serializer.instance.name))
             log.save()
             return req_inf.status_200()
         return req_inf.status_400(serializer.errors)
     else:
         return req_inf.status_404(folder_client)
Exemple #8
0
 def post(self, request):
     """User API POST
     Args:
         username: (str)
         first_name: (str)
         last_name: (str)
         email: (str)
         password: (str)
     Description:
         create user view
     """
     data = request.data
     username = data.get('username')
     first_name = data.get('first_name', None)
     last_name = data.get('last_name', None)
     email = data.get('email')
     password = data.get('password')
     req_inf = RequestInfo()
     user = None
     try:
         user = User.objects.get(email=email)
     except ObjectDoesNotExist as e:
         pass
     if user is not None:
         return req_inf.status_400('email already exists')
     try:
         user_cls = Client.create(
             username,
             first_name,
             last_name,
             email,
             None,
             password
         )
         user_cls.save()
         return req_inf.status_200()
     except ObjectDoesNotExist as e:
         return req_inf.status_404(e.args[0])
     except Exception as e:
         return req_inf.status_400(e.args[0])
Exemple #9
0
 def delete(self, request):
     """Address API PATCH
     Args:
         address_id: (int)
     Description:
         delete directions
     """
     user = get_jwt_user(request)
     data = request.data
     req_inf = RequestInfo()
     try:
         if user is not None:
             client = Client.objects.get(user=user)
             address = Address.objects.get(id=data.get('address_id'))
             address.delete()
             return req_inf.status_200('address deleted')
         else:
             return req_inf.status_401('token invalido')
     except ObjectDoesNotExist as e:
         return req_inf.status_404(e.args[0])
     except Exception as e:
         return req_inf.status_400(e.args[0])
Exemple #10
0
 def post(self, request):
     """Address API GET
     Args:
         country: (str)
         region: (str)
         town: (str)
         neighborhood: (str)
         zip_code: (str)
         street: (str)
         street_number: (str)
         suite_number: (str)
     Description:
         create directions
     """
     user = get_jwt_user(request)
     data = request.data
     req_inf = RequestInfo()
     try:
         if user is not None:
             client = Client.objects.get(user=user)
             address = Address.create(
                 data.get('country'),
                 data.get('region'),
                 data.get('town'),
                 data.get('neighborhood'),
                 data.get('zip_code'),
                 data.get('street'),
                 data.get('street_number'),
                 data.get('suite_number')
             )
             client.addresses.add(address)
             client.save()
             return req_inf.status_200('address created')
         else:
             return req_inf.status_401('token invalido')
     except ObjectDoesNotExist as e:
         return req_inf.status_404(e.args[0])
     except Exception as e:
         return req_inf.status_400(e.args[0])