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

Unified Diff: filters/subscription_sort.py

Issue 6265373108207616: Issue #1170 adblockplus.org migration from Anwiki to our CMS. (Closed)
Patch Set: Created Sept. 17, 2014, 8:22 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 | « filters/parse_interface.py ('k') | filters/unescape.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filters/subscription_sort.py
diff --git a/filters/subscription_sort.py b/filters/subscription_sort.py
new file mode 100644
index 0000000000000000000000000000000000000000..62084603ceb928db2f4317a7abbba01992939a10
--- /dev/null
+++ b/filters/subscription_sort.py
@@ -0,0 +1,17 @@
+def subscription_sort(value, prioritizeRecommended=True):
+ value = value[:] # create a copy of the list
+ if prioritizeRecommended:
+ value.sort(lambda a, b: (
+ cmp(a.get("type"), b.get("type")) or
+ cmp(a.get("deprecated"), b.get("deprecated")) or
+ cmp(b.get("catchall"), a.get("catchall")) or
+ cmp(b.get("recommendation") != None, a.get("recommendation") != None) or
+ cmp(a.get("name").lower(), b.get("name").lower())
+ ))
+ else:
+ value.sort(lambda a, b: (
+ cmp(a.get("type"), b.get("type")) or
+ cmp(a.get("deprecated"), b.get("deprecated")) or
+ cmp(a.get("name").lower(), b.get("name").lower())
+ ))
+ return value
« no previous file with comments | « filters/parse_interface.py ('k') | filters/unescape.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld