Exemplo n.º 1
0
    def patch(self, id):
        parser = reqparse.RequestParser()
        parser.add_argument('direction',
                            required=True,
                            help="No mandastes la dirección")
        parser.add_argument('country',
                            required=True,
                            help="No mandastes el país")

        args = parser.parse_args()

        book = Book.objects.get(_id=id)

        address = Address(country=args['country'], direction=args['direction'])
        book.addresses.append(address)

        book.save()

        books = Book.objects(_id=id).aggregate(pipes)
        try:
            book = list(books)[0]
        except IndexError:
            return

        return book
Exemplo n.º 2
0
    def delete(self, id):
        parser = reqparse.RequestParser()
        parser.add_argument('index',
                            required=True,
                            type=int,
                            help="No mandastes el indice o no es entero")

        args = parser.parse_args()

        book = Book.objects.get(_id=id)

        try:
            book.addresses.pop(args['index'])
            book.save()
        except IndexError:
            pass

        books = Book.objects(_id=book._id).aggregate(pipes)

        try:
            book = list(books)[0]
        except IndexError:
            return

        return book
Exemplo n.º 3
0
    def delete(self, id):
        parser = reqparse.RequestParser()
        parser.add_argument('tag_id',
                            required=True,
                            help="No mandastes el tag")

        args = parser.parse_args()

        book = Book.objects.get(_id=id)

        tag = Tag.objects.get(pk=args['tag_id'])

        try:
            book.tags.remove(tag)
            book.save()
        except ValueError:
            pass

        books = Book.objects(_id=book._id).aggregate(pipes)

        try:
            book = list(books)[0]
        except IndexError:
            return

        return book
Exemplo n.º 4
0
    def get(self, id):
        books = Book.objects(_id=id).aggregate(pipes)

        try:
            book = list(books)[0]
        except IndexError:
            return

        return book
Exemplo n.º 5
0
    def patch(self, id):
        parser = reqparse.RequestParser()
        parser.add_argument('name',
                            required=True,
                            help="No mandastes el nombre")
        parser.add_argument('content',
                            required=True,
                            help="No mandastes el contenido")
        parser.add_argument('category_id',
                            required=True,
                            help="No mandastes la categoría")
        parser.add_argument('dimention-x',
                            required=True,
                            help="No mandastes la dimención x")
        parser.add_argument('dimention-y',
                            required=True,
                            help="No mandastes la dimención y")
        parser.add_argument('dimention-z',
                            required=True,
                            help="No mandastes la dimención z")

        args = parser.parse_args()

        book = Book.objects.get(_id=id)
        book.name = args['name']
        book.content = args['content']

        try:
            category = Category.objects.get(pk=args['category_id'])
        except Category.DoesNotExist:
            raise BadRequest('Categoria no existe')

        book.category = category

        dimention = Dimention(x=args['dimention-x'],
                              y=args['dimention-y'],
                              z=args['dimention-z'])
        book.dimention = dimention

        book.save()

        #print(book._id)
        #print(book.pk)

        #book = Book.objects.get(_id=book.pk)
        books = Book.objects(_id=id).aggregate(pipes)
        try:
            book = list(books)[0]
        except IndexError:
            return

        return book
Exemplo n.º 6
0
    def patch(self, id):
        parser = reqparse.RequestParser()
        parser.add_argument('category_id',
                            required=True,
                            help="No mandastes la categoría")

        args = parser.parse_args()

        book = Book.objects.get(_id=id)

        category = Category.objects.get(pk=args['category_id'])
        book.category = category

        book.save()

        books = Book.objects(_id=book._id).aggregate(pipes)

        try:
            book = list(books)[0]
        except IndexError:
            return

        return book
Exemplo n.º 7
0
 def delete(self, id):
     Book.objects(_id=id).delete()
     return {'msj': 'ok'}