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

Django 4.2 #1938

Merged
merged 8 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ jobs:
- name: Push
uses: EndBug/add-and-commit@v9
with:
add: 'peachjam/static/js/*app-prod.js peachjam/static/js/pdf.worker-prod.js --force'
add: 'peachjam/static/js/*app-prod.{js,js.map} peachjam/static/js/pdf.worker-prod.{js,js.map} --force'
message: 'Update compiled javascript [nobuild]'
12 changes: 0 additions & 12 deletions .github/workflows/lint.yml

This file was deleted.

7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- liiweb
services:
postgres:
image: postgres:10
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
ports:
Expand All @@ -31,9 +31,10 @@ jobs:
- uses: actions/checkout@v3

- name: Set up Python Environment
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
cache: 'pip'
- uses: actions/setup-node@v3
with:
node-version: '18'
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-bullseye
FROM python:3.10-bullseye
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

Expand Down
24 changes: 24 additions & 0 deletions peachjam/debugging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import threading

import debug_toolbar.utils


class ThreadCollector:
def __init__(self):
self.data = threading.local()
self.data.collection = []

def collect(self, item):
if hasattr(self.data, "collection"):
self.data.collection.append(item)

def get_collection(self):
return getattr(self.data, "collection", [])

def clear_collection(self):
self.data.collection = []


# monkey patch django debug toolbar so that elastic_panel's broken import still works
# see https://github.com/Benoss/django-elasticsearch-debug-toolbar/pull/21
debug_toolbar.utils.ThreadCollector = ThreadCollector
8 changes: 5 additions & 3 deletions peachjam/models/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,11 @@ def assign_title(self):
if self.case_name:
parts.append(self.case_name)

case_number = "; ".join(n.string for n in self.case_numbers.all())
if case_number:
parts.append("(" + case_number + ")")
# can't lookup foreign keys without being saved
if self.pk:
case_number = "; ".join(n.string for n in self.case_numbers.all())
if case_number:
parts.append("(" + case_number + ")")

if self.mnc:
parts.append(self.mnc)
Expand Down
33 changes: 20 additions & 13 deletions peachjam/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def clean(self, value, row=None, *args, **kwargs):
values = [v.strip() for v in value.split(self.separator)]
return [self.model(**{self.field: v}) for v in values if v]

def render(self, value, obj=None):
if obj.pk:
return super().render(value, obj)


class StripHtmlWidget(CharWidget):
def clean(self, value, row=None, **kwargs):
Expand Down Expand Up @@ -386,7 +390,8 @@ def attach_source_file(self, instance, source_url):
self.download_attachment(url, instance, "Other documents")

def dehydrate_taxonomies(self, instance):
return "|".join(t.topic.slug for t in instance.taxonomies.all())
if instance.pk:
return "|".join(t.topic.slug for t in instance.taxonomies.all())


class DocumentNatureWidget(ForeignKeyWidget):
Expand Down Expand Up @@ -564,11 +569,12 @@ def after_import_row(self, row, instance, row_number=None, **kwargs):

def get_case_number_attributes(self, judgment, attribute):
values = []
for case_number in judgment.case_numbers.all().order_by(
"year", "number", "string_override"
):
val = getattr(case_number, attribute)
values.append(f"{val or ''}")
if judgment.pk:
for case_number in judgment.case_numbers.all().order_by(
"year", "number", "string_override"
):
val = getattr(case_number, attribute)
values.append(f"{val or ''}")

return "|".join(values)

Expand All @@ -583,13 +589,14 @@ def dehydrate_case_string_override(self, judgment):

def dehydrate_matter_type(self, judgment):
values = []
for case_number in judgment.case_numbers.all().order_by(
"year", "number", "string_override"
):
if getattr(case_number, "matter_type"):
values.append(case_number.matter_type.name)
else:
values.append("")
if judgment.pk:
for case_number in judgment.case_numbers.all().order_by(
"year", "number", "string_override"
):
if getattr(case_number, "matter_type"):
values.append(case_number.matter_type.name)
else:
values.append("")

