Skip to content
Snippets Groups Projects
Commit 99e868e1 authored by Martin Burchell's avatar Martin Burchell
Browse files

Merge branch 'tabbed_page_tab_html' into tab_rendering

Conflicts:
	django/website/tabbed_page/templatetags/render_tab.py
parents 99292f40 c9fa6c37
No related branches found
No related tags found
2 merge requests!23Tabbed view header styling,!22Tabbed page
......@@ -24,3 +24,26 @@ def clear_tabs():
global _pool
_pool = {}
class BasicHtmlTab(object):
""" A simple tab to display html
Settings:
title: The title of the tab
(in the header, not in
the tab)
body: The tab html
"""
template_name = 'tabbed_page/basic_html_tab.html'
def get_context_data(self, **kwargs):
title = kwargs.get('title', '(no title)')
body = kwargs.get('body', '(no body)')
return {
'title': title,
'body': body
}
register_tab('basic-html-tab', BasicHtmlTab())
{% load i18n %}
<div class="panel panel-default">
<div class="panel-heading container-fluid">
<div class="col-sm-5 col-xs-12">
<span class="fa fa-align-justify fa-fw"></span>
{% trans title %}
</div>
</div>
<div class="panel-body">
{{ body|safe }}
</div>
</div>
{% extends "base_side.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load render_widget %}
{% load render_tab %}
{% block maincontent %}
<h1 class="page-header"><span class="fa fa-tabbed-page fa-fw"></span>{% trans "Tabbed Page" %}</h1>
<h2>Page = {{ view.page }}</h2>
<div class="row">
<div class="col-xs-12">
<h1 class="page-header header-tabs"><span class="fa fa-pencil fa-fw"></span>{% trans "View &amp; Edit" %}</h1>
<ul class="nav nav-tabs pull-right" role="tablist">
{% for tab in view.tabs %}
<li role="presentation"
{% if tab == view.active_tab %}class="active"{% endif %}>
<a href="#" aria-controls="..." role="tab" data-toggle="tab">
{% trans tab.label %}
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
<ul>
{% for tab in view.tabs %}
<li>{{ tab }}</li>
{% endfor %}
</ul>
<div class='row'>
<div class="col-lg-12">
{{ view.active_tab|render_tab }}
</div>
</div>
{% endblock maincontent %}
......@@ -4,7 +4,9 @@ from django.contrib.auth.decorators import login_required
from .views import TabbedPageView
urlpatterns = [
url(r'^(?P<name>[^/]*)(/(?P<tab_name>.*))?$',
TabbedPageView.as_view(),
url(r'^/$', login_required(TabbedPageView.as_view())),
url(r'^(?P<name>\w+)/$', login_required(TabbedPageView.as_view())),
url(r'^(?P<name>\w+)/(?P<tab_name>\w+)/$',
login_required(TabbedPageView.as_view()),
name='tabbed-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