Profile sorting

This commit is contained in:
Ruud committed 2011-09-07 17:21:49 +02:00
1 parent 85c3b16e69
commit 6940477e48
5 files changed
+162 -15

No files matched your search

+2 -2
View File
@@ -1,3 +1,4 @@
from couchpotato.core.helpers.variable import natcmp
from flask.globals import current_app
from flask.helpers import json
from libs.werkzeug.urls import url_decode
@@ -42,7 +43,7 @@ def dictToList(params):
new = {}
for x, value in params.iteritems():
try:
new_value = [dictToList(value[k]) for k in sorted(value.iterkeys())]
new_value = [dictToList(value[k]) for k in sorted(value.iterkeys(), cmp = natcmp)]
except:
new_value = value
@@ -70,4 +71,3 @@ def jsonified(*args, **kwargs):
return padded_jsonify(callback, *args, **kwargs)
else:
return jsonify('text/javascript' if Env.doDebug() else 'application/json', *args, **kwargs)
+11
View File
@@ -1,5 +1,6 @@
import hashlib
import os.path
import re
def isDict(object):
return isinstance(object, dict)
@@ -41,3 +42,13 @@ def cleanHost(host):
host += '/'
return host
def tryInt(s):
try: return int(s)
except: return s
def natsortKey(s):
return map(tryInt, re.findall(r'(\d+|\D+)', s))
def natcmp(a, b):
return cmp(natsortKey(a), natsortKey(b))