Skip to content

Commit

Permalink
Merge pull request #1566 from laws-africa/future-commencements
Browse files Browse the repository at this point in the history
Show warning for legislation that has a future commencement date
  • Loading branch information
actlikewill authored Oct 17, 2023
2 parents 0e30948 + be2c73b commit 7c4394e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion peachjam/views/legislation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,22 @@ def get_notices(self):
}
)

if not commenced:
current_date = datetime.now().date()
latest_commencement_date = self.get_latest_commencement_date()
if commenced:
if latest_commencement_date and latest_commencement_date > current_date:
notices.append(
{
"type": messages.WARNING,
"html": _("This %(friendly_type)s will commence on %(date)s.")
% {
"friendly_type": friendly_type,
"date": format_date(latest_commencement_date, "j F Y"),
},
}
)

else:
notices.append(
{
"type": messages.WARNING,
Expand Down Expand Up @@ -174,6 +189,16 @@ def get_work_amendments(self):
def get_commencement_info(self):
return self.object.metadata_json.get("commenced", None)

def get_latest_commencement_date(self):
commencements = self.object.metadata_json.get("commencements", None)
if commencements:
commencement_dates = [
commencement["date"] for commencement in commencements
]
return datetime.strptime(max(commencement_dates), "%Y-%m-%d").date()

return None

def set_unapplied_amendment_notice(self, notices):
notices.append(
{
Expand Down

0 comments on commit 7c4394e

Please sign in to comment.