Skip to content

Commit

Permalink
Merge pull request #141 from springload/fix/various-fixes
Browse files Browse the repository at this point in the history
Fixes from content-loading issues document
  • Loading branch information
haydngreatnews authored Jul 22, 2024
2 parents ba45cda + 39fe271 commit f392b27
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 35 deletions.
2 changes: 2 additions & 0 deletions cdhweb/pages/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from wagtail.models import Page, Site
from wagtail_factories import ImageFactory

from cdhweb.pages.models import ContentPage, ExternalAttachment, HomePage, LandingPage
from cdhweb.pages.views import LastModifiedListMixin, LastModifiedMixin
Expand All @@ -34,6 +35,7 @@ def make_homepage(site):
body=json.dumps(
[{"type": "paragraph", "value": "<p>content of the home page</p>"}]
),
hero_image=ImageFactory(),
)
root.add_child(instance=home)
root.save()
Expand Down
23 changes: 10 additions & 13 deletions cdhweb/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,26 +560,23 @@ class Profile(BasePage):
content_panels = Page.content_panels + [
FieldRowPanel((FieldPanel("person"), FieldPanel("image")), "Person"),
FieldPanel("education"),
FieldPanel("tags"),
FieldPanel("body"),
FieldPanel("attachments"),
]

parent_page_types = ["people.PeopleLandingPageArchived", "people.PeopleLandingPage"]
subpage_types = []

promote_panels = (
[
MultiFieldPanel(
[
FieldPanel("short_title"),
FieldPanel("feed_image"),
],
"Share Page",
),
]
+ BasePage.promote_panels
+ [FieldPanel("tags")]
)
promote_panels = [
MultiFieldPanel(
[
FieldPanel("short_title"),
FieldPanel("feed_image"),
],
"Share Page",
),
] + BasePage.promote_panels

# index fields
search_fields = BasePage.search_fields + [index.SearchField("education")]
Expand Down
9 changes: 8 additions & 1 deletion cdhweb/people/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from wagtail_modeladmin.mixins import ThumbnailMixin
from wagtail_modeladmin.options import ModelAdmin, ModelAdminGroup, modeladmin_register

from cdhweb.pages.models import RelatedLinkType
from cdhweb.people.models import Person, Profile, Title


Expand Down Expand Up @@ -52,11 +53,17 @@ class ProfileAdmin(ThumbnailMixin, ModelAdmin):
thumb_image_field_name = "image"


class LinkTypeAdmin(ModelAdmin):
model = RelatedLinkType
menu_icon = "link"
list_display = ("name", "sort_order")


class PeopleGroup(ModelAdminGroup):
menu_label = "People"
menu_icon = "group"
menu_order = 200
items = (PersonAdmin, TitleAdmin, ProfileAdmin)
items = (PersonAdmin, TitleAdmin, ProfileAdmin, LinkTypeAdmin)


modeladmin_register(PeopleGroup)
6 changes: 3 additions & 3 deletions cdhweb/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ class ProjectFiltersForm(forms.Form):
empty_label="--Select--",
required=False,
blank=True,
label="Method/Approach"
label="Method/Approach",
)
field = forms.ModelChoiceField(
ProjectField.objects.all(),
empty_label="--Select--",
required=False,
blank=True,
label="Field of Study"
label="Field of Study",
)
role = forms.ModelChoiceField(
ProjectRole.objects.all(),
empty_label="--Select--",
required=False,
blank=True,
label="Role"
label="Role",
)
current = forms.BooleanField(required=False, initial=True)
cdh_built = forms.BooleanField(required=False, label="Built by CDH")
20 changes: 20 additions & 0 deletions cdhweb/projects/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import itertools

from django import forms
from django.db import models
from django.utils import timezone
Expand Down Expand Up @@ -279,6 +281,24 @@ def get_sitemap_urls(self, request):
urls[0]["priority"] = 0.6
return urls

def display_tags(self):
"""
Get role, method and field values as tag-y objects
The method/field/role fields are used for filtering
the projects in the search, but CDH have also
requested that they be shown the same way tags are
for many other types of object -- This function
delivers them in a (template-equivalent) manner so
they can be displayed
"""
return sorted(
str(t)
for t in itertools.chain(
self.method.all(), self.field.all(), self.role.all()
)
)


class GrantType(models.Model):
"""Model to track kinds of grants"""
Expand Down
5 changes: 2 additions & 3 deletions cdhweb/projects/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from django.utils import timezone
from wagtail_factories import ImageFactory

