-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add document detail view, url, and template
- Loading branch information
“OMosimege”
committed
Jul 18, 2024
1 parent
b248001
commit 5126c40
Showing
5 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from general.models import DocumentFile, Institution, Language, Project, Subject | ||
|
||
|
||
class DocumentDetailViewTest(TestCase): | ||
def setUp(self): | ||
self.institution = Institution.objects.create(name="University of Cape Town") | ||
|
||
self.subject1 = Subject.objects.create(name="Anatomy") | ||
self.subject2 = Subject.objects.create(name="Biology") | ||
|
||
self.language1 = Language.objects.create(name="Afrikaans", iso_code="af") | ||
self.language2 = Language.objects.create(name="English", iso_code="en") | ||
|
||
self.document = DocumentFile.objects.create( | ||
title="Afrikaans_HL_P1_Feb-March_2011", | ||
description="This is a description of the document.", | ||
url="https://externaldocumentrepository.com/document1", | ||
uploaded_file="path/to/document.pdf", | ||
available=True, | ||
license="(c)", | ||
document_type="Glossary", | ||
institution=self.institution, | ||
mime_type="application/pdf", | ||
document_data="", | ||
search_vector=None, | ||
) | ||
self.document.subjects.add(self.subject1, self.subject2) | ||
self.document.languages.add(self.language1, self.language2) | ||
|
||
def test_document_detail_num_queries(self): | ||
url = reverse("document_detail", args=[self.document.id]) | ||
with self.assertNumQueries(3): | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, self.document.title) | ||
self.assertContains(response, self.institution.name) | ||
self.assertContains(response, self.subject1.name) | ||
self.assertContains(response, self.language1.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{% extends "base.html" %} | ||
{% load static %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
<br/> | ||
<div class="detail"> | ||
<p><a href="{% url 'documents' %}">{% trans "Documents" %}</a> > {{ document.title }}</p> | ||
|
||
<div class="detail-row row"> | ||
<h1>{{ document.title }}</h1> | ||
|
||
<a href="{{ document.url }}" target="_blank" class="document-url text-decoration-underline float-left" title="External link"> | ||
{{ document.url }} | ||
</a> | ||
|
||
<div class="mb-3"> | ||
<a href="{{ document.uploaded_file.url }}" download> | ||
<button class="btn btn-primary btn-sm" type="submit"> | ||
<i class="detail-icon bi-file-earmark-arrow-down-fill"></i> {% trans "Download File" %} | ||
</button> | ||
</a> | ||
</div> | ||
|
||
<div class="project-body"> | ||
<p>{{ document.description }}</p> | ||
</div> | ||
|
||
<p> | ||
<a href="{% url 'institution_detail' document.institution.id %}" class="text-decoration-underline"> | ||
{{ document.institution.name }} | ||
</a> | ||
</p> | ||
|
||
<p><strong>{% trans "License:" %}</strong> {{ document.license }}</p> | ||
<p><strong>{% trans "Category:" %}</strong> {{ document.document_type }}</p> | ||
</div> | ||
|
||
|
||
<div class="detail-row row"> | ||
<div class="col-md-6 col-12 detail-col"> | ||
<div> | ||
<h2>{% trans "Subjects" %}</h2> | ||
<ul> | ||
{% for subject in document.subjects.all %} | ||
<li> | ||
<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 %} | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-6 col-12 detail-col"> | ||
<div> | ||
<h2>{% trans "Languages" %}</h2> | ||
<ul> | ||
{% for language in document.languages.all %} | ||
<li> | ||
<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 %} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends "base.html" %} | ||
{% load static %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
|
||
{% endblock content%} |