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

Side by Side Diff: sitescripts/notifications/web/notification.py

Issue 29328658: Issue 2982 - Only return notifications that have at least one entry for title and message (Closed)
Patch Set: Created Sept. 25, 2015, 12:24 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/notifications/test/notification.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 if variant == 0: 60 if variant == 0:
61 continue 61 continue
62 notification = next(x for x in notifications if x["id"] == group_id) 62 notification = next(x for x in notifications if x["id"] == group_id)
63 notification = copy.deepcopy(notification) 63 notification = copy.deepcopy(notification)
64 notification.update(notification["variants"][variant - 1]) 64 notification.update(notification["variants"][variant - 1])
65 for key_to_remove in ("sample", "variants"): 65 for key_to_remove in ("sample", "variants"):
66 notification.pop(key_to_remove, None) 66 notification.pop(key_to_remove, None)
67 return notification 67 return notification
68 68
69 def _can_be_shown(notification): 69 def _can_be_shown(notification):
70 return "title" in notification and "message" in notification 70 return notification.get("title", None) and notification.get("message", None)
71 71
72 def _generate_version(groups): 72 def _generate_version(groups):
73 version = time.strftime("%Y%m%d%H%M", time.gmtime()) 73 version = time.strftime("%Y%m%d%H%M", time.gmtime())
74 for group in groups: 74 for group in groups:
75 version += "-%s/%s" % (group["id"], group["variant"]) 75 version += "-%s/%s" % (group["id"], group["variant"])
76 return version 76 return version
77 77
78 def _get_notifications_to_send(notifications, groups): 78 def _get_notifications_to_send(notifications, groups):
79 active_variant = _get_active_variant(notifications, groups) 79 active_variant = _get_active_variant(notifications, groups)
80 if active_variant: 80 if active_variant:
(...skipping 25 matching lines...) Expand all
106 if not groups: 106 if not groups:
107 groups = _assign_groups(notifications) 107 groups = _assign_groups(notifications)
108 response = _create_response(notifications, groups) 108 response = _create_response(notifications, groups)
109 response_headers = [("Content-Type", "application/json; charset=utf-8"), 109 response_headers = [("Content-Type", "application/json; charset=utf-8"),
110 ("ABP-Notification-Version", response["version"])] 110 ("ABP-Notification-Version", response["version"])]
111 response_body = json.dumps(response, ensure_ascii=False, indent=2, 111 response_body = json.dumps(response, ensure_ascii=False, indent=2,
112 separators=(",", ": "), 112 separators=(",", ": "),
113 sort_keys=True).encode("utf-8") 113 sort_keys=True).encode("utf-8")
114 start_response("200 OK", response_headers) 114 start_response("200 OK", response_headers)
115 return response_body 115 return response_body
OLDNEW
« 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