mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-05 06:00:53 -04:00
Change sort order for templates from name to date using full timestamp
so that it would be most recently used at top.
This commit is contained in:
@@ -67,11 +67,9 @@ def dao_get_template_statistics_for_service(service_id, limit_days=None):
|
||||
desc(TemplateStatistics.day)).limit(1).first()
|
||||
if latest_stat:
|
||||
last_date_to_fetch = latest_stat.day - timedelta(days=limit_days)
|
||||
else:
|
||||
last_date_to_fetch = date.today() - timedelta(days=limit_days)
|
||||
filter.append(TemplateStatistics.day > last_date_to_fetch)
|
||||
filter.append(TemplateStatistics.day > last_date_to_fetch)
|
||||
return TemplateStatistics.query.filter(*filter).order_by(
|
||||
desc(TemplateStatistics.day)).join(Template).order_by(func.lower(Template.name)).all()
|
||||
desc(TemplateStatistics.updated_at)).all()
|
||||
|
||||
|
||||
@transactional
|
||||
@@ -102,7 +100,7 @@ def dao_create_notification(notification, notification_type):
|
||||
day=date.today(),
|
||||
service_id=notification.service_id,
|
||||
template_id=notification.template_id
|
||||
).update({'usage_count': TemplateStatistics.usage_count + 1})
|
||||
).update({'usage_count': TemplateStatistics.usage_count + 1, 'updated_at': datetime.utcnow()})
|
||||
|
||||
if update_count == 0:
|
||||
template_stats = TemplateStatistics(template_id=notification.template_id,
|
||||
|
||||
@@ -362,3 +362,9 @@ class TemplateStatistics(db.Model):
|
||||
template = db.relationship('Template')
|
||||
usage_count = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=1)
|
||||
day = db.Column(db.Date, index=True, nullable=False, unique=False, default=datetime.date.today)
|
||||
updated_at = db.Column(
|
||||
db.DateTime,
|
||||
index=False,
|
||||
unique=False,
|
||||
nullable=False,
|
||||
default=datetime.datetime.utcnow)
|
||||
|
||||
Reference in New Issue
Block a user