Skip to content

Commit

Permalink
Merge branch 'main' of github.com:laws-africa/peachjam
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmwangemi committed Aug 11, 2023
2 parents 0be59ce + 2733077 commit 7ed2608
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 110 deletions.
100 changes: 100 additions & 0 deletions africanlii/constants.py
Original file line number Diff line number Diff line change
@@ -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",
},
]
13 changes: 13 additions & 0 deletions africanlii/templates/africanlii/_lii_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% load i18n %}
{% for lii in liis %}
{% if lii.country == member_state.country.name %}
<div>
{% blocktrans trimmed with lii_name=lii.name %}
Visit {{ lii_name }} for more legal information.
{% endblocktrans %}
</div>
<div>
<a href="{{ lii.url }}" target="_blank">{{ lii.domain }}</a>
</div>
{% endif %}
{% endfor %}
29 changes: 18 additions & 11 deletions africanlii/templates/africanlii/au_detail_page.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "peachjam/layouts/main.html" %}
{% load i18n %}
{% load static i18n %}
{% block title %}
{% trans 'African Union (AU)' %}
{% endblock %}
Expand Down Expand Up @@ -75,16 +75,23 @@ <h3 class="mb-4 heading-underlined" id="au-institutions">{% trans 'African Union
</section>
<section class="container">
<div class="row">
<div class="col-sm-12">
<h3 class="mb-4 heading-underlined" id="member-states">{% trans 'Member States' %}</h3>
<ul class="list-unstyled">
{% for member_state in member_states %}
<li>
<a href="{% url 'member_state_detail_view' member_state.country.iso %}">{{ member_state.country }}</a>
</li>
{% endfor %}
</ul>
</div>
<h3 class="mb-4 heading-underlined" id="member-states">{% trans 'Member States' %}</h3>
{% for member_state in member_states %}
<div class="col-6 col-md-4 col-lg-3">
<div class="card lii-card mb-3">
<div class="card-body">
<img src="{% static 'lib/flag-icons/flags/4x3/'|add:member_state.country.iso|lower|add:".svg" %}"
alt="{{ member_state.name }}"
class="mb-3"/>
<h5 class="card-title">
<a href="{% url 'member_state_detail_view' member_state.country.iso %}"
target="_blank">{{ member_state.country }}</a>
</h5>
{% include 'africanlii/_lii_info.html' %}
</div>
</div>
</div>
{% endfor %}
</div>
</section>
{% endblock %}
1 change: 1 addition & 0 deletions africanlii/templates/africanlii/member_state_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{% endblock %}
{% block page-header %}
<h1 class="mt-4">{{ member_state }}</h1>
{% include 'africanlii/_lii_info.html' %}
{% include 'peachjam/_document_count.html' %}
{% endblock %}
{% block page-list-facets %}{% endblock %}
Expand Down
3 changes: 3 additions & 0 deletions africanlii/views/au.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -27,6 +28,7 @@ def get_context_data(self, **kwargs):
context["au_institutions"] = AfricanUnionInstitution.objects.prefetch_related(
"author"
)
context["liis"] = LIIS
return context


Expand Down Expand Up @@ -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
90 changes: 2 additions & 88 deletions africanlii/views/home.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.utils.translation import get_language_from_request

from africanlii.constants import LIIS
from africanlii.models import (
AfricanUnionInstitution,
AfricanUnionOrgan,
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions peachjam/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
32 changes: 32 additions & 0 deletions peachjam/migrations/0095_api_perms.py
Original file line number Diff line number Diff line change
@@ -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",
},
),
]
2 changes: 2 additions & 0 deletions peachjam/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions peachjam/templates/peachjam/_judgment_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<thead>
<tr>
<th scope="col" style="width: 70%">{% trans 'Title' %}</th>
<th scope="col">{% trans 'Judges' %}</th>
<th scope="col">{% trans 'Date' %}</th>
</tr>
</thead>
Expand All @@ -13,8 +12,8 @@
<tr>
<td>
<a href="{{ document.get_absolute_url }}">{{ document.title }}</a>
{% include 'peachjam/_labels.html' with labels=document.labels.all %}
</td>
<td>{{ document.judges_string }}</td>
<td style="white-space: nowrap;">{{ document.date }}</td>
</tr>
{% endfor %}
Expand Down
11 changes: 7 additions & 4 deletions peachjam/templates/peachjam/layouts/document_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
{% block breadcrumbs %}{% endblock %}
{% block document-title %}
<div class="d-md-flex justify-content-md-between py-4">
<h1>{{ document.title }}</h1>
{% include 'peachjam/_labels.html' %}
<div>
<h1>{{ document.title }}</h1>
{% include 'peachjam/_labels.html' %}
</div>
<div class="d-flex align-items-center">
<a href="https://api.whatsapp.com/send?text={{ request.build_absolute_uri }}"
class="btn btn-link"
Expand Down Expand Up @@ -213,8 +215,9 @@ <h1>{{ document.title }}</h1>
</dt>
<dd class="text-muted">
{% 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 %}
</dd>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion peachjam/views/courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 7ed2608

Please sign in to comment.