2017-11-09 10:32:39 +00:00
|
|
|
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:
|
2017-11-09 14:13:42 +00:00
|
|
|
monthly_stats = StatsTemplateUsageByMonth(
|
2017-11-09 10:32:39 +00:00
|
|
|
template_id=template_id,
|
|
|
|
|
month=month,
|
|
|
|
|
year=year,
|
|
|
|
|
count=count
|
|
|
|
|
)
|
2017-11-09 14:13:42 +00:00
|
|
|
db.session.add(monthly_stats)
|