From bd146d4249da57b7fca97367d5ea9a0c0eff70e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9COMosimege=E2=80=9D?= <“onalerona.mosimege@gmail.com”> Date: Fri, 28 Jun 2024 10:39:44 +0200 Subject: [PATCH] Add individual institution page view, template, and styling add tests --- app/app/urls.py | 3 +- app/app/views.py | 25 +++++++- app/general/tests/test_institution_detail.py | 30 +++++++++ app/static/css/styles.css | 21 ++++--- app/templates/app/institution_detail.html | 66 ++++++++++++++++++++ app/templates/app/institutions.html | 2 +- app/templates/app/project_detail.html | 14 ++--- 7 files changed, 140 insertions(+), 21 deletions(-) create mode 100644 app/general/tests/test_institution_detail.py diff --git a/app/app/urls.py b/app/app/urls.py index d2e4b13f..74103c3c 100644 --- a/app/app/urls.py +++ b/app/app/urls.py @@ -33,7 +33,8 @@ path("institutions/", views.institutions, name="institutions"), path("projects/", views.projects, name="projects"), path("projects//", views.project_detail, name="project_detail"), - path("institution//", views.institution_detail, name="institution_detail"), + path("institution//", views.institution_detail, name="institution_detail"), + path("documents//", views.document_detail, name="document_detail"), path("language//", views.language_detail, name="language_detail"), path("subject//", views.subject_detail, name="subject_detail"), path("search/", views.search, name="search"), diff --git a/app/app/views.py b/app/app/views.py index af335750..da58000f 100644 --- a/app/app/views.py +++ b/app/app/views.py @@ -139,13 +139,33 @@ def project_detail(request, project_id): return render(request, template_name=template, context=context) -def institution_detail(request, project_id): +def institution_detail(request, institution_id): template = "app/institution_detail.html" - project = Project.objects.get(id=project_id) + institution = get_object_or_404(Institution, id=institution_id) + projects = Project.objects.filter(institution=institution) + documents = DocumentFile.objects.filter(institution=institution) + + logo = institution.logo context = { "current_page": "institution_detail", + "institution": institution, + "projects": projects, + "documents": documents, + "logo": logo, + } + + return render(request, template_name=template, context=context) + + +def document_detail(request, project_id): + template = "app/document_detail.html" + + document = DocumentFile.objects.get(id=document_id) + + context = { + "current_page": "document_detail", } return render(request, template_name=template, context=context) @@ -201,6 +221,7 @@ def institutions(request): rating = (completed_fields_count / len(institution_dict)) * 100 institution_dict["rating"] = round(rating) institution_dict["project_count"] = institution.project_count + institution_dict["id"] = institution.id institutions_array.append(institution_dict) context = {"current_page": "institutions", "institutions": institutions_array} diff --git a/app/general/tests/test_institution_detail.py b/app/general/tests/test_institution_detail.py new file mode 100644 index 00000000..71da4cb7 --- /dev/null +++ b/app/general/tests/test_institution_detail.py @@ -0,0 +1,30 @@ +from django.http import Http404 +from django.test import TestCase +from django.urls import reverse + +from general.models import DocumentFile, Institution, Project + + +class InstitutionDetailViewTests(TestCase): + def setUp(self): + self.institution = Institution.objects.create( + name="Sample Institution", + abbreviation="SI", + url="https://example.com", + email="info@example.com", + logo="path/to/logo.png", + ) + + def test_institution_detail_view_with_valid_id(self): + response = self.client.get(reverse("institution_detail", args=[self.institution.id])) + self.assertEqual(response.status_code, 200) + self.assertContains(response, self.institution.name) + + def test_institution_detail_view_with_invalid_id(self): + invalid_id = self.institution.id + 1 + response = self.client.get(reverse("institution_detail", args=[invalid_id])) + self.assertEqual(response.status_code, 404) + + def test_project_detail_view_num_queries(self): + with self.assertNumQueries(1): + response = self.client.get(reverse("project_detail", args=[self.institution.id])) diff --git a/app/static/css/styles.css b/app/static/css/styles.css index 3a5aece8..059f1586 100755 --- a/app/static/css/styles.css +++ b/app/static/css/styles.css @@ -219,7 +219,6 @@ html { } .project-name { - color: var(--text-color); text-decoration: none; } @@ -281,16 +280,16 @@ html { font-size: 0.95rem; } -/*Project detail*/ -.project-detail { +/*Project & Institution detail*/ +.detail { width: 80%; margin: 0 auto; font-size: 0.875rem; } -.project-detail h1 { +.detail h1 { font-size: 2em; } -.project-detail a { +.detail a { text-decoration: none; color: var(--link-text); } @@ -299,12 +298,12 @@ html { text-decoration: underline; } -.project-detail { +.detail { width: 80%; margin-left: 40px; } -.project-div-row { +.detail-row { display: flex; justify-content: space-between; margin-bottom: 20px; @@ -345,11 +344,11 @@ html { color: var(--link-text); } -.project-detail-left-col { +.detail-left-col { width: 50%; } -.project-detail-right-col { +.detail-right-col { width: 50%; flex: 0 0 auto; display: flex; @@ -360,6 +359,8 @@ html { font-size: 0.875rem; } + + /*Error pages*/ .error-card { border-color: var(--primary-red); @@ -371,7 +372,7 @@ html { .bi { font-size: 50px; } -.project-icon { +.detail-icon { font-size: 20px; margin-right: 3px; } diff --git a/app/templates/app/institution_detail.html b/app/templates/app/institution_detail.html index e69de29b..08d8131c 100644 --- a/app/templates/app/institution_detail.html +++ b/app/templates/app/institution_detail.html @@ -0,0 +1,66 @@ +{% extends "base.html" %} +{% load static %} +{% load i18n %} + +{% block content %} +
+
+

{% trans "Institutions" %} > {{ institution.name }}

+ +
+ +
+

{{ institution.name }} ({{ institution.abbreviation }})

+ {% if institution.url %} +

{{ institution.url }}

+ {% endif %} + {% if institution.email %} +

{{ institution.email }}

+ {% endif %} +
+ +
+ {% if institution.logo %} + + {% endif %} +
+
+ +
+ +
+
+

{% trans "Projects" %}

+ {% if projects %} + + {% else %} +

{% trans "No projects available for this institution." %}

+ {% endif %} +
+
+

{% trans "Documents" %}

+ {% if documents %} + + {% else %} +

{% trans "No documents available for this institution." %}

+ {% endif %} +
+
+ +
+ +{% endblock content %} diff --git a/app/templates/app/institutions.html b/app/templates/app/institutions.html index 4973269b..663ab27f 100644 --- a/app/templates/app/institutions.html +++ b/app/templates/app/institutions.html @@ -10,7 +10,7 @@
-
{{ institution.name }}
+
{{ institution.name }}

{{ institution.abbreviation }}

diff --git a/app/templates/app/project_detail.html b/app/templates/app/project_detail.html index 4b9159c5..c94c1ce1 100644 --- a/app/templates/app/project_detail.html +++ b/app/templates/app/project_detail.html @@ -4,12 +4,12 @@ {% block content %}
-
+

{% trans "Projects" %} > {{ project.name }}

-
+
-
+

{{ project.name }}

{{ project.url }}

@@ -36,7 +36,7 @@

{{ project.name }}

-
+
{% if project.logo %} @@ -46,14 +46,14 @@

{{ project.name }}

-
+

{% trans "Subjects" %}