Skip to content
Snippets Groups Projects
Commit b5e1770e authored by Alice Heaton's avatar Alice Heaton :speech_balloon:
Browse files

Add a property to get the currently active tab

parent ccf0be69
No related branches found
No related tags found
2 merge requests!23Tabbed view header styling,!22Tabbed page
......@@ -6,6 +6,7 @@ from .models import TabbedPage
class TabbedPageView(TemplateView):
template_name = "tabbed_page/tabbed_page.html"
_page = None
_active_tab = None
@property
def tabs(self):
......@@ -24,3 +25,18 @@ class TabbedPageView(TemplateView):
self._page = TabbedPage.objects.get(name=name)
return self._page
@property
def active_tab(self):
if self._active_tab is None:
candidates = []
tab_name = self.kwargs.get('tab_name')
if tab_name:
candidates = self.page.tabs.all().filter(name=tab_name)
if len(candidates) == 0:
candidates = self.page.tabs.all().filter(default=True)
if len(candidates) == 0:
candidates = self.page.tabs.all()
if len(candidates) > 0:
self._active_tab = candidates[0]
return self._active_tab
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment