Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support entity profiles in more places #2003

Merged
merged 9 commits into from
Sep 6, 2024
2 changes: 1 addition & 1 deletion africanlii/templates/africanlii/au_institution_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% block entity-profile %}
{% with entity_profile=author.au_institution.entity_profile.first entity_profile_title=author.name %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% include 'peachjam/_entity_profile.html' %}
{% endif %}
{% endwith %}
{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion africanlii/templates/africanlii/au_organ_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{% block entity-profile %}
{% with entity_profile=author.au_organ.entity_profile.first entity_profile_title=author.name %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% include 'peachjam/_entity_profile.html' %}
{% endif %}
{% endwith %}
{% endblock %}
2 changes: 1 addition & 1 deletion africanlii/templates/africanlii/member_state_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% block entity-profile %}
{% with entity_profile=member_state.entity_profile.first entity_profile_title=member_state.name %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% include 'peachjam/_entity_profile.html' %}
{% endif %}
{% endwith %}
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% block entity-profile %}
{% with entity_profile=rec.entity_profile.first entity_profile_title=rec.name %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% include 'peachjam/_entity_profile.html' %}
{% endif %}
{% endwith %}
{% endblock %}
Expand Down
9 changes: 3 additions & 6 deletions liiweb/templates/liiweb/legislation_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
{% trans 'Legislation' %}
{% endblock %}
{% block page-title %}
<h1 class="my-4">{% trans 'Legislation' %}</h1>
{% if not entity_profile %}
<h1 class="my-4">{% trans 'Legislation' %}</h1>
{% endif %}
{% endblock %}
{% block alerts %}
{% if view.variant == 'repealed' %}
Expand Down Expand Up @@ -59,8 +61,3 @@ <h1 class="my-4">{% trans 'Legislation' %}</h1>
</li>
</nav>
{% endblock %}
{% block entity-profile %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% endif %}
{% endblock %}
32 changes: 14 additions & 18 deletions liiweb/views/legislation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
from django.views.generic import TemplateView

from peachjam.helpers import chunks, get_language
from peachjam.models import JurisdictionProfile, Legislation, Locality, pj_settings
from peachjam.views import FilteredDocumentListView
from peachjam.models import JurisdictionProfile, Locality, pj_settings
from peachjam.views import LegislationListView as BaseLegislationListView


class LegislationListView(FilteredDocumentListView):
class LegislationListView(BaseLegislationListView):
template_name = "liiweb/legislation_list.html"
variant = "current"
navbar_link = "legislation"
model = Legislation
queryset = Legislation.objects.prefetch_related("work", "labels")
latest_expression_only = True
form_defaults = None

Expand Down Expand Up @@ -58,36 +55,35 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
self.add_children(context["documents"])

site_jurisdictions = pj_settings().document_jurisdictions.all()
if site_jurisdictions.count() == 1:
jurisdiction_profile = JurisdictionProfile.objects.filter(
jurisdiction=site_jurisdictions.first()
).first()
if jurisdiction_profile:
context["entity_profile"] = jurisdiction_profile.entity_profile.first()
context["entity_profile_title"] = jurisdiction_profile.jurisdiction.name

context["doc_type"] = "Legislation" # for quick search
context["doc_table_toggle"] = True
context["doc_table_citations"] = True
context["doc_table_show_doc_type"] = False
context["doc_table_show_court"] = False
context["doc_table_show_author"] = False
context["doc_table_show_jurisdiction"] = False
context["help_link"] = "legislation/"

context["documents"] = self.group_documents(context["documents"])

return context

def add_entity_profile(self, context):
site_jurisdictions = pj_settings().document_jurisdictions.all()
if site_jurisdictions.count() == 1:
jurisdiction_profile = JurisdictionProfile.objects.filter(
jurisdiction=site_jurisdictions.first()
).first()
if jurisdiction_profile:
context["entity_profile"] = jurisdiction_profile.entity_profile.first()
context["entity_profile_title"] = jurisdiction_profile.jurisdiction.name

def add_children(self, queryset):
# pull in children (subleg)
parents = list(
{r.work_id for r in queryset.only("work_id", "polymorphic_ctype_id")}
)

children = defaultdict(list)
children_qs = Legislation.objects.filter(
children_qs = self.queryset.filter(
parent_work_id__in=parents, repealed=False, metadata_json__principal=True
).order_by("-date")
children_qs = children_qs.preferred_language(get_language(self.request))
Expand Down
20 changes: 20 additions & 0 deletions peachjam/migrations/0155_entityprofile_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.14 on 2024-09-05 08:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0154_backfill_nature_elasticsearch"),
]

