Skip to content

Commit

Permalink
Merge pull request #85 from SADiLaR/feature/institution-detail-page
Browse files Browse the repository at this point in the history
Add individual institution page
  • Loading branch information
OnaMosimege authored Jun 28, 2024
2 parents eb60543 + bd146d4 commit b9830d5
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 21 deletions.
3 changes: 2 additions & 1 deletion app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
path("institutions/", views.institutions, name="institutions"),
path("projects/", views.projects, name="projects"),
path("projects/<int:project_id>/", views.project_detail, name="project_detail"),
path("institution/<int:pk>/", views.institution_detail, name="institution_detail"),
path("institution/<int:institution_id>/", views.institution_detail, name="institution_detail"),
path("documents/<int:document_id>/", views.document_detail, name="document_detail"),
path("language/<int:pk>/", views.language_detail, name="language_detail"),
path("subject/<int:pk>/", views.subject_detail, name="subject_detail"),
path("search/", views.search, name="search"),
Expand Down
25 changes: 23 additions & 2 deletions app/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}
Expand Down
30 changes: 30 additions & 0 deletions app/general/tests/test_institution_detail.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
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]))
21 changes: 11 additions & 10 deletions app/static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ html {
}

.project-name {
color: var(--text-color);
text-decoration: none;
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -360,6 +359,8 @@ html {
font-size: 0.875rem;
}



/*Error pages*/
.error-card {
border-color: var(--primary-red);
Expand All @@ -371,7 +372,7 @@ html {
.bi {
font-size: 50px;
}
.project-icon {
.detail-icon {
font-size: 20px;
margin-right: 3px;
}
Expand Down
66 changes: 66 additions & 0 deletions app/templates/app/institution_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{% extends "base.html" %}
{% load static %}
{% load i18n %}

{% block content %}
<br/>
<div class="detail">
<p><a href="{% url 'institutions' %}">{% trans "Institutions" %}</a> > {{ institution.name }}</p>

<div class="detail-row">

<div class="col-sm-6 detail-left-col">
<h1>{{ institution.name }} ({{ institution.abbreviation }})</h1>
{% if institution.url %}
<p><a href="{{ institution.url }}">{{ institution.url }}</a></p>
{% endif %}
{% if institution.email %}
<p><a href="mailto:{{ institution.email }}">{{ institution.email }}</a></p>
{% endif %}
</div>

<div class="col-sm-6 detail-right-col">
{% if institution.logo %}
<img src="{{ institution.logo.url }}" alt="{{ institution.name }}" class="project-logo">
{% endif %}
</div>
</div>

<br/>

<div class="detail-row">
<div class="col-sm-6 detail-col">
<h2>{% trans "Projects" %}</h2>
{% if projects %}
<ul>
{% for project in projects %}
<li>
<span class="icon-text"><i class="detail-icon bi-clipboard2"></i></span>
<span class="icon-text"><a href="{% url 'project_detail' project.id %}">{{ project.name }}</a></span>
</li>
{% endfor %}
</ul>
{% else %}
<p>{% trans "No projects available for this institution." %}</p>
{% endif %}
</div>
<div class="col-sm-6 detail-col">
<h2>{% trans "Documents" %}</h2>
{% if documents %}
<ul>
{% for document in documents %}
<li>
<span class="icon-text"><i class="detail-icon bi-file-earmark"></i></span>
<span class="icon-text"><a href="{% url 'document_detail' document.id %}">{{ document.title }}</a></span>
</li>
{% endfor %}
</ul>
{% else %}
<p>{% trans "No documents available for this institution." %}</p>
{% endif %}
</div>
</div>

</div>

{% endblock content %}
2 changes: 1 addition & 1 deletion app/templates/app/institutions.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="card uni-card">
<div class="row">
<div class="col-sm-6 left-col">
<h5 class="card-title">{{ institution.name }}</h5>
<h5 class="card-title"><a href="{% url 'institution_detail' institution.id %}">{{ institution.name }}</a></h5>
<p class="card-text">
{{ institution.abbreviation }}
</p>
Expand Down
14 changes: 7 additions & 7 deletions app/templates/app/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

{% block content %}
<br/>
<div class="project-detail">
<div class="detail">
<p><a href="{% url 'projects' %}">{% trans "Projects" %}</a> > {{ project.name }}</p>

<div class=project-div-row>
<div class=detail-row>

<div class="col-sm-6 project-detail-left-col">
<div class="col-sm-6 detail-left-col">
<h1>{{ project.name }}</h1>
<a href="{{ project.url }}">{{ project.url }}</a>
<p>
Expand All @@ -36,7 +36,7 @@ <h1>{{ project.name }}</h1>

</div>

<div class="col-sm-6 project-detail-right-col">
<div class="col-sm-6 detail-right-col">
{% if project.logo %}
<img src="{{ project.logo.url }}" alt="{% blocktrans with project_name=project.name %}{{ project_name }} logo{% endblocktrans %}"
class="project-logo">
Expand All @@ -46,14 +46,14 @@ <h1>{{ project.name }}</h1>
</div>


<div class="project-div-row">
<div class="detail-row">
<div class="col-sm-6 detail-col">
<div>
<h2>{% trans "Subjects" %}</h2>
<ul>
{% for subject in subjects %}
<li>
<span class="icon-text"><i class="project-icon bi-book"></i></span>
<span class="icon-text"><i class="detail-icon bi-book"></i></span>
<span class="icon-text"><a href="{% url 'subject_detail' subject.id %}">{{ subject.name }}</a></span>
</li>
{% endfor %}
Expand All @@ -67,7 +67,7 @@ <h2>{% trans "Languages" %}</h2>
<ul>
{% for language in languages %}
<li>
<span class="icon-text"><i class="project-icon bi-vector-pen"></i></span>
<span class="icon-text"><i class="detail-icon bi-vector-pen"></i></span>
<span class="icon-text"><a href="{% url 'language_detail' language.id %}">{{ language.name }}</a></span>
</li>
{% endfor %}
Expand Down

0 comments on commit b9830d5

Please sign in to comment.