Skip to content

Commit

Permalink
Display categories for links. Move admin area, tidy up filter
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettc committed Aug 19, 2024
1 parent 1e7f9aa commit d101117
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 6 deletions.
22 changes: 21 additions & 1 deletion digitaloxford/scss/custom/_custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ ul.filter-list {
ul.links {
display: flex;
flex-direction: column;
gap: ms(2);
gap: ms(3);

& .link {
& h2 {
Expand All @@ -592,6 +592,26 @@ ul.links {
flex: 0 0 100px;
}
}

& .details *:last-child {
margin-bottom: ms(-1);
}

& .categories {
border-top: 1px solid $light-grey;
display: flex;
flex-direction: row;
flex-wrap: wrap;
column-gap: ms(-1);
font-size: ms(0);

& h3 {
margin: 0 0 0 0;
padding: 0 0 0 0;
font-size: ms(0);
font-weight: bold;
}
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions digitaloxford/scss/custom/_utilities.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Utilities */
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
}

.full-bleed {
width: 100vw;
margin-left: calc(50% - 50vw);
}

.list-reset {
margin: 0 0 0 0;
padding: 0 0 0 0;
list-style-type: none;
}

.list-inline {
display: flex;
flex-direction: row;
column-gap: ms(-1)
}
3 changes: 3 additions & 0 deletions digitaloxford/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// Normalise
@import "base/normalize";

// Utilities
@import "custom/utilities";

// Layout/branding/etc
@import "custom/variables";
@import "custom/custom";
11 changes: 11 additions & 0 deletions digitaloxford/templates/links/link_index_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ <h2><a href="{{ link.link }}">{{ link.title }}</a></h2>
<blockquote>{{ link.testimonial }}</blockquote>
{% endif %}
</div>
{% if link.categories %}
<div class="categories">
<h3>Categories:</h3>
<ul class="list-reset list-inline">
{% for category in link.prefetched_categories %}
<li><a href="{{ page.url }}?category={{ category.link_category.slug }}">{{ category.link_category.name }}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}

</li>
{% endfor %}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions digitaloxford/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from search import views as search_views

urlpatterns = [
path("django-admin/", admin.site.urls),
path("admin/", include(wagtailadmin_urls)),
path("django-spires/", admin.site.urls),
path("spires/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
path("search/", search_views.search, name="search"),
path("robots.txt", RobotsView.as_view()),
Expand Down
4 changes: 2 additions & 2 deletions links/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class LinkFilter(django_filters.FilterSet):
categories = django_filters.ChoiceFilter(
category = django_filters.ChoiceFilter(
label="Category",
field_name="categories__link_category__slug",
empty_label="-- All --",
Expand All @@ -26,4 +26,4 @@ class LinkFilter(django_filters.FilterSet):

class Meta:
model = LinkPage
fields = ["categories"]
fields = ["category"]
9 changes: 8 additions & 1 deletion links/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.conf import settings
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models
from django.db.models import Prefetch
from django.shortcuts import render
from django.utils.functional import cached_property
from modelcluster.contrib.taggit import ClusterTaggableManager
Expand Down Expand Up @@ -41,7 +42,13 @@ def get_context(self, request, *args, **kwargs):
# TODO: I could just define the filter in models.py
from .filters import LinkFilter

links_list = LinkPage.objects.descendant_of(self).live().order_by("title")
links_list = LinkPage.objects.descendant_of(self).live().order_by("title").prefetch_related(
Prefetch(
'categories',
queryset=LinkPageCategory.objects.select_related('link_category'),
to_attr='prefetched_categories'
)
)

queryset = links_list
link_page_filter = LinkFilter(request.GET, queryset=queryset)
Expand Down

0 comments on commit d101117

Please sign in to comment.