This repository has been archived by the owner on Sep 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,42 @@ | ||
from onegov.ballot.models import Election, Vote | ||
from onegov.election_day.models import Notification | ||
from onegov.election_day.models import Notification, WebhookNotification | ||
|
||
|
||
class NotificationCollection(object): | ||
|
||
def __init__(self, session): | ||
self.session = session | ||
|
||
def add(self, url, last_change, election_or_vote): | ||
""" Adds a new notification. """ | ||
|
||
notification = Notification() | ||
notification.url = url | ||
notification.last_change = last_change | ||
if isinstance(election_or_vote, Election): | ||
notification.election_id = election_or_vote.id | ||
if isinstance(election_or_vote, Vote): | ||
notification.vote_id = election_or_vote.id | ||
|
||
self.session.add(notification) | ||
self.session.flush() | ||
|
||
return notification | ||
|
||
def query(self): | ||
return self.session.query(Notification) | ||
|
||
def by_election(self, election, url, last_change): | ||
""" Returns the notification specified by given parameters. """ | ||
def by_election(self, election): | ||
""" Returns the notification for the given election and its | ||
modification times. | ||
""" | ||
|
||
return self.query().filter( | ||
Notification.election_id == election.id, | ||
Notification.url == url, | ||
Notification.last_change == last_change | ||
).first() | ||
Notification.last_change == election.last_result_change | ||
).all() | ||
|
||
def by_vote(self, vote): | ||
""" Returns the notification for the given vote and its modification | ||
time. | ||
def by_vote(self, vote, url, last_change): | ||
""" Returns the notification specified by given parameters. """ | ||
""" | ||
|
||
return self.query().filter( | ||
Notification.vote_id == vote.id, | ||
Notification.url == url, | ||
Notification.last_change == last_change | ||
).first() | ||
Notification.last_change == vote.last_result_change | ||
).all() | ||
|
||
def trigger(self, request, model): | ||
""" Triggers and adds all notifications. """ | ||
|
||
if request.app.principal.webhooks: | ||
notification = WebhookNotification() | ||
notification.trigger(request, model) | ||
self.session.add(notification) | ||
|
||
self.session.flush() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
from onegov.election_day.models.archive import Archive | ||
from onegov.election_day.models.principal import Principal | ||
from onegov.election_day.models.notification import Notification | ||
from onegov.election_day.models.notification import WebhookNotification | ||
from onegov.election_day.models.principal import Principal | ||
|
||
|
||
__all__ = ['Archive', 'Principal', 'Notification'] | ||
__all__ = [ | ||
'Archive', | ||
'Notification', | ||
'Principal', | ||
'WebhookNotification' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters