diff --git a/africanlii/constants.py b/africanlii/constants.py new file mode 100644 index 000000000..8e01c692b --- /dev/null +++ b/africanlii/constants.py @@ -0,0 +1,100 @@ +LIIS = [ + { + "name": "EswatiniLII", + "country": "Eswatini", + "url": "https://eswatinilii.org", + "logo": "images/liis/eswatinilii.png", + "domain": "eswatinilii.org", + }, + { + "name": "GhaLII", + "country": "Ghana", + "url": "https://ghalii.org", + "logo": "images/liis/ghalii.png", + "domain": "ghalii.org", + }, + { + "name": "Kenya Law", + "country": "Kenya", + "url": "http://kenyalaw.org", + "logo": "images/liis/kenyalaw.png", + "domain": "kenyalaw.org", + }, + { + "name": "LesothoLII", + "country": "Lesotho", + "url": "https://lesotholii.org", + "logo": "images/liis/lesotholii.png", + "domain": "lesotholii.org", + }, + { + "name": "MalawiLII", + "country": "Malawi", + "url": "https://malawilii.org", + "logo": "images/liis/malawilii.png", + "domain": "malawilii.org", + }, + { + "name": "NamibLII", + "country": "Namibia", + "url": "https://namiblii.org", + "logo": "images/liis/namiblii.png", + "domain": "namiblii.org", + }, + { + "name": "SierraLII", + "country": "Sierra Leone", + "url": "https://sierralii.org", + "logo": "images/liis/sierralii.png", + "domain": "sierralii.org", + }, + { + "name": "SeyLII", + "country": "Seychelles", + "url": "https://seylii.org", + "logo": "images/liis/seylii.png", + "domain": "seylii.org", + }, + { + "name": "LawLibrary", + "country": "South Africa", + "url": "https://lawlibrary.org.za", + "logo": "images/liis/lawlibrary.png", + "domain": "lawlibrary.org.za", + }, + { + "name": "TanzLII", + "country": "Tanzania", + "url": "https://tanzlii.org", + "logo": "images/liis/tanzlii.png", + "domain": "tanzlii.org", + }, + { + "name": "ULII", + "country": "Uganda", + "url": "https://ulii.org", + "logo": "images/liis/ulii.png", + "domain": "ulii.org", + }, + { + "name": "ZambiaLII", + "country": "Zambia", + "url": "https://zambialii.org", + "logo": "images/liis/zambialii.png", + "domain": "zambialii.org", + }, + { + "name": "ZanzibarLII", + "country": "Zanzibar", + "url": "https://zanzibarlii.org", + "logo": "images/liis/zanzibarlii.png", + "domain": "zanzibarlii.org", + }, + { + "name": "ZimLII", + "country": "Zimbabwe", + "url": "https://zimlii.org", + "logo": "images/liis/zimlii.png", + "domain": "zimlii.org", + }, +] diff --git a/africanlii/templates/africanlii/_lii_info.html b/africanlii/templates/africanlii/_lii_info.html new file mode 100644 index 000000000..f7fc74e38 --- /dev/null +++ b/africanlii/templates/africanlii/_lii_info.html @@ -0,0 +1,13 @@ +{% load i18n %} +{% for lii in liis %} + {% if lii.country == member_state.country.name %} +
+ {% blocktrans trimmed with lii_name=lii.name %} + Visit {{ lii_name }} for more legal information. + {% endblocktrans %} +
+
+ {{ lii.domain }} +
+ {% endif %} +{% endfor %} diff --git a/africanlii/templates/africanlii/au_detail_page.html b/africanlii/templates/africanlii/au_detail_page.html index 0b64ae91e..27b6cb064 100644 --- a/africanlii/templates/africanlii/au_detail_page.html +++ b/africanlii/templates/africanlii/au_detail_page.html @@ -1,5 +1,5 @@ {% extends "peachjam/layouts/main.html" %} -{% load i18n %} +{% load static i18n %} {% block title %} {% trans 'African Union (AU)' %} {% endblock %} @@ -75,16 +75,23 @@

{% trans 'African Union
-
-

{% trans 'Member States' %}

- -
+

{% trans 'Member States' %}

+ {% for member_state in member_states %} +
+
+
+ {{ member_state.name }} +
+ {{ member_state.country }} +
+ {% include 'africanlii/_lii_info.html' %} +
+
+
+ {% endfor %}
{% endblock %} diff --git a/africanlii/templates/africanlii/member_state_detail.html b/africanlii/templates/africanlii/member_state_detail.html index d7208b13c..6f0c99c6a 100644 --- a/africanlii/templates/africanlii/member_state_detail.html +++ b/africanlii/templates/africanlii/member_state_detail.html @@ -27,6 +27,7 @@ {% endblock %} {% block page-header %}

{{ member_state }}

+ {% include 'africanlii/_lii_info.html' %} {% include 'peachjam/_document_count.html' %} {% endblock %} {% block page-list-facets %}{% endblock %} diff --git a/africanlii/views/au.py b/africanlii/views/au.py index cc894e2bd..3947f569e 100644 --- a/africanlii/views/au.py +++ b/africanlii/views/au.py @@ -1,6 +1,7 @@ from django.shortcuts import get_object_or_404 from django.views.generic import DetailView, TemplateView +from africanlii.constants import LIIS from africanlii.models import ( AfricanUnionInstitution, AfricanUnionOrgan, @@ -27,6 +28,7 @@ def get_context_data(self, **kwargs): context["au_institutions"] = AfricanUnionInstitution.objects.prefetch_related( "author" ) + context["liis"] = LIIS return context @@ -67,5 +69,6 @@ def get_context_data(self, **kwargs): country=self.get_object().country ) context["doc_count"] = ratification_countries.count() + context["liis"] = LIIS return context diff --git a/africanlii/views/home.py b/africanlii/views/home.py index 0dca03faa..1aed87825 100644 --- a/africanlii/views/home.py +++ b/africanlii/views/home.py @@ -1,5 +1,6 @@ from django.utils.translation import get_language_from_request +from africanlii.constants import LIIS from africanlii.models import ( AfricanUnionInstitution, AfricanUnionOrgan, @@ -39,94 +40,7 @@ def get_context_data(self, **kwargs): context["taxonomies"] = Taxonomy.get_tree() context["court_classes"] = CourtClass.objects.prefetch_related("courts") - context["liis"] = [ - { - "name": "EswatiniLII", - "country": "Eswatini", - "url": "https://eswatinilii.org", - "logo": "images/liis/eswatinilii.png", - }, - { - "name": "GhaLII", - "country": "Ghana", - "url": "https://ghalii.org", - "logo": "images/liis/ghalii.png", - }, - { - "name": "Kenya Law", - "country": "Kenya", - "url": "http://kenyalaw.org", - "logo": "images/liis/kenyalaw.png", - }, - { - "name": "LesothoLII", - "country": "Lesotho", - "url": "https://lesotholii.org", - "logo": "images/liis/lesotholii.png", - }, - { - "name": "MalawiLII", - "country": "Malawi", - "url": "https://malawilii.org", - "logo": "images/liis/malawilii.png", - }, - { - "name": "NamibLII", - "country": "Namibia", - "url": "https://namiblii.org", - "logo": "images/liis/namiblii.png", - }, - { - "name": "SierraLII", - "country": "Sierra Leone", - "url": "https://sierralii.org", - "logo": "images/liis/sierralii.png", - }, - { - "name": "SeyLII", - "country": "Seychelles", - "url": "https://seylii.org", - "logo": "images/liis/seylii.png", - }, - { - "name": "LawLibrary", - "country": "South Africa", - "url": "https://lawlibrary.org.za", - "logo": "images/liis/lawlibrary.png", - }, - { - "name": "TanzLII", - "country": "Tanzania", - "url": "https://tanzlii.org", - "logo": "images/liis/tanzlii.png", - }, - { - "name": "ULII", - "country": "Uganda", - "url": "https://ulii.org", - "logo": "images/liis/ulii.png", - }, - { - "name": "ZambiaLII", - "country": "Zambia", - "url": "https://zambialii.org", - "logo": "images/liis/zambialii.png", - }, - { - "name": "ZanzibarLII", - "country": "Zanzibar", - "url": "https://zanzibarlii.org", - "logo": "images/liis/zanzibarlii.png", - }, - { - "name": "ZimLII", - "country": "Zimbabwe", - "url": "https://zimlii.org", - "logo": "images/liis/zimlii.png", - }, - ] - for lii in context["liis"]: - lii["domain"] = lii["url"].split("/", 3)[2] + context["liis"] = LIIS # check user's preferred language current_language = get_language_from_request(self.request) diff --git a/peachjam/helpers.py b/peachjam/helpers.py index d4acb1234..7b3679349 100644 --- a/peachjam/helpers.py +++ b/peachjam/helpers.py @@ -33,8 +33,11 @@ def _wrapped_view(request, *args, **kwargs): def get_language(request): """Get language from the request object and return its 3-letter language code.""" - language = get_language_from_request(request) - return Language.objects.get(iso_639_1__iexact=language).iso_639_3 + if not hasattr(request, "language"): + language = get_language_from_request(request) + # store it on the request object because it won't change + request.language = Language.objects.get(iso_639_1__iexact=language).iso_639_3 + return request.language def pdfjs_to_text(fname): diff --git a/peachjam/migrations/0095_api_perms.py b/peachjam/migrations/0095_api_perms.py new file mode 100644 index 000000000..a6158d6c1 --- /dev/null +++ b/peachjam/migrations/0095_api_perms.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.20 on 2023-08-03 14:17 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("peachjam", "0094_alter_judge_options"), + ] + + operations = [ + migrations.AlterModelOptions( + name="gazette", + options={ + "base_manager_name": "objects", + "permissions": [("api_gazette", "API gazette access")], + "verbose_name": "gazette", + "verbose_name_plural": "gazettes", + }, + ), + migrations.AlterModelOptions( + name="judgment", + options={ + "base_manager_name": "objects", + "ordering": ["title"], + "permissions": [("api_judgment", "API judgment access")], + "verbose_name": "judgment", + "verbose_name_plural": "judgments", + }, + ), + ] diff --git a/peachjam/settings.py b/peachjam/settings.py index 6f7ad0e3d..f35b0603b 100644 --- a/peachjam/settings.py +++ b/peachjam/settings.py @@ -493,6 +493,8 @@ SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies" SESSION_COOKIE_SECURE = True +# nginx sets this header to indicate if the upstream request was secure +SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") # Caches if DEBUG: diff --git a/peachjam/templates/peachjam/_judgment_table.html b/peachjam/templates/peachjam/_judgment_table.html index 9b9ddfbb5..182769c48 100644 --- a/peachjam/templates/peachjam/_judgment_table.html +++ b/peachjam/templates/peachjam/_judgment_table.html @@ -4,7 +4,6 @@ {% trans 'Title' %} - {% trans 'Judges' %} {% trans 'Date' %} @@ -13,8 +12,8 @@ {{ document.title }} + {% include 'peachjam/_labels.html' with labels=document.labels.all %} - {{ document.judges_string }} {{ document.date }} {% endfor %} diff --git a/peachjam/templates/peachjam/layouts/document_detail.html b/peachjam/templates/peachjam/layouts/document_detail.html index 73e139349..2d211bd65 100644 --- a/peachjam/templates/peachjam/layouts/document_detail.html +++ b/peachjam/templates/peachjam/layouts/document_detail.html @@ -30,8 +30,10 @@ {% block breadcrumbs %}{% endblock %} {% block document-title %}
-

{{ document.title }}

- {% include 'peachjam/_labels.html' %} +
+

{{ document.title }}

+ {% include 'peachjam/_labels.html' %} +
{{ document.title }}
{% for bench in judges %} - {{ bench.judge.name }} - {% if not forloop.last %},{% endif %} + {# djlint:off #} + {{ bench.judge.name }}{% if not forloop.last %},{% endif %} + {# djlint:on #} {% endfor %}
{% endif %} diff --git a/peachjam/views/courts.py b/peachjam/views/courts.py index bf5903a19..16b0eb81d 100644 --- a/peachjam/views/courts.py +++ b/peachjam/views/courts.py @@ -15,7 +15,7 @@ class CourtDetailView(FilteredDocumentListView): model = Judgment template_name = "peachjam/court_detail.html" navbar_link = "judgments" - queryset = Judgment.objects.prefetch_related("judges") + queryset = Judgment.objects.prefetch_related("labels") def get_base_queryset(self): qs = super().get_base_queryset().filter(court=self.court) diff --git a/peachjam_api/urls_public.py b/peachjam_api/urls_public.py index 1d2bb4e55..411279c54 100644 --- a/peachjam_api/urls_public.py +++ b/peachjam_api/urls_public.py @@ -17,5 +17,5 @@ urlpatterns = [ # public-facing API - path("v1/", include(router.urls)), + path("", include(router.urls)), ] diff --git a/pyproject.toml b/pyproject.toml index b43b0541d..68acc5322 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ dependencies = [ "django-ckeditor>=6.4.2", "django-compressor>=3.1", "django-countries-plus>=1.3.2", - "django-debug-toolbar>=3.2.4", + "django-debug-toolbar>=3.2.4,<4.2.0", "django-elasticsearch-debug-toolbar>=3.0.2", "django-elasticsearch-dsl>=7.2.2", "django-elasticsearch-dsl-drf>=0.22.4",