From 8759edd5871fa9743d6b7aa0c52f37ec1fd003b5 Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Sat, 14 Jan 2017 13:18:35 +0100 Subject: [PATCH] Calibre-companion now working (#79) --- cps/templates/json.txt | 10 ++++++++-- cps/web.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cps/templates/json.txt b/cps/templates/json.txt index d23138c9..b724f4e9 100644 --- a/cps/templates/json.txt +++ b/cps/templates/json.txt @@ -22,7 +22,7 @@ "{{lang.lang_code}}"{% if not loop.last %},{% endif %} {% endfor %} ], - "comments": "{% if entry.comments|length > 0 %}{{entry.comments[0].text|safe}}{% endif %}", + "comments": "{% if entry.comments|length > 0 %}{{entry.comments[0].text.replace('"', '\\"')|safe}}{% endif %}", "tags": [ {% for tag in entry.tags %} "{{tag.name}}"{% if not loop.last %},{% endif %} @@ -38,11 +38,17 @@ "main_format": { "{{entry.data[0].format|lower}}": "/download/{{entry.id}}/{{entry.data[0].format|lower}}" }, + "rating":{% if entry.ratings.__len__() > 0 %} "{{entry.ratings[0].rating}}.0"{% else %}0.0{% endif %}, "authors": [ {% for author in entry.authors %} "{{author.name}}"{% if not loop.last %},{% endif %} {% endfor %} ], - "other_formats": {}, + "other_formats": { + {% if entry.data.__len__() > 1 %} + {% for format in entry.data[1:] %} + "{{format.format|lower}}": "/download/{{entry.id}}/{{format.format|lower}}"{% if not loop.last %},{% endif %} + {% endfor %} + {% endif %} }, "title_sort": "{{entry.sort}}" } \ No newline at end of file diff --git a/cps/web.py b/cps/web.py index 737551be..16279616 100755 --- a/cps/web.py +++ b/cps/web.py @@ -638,7 +638,7 @@ def get_metadata_calibre_companion(uuid): if entry is not None : js = render_template('json.txt',entry=entry) response = make_response(js) - response.headers["Content-Type"] = "application/json" + response.headers["Content-Type"] = "application/json; charset=utf-8" return response else: return ""