aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-11-27 10:15:59 +0200
committerFilipp Lepalaan <filipp@mac.com>2015-11-27 10:15:59 +0200
commitfbc56b5be6443bc681ab67283ab7a3e68b3d68c9 (patch)
treec5021aca5929d1fbb45c172bf898ba5a73d83249
parentc605f2bc0bc4b098e231b6469f588605e96e4dd9 (diff)
downloadServo-fbc56b5be6443bc681ab67283ab7a3e68b3d68c9.tar.gz
Servo-fbc56b5be6443bc681ab67283ab7a3e68b3d68c9.tar.bz2
Servo-fbc56b5be6443bc681ab67283ab7a3e68b3d68c9.zip
Cleanup
-rw-r--r--servo/lib/utils.py13
-rw-r--r--servo/views/note.py4
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)