operations = [
migrations.AddField(
model_name="entityprofile",
name="title",
field=models.CharField(
blank=True, max_length=1024, null=True, verbose_name="Title"
),
),
]
1 change: 1 addition & 0 deletions peachjam/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def entity_profile_photo_filename(instance, filename):


class EntityProfile(models.Model):
title = models.CharField(_("Title"), max_length=1024, null=True, blank=True)
about_html = models.TextField(_("about HTML"), null=True, blank=True)
website_url = models.URLField(_("website URL"), null=True, blank=True)
address = models.TextField(_("address"), null=True, blank=True)
Expand Down
9 changes: 4 additions & 5 deletions peachjam/static/stylesheets/_global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ footer {
}
}

.breadcrumb {
padding-top: 1rem;
margin-bottom: 0;
}

// xs btn
.btn.btn-xs {
@include button-size(0.125rem, 0.25rem, $btn-font-size-sm, $btn-border-radius-sm);
Expand Down Expand Up @@ -194,3 +189,7 @@ a:visited {
#skip-links a:focus {
top: -1px;
}

.breadcrumb {
padding-top: 1rem;
}
2 changes: 2 additions & 0 deletions peachjam/static/stylesheets/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ $visited-link: #1A77F2 !default;
--diff-green-color: #{$diff-green-color};
--diff-red-color: #{$diff-red-color};
}

