本文整理汇总了Python中autonomie_base.models.base.DBSESSION.order_by方法的典型用法代码示例。如果您正苦于以下问题:Python DBSESSION.order_by方法的具体用法?Python DBSESSION.order_by怎么用?Python DBSESSION.order_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autonomie_base.models.base.DBSESSION
的用法示例。
在下文中一共展示了DBSESSION.order_by方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: taskyears
# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import order_by [as 别名]
def taskyears():
"""
return the distinct financial years available in the database
"""
query = DBSESSION().query(distinct(Invoice.financial_year))
query = query.order_by(Invoice.financial_year)
years = [year[0] for year in query]
current = datetime.date.today().year
if current not in years:
years.append(current)
return years
示例2: expenseyears
# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import order_by [as 别名]
def expenseyears():
"""
return distinct expense years available in the database
"""
query = DBSESSION().query(distinct(ExpenseSheet.year))
query = query.order_by(ExpenseSheet.year)
years = [year[0] for year in query]
current = datetime.date.today().year
if current not in years:
years.append(current)
return years
示例3: query
# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import order_by [as 别名]
def query(cls, keys=None, active=True):
"""
Return a query
"""
if keys:
query = DBSESSION().query(*keys)
else:
query = super(Company, cls).query()
if active:
query = query.filter(cls.active == True)
return query.order_by(cls.name)
示例4: get_expensesheet_years
# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import order_by [as 别名]
def get_expensesheet_years(company):
"""
List of years an expensesheet has been retrieved for
"""
query = DBSESSION().query(distinct(ExpenseSheet.year)).filter_by(
company_id=company.id
)
years = [data[0] for data in query.order_by(desc(ExpenseSheet.year))]
today = datetime.date.today()
if today.year not in years:
years.insert(0, today.year)
return years
示例5: get_tasks
# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import order_by [as 别名]
def get_tasks(cls, instance, offset=None, limit=None):
from autonomie.models.task import Task
query = DBSESSION().query(Task)
query = query.filter(Task.company_id == instance.id)
query = query.filter(
Task.type_.in_(('invoice', 'estimation', 'cancelinvoice'))
)
query = query.order_by(desc(Task.status_date))
if offset is not None:
query = query.offset(offset)
if limit is not None:
query = query.limit(limit)
return query
示例6: get_customer_codes_and_names
# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import order_by [as 别名]
def get_customer_codes_and_names(cls, company):
"""
Return a query for code and names of customers related to company
:param company: the company we're working on
:returns: an orm query loading Customer instances with only the columns
we want
:rtype: A Sqlalchemy query object
"""
from autonomie.models.customer import Customer
query = DBSESSION().query(Customer)
query = query.options(load_only('code', 'name'))
query = query.filter(Customer.code != None)
query = query.filter(Customer.company_id == company.id)
return query.order_by(Customer.code)
示例7: get_users_options
# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import order_by [as 别名]
def get_users_options(roles=None):
"""
Return the list of active users from the database formatted as choices:
[(user_id, user_label)...]
:param role: roles of the users we want
default: all
values : ('contractor', 'manager', 'admin'))
"""
query = DBSESSION().query(User).options(
load_only('id', 'firstname', 'lastname')
)
# Only User accounts with logins
query = query.join(Login).filter(Login.active == True)
query = query.order_by(User.lastname)
if roles and not hasattr(roles, "__iter__"):
roles = [roles]
query = _filter_by_group(query, roles)
return [(unicode(u.id), format_account(u)) for u in query]
示例8: last
# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import order_by [as 别名]
def last(cls, grid_class, company_id):
query = DBSESSION().query(grid_class).filter_by(company_id=company_id)
query = query.order_by(desc(grid_class.date))
return query.first()