Skip to content

Commit

Permalink
Merge branch 'main' into document-media
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmwangemi committed Jan 22, 2024
2 parents dfdb4dc + f2d9599 commit d595fb1
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 144 deletions.
4 changes: 4 additions & 0 deletions peachjam/adapters/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def get_doc_list(self):
while url:
res = self.client_get(url).json()

# ignore bills
# TODO: later, make this configurable
res["results"] = [r for r in res["results"] if r["nature"] != "bill"]

# Filter by actor, if setting is present
actor = self.settings.get("actor", None)
if actor:
Expand Down
4 changes: 2 additions & 2 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,14 +731,14 @@ class JudgmentAdmin(ImportExportMixin, DocumentAdmin):
CaseNumberAdmin,
JudgmentRelationshipStackedInline,
] + DocumentAdmin.inlines
filter_horizontal = ("judges", "attorneys")
filter_horizontal = ("judges", "attorneys", "order_outcomes")
list_filter = (*DocumentAdmin.list_filter, "court")
fieldsets = copy.deepcopy(DocumentAdmin.fieldsets)

fieldsets[0][1]["fields"].insert(3, "court")
fieldsets[0][1]["fields"].insert(4, "registry")
fieldsets[0][1]["fields"].insert(5, "case_name")
fieldsets[0][1]["fields"].insert(6, "order_outcome")
fieldsets[0][1]["fields"].insert(6, "order_outcomes")
fieldsets[0][1]["fields"].insert(7, "mnc")
fieldsets[0][1]["fields"].insert(8, "serial_number_override")
fieldsets[0][1]["fields"].insert(9, "serial_number")
Expand Down
4 changes: 3 additions & 1 deletion peachjam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ def filter_queryset(self, queryset, exclude=None):
queryset = queryset.filter(attorneys__name__in=attorneys)

if order_outcomes and exclude != "order_outcomes":
queryset = queryset.filter(order_outcome__name__in=order_outcomes)
queryset = queryset.filter(
order_outcomes__name__in=order_outcomes
).distinct()

return queryset

Expand Down
5 changes: 1 addition & 4 deletions peachjam/models/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,8 @@ class Judgment(CoreDocument):
attorneys = models.ManyToManyField(
Attorney, blank=True, verbose_name=_("attorneys")
)
order_outcome = models.ForeignKey(
order_outcomes = models.ManyToManyField(
OrderOutcome,
on_delete=models.PROTECT,
null=True,
related_name="judgments",
blank=True,
)
case_summary = models.TextField(_("case summary"), null=True, blank=True)
Expand Down
114 changes: 114 additions & 0 deletions peachjam/resolver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from django.conf import settings


class RedirectResolver:
RESOLVER_MAPPINGS = {
"africanlii": {
"country_code": "aa",
"domain": "africanlii.org",
},
"eswatinilii": {
"country_code": "sz",
"domain": "eswatinilii.org",
},
"ghalii": {
"country_code": "gh",
"domain": "ghalii.org",
},
"lawlibrary": {
"country_code": "za",
"domain": "lawlibrary.org.za",
},
"leslii": {
"country_code": "ls",
"domain": "lesotholii.org",
},
"malawilii": {
"country_code": "mw",
"domain": "malawilii.org",
},
"mauritiuslii": {
"country_code": "mu",
"domain": "mauritiuslii.org",
},
"namiblii": {
"country_code": "na",
"domain": "namiblii.org",
},
"nigerialii": {
"country_code": "ng",
"domain": "nigerialii.org",
},
"open by-laws": {
"place_code": [],
"domain": "openbylaws.org.za",
},
"rwandalii": {
"country_code": "rw",
"domain": "rwandalii.org",
},
"seylii": {
"country_code": "sc",
"domain": "seylii.org",
},
"sierralii": {
"country_code": "sl",
"domain": "sierralii.org",
},
"tanzlii": {
"country_code": "tz",
"domain": "tanzlii.org",
},
"tcilii": {
"country_code": "tc",
"domain": "tcilii.org",
},
"ulii": {
"country_code": "ug",
"domain": "ulii.org",
},
"zambialii": {
"country_code": "zm",
"domain": "zambialii.org",
},
"zanzibarlii": {
"place_code": "tz-znz",
"domain": "zanzibarlii.org",
},
"zimlii": {
"country_code": "zw",
"domain": "zimlii.org",
},
}

def __init__(self, app_name):
self.current_authority = self.RESOLVER_MAPPINGS.get(app_name.lower())

def get_domain_for_frbr_uri(self, parsed_frbr_uri):
best_domain = self.get_best_domain(parsed_frbr_uri)
if self.current_authority and best_domain != self.current_authority["domain"]:
return best_domain
return None

def get_url_for_frbr_uri(self, parsed_frbr_uri, raw_frbr_uri):
domain = self.get_domain_for_frbr_uri(parsed_frbr_uri)
if domain:
return f"https://{domain}{raw_frbr_uri}"

def get_best_domain(self, parsed_uri):
country_code = parsed_uri.country
place_code = parsed_uri.place

if country_code != place_code:
for key, mapping in self.RESOLVER_MAPPINGS.items():
if mapping.get("place_code") == place_code:
return mapping.get("domain")

# if no domain matching with place code is found use country code
for key, mapping in self.RESOLVER_MAPPINGS.items():
if mapping.get("country_code") == country_code:
return mapping.get("domain")
return None


resolver = RedirectResolver(settings.PEACHJAM["APP_NAME"])
6 changes: 6 additions & 0 deletions peachjam/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"drf_spectacular",
"django_advanced_password_validation",
"martor",
"corsheaders",
]

