Commit 3d957d9f authored by Serge S. Koval's avatar Serge S. Koval

Fixed #168. Allow base template overriding

parent bc6d7555
......@@ -174,7 +174,7 @@ class BaseView(object):
# If endpoint name is not provided, get it from the class name
if self.endpoint is None:
self.endpoint = self.__class__.__name__.lower()
# If the static_url_path is not provided, use the admin's
if not self.static_url_path:
self.static_url_path = admin.static_url_path
......@@ -227,6 +227,7 @@ class BaseView(object):
"""
# Store self as admin_view
kwargs['admin_view'] = self
kwargs['admin_base_template'] = self.admin.base_template
# Provide i18n support even if flask-babel is not installed
# or enabled.
......@@ -385,7 +386,8 @@ class Admin(object):
index_view=None,
translations_path=None,
endpoint=None,
static_url_path=None):
static_url_path=None,
base_template=None):
"""
Constructor.
......@@ -407,7 +409,9 @@ class Admin(object):
a single Flask application, you have to set a unique endpoint name for each instance.
:param static_url_path:
Static URL Path. If provided, this specifies the default path to the static url directory for
all its views. Can be overriden in view configuration.
all its views. Can be overridden in view configuration.
:param base_template:
Override base HTML template for all static views. Defaults to `admin/base.html`.
"""
self.app = app
......@@ -427,6 +431,7 @@ class Admin(object):
self.url = url or self.index_view.url
self.static_url_path = static_url_path
self.subdomain = subdomain
self.base_template = base_template or 'admin/base.html'
# Add predefined index view
self.add_view(self.index_view)
......
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% if admin_view.category %}{{ admin_view.category }} - {% endif %}{{ admin_view.name }} - {{ admin_view.admin.name }}{% endblock %}</title>
{% block head_meta %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
{% endblock %}
{% block head_css %}
<link href="{{ url_for('admin.static', filename='bootstrap/css/bootstrap.css') }}" rel="stylesheet">
<link href="{{ url_for('admin.static', filename='bootstrap/css/bootstrap-responsive.css') }}" rel="stylesheet">
<link href="{{ url_for('admin.static', filename='css/admin.css') }}" rel="stylesheet">
{% endblock %}
{% block head %}
{% endblock %}
</head>
<body>
{% block page_body %}
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
{% block brand %}
<span class="brand">{{ admin_view.admin.name }}</span>
{% endblock %}
<ul class="nav">
{% for item in admin_view.admin.menu() %}
{% if item.is_category() %}
{% set children = item.get_children() %}
{% if children %}
{% if item.is_active(admin_view) %}<li class="active dropdown">{% else %}<li class="dropdown">{% endif %}
<a class="dropdown-toggle" data-toggle="dropdown" href="#">{{ item.name }}<b class="caret"></b></a>
<ul class="dropdown-menu">
{% for child in children %}
{% if child.is_active(admin_view) %}<li class="active">{% else %}<li>{% endif %}
<a href="{{ child.get_url() }}">{{ child.name }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endif %}
{% else %}
{% if item.is_accessible() %}
{% if item.is_active(admin_view) %}<li class="active">{% else %}<li>{% endif %}
<a href="{{ item.get_url() }}">{{ item.name }}</a>
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
<ul class="nav pull-right">
{% for item in admin_view.admin.menu_links() %}
{% if item.is_accessible() %}
<li>
<a href="{{ item.get_url() }}">{{ item.name }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
</div>
{% with messages = get_flashed_messages(with_categories=True) %}
{% if messages %}
{% for category, m in messages %}
{% if category == 'error' %}
<div class="alert alert-error">
{% else %}
<div class="alert">
{% endif %}
<a href="#" class="close" data-dismiss="alert">x</a>
{{ m }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="container">
{% block body %}{% endblock %}
</div>
{% endblock %}
<script src="{{ url_for('admin.static', filename='js/jquery-1.8.3.min.js') }}" type="text/javascript"></script>
<script src="{{ url_for('admin.static', filename='bootstrap/js/bootstrap.min.js') }}" type="text/javascript"></script>
<script src="{{ url_for('admin.static', filename='select2/select2.min.js') }}" type="text/javascript"></script>
{% block tail %}
{% endblock %}
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% if admin_view.category %}{{ admin_view.category }} - {% endif %}{{ admin_view.name }} - {{ admin_view.admin.name }}{% endblock %}</title>
{% block head_meta %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
{% endblock %}
{% block head_css %}
<link href="{{ url_for('admin.static', filename='bootstrap/css/bootstrap.css') }}" rel="stylesheet">
<link href="{{ url_for('admin.static', filename='bootstrap/css/bootstrap-responsive.css') }}" rel="stylesheet">
<link href="{{ url_for('admin.static', filename='css/admin.css') }}" rel="stylesheet">
{% endblock %}
{% block head %}
{% endblock %}
</head>
<body>
{% block page_body %}
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
{% block brand %}
<span class="brand">{{ admin_view.admin.name }}</span>
{% endblock %}
<ul class="nav">
{% for item in admin_view.admin.menu() %}
{% if item.is_category() %}
{% set children = item.get_children() %}
{% if children %}
{% if item.is_active(admin_view) %}<li class="active dropdown">{% else %}<li class="dropdown">{% endif %}
<a class="dropdown-toggle" data-toggle="dropdown" href="#">{{ item.name }}<b class="caret"></b></a>
<ul class="dropdown-menu">
{% for child in children %}
{% if child.is_active(admin_view) %}<li class="active">{% else %}<li>{% endif %}
<a href="{{ child.get_url() }}">{{ child.name }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endif %}
{% else %}
{% if item.is_accessible() %}
{% if item.is_active(admin_view) %}<li class="active">{% else %}<li>{% endif %}
<a href="{{ item.get_url() }}">{{ item.name }}</a>
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
<ul class="nav pull-right">
{% for item in admin_view.admin.menu_links() %}
{% if item.is_accessible() %}
<li>
<a href="{{ item.get_url() }}">{{ item.name }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
</div>
{% with messages = get_flashed_messages(with_categories=True) %}
{% if messages %}
{% for category, m in messages %}
{% if category == 'error' %}
<div class="alert alert-error">
{% else %}
<div class="alert">
{% endif %}
<a href="#" class="close" data-dismiss="alert">x</a>
{{ m }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="container">
{% block body %}{% endblock %}
</div>
{% endblock %}
<script src="{{ url_for('admin.static', filename='js/jquery-1.8.3.min.js') }}" type="text/javascript"></script>
<script src="{{ url_for('admin.static', filename='bootstrap/js/bootstrap.min.js') }}" type="text/javascript"></script>
<script src="{{ url_for('admin.static', filename='select2/select2.min.js') }}" type="text/javascript"></script>
{% block tail %}
{% endblock %}
</body>
</html>
{% extends admin_base_template %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment