Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/notifications/web/notification.py

Issue 29325919: Issue 2982 - Return all notifications that have title and message (Closed)
Patch Set: Address comments Created Sept. 7, 2015, 7:51 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sitescripts/notifications/test/notification.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/notifications/web/notification.py
===================================================================
--- a/sitescripts/notifications/web/notification.py
+++ b/sitescripts/notifications/web/notification.py
@@ -68,23 +68,35 @@
notification.pop(key_to_remove, None)
return notification
+def _can_be_shown(notification):
+ return "title" in notification and "message" in notification
+
def _generate_version(groups):
version = time.strftime("%Y%m%d%H%M", time.gmtime())
for group in groups:
version += "-%s/%s" % (group["id"], group["variant"])
return version
-def _create_response(notifications, groups):
+def _get_notifications_to_send(notifications, groups):
active_variant = _get_active_variant(notifications, groups)
if active_variant:
- notifications = [active_variant]
- else:
- notifications = [x for x in notifications if "variants" not in x]
- response = {
+ return [active_variant] if _can_be_shown(active_variant) else []
+
+ notifications_to_send = []
+ for notification in notifications:
+ if not _can_be_shown(notification):
+ continue
+ if "variants" in notification:
+ notification = copy.deepcopy(notification)
+ del notification["variants"]
+ notifications_to_send.append(notification)
+ return notifications_to_send
+
+def _create_response(notifications, groups):
+ return {
"version": _generate_version(groups),
- "notifications": notifications
+ "notifications": _get_notifications_to_send(notifications, groups)
}
- return response
@url_handler("/notification.json")
def notification(environ, start_response):
« no previous file with comments | « sitescripts/notifications/test/notification.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld