This commit is contained in:
Ross
2022-03-22 22:09:49 +00:00
parent 7577a031c1
commit e3e5eee1e0
6 changed files with 59 additions and 7 deletions
+21 -1
View File
@@ -290,6 +290,17 @@ class Case(models.Model):
return format_html("<a href='{}'>{}</a>", self.get_absolute_url(), str(self))
def __str__(self):
return f"{self.pk}:{self.title}"
def get_series_blocks(self):
html = ""
for s in self.series.all():
html += s.get_block()
return html
def get_long_str(self):
examinations = [series.get_examination() for series in self.series.all()]
return f"{self.pk}:{self.title} {'/'.join([str(c) for c in self.condition.all()])} [{', '.join(examinations)}]"
@@ -541,8 +552,17 @@ class CaseCollection(models.Model):
help_text="If a collection should be freely available to browse", default=True
)
def get_absolute_url(self):
return reverse("atlas:collection_detail_view", kwargs={"pk": self.pk})
def __str__(self) -> str:
return self.name
class CaseDetail(models.Model):
case = models.ForeignKey(Case, on_delete=models.CASCADE)
collection = models.ForeignKey(CaseCollection, on_delete=models.CASCADE)
sort_order = models.IntegerField()
sort_order = models.IntegerField()
class Meta:
ordering = ("sort_order",)
@@ -0,0 +1,16 @@
{% extends 'atlas/base.html' %}
{% block content %}
<h2>Case {{case_number|add:1}}</h2>
{{case.get_series_blocks}}
{% if previous %}
<a href="{% url 'atlas:collection_case_view' pk=collection.pk case_number=case_number|add:-1 %}">Previous</a>
{% endif %}
{% if next %}
<a href="{% url 'atlas:collection_case_view' pk=collection.pk case_number=case_number|add:1 %}">Next</a>
{% endif %}
<br/>
Return to <a href='{{collection.get_absolute_url}}'>collection</a>
{% endblock %}
@@ -1,9 +1,12 @@
{% extends 'atlas/base.html' %}
{% block content %}
<h2>{{collection.name}}
<ul>
{% for case in collection %}
<li>{{case.title}}: {{case.descriptions}}</li>
{% for case in collection.cases.all %}
<li><a href="{% url 'atlas:collection_case_view' pk=collection.pk case_number=forloop.counter0 %}">Case {{forloop.counter}}</a></li>
{% endfor %}
</ul>
{% endblock %}
@@ -3,7 +3,7 @@
{% block content %}
<ul>
{% for collection in collections %}
<li>{{collection.name}}</li>
<li><a href='{{collection.get_absolute_url}}'>{{collection.name}}</a></li>
{% endfor %}
</ul>
{% endblock %}
+1
View File
@@ -12,6 +12,7 @@ urlpatterns = [
path("case/", views.CaseView.as_view(), name="case_view"),
path("collection/", views.collection_index_view, name="collection_index_view"),
path("collections/<int:pk>", views.collection_detail_view, name="collection_detail_view"),
path("collections/<int:pk>/<int:case_number>", views.collection_case_view, name="collection_case_view"),
path("condition/", views.ConditionView.as_view(), name="condition_view"),
path("categories/", views.categories_list, name="categories_list"),
path("condition/<int:pk>", views.condition_detail, name="condition_detail"),
+15 -3
View File
@@ -897,9 +897,21 @@ def categories_list(request):
def collection_index_view(request):
collections = CaseCollection.objects.all()
return render(request, "atlas/collection_index.html", {"collections": collections})
return render(request, "atlas/collection_index_view.html", {"collections": collections})
def collection_detail_view(request, pk):
collection = get_object_or_404(CaseCollection, pk)
collection = get_object_or_404(CaseCollection, pk=pk)
return render(request, "atlas/collection_index.html", {"collection": collection})
return render(request, "atlas/collection_detail_view.html", {"collection": collection})
def collection_case_view(request, pk, case_number):
collection = get_object_or_404(CaseCollection, pk=pk)
cases = collection.cases.all()
case = cases[case_number]
previous = case_number > 0
next = case_number < (len(cases) - 1)
return render(request, "atlas/collection_case_view.html", {"collection": collection, "case": case, "case_number": case_number, "previous": previous, "next": next})