mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 06:22:24 +01:00
Fix crash on user stats page with no packages
This commit is contained in:
parent
c9b5e3374c
commit
9f375c6235
@ -14,9 +14,6 @@ keys = ["platform_minetest", "platform_other", "reason_new",
|
|||||||
|
|
||||||
|
|
||||||
def _flatten_data(stats):
|
def _flatten_data(stats):
|
||||||
if len(stats) == 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
start_date = stats[0].date
|
start_date = stats[0].date
|
||||||
end_date = stats[-1].date
|
end_date = stats[-1].date
|
||||||
result = {
|
result = {
|
||||||
@ -44,6 +41,9 @@ def _flatten_data(stats):
|
|||||||
|
|
||||||
def get_package_stats(package: Package):
|
def get_package_stats(package: Package):
|
||||||
stats = package.daily_stats.order_by(db.asc(PackageDailyStats.date)).all()
|
stats = package.daily_stats.order_by(db.asc(PackageDailyStats.date)).all()
|
||||||
|
if len(stats) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
return _flatten_data(stats)
|
return _flatten_data(stats)
|
||||||
|
|
||||||
|
|
||||||
@ -59,6 +59,8 @@ def get_package_stats_for_user(user: User):
|
|||||||
.order_by(db.asc(PackageDailyStats.date)) \
|
.order_by(db.asc(PackageDailyStats.date)) \
|
||||||
.group_by(PackageDailyStats.date) \
|
.group_by(PackageDailyStats.date) \
|
||||||
.all()
|
.all()
|
||||||
|
if len(stats) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
results = _flatten_data(stats)
|
results = _flatten_data(stats)
|
||||||
results["package_downloads"] = get_package_overview_for_user(user, stats[0].date, stats[-1].date)
|
results["package_downloads"] = get_package_overview_for_user(user, stats[0].date, stats[-1].date)
|
||||||
|
Loading…
Reference in New Issue
Block a user