add raw query
This commit is contained in:
parent
1efc650bea
commit
ade9fbd018
|
@ -118,19 +118,33 @@ class ErasureListView(DeviceListMixin):
|
||||||
def dispatch_request(self, orphans=0):
|
def dispatch_request(self, orphans=0):
|
||||||
self.get_context()
|
self.get_context()
|
||||||
self.get_devices(orphans)
|
self.get_devices(orphans)
|
||||||
if orphans:
|
|
||||||
self.context['orphans'] = True
|
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
def get_devices(self, orphans):
|
def get_devices(self, orphans):
|
||||||
|
page = int(request.args.get('page', 1))
|
||||||
|
per_page = int(request.args.get('per_page', 5))
|
||||||
|
|
||||||
erasure = EraseBasic.query.filter_by(author=g.user).order_by(
|
erasure = EraseBasic.query.filter_by(author=g.user).order_by(
|
||||||
EraseBasic.created.desc()
|
EraseBasic.created.desc()
|
||||||
)
|
)
|
||||||
if orphans:
|
if orphans:
|
||||||
erasure = [e for e in erasure if e.device.orphan]
|
schema = app.config.get('SCHEMA')
|
||||||
|
sql = f"""
|
||||||
page = int(request.args.get('page', 1))
|
select action.id from {schema}.action as action
|
||||||
per_page = int(request.args.get('per_page', 5))
|
inner join {schema}.erase_basic as erase
|
||||||
|
on action.id=erase.id
|
||||||
|
inner join {schema}.device as device
|
||||||
|
on device.id=action.parent_id
|
||||||
|
inner join {schema}.placeholder as placeholder
|
||||||
|
on placeholder.binding_id=device.id
|
||||||
|
where action.parent_id is null or placeholder.kangaroo=true
|
||||||
|
"""
|
||||||
|
ids = (e[0] for e in db.session.execute(sql))
|
||||||
|
erasure = EraseBasic.query.filter(EraseBasic.id.in_(ids)).order_by(
|
||||||
|
EraseBasic.created.desc()
|
||||||
|
)
|
||||||
|
self.context['orphans'] = True
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
|
||||||
erasure = erasure.paginate(page=page, per_page=per_page)
|
erasure = erasure.paginate(page=page, per_page=per_page)
|
||||||
erasure.first = per_page * erasure.page - per_page + 1
|
erasure.first = per_page * erasure.page - per_page + 1
|
||||||
|
|
Reference in New Issue