mirror of
https://github.com/TrentSPalmer/hugo_themes_report.git
synced 2024-12-04 16:41:31 -08:00
extend get_themes_orderedby_cname() in test/database.py
This commit is contained in:
parent
2b74eacd3b
commit
ca15a18c53
@ -2,7 +2,8 @@ from rank_hugo_themes import (
|
||||
engine, Hugothemes,
|
||||
Hugothemes_from_gitlab, sessionmaker
|
||||
)
|
||||
from sqlalchemy import asc, func
|
||||
from test.theme_compare import cname_compare
|
||||
from functools import cmp_to_key
|
||||
|
||||
|
||||
def get_theme_count():
|
||||
@ -36,8 +37,9 @@ def get_newest_update_time_from_gitlab():
|
||||
|
||||
def get_themes_orderedby_cname():
|
||||
session = sessionmaker(bind=engine)()
|
||||
return session.query(
|
||||
Hugothemes).order_by(asc(func.lower(Hugothemes.cname))).all()
|
||||
result = session.query(Hugothemes).all()
|
||||
result.sort(key=cmp_to_key(lambda a, b: cname_compare(a, b)))
|
||||
return result
|
||||
|
||||
|
||||
def get_themes_as_dicts_of_sortable_columns():
|
||||
|
@ -17,6 +17,9 @@ def semver_split(item):
|
||||
|
||||
def compare_theme(x, y, sort_key):
|
||||
if sort_key == 'sortByName':
|
||||
if y['name'].lower() == x['name'].lower():
|
||||
return compare_jk(x['name'], y['name'])
|
||||
else:
|
||||
return compare_jk(y['name'].lower(), x['name'].lower())
|
||||
|
||||
elif sort_key == 'sortByStars':
|
||||
@ -41,3 +44,10 @@ def theme_compare(a, b, y):
|
||||
if len(y) == 0: return -1
|
||||
rslt = compare_theme(a, b, y[0])
|
||||
return theme_compare(a, b, y[1:]) if rslt == 0 else rslt
|
||||
|
||||
|
||||
def cname_compare(a, b):
|
||||
if a.cname.lower() == b.cname.lower():
|
||||
return 1 if a.cname < b.cname else -1
|
||||
else:
|
||||
return -1 if a.cname.lower() < b.cname.lower() else 1
|
||||
|
Loading…
Reference in New Issue
Block a user