Skip to content
Snippets Groups Projects
Commit a54da7ac authored by Felix Blanke's avatar Felix Blanke
Browse files

Change funcs to export json dict instead of str

parent abbe82a1
No related branches found
No related tags found
1 merge request!19Change json export to assemble a dict instead of sts in the template
......@@ -4,7 +4,7 @@ import json
import math
from dataclasses import dataclass
from datetime import datetime, timedelta
from typing import Iterable, Generator
from typing import Any, Iterable, Generator
from django.db import models, transaction
from django.apps import apps
......@@ -852,7 +852,7 @@ class Room(models.Model):
def __str__(self):
return self.title
def as_json(self) -> str:
def as_json_dict(self) -> dict[str, Any]:
"""Return a json string representation of this room object.
:return: The json string representation is constructed
......@@ -887,7 +887,7 @@ class Room(models.Model):
if not any(constr.startswith("proxy") for constr in data["fulfilled_room_constraints"]):
data["fulfilled_room_constraints"].append("no-proxy")
return json.dumps(data)
return data
class AKSlot(models.Model):
......@@ -984,7 +984,7 @@ class AKSlot(models.Model):
self.duration = min(self.duration, event_duration_hours)
super().save(force_insert, force_update, using, update_fields)
def as_json(self) -> str:
def as_json_dict(self) -> dict[str, Any]:
"""Return a json string representation of the AK object of this slot.
:return: The json string representation is constructed
......@@ -1055,7 +1055,7 @@ class AKSlot(models.Model):
if not any(constr.startswith("proxy") for constr in data["room_constraints"]):
data["room_constraints"].append("no-proxy")
return json.dumps(data)
return data
class AKOrgaMessage(models.Model):
"""
......
......@@ -4,17 +4,6 @@
{% block content %}
<pre>
{"aks": [
{% for slot in slots %}{{ slot.as_json }}{% if not forloop.last %},
{% endif %}{% endfor %}
],
"rooms": [
{% for room in rooms %}{{ room.as_json }}{% if not forloop.last %},
{% endif %}{% endfor %}
],
"participants": {{ participants }},
"timeslots": {{ timeslots }},
"info": {{ info_dict }}
}
{{ json_data }}
</pre>
{% endblock %}
......@@ -86,10 +86,10 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["participants"] = json.dumps([])
data = {}
rooms = Room.objects.filter(event=self.event)
context["rooms"] = rooms
data["rooms"] = [r.as_json_dict() for r in rooms]
timeslots = {
"info": {"duration": float(self.event.export_slot)},
......@@ -179,17 +179,21 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
timeslots["info"]["blocknames"] = block_names
context["timeslots"] = json.dumps(timeslots)
info_dict = {
"title": self.event.name,
"slug": self.event.slug
}
for attr in ["contact_email", "place"]:
if hasattr(self.event, attr) and getattr(self.event, attr):
info_dict[attr] = getattr(self.event, attr)
context["info_dict"] = json.dumps(info_dict)
data["timeslots"] = timeslots
data["info"] = info_dict
data["participants"] = []
data["aks"] = [ak.as_json_dict() for ak in context["slots"]]
context["json_data"] = json.dumps(data, indent=2)
return context
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment