Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions cincoctrl/cincoctrl/findingaids/filters.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import django_filters
from django.db.models import Q
from django.forms.widgets import TextInput

from cincoctrl.findingaids.models import FindingAid
from cincoctrl.users.models import Repository


class FindingAidFilter(django_filters.FilterSet):
search = django_filters.CharFilter(
method="filter_search",
label="Search for collections",
widget=TextInput(
attrs={
"placeholder": "Collection Title, Collection Number, or ARK",
"class": "form-control me-2",
"aria-label": "Search",
},
),
)

class Meta:
model = FindingAid
fields = {
"repository": ["exact"],
"collection_title": ["icontains"],
}
fields = ["repository", "search"]

def filter_search(self, queryset, name, value):
return queryset.filter(
Q(collection_title__icontains=value)
| Q(collection_number__icontains=value)
| Q(ark__icontains=value),
).distinct()

def __init__(self, *args, **kwargs):
repo_qs = kwargs.pop("repo_qs", Repository.objects.all())
Expand Down
45 changes: 39 additions & 6 deletions cincoctrl/cincoctrl/findingaids/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ def get_context_data(self, **kwargs):
repo_qs=self.request.user.repositories(),
)

sortable_fields = [
"collection_title",
"collection_number",
"repository",
"ark",
"record_type",
"date_updated",
"status",
]
sort_links = {
field: {"link": f"{field}", "direction": ""} for field in sortable_fields
}

if "sort" in self.request.GET:
sort_value = self.request.GET["sort"]
sort_field = sort_value[1:] if sort_value.startswith("-") else sort_value
if sort_field in sortable_fields:
f.qs.order_by(sort_value)

sort_links[sort_field] = {
"link": sort_field if sort_value.startswith("-") else f"-{sort_field}",
"direction": "asc" if sort_value.startswith("-") else "desc",
}

items_per_page = 25
paginator = Paginator(f.qs, items_per_page)

Expand All @@ -52,15 +76,24 @@ def get_context_data(self, **kwargs):
except EmptyPage:
records_page = paginator.page(paginator.num_pages)

context["filter"] = f
context["records_page"] = records_page
sep = "&" if len(self.request.GET) > 0 else "?"
context["base_page_url"] = f"{self.request.get_full_path()}{sep}"
return context
return {
**context,
"paginator_range": paginator.get_elided_page_range(
number=records_page.number,
on_each_side=2,
on_ends=1,
),
"filter": f,
"records_page": records_page,
"sortable": sort_links,
}

def get_queryset(self):
queryset = super().get_queryset()
return queryset.filter(repository__in=self.request.user.repositories())
queryset = queryset.filter(repository__in=self.request.user.repositories())
if "sort" in self.request.GET:
queryset = queryset.order_by(self.request.GET["sort"])
return queryset


manage_records_view = ManageRecordsView.as_view()
Expand Down
8 changes: 8 additions & 0 deletions cincoctrl/cincoctrl/static/css/project.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@
background-color: #f2dede;
border-color: #eed3d7;
}

th.asc::after {
content: "▲";
}

th.desc::after {
content: "▼";
}
136 changes: 90 additions & 46 deletions cincoctrl/cincoctrl/templates/findingaids/list_records.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "base.html" %}

