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

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

Issue 29327106: Issue 3048 - Mark inactive notifications instead of removing them (Closed)
Patch Set: Created Sept. 10, 2015, 11:25 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
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 11 matching lines...) Expand all
22 import urlparse 22 import urlparse
23 23
24 from sitescripts.notifications.parser import load_notifications 24 from sitescripts.notifications.parser import load_notifications
25 from sitescripts.web import url_handler 25 from sitescripts.web import url_handler
26 26
27 def _determine_groups(version, notifications): 27 def _determine_groups(version, notifications):
28 version_groups = dict(x.split("/") for x in version.split("-")[1:] 28 version_groups = dict(x.split("/") for x in version.split("-")[1:]
29 if x.count("/") == 1) 29 if x.count("/") == 1)
30 groups = [] 30 groups = []
31 for notification in notifications: 31 for notification in notifications:
32 if "variants" not in notification:
33 continue
34 group_id = notification["id"] 32 group_id = notification["id"]
35 if group_id in version_groups: 33 if group_id in version_groups:
36 groups.append({"id": group_id, "variant": int(version_groups[group_id])}) 34 groups.append({"id": group_id, "variant": int(version_groups[group_id])})
37 return groups 35 return groups
38 36
39 def _assign_groups(notifications): 37 def _assign_groups(notifications):
40 groups = [] 38 groups = []
41 selection = random.random() 39 selection = random.random()
42 start = 0 40 start = 0
43 for notification in notifications: 41 for notification in notifications:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 "version": _generate_version(groups), 95 "version": _generate_version(groups),
98 "notifications": _get_notifications_to_send(notifications, groups) 96 "notifications": _get_notifications_to_send(notifications, groups)
99 } 97 }
100 98
101 @url_handler("/notification.json") 99 @url_handler("/notification.json")
102 def notification(environ, start_response): 100 def notification(environ, start_response):
103 params = urlparse.parse_qs(environ.get("QUERY_STRING", "")) 101 params = urlparse.parse_qs(environ.get("QUERY_STRING", ""))
104 version = params.get("lastVersion", [""])[0] 102 version = params.get("lastVersion", [""])[0]
105 notifications = load_notifications() 103 notifications = load_notifications()
106 groups = _determine_groups(version, notifications) 104 groups = _determine_groups(version, notifications)
105 notifications = [x for x in notifications
106 if not ("inactive" in x and x["inactive"])]
Sebastian Noack 2015/09/10 13:29:20 How about |not x.get("inactive", False)| ?
Felix Dahlke 2015/09/11 07:04:43 Done.
107 if not groups: 107 if not groups:
108 groups = _assign_groups(notifications) 108 groups = _assign_groups(notifications)
109 response = _create_response(notifications, groups) 109 response = _create_response(notifications, groups)
110 response_headers = [("Content-Type", "application/json; charset=utf-8"), 110 response_headers = [("Content-Type", "application/json; charset=utf-8"),
111 ("ABP-Notification-Version", response["version"])] 111 ("ABP-Notification-Version", response["version"])]
112 response_body = json.dumps(response, ensure_ascii=False, indent=2, 112 response_body = json.dumps(response, ensure_ascii=False, indent=2,
113 separators=(",", ": "), 113 separators=(",", ": "),
114 sort_keys=True).encode("utf-8") 114 sort_keys=True).encode("utf-8")
115 start_response("200 OK", response_headers) 115 start_response("200 OK", response_headers)
116 return response_body 116 return response_body
OLDNEW
« sitescripts/notifications/parser.py ('K') | « sitescripts/notifications/test/parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld