-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1586 from DDMAL/add-institution-views
New: Add views for institutions
- Loading branch information
Showing
7 changed files
with
212 additions
and
0 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
71 changes: 71 additions & 0 deletions
71
django/cantusdb_project/main_app/templates/institution_detail.html
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" %} | ||
|
||
{% block title %} | ||
|
||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="mr-3 p-3 col-md-12 mx-auto bg-white rounded"> | ||
<object align="right" class="search-bar"> | ||
{% include "global_search_bar.html" %} | ||
</object> | ||
<h3>{{ institution.name }} {% if institution.siglum %}({{ institution.siglum }}){% endif %}</h3> | ||
<h4>{{ institution.city }}, {{ institution.country }}</h4> | ||
{% if institution_authorities %} | ||
<hr /> | ||
<div class="row"> | ||
<div class="col"> | ||
{% for authority in institution_authorities %} | ||
View this institution in <a href="{{ authority.1 }}">{{ authority.0 }}</a> | ||
{% endfor %} | ||
</div> | ||
</div> | ||
{% endif %} | ||
<hr /> | ||
<div class="row"> | ||
{% if num_cantus_sources > 0 %} | ||
<div class="col"> | ||
<h5>Cantus Database</h5> | ||
<table class="table table-bordered table-sm small"> | ||
<thead> | ||
<tr> | ||
<th>Shelfmark</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for source in cantus_sources %} | ||
<tr> | ||
<td> | ||
<a href="{% url "source-detail" source.id %}"><b>{{ source.shelfmark }}</b></a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
{% endif %} | ||
|
||
{% if num_bower_sources > 0 %} | ||
<div class="col"> | ||
<h5>Bower Sequence Database</h5> | ||
<table class="table table-bordered table-sm small"> | ||
<thead> | ||
<tr> | ||
<th>Shelfmark</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for source in bower_sources %} | ||
<tr> | ||
<td> | ||
<a href="{% url "source-detail" source.id %}"><b>{{ source.shelfmark }}</b></a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endblock %} |
44 changes: 44 additions & 0 deletions
44
django/cantusdb_project/main_app/templates/institution_list.html
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,44 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %} | ||
|
||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="mr-3 p-3 col-md-12 mx-auto bg-white rounded"> | ||
<object align="right" class="search-bar"> | ||
{% include "global_search_bar.html" %} | ||
</object> | ||
<h3>Institutions</h3> | ||
<small>Displaying {{ page_obj.start_index }}-{{ page_obj.end_index }} of {{ page_obj.paginator.count }}</small> | ||
<table class="table table-bordered table-sm small"> | ||
<thead> | ||
<tr> | ||
<th scope="col" class="text-wrap" title="Country">Country</th> | ||
<th scope="col" class="text-wrap" title="City">City</th> | ||
<th scope="col" class="text-wrap" title="Name">Name</th> | ||
<th scope="col" class="text-wrap" title="Sources">Sources</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for institution in institutions %} | ||
<tr> | ||
<td class="text-wrap"> | ||
{{ institution.country }} | ||
</td> | ||
<td> | ||
{{ institution.city }} | ||
</td> | ||
<td class="text-wrap"> | ||
<a href="{% url "institution-detail" institution.id %}"> | ||
<b>{{ institution.name }} {% if institution.siglum %}({{ institution.siglum }}){% endif %}</b> | ||
</a> | ||
</td> | ||
<td>{{ institution.num_sources }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% include "pagination.html" %} | ||
</div> | ||
{% endblock %} |
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,77 @@ | ||
from django.db.models import Count, Subquery, OuterRef, Aggregate, F, Q, Func | ||
from django.views.generic import DetailView, ListView | ||
|
||
from main_app.identifiers import IDENTIFIER_TYPES, TYPE_PREFIX | ||
from main_app.models import Institution, Source, Segment, InstitutionIdentifier | ||
|
||
|
||
class InstitutionListView(ListView): | ||
model = Institution | ||
context_object_name = "institutions" | ||
paginate_by = 100 | ||
template_name = "institution_list.html" | ||
|
||
def get_queryset(self): | ||
display_unpublished: bool = self.request.user.is_authenticated | ||
|
||
# uses a subquery to get a count of the sources, filtering by published | ||
# sources only it the user is not logged in. | ||
qargs = {"holding_institution": OuterRef("pk")} | ||
if display_unpublished is False: | ||
qargs["published"] = True | ||
|
||
sources = ( | ||
Source.objects.filter(**qargs) | ||
.annotate(c=Func(F("id"), function="COUNT")) | ||
.values("c") | ||
) | ||
|
||
# Only display institution records if they have sources in them that the user | ||
# can access. | ||
qset = Institution.objects.annotate(num_sources=Subquery(sources)).filter( | ||
num_sources__gt=0 | ||
) | ||
return qset | ||
|
||
|
||
class InstitutionDetailView(DetailView): | ||
model = Institution | ||
context_object_name = "institution" | ||
template_name = "institution_detail.html" | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
institution = self.get_object() | ||
|
||
# Show the Cantus and Bower sources in separate tables, and pre-format | ||
# the external authority links. | ||
cantus_segment = Segment.objects.get(id=4063) | ||
bower_segment = Segment.objects.get(id=4064) | ||
cantus_sources = Source.objects.filter( | ||
holding_institution=institution, segment=cantus_segment | ||
).select_related("holding_institution") | ||
bower_sources = Source.objects.filter( | ||
holding_institution=institution, segment=bower_segment | ||
).select_related("holding_institution") | ||
institution_authorities = InstitutionIdentifier.objects.filter( | ||
institution=institution | ||
) | ||
|
||
display_unpublished = self.request.user.is_authenticated | ||
if display_unpublished is False: | ||
cantus_sources = cantus_sources.filter(published=True) | ||
bower_sources = bower_sources.filter(published=True) | ||
|
||
formatted_authorities = [] | ||
for authority in institution_authorities: | ||
formatted_authorities.append( | ||
(authority.identifier_label, authority.identifier_url) | ||
) | ||
|
||
context["cantus_sources"] = cantus_sources | ||
context["num_cantus_sources"] = cantus_sources.count() | ||
context["bower_sources"] = bower_sources | ||
context["num_bower_sources"] = bower_sources.count() | ||
context["institution_authorities"] = formatted_authorities | ||
|
||
return context |