Beispiel #1
0
    def post(self, request, *args, **kwargs):
        data = request.data
        try:
            s_id = data['id']
        except KeyError as ex:
            logger.warning(f"'id' not specified | {self.__class__.__name__}",
                           exc_info=True)
            raise NoParameterSpecified('id')
        try:
            amount = float(data['amount'])
        except KeyError as ex:
            logger.warning(
                f"'amount' not specified | {self.__class__.__name__}",
                exc_info=True)
            raise NoParameterSpecified('amount')
        except TypeError as ex:
            logger.warning(f"'amount' wrong type")
            raise NoParameterSpecified('amount')

        from_resources = data.get('from_resources', True)
        try:
            Specifications.build_set(s_id,
                                     amount,
                                     from_resources,
                                     user=request.user)
        except Specifications.CantBuildSet:
            logger.warning(f"Building set error | {self.__class__.__name__}",
                           exc_info=True)
            raise AssembleError()
        return Response(data={'correct': True},
                        status=status.HTTP_202_ACCEPTED)
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        data = request.data

        try:
            ids = data['ids']
        except KeyError as ex:
            logger.warning(f"'ids' not specified | {self.__class__.__name__}",
                           exc_info=True)
            raise NoParameterSpecified('ids')

        if not isinstance(ids, list):
            logger.warning(
                f"'ids' has wrong type. Type: {type(ids)} | {self.__class__.__name__}"
            )
            raise ParameterExceptions(detail="'ids' must be list object.")

        try:
            category = data['category']
        except KeyError as ex:
            logger.warning(
                f"'category' not specified | {self.__class__.__name__}",
                exc_info=True)
            raise NoParameterSpecified('category')

        Specifications.set_category_many(ids, category, request.user)
        return Response(data={'correct': True},
                        status=status.HTTP_202_ACCEPTED)
Beispiel #3
0
 def post(self, request, *args, **kwargs):
     data = request.data
     try:
         s_id = data['id']
     except KeyError as ex:
         logger.warning(f"'id' not specified  | {self.__class__.__name__}",
                        exc_info=True)
         raise NoParameterSpecified('id')
     try:
         value = float(data['price'])
     except KeyError as ex:
         logger.warning(
             f"'price' not specified  | {self.__class__.__name__}",
             exc_info=True)
         raise NoParameterSpecified('price')
     except TypeError as ex:
         logger.warning(f"'price' wrong type")
         raise WrongParameterType('price', 'float')
     if value is not None and s_id is not None:
         try:
             Specifications.set_price(specification=s_id,
                                      price=value,
                                      user=request.user,
                                      send=True)
         except Specifications.EditError:
             logger.warning(f"Set price error | {self.__class__.__name__}",
                            exc_info=True)
         return Response(data={
             'id': s_id,
             'price': value
         },
                         status=status.HTTP_202_ACCEPTED)
     else:
         raise NoParameterSpecified()
Beispiel #4
0
    def post(self, request, *args, **kwargs):
        data = request.data
        try:
            s_id = data['id']
        except KeyError as ex:
            logger.warning(f"'id' not specified | {self.__class__.__name__}",
                           exc_info=True)
            raise NoParameterSpecified('id')
        try:
            amount = float(data['amount'])
        except KeyError as ex:
            logger.warning(
                f"'amount' not specified | {self.__class__.__name__}",
                exc_info=True)
            raise NoParameterSpecified('amount')

        resources = Specifications.manage_build(s_id, amount)

        return Response(data=resources, status=status.HTTP_200_OK)
Beispiel #5
0
    def post(self, request, *args, **kwargs):
        data = request.data

        try:
            order_id = data['id']
        except KeyError as ex:
            logger.warning(f"'id' not specified | {self.__class__.__name__}",
                           exc_info=True)
            raise NoParameterSpecified('id')

        try:
            action = data['action']
        except KeyError as ex:
            logger.warning(
                f"'action' not specified | {self.__class__.__name__}",
                exc_info=True)
            raise NoParameterSpecified('action')

        if order_id is not None and action is not None:
            try:
                if action == 'confirm':
                    order = Orders.get(order_id)
                    Orders.confirm(order, request.user)
                    Orders.notify_new_status(order)
                elif action == 'cancel':
                    order = Orders.get(order_id)
                    Orders.cancel(order, request.user)
                    Orders.notify_new_status(order)
                else:
                    raise WrongParameterValue('action')
            except Orders.ActionError:
                logger.warning(
                    f"Manage action error for order with id: {order_id} | {self.__class__.__name__}"
                )
                raise StatusError()
            return Response(data={'correct': True},
                            status=status.HTTP_202_ACCEPTED)
        else:
            if order_id is None:
                logger.warning(f"id id is None| {self.__class__.__name__}")
            if action is None:
                logger.warning(f"action is none | {self.__class__.__name__}")
            raise NoParameterSpecified()
Beispiel #6
0
 def get_object(self):
     data = self.request.data
     try:
         a_id = data['id']
         return Account.objects.filter(id=a_id)
     except KeyError as ex:
         logger.warning(f"'id' not specified | {self.__class__.__name__}")
         raise NoParameterSpecified('ids')
     except Account.DoesNotExist:
         logger.warning("Update error | ResourceBulkDeleteView")
         raise UpdateError()
Beispiel #7
0
 def post(self, request, *args, **kwargs):
     data = request.data
     try:
         ids = data['ids']
     except KeyError as ex:
         logger.warning(f"'ids' not specified | {self.__class__.__name__}")
         raise NoParameterSpecified('ids')
     if not isinstance(ids, list):
         raise WrongParameterType('ids', 'list')
     Orders.bulk_delete(ids, request.user)
     return Response(data={'correct': True},
                     status=status.HTTP_202_ACCEPTED)
Beispiel #8
0
 def post(self, request, *args, **kwargs):
     data = request.data
     try:
         ids = data['ids']
     except KeyError as ex:
         raise NoParameterSpecified('ids')
     if not isinstance(ids, list):
         raise ParameterExceptions(detail="'ids' must be list object.")
     try:
         Specifications.bulk_delete(ids, request.user)
     except Specifications.QueryError:
         logger.warning(f"Delete error | {self.__class__.__name__}",
                        exc_info=True)
     return Response(data={'correct': True},
                     status=status.HTTP_202_ACCEPTED)
Beispiel #9
0
 def post(self, request, *args, **kwargs):
     data = request.data
     try:
         ids = data['ids']
     except KeyError as ex:
         logger.warning(f"'id' not specified | {self.__class__.__name__}")
         raise NoParameterSpecified('ids')
     if not isinstance(ids, list):
         logger.warning(
             f"'ids' has wrong type. Type: {type(ids)} | {self.__class__.__name__}"
         )
         raise ParameterExceptions(detail="'ids' must be list object.")
     try:
         Resources.bulk_delete(ids, request.user)
     except Resources.UpdateError:
         logger.warning("Update error | {self.__class__.__name__}")
         raise UpdateError()
     return Response(data={'correct': True},
                     status=status.HTTP_202_ACCEPTED)