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

make events url include year and month #176

Merged
merged 1 commit into from
Aug 26, 2024
Merged
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
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
Loading