Skip to content

Commit

Permalink
Upgrade Python from 3.6=>3.12 and Django from 1.11=>3.2.5 (#200)
Browse files Browse the repository at this point in the history
This PR updates the Python and Django version, and most other dependencies.

We only go to 3.2.5 for Django instead of 5.0.4 because the django-bootstrap-pagination requirement will not work with Django > 3.2.

It would be pretty simple to fork the bootstrap pagination project and make the changes necessary to get it working with new Django, but we might want to also update the Boostrap version, so I'll leave all that to another day.

Nearly all the templates had to be touched, but the only substantive change in them is changing {% load staticfiles %} to {% load static %}. The rest of it is just formatting changes from djhtml.
  • Loading branch information
fgregg authored Apr 25, 2024
1 parent c09ff24 commit 4f565ad
Show file tree
Hide file tree
Showing 33 changed files with 2,425 additions and 2,213 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6
FROM python:3.12
LABEL maintainer "DataMade <[email protected]>"

RUN apt-get update && \
Expand Down
43 changes: 12 additions & 31 deletions camp_fin/management/commands/aggregate_data.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import sqlalchemy as sa
from django.conf import settings
from django.core.management.base import BaseCommand

DB_CONN = "postgresql://{USER}:{PASSWORD}@{HOST}:{PORT}/{NAME}"

engine = sa.create_engine(
DB_CONN.format(**settings.DATABASES["default"]),
convert_unicode=True,
server_side_cursors=True,
)
from django.db import connections, transaction
from django.db.utils import ProgrammingError


class Command(BaseCommand):
help = "Import New Mexico Campaign Finance data"

def handle(self, *args, **options):
self.connection = engine.connect()

self.makeLoanBalanceView()
self.makeTransactionAggregates()
Expand All @@ -31,7 +22,7 @@ def makeTransactionAggregates(self):
interval
)
)
except sa.exc.ProgrammingError:
except ProgrammingError:
view = """
CREATE MATERIALIZED VIEW contributions_by_{0} AS (
SELECT
Expand Down Expand Up @@ -78,7 +69,7 @@ def makeTransactionAggregates(self):
interval
)
)
except sa.exc.ProgrammingError:
except ProgrammingError:
view = """
CREATE MATERIALIZED VIEW expenditures_by_{0} AS (
SELECT
Expand Down Expand Up @@ -135,7 +126,7 @@ def makeLoanBalanceView(self):
""",
raise_exc=True,
)
except sa.exc.ProgrammingError:
except ProgrammingError:
self.executeTransaction(
"""
CREATE MATERIALIZED VIEW current_loan_status AS (
Expand All @@ -154,20 +145,10 @@ def makeLoanBalanceView(self):
)

def executeTransaction(self, query, *args, **kwargs):
trans = self.connection.begin()

raise_exc = kwargs.get("raise_exc", True)

try:
self.connection.execute("SET local timezone to 'America/Denver'")
if kwargs:
self.connection.execute(query, **kwargs)
else:
self.connection.execute(query, *args)
trans.commit()
except sa.exc.ProgrammingError as e:
# TODO: Make some kind of logger
# logger.error(e, exc_info=True)
trans.rollback()
if raise_exc:
raise e
with connections["default"].cursor() as cursor:
with transaction.atomic():
cursor.execute("SET local timezone to 'America/Denver'")
if kwargs:
cursor.execute(query, kwargs)
else:
cursor.execute(query, args)
68 changes: 68 additions & 0 deletions camp_fin/migrations/0085_auto_20240422_0850.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Generated by Django 3.2.25 on 2024-04-22 14:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("camp_fin", "0084_auto_20240418_1048"),
]

operations = [
migrations.AlterField(
model_name="campaign",
name="biannual",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="campaign",
name="initial_balance_from_self",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="campaign",
name="initial_debt_from_self",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="filing",
name="final",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="filing",
name="no_activity",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="lobbyistfilingperiod",
name="allow_statement_of_no_activity",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="lobbyistregistration",
name="is_registered",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="pac",
name="initial_balance_from_self",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="pac",
name="initial_debt_from_self",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="transaction",
name="expenditure_for_certified_candidate",
field=models.BooleanField(null=True),
),
migrations.AlterField(
model_name="transaction",
name="redact",
field=models.BooleanField(default=False, null=True),
),
]
2 changes: 1 addition & 1 deletion camp_fin/migrations/0085_auto_20240424_1218.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Migration(migrations.Migration):

dependencies = [
("camp_fin", "0084_auto_20240418_1048"),
("camp_fin", "0085_auto_20240422_0850"),
]

operations = [
Expand Down
Loading

0 comments on commit 4f565ad

Please sign in to comment.