Skip to content

Commit

Permalink
Merge pull request #655 from praekeltfoundation/feature/helper-method…
Browse files Browse the repository at this point in the history
…s-molo-page-model

add is_content_page MoloPage method
  • Loading branch information
moh-moola committed Jun 3, 2019
2 parents 7e6463e + 40dbe60 commit b4d9e51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion molo/core/molo_wagtail_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ class MoloPage(Page):
class Meta:
proxy = True

def exact_type(self):
return self.__class__.__name__

def is_content_page(self, page):
if self.title.lower() == page.lower():
return True
else:
if hasattr(self.specific, 'translated_pages'):
for translation in self.specific.translated_pages.all():
if translation.title.lower() == page.lower():
return True
return False

def get_top_level_parent(self, locale=None, depth=3):
# exclude main has no attribute 'language'
if depth < 1:
Expand All @@ -18,7 +31,7 @@ def get_top_level_parent(self, locale=None, depth=3):

parent = self._cached_parent_obj.specific \
if hasattr(self._cached_parent_obj, 'specific')\
else self._cached_parent_obj
else self._cached_parent_obj.specific

if parent and hasattr(parent, 'language'):
if locale and parent.language.locale != locale:
Expand Down
4 changes: 4 additions & 0 deletions molo/core/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ def test_is_hero_article(self):
self.yourmind.add_child(instance=article_2)
self.assertFalse(article_2.is_current_hero_article())

def test_molo_page_helper_method_is_content_page(self):
self.assertTrue(self.yourmind.is_content_page("Your mind"))
self.assertFalse(self.yourmind.is_content_page("Not Your mind"))

# exclude future-scheduled Hero Article articles from the
# latest articles queryset.
# Create two articles, one with present promote date and one
Expand Down

0 comments on commit b4d9e51

Please sign in to comment.