Fix escaping json
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 13 Oct 2026 10:46:47 +0000 (12:46 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 13 Oct 2026 10:46:47 +0000 (12:46 +0200)
src/catalogue/templates/catalogue/book_text.html
src/references/models.py

index a35738f..45805c4 100644 (file)
    {
        {% for ref in book.references %}
        {% if ref.entity.is_interesting %}
    {
        {% for ref in book.references %}
        {% if ref.entity.is_interesting %}
-       "{{ ref.entity.uri }}": {
-           "id": {{ ref.entity.id }},
-           {% if ref.entity.lat and ref.entity.lon %}
-           "location": [{{ ref.entity.lat }}, {{ ref.entity.lon }}],
-           {% endif %}
-           "images": {{ ref.entity.images|safe }},
-           "label": "{{ ref.entity.label }}",
-           "description": "{{ ref.entity.description }}",
-           "wikipedia_link": "{{ ref.entity.wikipedia_link }}"
-       },
+       "{{ ref.entity.uri }}": {{ ref.entity.get_json|safe }},
        {% endif %}
        {% endfor %}
        "": null
        {% endif %}
        {% endfor %}
        "": null
index e8813a0..d971ba6 100644 (file)
@@ -107,7 +107,18 @@ class Entity(models.Model):
             *to_minutes(lon),
             lonm,
         )
             *to_minutes(lon),
             lonm,
         )
-        
+
+    def get_json(self):
+        data = {
+            "id": self.id,
+            "images": self.get_images(),
+            "label": self.label,
+            "description": self.description,
+            "wikipedia_link": self.wikipedia_link,
+        }
+        if self.lat and self.lon:
+            data['location'] = [self.lat, self.lon]
+        return json.dumps(data)
     
 
 class Reference(models.Model):
     
 
 class Reference(models.Model):