{% load crispy_forms_tags %}
{# load querystring from django.contrib.staticfiles #}

{% block title %}
Manage Collection Guides
Expand All @@ -18,8 +19,7 @@ <h2>Add a new collection guide</h2>
<p>
+ <a href="{% url 'findingaids:create_record_express' %}">Create a new RecordEXPRESS guide</a>
</p>
{% if records_page %}
<h2>Your collection guides</h2>
<h2>Your collection guides</h2>
<p>
<div class="col-sm-4">
<form method="get">
Expand All @@ -28,54 +28,98 @@ <h2>Your collection guides</h2>
</form>
</div>
</p>
<table class="table table-striped">
<thead>
<th>Collection Title</th>
<th>Collection Number</th>
<th>Repository</th>
<th>ARK</th>
<th>Submission Type</th>
<th>Date Updated</th>
<th>Publication Status</th>
</thead>
{% for record in records_page %}
<tr>
<td><a href="{{ record.get_absolute_url }}">{{ record.collection_title }}</a></td>
<td>{{ record.collection_number }}</td>
<td>{{ record.repository }}</td>
<td>{{ record.ark|slice:"-8:" }}</td>
<td>{{ record.record_type }}</td>
<td>{{ record.date_updated|date:"Y-m-d" }}</td>
<td>{{ record.status }}</td>
</tr>
{% endfor %}
</table>
{% if records_page %}
<p>
Showing {{ records_page.start_index }} to {{ records_page.end_index }} of {{ records_page.paginator.count }} records found.
</p>
<table class="table table-striped">
<thead>
<th class="{{ sortable.collection_title.direction }}">
<a href="{% querystring sort=sortable.collection_title.link %}">
Collection Title
</a>
</th>
<th class="{{ sortable.collection_number.direction }}">
<a href="{% querystring sort=sortable.collection_number.link %}">
Collection Number
</a>
</th>
<th class="{{ sortable.ark.direction }}">
<a href="{% querystring sort=sortable.ark.link %}">
ARK
</a>
</th>
<th class="{{ sortable.repository.direction }}">
<a href="{% querystring sort=sortable.repository.link %}">
Repository
</a>
</th>
<th class="{{ sortable.record_type.direction }}">
<a href="{% querystring sort=sortable.record_type.link %}">
Submission Type
</a>
</th>
<th class="{{ sortable.status.direction }}">
<a href="{% querystring sort=sortable.status.link %}">
Publication Status
</a>
</th>
<th class="{{ sortable.date_updated.direction }}">
<a href="{% querystring sort=sortable.date_updated.link %}">
Date Updated
</a>
</th>
<th>
Includes PDFs?
</th>
<th>
Download EAD File
</th>
</thead>
{% for record in records_page %}
<tr>
<td><a href="{{ record.get_absolute_url }}">{{ record.collection_title }}</a></td>
<td>{{ record.collection_number }}</td>
<td>{{ record.ark }}</td>
<td>{{ record.repository }}</td>
<td>{{ record.record_type }}</td>
<td>{{ record.status }}</td>
<td>{{ record.date_updated|date:"Y-m-d" }}</td>
<td>{% if record.supplemental_pdfs.count > 0 %}Yes{% else %}No{% endif %}</td>
<td>{% if record.ead_file %}<a href="{{ record.ead_file.url }}">{{ record.ead_file }}</a>{% else %}N/A{% endif %}</td>
</tr>
{% endfor %}
</table>

{% if records_page.has_other_pages %}
<div class="btn-group" role="group" aria-label="Record pagination">
{% if records_page.has_previous %}
<a href="{{ base_page_url }}page={{ records_page.previous_page_number }}" class="btn btn-outline-primary">&laquo;</a>
{% endif %}
{% for page_number in records_page.paginator.page_range %}
{% if records_page.number == page_number %}
<button class="btn btn-outline-primary active">
<span>{{ page_number }} <span class="sr-only">(current)</span></span>
</button>
{% else %}
<a href="{{ base_page_url }}page={{ page_number }}" class="btn btn-outline-primary">
{{ page_number }}
</a>
{% endif %}
{% endfor %}
{% if records_page.has_other_pages %}
<div class="btn-group" role="group" aria-label="Record pagination">
{% if records_page.has_previous %}
<a href="{% querystring page=records_page.previous_page_number %}" class="btn btn-outline-primary">&lsaquo;</a>
{% endif %}

{% if records_page.has_next %}
<a href="{{ base_page_url }}page={{ records_page.next_page_number }}" class="btn btn-outline-primary">&raquo;</a>
{% endif %}
</div>
{% for page_number in paginator_range %}
{% if records_page.number == page_number %}
<button class="btn btn-outline-primary active">
<span>{{ page_number }} <span class="visually-hidden">(current)</span></span>
</button>
{% elif page_number == "…" %}
<button class="btn btn-outline-primary disabled">…</button>
{% else %}
<a href="{% querystring page=page_number %}" class="btn btn-outline-primary">
{{ page_number }}
</a>
{% endif %}
{% else %}
<p>No records found</p>
{% endfor %}

{% if records_page.has_next %}
<a href="{% querystring page=records_page.next_page_number %}" class="btn btn-outline-primary">&rsaquo;</a>
{% endif %}
</div>
{% endif %}

{% else %}
<p>No records found.</p>
{% endif %}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion cincoctrl/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ argon2-cffi==23.1.0 # https://github.com/hynek/argon2_cffi

# Django
# ------------------------------------------------------------------------------
django==5.0.9 # pyup: < 5.1 # https://www.djangoproject.com/
django==5.2.9 # pyup: < 5.1 # https://www.djangoproject.com/
django-environ==0.11.2 # https://github.com/joke2k/django-environ
django-model-utils==5.0.0 # https://github.com/jazzband/django-model-utils
django-allauth[mfa]==65.0.2 # https://github.com/pennersr/django-allauth
Expand Down