from cdhweb.people.models import Person
from cdhweb.projects.models import (
Expand Down Expand Up @@ -34,9 +35,7 @@ def add_project_member(project, role, start_date=None, end_date=None, **person_o

def make_projects_landing_page(homepage):
"""create a test projects landing page underneath the homepage"""
plp = ProjectsLandingPageArchived(
title="projects", slug="projects", tagline="let's do some stuff"
)
plp = ProjectsLandingPageArchived(title="projects", slug="projects")
homepage.add_child(instance=plp)
homepage.save()
return plp
Expand Down
42 changes: 41 additions & 1 deletion cdhweb/projects/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from datetime import datetime, timedelta

from cdhweb.pages.models import RelatedLinkType
from cdhweb.projects.models import GrantType, Project, ProjectRelatedLink, Role
from cdhweb.projects.models import (
GrantType,
Project,
ProjectField,
ProjectMethod,
ProjectRelatedLink,
ProjectRole,
Role,
)


class TestGrantType:
Expand Down Expand Up @@ -140,3 +148,35 @@ def test_display_url(self, derrida):
# https
res.url = "https://%s" % base_url
assert res.display_url == base_url


class TestProjectDisplayTags:
def test_no_values(self, derrida):
assert derrida.display_tags() == []

def test_just_role(self, derrida):
role = ProjectRole(role="test role")
role.save()
derrida.role.add(role)
assert derrida.display_tags() == ["test role"]

def test_all_relations(self, derrida):
role1 = ProjectRole(role="test role 1")
role2 = ProjectRole(role="test role 2")
method = ProjectMethod(method="test method")
field = ProjectField(field="test field")
role1.save()
role2.save()
method.save()
field.save()

derrida.role.add(role1)
derrida.role.add(role2)
derrida.method.add(method)
derrida.field.add(field)
assert derrida.display_tags() == [
"test field",
"test method",
"test role 1",
"test role 2",
]
3 changes: 1 addition & 2 deletions docker/application/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ RUN --mount=type=cache,target=/var/lib/apt/lists \
netcat

RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install -r /app/requirements/dev.txt \
npm install
pip3 install -r /app/requirements/dev.txt

# No COPY here as the local directory is volume-mounted in docker-compose

Expand Down
3 changes: 2 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ wheel
# fix issue with taggit fields: https://github.com/makecodes/django-dbml/pull/4
django-dbml
#git+https://github.com/thatbudakguy/django-dbml@patch-1#egg=django-dbml
percy-selenium
percy-selenium
wagtail-factories~=4.2.1
10 changes: 6 additions & 4 deletions templates/includes/person_hero.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
{% load wagtailcore_tags wagtailimages_tags l10n %}

<div class="person-hero content-width grid-standard">

<div class="person-hero__intro">
<h1>{{ self.title}}</h1>
<p class="person-hero__job">{{ person.current_title }}</p>
{% if person.current_title %}
<p class="person-hero__job">{{ person.current_title }}</p>
{% endif %}
<div class="person-hero__education">{{ page.education|richtext }}</div>
{% if self.tags.all %}
<div class="tag-list">
{% for tag in self.tags.all %}
<div class="tag">{{ tag }}</div>
<div class="tag">{{ tag }}</div>
{% endfor %}
</div>
{% endif %}
</div>

{% if person.email or person.phone_number or person.office_location %}
<div class="person-hero__contact">
<ul class="person-hero__contact-links">
Expand Down
14 changes: 7 additions & 7 deletions templates/includes/project_hero.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load wagtailcore_tags wagtailimages_tags l10n %}

<div class="project-hero content-width grid-standard">

<div class="project-hero__title">
<h1>{{ self.title}}</h1>
{% if page.cdh_built %}<div class="tag tag--dark">Built by CDH</div>{% endif %}
Expand All @@ -11,10 +11,10 @@ <h1>{{ self.title}}</h1>
{{ self.description | richtext }}
{% endif %}

{% if self.tags.all %}
{% if self.display_tags %}
<div class="tag-list">
{% for tag in self.tags.all %}
<div class="tag">{{ tag }}</div>
{% for tag in self.display_tags %}
<div class="tag">{{ tag }}</div>
{% endfor %}
</div>
{% endif %}
Expand All @@ -28,7 +28,7 @@ <h1>{{ self.title}}</h1>
</div>

{% if self.hero_image %}
{% comment %}
{% comment %}
All are cropped to a 16:9 ratio. This differs from design, as discussed.
If changing this by image rendition, update aspect-ratio in the CSS instead
of via inline style.
Expand All @@ -42,11 +42,11 @@ <h1>{{ self.title}}</h1>
<source srcset="{{ img_sm.url }}" media="(min-width: 500px)">
<source srcset="{{ img_xl.url }}" media="(min-width: 1200px)">
<img
src="{{ img_base.url }}"
src="{{ img_base.url }}"
alt="{{ self.alt_text|default:img_base.alt }}"
style="aspect-ratio: {{ img_base.width|unlocalize }} / {{ img_base.height|unlocalize }}"
/>
</picture>
{% endif %}

</div>

0 comments on commit f392b27

Please sign in to comment.