Skip to content

Commit

Permalink
adds uncommenced label to legislation
Browse files Browse the repository at this point in the history
  • Loading branch information
actlikewill committed May 24, 2024
1 parent f3bf538 commit 2efbc37
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions peachjam/models/generic_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,40 @@ def search_penalty(self):
return 10.0
return super().search_penalty()

@property
def commenced(self):
return bool(self.metadata_json["commencement_date"])

def apply_labels(self):
labels = list(self.labels.all())

# label to indicate that this legislation is repealed
label, _ = Label.objects.get_or_create(
repealed_label, _ = Label.objects.get_or_create(
code="repealed",
defaults={"name": "Repealed", "code": "repealed", "level": "danger"},
)

labels = list(self.labels.all())
uncommenced_label, _ = Label.objects.get_or_create(
code="uncommenced",
defaults={
"name": "Uncommenced",
"level": "danger",
},
)

# apply label if repealed
if self.repealed:
if label not in labels:
self.labels.add(label.pk)
elif label in labels:
if repealed_label not in labels:
self.labels.add(repealed_label.pk)
elif repealed_label in labels:
# not repealed, remove label
self.labels.remove(label.pk)
self.labels.remove(repealed_label.pk)

# apply label if not commenced
if not self.commenced:
if uncommenced_label not in labels:
self.labels.add(uncommenced_label.pk)
elif uncommenced_label in labels:
self.labels.remove(uncommenced_label.pk)

super().apply_labels()

Expand Down

0 comments on commit 2efbc37

Please sign in to comment.