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

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

Issue 29329851: Issue 3216 - Prevent StopIteration exception (Closed)
Patch Set: Created Nov. 9, 2015, 9:16 a.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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 group["variant"] = i + 1 52 group["variant"] = i + 1
53 break 53 break
54 return groups 54 return groups
55 55
56 def _get_active_variant(notifications, groups): 56 def _get_active_variant(notifications, groups):
57 for group in groups: 57 for group in groups:
58 group_id = group["id"] 58 group_id = group["id"]
59 variant = group["variant"] 59 variant = group["variant"]
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), None)
63 if not notification:
64 continue
63 notification = copy.deepcopy(notification) 65 notification = copy.deepcopy(notification)
64 notification.update(notification["variants"][variant - 1]) 66 notification.update(notification["variants"][variant - 1])
65 for key_to_remove in ("sample", "variants"): 67 for key_to_remove in ("sample", "variants"):
66 notification.pop(key_to_remove, None) 68 notification.pop(key_to_remove, None)
67 return notification 69 return notification
68 70
69 def _can_be_shown(notification): 71 def _can_be_shown(notification):
70 return notification.get("title", None) and notification.get("message", None) 72 return notification.get("title", None) and notification.get("message", None)
71 73
72 def _generate_version(groups): 74 def _generate_version(groups):
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 if not groups: 108 if not groups:
107 groups = _assign_groups(notifications) 109 groups = _assign_groups(notifications)
108 response = _create_response(notifications, groups) 110 response = _create_response(notifications, groups)
109 response_headers = [("Content-Type", "application/json; charset=utf-8"), 111 response_headers = [("Content-Type", "application/json; charset=utf-8"),
110 ("ABP-Notification-Version", response["version"])] 112 ("ABP-Notification-Version", response["version"])]
111 response_body = json.dumps(response, ensure_ascii=False, indent=2, 113 response_body = json.dumps(response, ensure_ascii=False, indent=2,
112 separators=(",", ": "), 114 separators=(",", ": "),
113 sort_keys=True).encode("utf-8") 115 sort_keys=True).encode("utf-8")
114 start_response("200 OK", response_headers) 116 start_response("200 OK", response_headers)
115 return response_body 117 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