$breadcrumb-margin-bottom: 1rem !default;
3 changes: 1 addition & 2 deletions peachjam/static/stylesheets/components/_entity-profile.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.entity-profile {
@extend .bg-light;

margin-top: -1rem;
margin-bottom: 1rem;

&.has-background-photo {
background-color: transparent !important;
Expand Down
2 changes: 1 addition & 1 deletion peachjam/templates/peachjam/_entity_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
loading="lazy"/>
{% endif %}
<div class="entity-profile__body__info">
<h1>{{ entity_profile_title }}</h1>
<h1>{{ entity_profile_title|default:entity_profile.title }}</h1>
{% if entity_profile.about_html %}<div class="mb-2">{{ entity_profile.about_html|safe }}</div>{% endif %}
<div class="row">
{% if entity_profile.address %}
Expand Down
4 changes: 3 additions & 1 deletion peachjam/templates/peachjam/author_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
{% load i18n %}
{% block title %}{{ author }}{% endblock %}
{% block page-title %}
<h1 class="mt-4">{% blocktrans %} Documents by {{ author }} {% endblocktrans %}</h1>
{% if not entity_profile %}
<h1 class="mt-4">{% blocktrans %} Documents by {{ author }} {% endblocktrans %}</h1>
{% endif %}
{% endblock %}
{% block entity-profile %}
{% with entity_profile_title=author entity_profile=author.entity_profile.first %}
Expand Down
9 changes: 2 additions & 7 deletions peachjam/templates/peachjam/court_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@
</nav>
</div>
{% endblock %}
{% block entity-profile %}
{% with entity_profile=court.entity_profile.first entity_profile_title=court.name %}
{% if entity_profile %}
<div class="mt-3">{% include 'peachjam/_entity_profile.html' %}</div>
{% endif %}
{% endwith %}
{% block page-title %}
{% if not entity_profile %}<h1 class="mt-4">{{ page_title }}</h1>{% endif %}
{% endblock %}
{% block page-title %}<h1 class="mt-4">{{ page_title }}</h1>{% endblock %}
{% block page-header %}
{{ block.super }}
{% block court_list %}
Expand Down
162 changes: 81 additions & 81 deletions peachjam/templates/peachjam/gazette_list.html
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
{% extends "peachjam/layouts/main.html" %}
{% extends "peachjam/layouts/document_list.html" %}
{% load i18n %}
{% block title %}
{{ place|default_if_none:"" }} {% trans 'Gazettes' %} {{ year }}
{% endblock %}
{% block page-content %}
<section class="pb-5">
<div class="container">
{% block breadcrumbs %}
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="{% url 'home_page' %}">{% trans 'Home' %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'gazettes' %}">{% trans 'Gazettes' %}</a>
</li>
{% if country %}
<li class="breadcrumb-item">
<a href="{% url 'gazettes_by_locality' country.pk.lower %}">{{ country }}</a>
</li>
{% endif %}
{% if locality %}
<li class="breadcrumb-item">
<a href="{% url 'gazettes_by_locality' locality.place_code %}">{{ locality }}</a>
</li>
{% endif %}
</ol>
</nav>
{% endblock %}
{% block page-title %}
<h1 class="my-4">
{% if place %}{{ place }}{% endif %}
{% trans 'Gazettes' %}
</h1>
{% endblock %}
{% block count-and-search %}
{% block localities %}
{% if localities %}
{% include 'peachjam/_gazette_localities.html' %}
{% endif %}
{% endblock %}
{% include 'peachjam/_count_and_search.html' %}
{% endblock %}
{% if doc_count %}
{% block years-list %}
<div class="row mt-5">
{% for year in years %}
<div class="col-md-4 col-sm-6 col-12 mb-5 mr-3">
<div class="card">
<div class="card-body">
<h2 class="text-center fw-bold">
{% block gazette-year-link %}
{% if locality %}
<a href="{% url 'gazettes_by_year' locality.place_code year.year %}">{{ year.year }}</a>
{% elif country %}
<a href="{% url 'gazettes_by_year' country.pk.lower year.year %}">{{ year.year }}</a>
{% else %}
<a href="{% url 'gazettes_by_year' year.year %}">{{ year.year }}</a>
{% endif %}
{% endblock %}
</h2>
<div class="text-center mb-3">
{% blocktrans trimmed count num_gazettes=year.count %}
{{ num_gazettes }} gazette
{% plural %}
{{ num_gazettes }} gazettes
{% endblocktrans %}
</div>
{% block monthly-chart %}
{% if locality %}
{% url 'gazettes_by_year' locality.place_code year.year as url %}
{% elif country %}
{% url 'gazettes_by_year' country.pk.lower year.year as url %}
{% else %}
{% url 'gazettes_by_year' year.year as url %}
{% endif %}
{% include 'peachjam/_monthly_column_chart.html' %}
{% endblock %}
</div>
{% block breadcrumbs %}
<div class="container">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="{% url 'home_page' %}">{% trans 'Home' %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'gazettes' %}">{% trans 'Gazettes' %}</a>
</li>
{% if country %}
<li class="breadcrumb-item">
<a href="{% url 'gazettes_by_locality' country.pk.lower %}">{{ country }}</a>
</li>
{% endif %}
{% if locality %}
<li class="breadcrumb-item">
<a href="{% url 'gazettes_by_locality' locality.place_code %}">{{ locality }}</a>
</li>
{% endif %}
</ol>
</nav>
</div>
{% endblock %}
{% block page-title %}
{% if not entity_profile %}
<h1 class="my-4">
{% if place %}{{ place }}{% endif %}
{% trans 'Gazettes' %}
</h1>
{% endif %}
{% endblock %}
{% block count-and-search %}
{% block localities %}
{% if localities %}
{% include 'peachjam/_gazette_localities.html' %}
{% endif %}
{% endblock %}
{% include 'peachjam/_count_and_search.html' %}
{% endblock %}
{% block document-table %}
{% if doc_count %}
{% block years-list %}
<div class="row mt-5">
{% for year in years %}
<div class="col-md-4 col-sm-6 col-12 mb-5 mr-3">
<div class="card">
<div class="card-body">
<h2 class="text-center fw-bold">
{% block gazette-year-link %}
{% if locality %}
<a href="{% url 'gazettes_by_year' locality.place_code year.year %}">{{ year.year }}</a>
{% elif country %}
<a href="{% url 'gazettes_by_year' country.pk.lower year.year %}">{{ year.year }}</a>
{% else %}
<a href="{% url 'gazettes_by_year' year.year %}">{{ year.year }}</a>
{% endif %}
{% endblock %}
</h2>
<div class="text-center mb-3">
{% blocktrans trimmed count num_gazettes=year.count %}
{{ num_gazettes }} gazette
{% plural %}
{{ num_gazettes }} gazettes
{% endblocktrans %}
</div>
{% block monthly-chart %}
{% if locality %}
{% url 'gazettes_by_year' locality.place_code year.year as url %}
{% elif country %}
{% url 'gazettes_by_year' country.pk.lower year.year as url %}
{% else %}
{% url 'gazettes_by_year' year.year as url %}
{% endif %}
{% include 'peachjam/_monthly_column_chart.html' %}
{% endblock %}
</div>
{% endfor %}
</div>
</div>
{% endblock %}
{% endif %}
</div>
</section>
{% endfor %}
</div>
{% endblock %}
{% endif %}
{% endblock %}
Loading
Loading