Skip to content

Commit

Permalink
make events url include year and month
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahframe committed Aug 26, 2024
1 parent 62cf444 commit 773c105
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions cdhweb/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,31 @@ def clean(self):
if not self.type:
raise ValidationError("Event must specify a type.")

# def get_url_parts(self, *args, **kwargs):
# """Custom event page URLs of the form /events/2014/03/my-event."""
# url_parts = super().get_url_parts(*args, **kwargs)
# # NOTE evidently this can sometimes be None; unclear why – perhaps it
# # gets called in a context where the request is unavailable? Only
# # happens in QA, not locally.
# if url_parts:
# site_id, root_url, _ = url_parts
# page_path = reverse(
# "events:detail",
# kwargs={
# "year": self.start_time.year,
# # force two-digit month
# "month": "%02d" % self.start_time.month,
# "slug": self.slug,
# },
# )
# return site_id, root_url, page_path
def get_url_parts(self, request, *args, **kwargs):
"""Custom event page URLs of the form /events/2014/03/my-event."""
url_parts = super().get_url_parts(request, *args, **kwargs)
# NOTE evidently this can sometimes be None; unclear why – perhaps it
# gets called in a context where the request is unavailable? Only
# happens in QA, not locally.
if url_parts:
site_id, root_url, _remainder = url_parts
parent = self.get_parent().specific

# If for some reason we don't have a eventlanding-style parent, just
# use `super()`
if not hasattr(parent, "reverse_subpage"):
return url_parts

page_path = parent.reverse_subpage(
"dated_child",
kwargs={
"year": self.start_time.year,
# force two-digit month
"month": "%02d" % self.start_time.month,
"slug": self.slug,
},
)
return site_id, root_url, parent.get_url(request) + page_path

def get_ical_url(self):
"""URL to download this event as a .ics (iCal) file."""
Expand Down Expand Up @@ -466,7 +473,7 @@ def get_upcoming_events_for_semester(self, semester, year):
else:
raise ValueError(f"Invalid semester: {semester}")

child_pages = self.get_children().live().type(Event)
child_pages = self.get_children().live().specific().type(Event)
# Filter events based on start_time within the semester range
return child_pages.filter(
event__start_time__gte=start_date, event__start_time__lte=end_date
Expand All @@ -475,7 +482,7 @@ def get_upcoming_events_for_semester(self, semester, year):
def get_upcoming_events(self):
current_datetime = timezone.now()

child_pages = self.get_children().live().type(Event)
child_pages = self.get_children().live().specific().type(Event)

# Fetch upcoming events among the child pages
return child_pages.filter(event__start_time__gte=current_datetime).order_by(
Expand Down

0 comments on commit 773c105

Please sign in to comment.