From fbc56b5be6443bc681ab67283ab7a3e68b3d68c9 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Fri, 27 Nov 2015 10:15:59 +0200 Subject: Cleanup --- servo/lib/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'servo/lib') diff --git a/servo/lib/utils.py b/servo/lib/utils.py index fa7c37c..6644a7e 100644 --- a/servo/lib/utils.py +++ b/servo/lib/utils.py @@ -23,15 +23,18 @@ def paginate(queryset, page, count=10): return results + def text_response(data): - return HttpResponse(data, content_type="text/plain; charset=utf-8") - + return HttpResponse(data, content_type='text/plain; charset=utf-8') + + def csv_response(data): """ Shortcut for sending a CSV response """ return HttpResponse(data, content_type='text/csv') + def send_csv(data, filename): """ Shortcut for sending CSV data as a file @@ -40,12 +43,14 @@ def send_csv(data, filename): response['Content-Disposition'] = 'attachment; filename="%s.txt"' % filename return response + def json_response(data): """ Shortcut for sending a JSON response """ return HttpResponse(json.dumps(data), content_type='application/json') + def strip_keypass(keypass, infile, outfile): """ Strips a passphrase from a private key @@ -53,12 +58,14 @@ def strip_keypass(keypass, infile, outfile): subprocess.call(['openssl', 'rsa', '-passin', 'pass:' + keypass, '-in', infile, '-out', outfile]) + def multiprint(*args): """ Emulate JS console.log() """ print(', '.join(args)) + def choices_to_dict(t): """ Converts a ChoiceField two-tuple to a dict (for JSON) @@ -71,9 +78,11 @@ def choices_to_dict(t): return d + def empty(v): return v in ('', ' ', None,) + def cache_getset(k, v): """ Shortcut for getting and setting cache -- cgit v1.2.3