mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
- Modified the services_dao to return an int instead of a datetime to make usage easier and removed the BST function on year as it is not relevant for year - Improved tests do there is less logic by ordering the result so there is less reliance on the template id - Renamed variable in stats_template_usage_by_month_dao.py to make it consistent with the method
25 lines
677 B
Python
25 lines
677 B
Python
from app import db
|
|
from app.models import StatsTemplateUsageByMonth
|
|
|
|
|
|
def insert_or_update_stats_for_template(template_id, month, year, count):
|
|
result = db.session.query(
|
|
StatsTemplateUsageByMonth
|
|
).filter(
|
|
StatsTemplateUsageByMonth.template_id == template_id,
|
|
StatsTemplateUsageByMonth.month == month,
|
|
StatsTemplateUsageByMonth.year == year
|
|
).update(
|
|
{
|
|
'count': count
|
|
}
|
|
)
|
|
if result == 0:
|
|
monthly_stats = StatsTemplateUsageByMonth(
|
|
template_id=template_id,
|
|
month=month,
|
|
year=year,
|
|
count=count
|
|
)
|
|
db.session.add(monthly_stats)
|