Skip to content

Commit

Permalink
Merge pull request #982 from ubyssey/get_absolute_url
Browse files Browse the repository at this point in the history
get_absolute_url changed for guide articles
  • Loading branch information
keeganland authored Aug 20, 2020
2 parents 9180658 + bd52caa commit 77c5266
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion dispatch/modules/content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,16 @@ def save_topic(self, topic_id):
pass

def get_absolute_url(self):
""" Returns article URL. """
""" Returns article URL. Uses alternate logic when section slug is 'guide'"""
if self.section.slug == 'guide' and self.subsection:
# Subsection is "supposed" to be optional in most circumstances. But it's needed for guide URLs, so we need to check self.subsection.
# Worst case scenario should the viewer will see a guide article in the wrong template
if self.published_at is not None:
year = self.published_at.strftime("%Y")
else:
# You might enter this block when you are writing a new guide article and there is no published_at yet.
year = datetime.datetime.now().strftime("%Y")
return "%s%s/%s/%s/%s/" % (settings.BASE_URL, self.section.slug, year, self.subsection.slug, self.slug)
return "%s%s/%s/" % (settings.BASE_URL, self.section.slug, self.slug)

def get_subsection(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(name='dispatch',
description='A publishing platform for modern newspapers',
version='1.3.5',
version='1.3.6',
url='https://github.com/ubyssey/dispatch',
author='Peter Siemens',
author_email='[email protected]',
Expand Down

0 comments on commit 77c5266

Please sign in to comment.