MIDDLEWARE = [
Expand All @@ -87,6 +88,7 @@
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
Expand Down Expand Up @@ -607,3 +609,7 @@ def before_send(event, hint):
}
# disable the normal martor theme which pulls in another bootstrap version
MARTOR_ALTERNATIVE_CSS_FILE_THEME = "martor/css/peachjam.css"

# CORS
# disable regex matches, we do matching using signals
CORS_URLS_REGEX = r"^$"
14 changes: 11 additions & 3 deletions peachjam/templates/peachjam/document_popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</la-akoma-ntoso>
{% endblock %}
{% else %}
<div class="mb-2">
<div>
<div>
{% block title %}
<b>{{ document.title }}</b>
Expand All @@ -19,13 +19,21 @@
{% endblock %}
</div>
{% block citation %}
{% if document.citation %}
{% if document.citation and document.citation != document.title %}
<div>
<i>{{ document.citation }}</i>
</div>
{% endif %}
{% endblock %}
{% block date %}<div>{{ document.date }}</div>{% endblock %}
</div>
{% block date %}<div>{{ document.date }}</div>{% endblock %}
{% block offsite_request %}
{% if offsite_request %}
<div class="mt-2">
<a href="https://{{ request.get_host }}{{ document.expression_frbr_uri }}"
target="_blank">{{ APP_NAME }}</a>
</div>
{% endif %}
{% endblock %}
{% endif %}
</div>
21 changes: 13 additions & 8 deletions peachjam/templates/peachjam/judgment_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@
<a href="{% url 'court_registry' document.court.code document.registry.code %}">{{ document.registry.name }}</a>
</dd>
{% endif %}
{% if document.order_outcome %}
<dt>
{% trans 'Order' %}
</dt>
<dd class="text-muted">
{{ document.order_outcome.name }}
</dd>
{% endif %}
{% with document.order_outcomes.all as order_outcomes %}
{% if order_outcomes %}
<dt>
{% trans 'Order' %}
</dt>
<dd class="text-muted">
{% for order_outcome in order_outcomes %}
{{ order_outcome.name }}
{% if not forloop.last %},{% endif %}
{% endfor %}
</dd>
{% endif %}
{% endwith %}
{% with document.case_numbers.all as case_numbers %}
{% if case_numbers %}
<dt>
Expand Down
2 changes: 1 addition & 1 deletion peachjam/tests/test_resolver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cobalt import FrbrUri
from django.test import TestCase

from peachjam.views.documents import RedirectResolver
from peachjam.resolver import RedirectResolver

urls = [
"/akn/zm/judgment/zmsc/2021/7/eng@2021-01-19",
Expand Down
2 changes: 1 addition & 1 deletion peachjam/views/courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def populate_facets(self, context):
self.get_base_queryset(), exclude="order_outcomes"
)
.order_by()
.values_list("order_outcome__name", flat=True)
.values_list("order_outcomes__name", flat=True)
.distinct()
if order_outcome
)
Expand Down
Loading

0 comments on commit d595fb1

Please sign in to comment.