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 +++++++++++-- servo/views/note.py | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) 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 diff --git a/servo/views/note.py b/servo/views/note.py index e406cc1..7a8feaf 100644 --- a/servo/views/note.py +++ b/servo/views/note.py @@ -269,8 +269,8 @@ def render_template(request, order_id=None): def templates(request, template_id=None): - if template_id is not None: - tpl = Template.objects.get(pk=template_id) + if template_id: + tpl = get_object_or_404(Template, pk=template_id) content = tpl.content if request.session.get('current_order_id'): tpl = template.Template(content) -- cgit v1.2.3