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

Update things to work with newer versions of Django #155

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
django-series: ['3.2', '4.0', '4.2']
django-series: ['4.2', '5.1']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

* Add a --sync flag to the loaddivisions management command, to delete divisions that are in the DB but not the CSV, even if the DB contains the CSV. This flag is relevant if you synchronize with a single CSV.

## 3.4.0 (put the date here, I guess)

* Support Django versions >=4.2

## 3.3.0 (2023-05-08)

* Add last_seen field to database objects
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python-opencivicdata
Python utilities (including Django models) for implementing the
Open Civic Data specification.

**Requires Django >=2.2 and Python >= 3.6, pin to <3.0 for older versions**
**Requires Django >=4.2 and Python >= 3.6, pin to <3.0 for Django versions < 2.2 and < 3.3 for Django versions < 4.2 **

The Organization, Person, Membership, Post, and VoteEvent models and related models are based on the [Popolo specification](http://popoloproject.com/).

Expand Down
22 changes: 12 additions & 10 deletions opencivicdata/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,17 +825,19 @@ class Migration(migrations.Migration):
to="core.Post",
),
),
migrations.AlterIndexTogether(
name="post", index_together=set([("organization", "label")])
migrations.AddIndex(
model_name="post", index=django.db.models.Index(name="post", fields=["organization", "label"])
),
migrations.AlterIndexTogether(
name="organization",
index_together=set(
[("classification", "name"), ("jurisdiction", "classification", "name")]
),
migrations.AddIndex(
model_name="organization",
index=django.db.models.Index(name="organization_class_name", fields=["classification", "name"])
),
migrations.AddIndex(
model_name="organization",
index=django.db.models.Index(name="organization", fields=["jurisdiction", "classification", "name"])
),
migrations.AlterIndexTogether(
name="membership",
index_together=set([("organization", "person", "label", "post")]),
migrations.AddIndex(
model_name="membership",
index=django.db.models.Index(name="membership", fields=["organization", "person", "label", "post"])
),
]
1 change: 1 addition & 0 deletions opencivicdata/core/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import uuid
from django.db import models

from django.contrib.postgres.fields import ArrayField
from django.core.validators import RegexValidator

Expand Down
10 changes: 5 additions & 5 deletions opencivicdata/core/models/people_orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ def get_current_members(self):

class Meta:
db_table = "opencivicdata_organization"
index_together = [
["jurisdiction", "classification", "name"],
["classification", "name"],
indexes = [
models.Index(fields=["jurisdiction", "classification", "name"]),
models.Index(fields=["classification", "name"]),
]


Expand Down Expand Up @@ -280,7 +280,7 @@ class Post(OCDBase):

class Meta:
db_table = "opencivicdata_post"
index_together = [["organization", "label"]]
indexes = [models.Index(fields=["organization", "label"])]

def __str__(self):
return "{} - {} - {}".format(self.role, self.label, self.organization)
Expand Down Expand Up @@ -549,7 +549,7 @@ class Membership(OCDBase):

class Meta:
db_table = "opencivicdata_membership"
index_together = [["organization", "person", "label", "post"]]
indexes = [models.Index(fields=["organization", "person", "label", "post"])]

def __str__(self):
return "{} in {} ({})".format(self.person, self.organization, self.role)
Expand Down
5 changes: 3 additions & 2 deletions opencivicdata/elections/models/candidacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class Candidacy(OCDBase):
filed_date = models.DateField(
null=True, help_text="Specifies when the candidate filed for the contest."
)
is_incumbent = models.NullBooleanField(
is_incumbent = models.BooleanField(
help_text="Indicates whether the candidate is seeking re-election to a "
"public office he/she currently holds"
"public office he/she currently holds",
null=True
)
party = models.ForeignKey(
Organization,
Expand Down
5 changes: 3 additions & 2 deletions opencivicdata/elections/models/contests/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class PartyContestOption(models.Model):
help_text="Reference to an Organization representing a political party "
"voters may choose in the contest.",
)
is_incumbent = models.NullBooleanField(
help_text="Indicates whether the party currently holds majority power."
is_incumbent = models.BooleanField(
help_text="Indicates whether the party currently holds majority power.",
null=True
)

def __str__(self):
Expand Down
28 changes: 13 additions & 15 deletions opencivicdata/legislative/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,22 +1180,20 @@ class Migration(migrations.Migration):
to="legislative.LegislativeSession",
),
),
migrations.AlterIndexTogether(
name="voteevent",
index_together=set(
[
("legislative_session", "bill"),
("legislative_session", "identifier", "bill"),
]
),
migrations.AddIndex(
model_name="voteevent",
index=django.db.models.Index(name="voteevent_session_bill", fields=["legislative_session", "bill"])
),
migrations.AlterIndexTogether(
name="event", index_together=set([("jurisdiction", "start_time", "name")])
migrations.AddIndex(
model_name="voteevent",
index=django.db.models.Index(name="voteevent_session_id_bill", fields=["legislative_session", "identifier", "bill"]),
),
migrations.AlterIndexTogether(
name="bill",
index_together=set(
[("from_organization", "legislative_session", "identifier")]
),
migrations.AddIndex(
model_name="event",
index=django.db.models.Index(name="event", fields=["jurisdiction", "start_time", "name"])
),
migrations.AddIndex(
model_name="bill",
index=django.db.models.Index(name="bill", fields=["from_organization", "legislative_session", "identifier"])
),
]
4 changes: 2 additions & 2 deletions opencivicdata/legislative/migrations/0003_time_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class Migration(migrations.Migration):
migrations.RenameField(
model_name="event", old_name="start_time", new_name="start_date"
),
migrations.AlterIndexTogether(
name="event", index_together=set([("jurisdiction", "start_date", "name")])
migrations.AddIndex(
model_name="event", index=models.Index(name="event_juris_name", fields=["jurisdiction", "start_date", "name"])
),
migrations.RemoveField(model_name="event", name="timezone"),
migrations.RunSQL(
Expand Down
2 changes: 1 addition & 1 deletion opencivicdata/legislative/models/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __str__(self):

class Meta:
db_table = "opencivicdata_bill"
index_together = [["from_organization", "legislative_session", "identifier"]]
indexes = [models.Index(fields=["from_organization", "legislative_session", "identifier"])]


class BillAbstract(RelatedBase):
Expand Down
4 changes: 3 additions & 1 deletion opencivicdata/legislative/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def __str__(self):

class Meta:
db_table = "opencivicdata_event"
index_together = [["jurisdiction", "start_date", "name"]]
indexes = [
models.Index(fields=["jurisdiction", "start_date", "name"])
]


class EventMedia(EventMediaBase):
Expand Down
6 changes: 3 additions & 3 deletions opencivicdata/legislative/models/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def __str__(self):

class Meta:
db_table = "opencivicdata_voteevent"
index_together = [
["legislative_session", "identifier", "bill"],
["legislative_session", "bill"],
indexes = [
models.Index(fields=["legislative_session", "identifier", "bill"]),
models.Index(fields=["legislative_session", "bill"]),
]


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
from setuptools import setup, find_packages

install_requires = ["Django>=3.2", "psycopg2-binary"]
install_requires = ["Django>=4.2", "psycopg2-binary"]

extras_require = {
"dev": ["pytest>=3.6", "pytest-cov", "pytest-django", "coveralls==3.2.0", "flake8"]
Expand Down
Loading