Example #1
0
    def find(self, args: dict):
        """
        Gets lots.

        By passing the value `UiTree` in the parameter `format`
        of the query you get a recursive nested suited for ui-tree::

             [
                {title: 'lot1',
                nodes: [{title: 'child1', nodes:[]}]
            ]

        Note that in this format filters are ignored.

        Otherwise it just returns the standard flat view of lots that
        you can filter.
        """
        if args['format'] == LotFormat.UiTree:
            lots = self.schema.dump(Lot.query, many=True, nested=1)
            ret = {
                'items': {l['id']: l for l in lots},
                'tree': self.ui_tree(),
                'url': request.path
            }
        else:
            query = Lot.query
            if args['search']:
                query = query.filter(Lot.name.ilike(args['search'] + '%'))
            lots = query.paginate(per_page=6 if args['search'] else 30)
            return things_response(
                self.schema.dump(lots.items, many=True, nested=0),
                lots.page, lots.per_page, lots.total, lots.prev_num, lots.next_num
            )
        return jsonify(ret)
Example #2
0
 def find(self, args: dict):
     tags = Tag.query.filter(Tag.is_printable_q()) \
         .order_by(Tag.created.desc()) \
         .paginate(per_page=200)  # type: Pagination
     return things_response(
         self.schema.dump(tags.items, many=True, nested=0), tags.page,
         tags.per_page, tags.total, tags.prev_num, tags.next_num)
Example #3
0
 def find(self, args: dict):
     res_objs = self.model.query.filter_by(author=g.user) \
         .order_by(self.model.created.desc()) \
         .paginate(per_page=200)
     return things_response(
         self.schema.dump(res_objs.items, many=True,
                          nested=0), res_objs.page, res_objs.per_page,
         res_objs.total, res_objs.prev_num, res_objs.next_num)
Example #4
0
 def find(self, args: dict):
     """Gets many devices."""
     # Compute query
     query = self.query(args)
     devices = query.paginate(page=args['page'], per_page=30)  # type: Pagination
     return things_response(
         self.schema.dump(devices.items, many=True, nested=1),
         devices.page, devices.per_page, devices.total, devices.prev_num, devices.next_num
     )
Example #5
0
 def _create_many_regular_tags(self, num: int):
     tags_id, _ = g.tag_provider.post('/', {}, query=[('num', num)])
     tags = [
         Tag(id=tag_id, provider=g.inventory.tag_provider)
         for tag_id in tags_id
     ]
     db.session.add_all(tags)
     db.session().final_flush()
     response = things_response(self.schema.dump(tags, many=True, nested=1),
                                code=201)
     db.session.commit()
     return response