return "|".join(values)

Expand Down
1 change: 1 addition & 0 deletions peachjam/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
INSTALLED_APPS.append("elastic_panel")
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
INTERNAL_IPS = ["127.0.0.1"]
import peachjam.debugging # noqa

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
Expand Down
2 changes: 1 addition & 1 deletion peachjam/static/js/app-prod.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions peachjam/static/js/app-prod.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion peachjam/static/js/pdf.worker-prod.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions peachjam/static/js/pdf.worker-prod.js.map

Large diffs are not rendered by default.

This file was deleted.

20 changes: 10 additions & 10 deletions peachjam/templates/peachjam/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@
type="application/atom+xml"
title="Atom RSS Feed"
href="{% url 'atom_feed' %}"/>
{% ifequal request.path '/judgments/' %}
{% if request.path == '/judgments/' %}
<link rel="alternate"
type="application/atom+xml"
title="Judgments Atom RSS Feed"
href="{% url 'judgment_feed' %}"/>
{% endifequal %}
{% ifequal request.path '/doc/' %}
{% endif %}
{% if request.path == '/doc/' %}
<link rel="alternate"
type="application/atom+xml"
title="AU Documents Atom RSS Feed"
href="{% url 'generic_document_feed' %}"/>
{% endifequal %}
{% ifequal request.path '/legal_instruments/' %}
{% endif %}
{% if request.path == '/legal_instruments/' %}
<link rel="alternate"
type="application/atom+xml"
title="Legal Instruments Atom RSS Feed"
href="{% url 'legal_instrument_feed' %}"/>
{% endifequal %}
{% ifequal request.path '/legislation/' %}
{% endif %}
{% if request.path == '/legislation/' %}
<link rel="alternate"
type="application/atom+xml"
title="Treaties & Protocols Atom RSS Feed"
href="{% url 'legislation_feed' %}"/>
{% endifequal %}
{% ifequal request.path '/articles/' %}
{% endif %}
{% if request.path == '/articles/' %}
<link rel="alternate"
type="application/atom+xml"
title="{{ APP_NAME }} Articles RSS Feed"
href="{% url 'article_feed' %}"/>
{% endifequal %}
{% endif %}
{% block favicon %}
<link rel="icon" type="image/ico" href="{% static 'images/favicon.ico' %}" />
<link rel="icon"
Expand Down
2 changes: 0 additions & 2 deletions peachjam/tests/test_preferred_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class TestPreferredLanguage(TestCase):

def test_preferred_language(self):
response = self.client.get("/legal_instruments/")

assert response.context.get("documents").count() == 2
assert response.context.get("LANGUAGE_CODE") == "en"

def test_update_work_languages(self):
doc = Legislation.objects.get(
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ dependencies = [
"cobalt>=6.0.0",
"cssutils >= 2",
"dj-database-url>=0.5.0",
"Django~=3.2.13",
"django-advanced-password-validation==1.1.1",
"Django~=4.2",
"django-advanced-password-validation>=1.1",
"django-allauth[socialaccount]>=0.62.0",
"django-autocomplete-light>=3.9.7",
"django-background-tasks>=1.2.5",
"django-background-tasks-updated>=1.2.8",
"django-ckeditor>=6.4.2",
"django-compressor>=3.1",
"django-cors-headers>=4.3.1",
"django-countries-plus>=1.3.2",
"django-debug-toolbar>=3.2.4,<4.2.0",
"django-debug-toolbar>=4.4",
"django-elasticsearch-debug-toolbar>=3.0.2",
"django-elasticsearch-dsl>=7.2.2,<8.0.0",
"django-elasticsearch-dsl-drf>=0.22.4",
"django-extensions>=3.1.5",
"django-filter>=22.1",
"django-htmx>=1.18.0",
"django-import-export~=3.2.0",
"django-import-export<4.0",
"django-jazzmin>=2.5.0",
"django-languages-plus>=1.1.1",
"django-log-request-id>=2.0.0",
Expand Down
Loading