2016-03-01 13:30:10 +00:00
|
|
|
from flask import current_app
|
2016-02-09 12:01:17 +00:00
|
|
|
from app import db
|
2016-03-04 14:25:28 +00:00
|
|
|
from app.models import Notification, Job
|
2016-03-01 14:58:27 +00:00
|
|
|
from sqlalchemy import desc
|
2016-02-09 12:01:17 +00:00
|
|
|
|
|
|
|
|
|
2016-02-25 09:59:50 +00:00
|
|
|
def dao_create_notification(notification):
|
2016-03-04 14:25:28 +00:00
|
|
|
if notification.job_id:
|
|
|
|
|
db.session.query(Job).update({Job.notifications_sent: Job.notifications_sent + 1})
|
2016-02-25 09:59:50 +00:00
|
|
|
db.session.add(notification)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dao_update_notification(notification):
|
|
|
|
|
db.session.add(notification)
|
2016-02-09 12:01:17 +00:00
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 11:22:44 +00:00
|
|
|
def get_notification_for_job(service_id, job_id, notification_id):
|
2016-02-09 14:17:42 +00:00
|
|
|
return Notification.query.filter_by(service_id=service_id, job_id=job_id, id=notification_id).one()
|
2016-02-09 12:01:17 +00:00
|
|
|
|
|
|
|
|
|
2016-03-01 13:30:10 +00:00
|
|
|
def get_notifications_for_job(service_id, job_id, page=1):
|
2016-03-04 14:25:28 +00:00
|
|
|
query = Notification.query.filter_by(service_id=service_id, job_id=job_id) \
|
|
|
|
|
.order_by(desc(Notification.created_at)) \
|
2016-03-01 13:30:10 +00:00
|
|
|
.paginate(
|
2016-03-04 14:25:28 +00:00
|
|
|
page=page,
|
|
|
|
|
per_page=current_app.config['PAGE_SIZE']
|
|
|
|
|
)
|
2016-03-01 13:30:10 +00:00
|
|
|
return query
|
2016-02-16 11:22:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_notification(service_id, notification_id):
|
|
|
|
|
return Notification.query.filter_by(service_id=service_id, id=notification_id).one()
|
2016-03-01 13:30:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_notifications_for_service(service_id, page=1):
|
2016-03-01 14:58:27 +00:00
|
|
|
query = Notification.query.filter_by(service_id=service_id).order_by(desc(Notification.created_at)).paginate(
|
2016-03-01 13:30:10 +00:00
|
|
|
page=page,
|
|
|
|
|
per_page=current_app.config['PAGE_SIZE']
|
|
|
|
|
)
|
|
|
|
|
return query
|