You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

from minibase.app import db
from sqlalchemy import case
class table_printable:
def __init__(self, table, link_for_item, item_to_be_linked):
self.titles = table.__table__.columns.keys()
self.lines = table.query.all()
self.link_for_item = link_for_item
self.item_to_be_linked = item_to_be_linked
self.paginate = 0
# https://www.youtube.com/watch?v=PSWf2TjTGNY&list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH&index=9
class table_printable_paginate:
def __init__(self, table, current_page, per_page, link_for_item, item_to_be_linked):
self.titles = table.__table__.columns.keys()
self.lines = table.query.paginate(page=current_page, per_page=per_page)
self.link_for_item = link_for_item
self.item_to_be_linked = item_to_be_linked
self.paginate = 1
def queryNameWithDefaultId(table,defId):
choices = table.query.order_by(case((table.id == defId, 0),else_=1),table.name.asc())
return choices
def queryItemWithId(table,defId):
choices = table.query.order_by(case((table.id == defId, 0),else_=1),table.name.asc())
return choices
def dbAdd(dbClass):
db.session.add(dbClass)
def dbCommit():
db.session.commit()
def dbAddAndCommit(dbClass):
db.session.add(dbClass)
db.session.commit()