implement custom template view, add docs for it

This commit is contained in:
Thomas Waldmann 2014-01-21 23:48:51 +01:00
parent efd4f79ef9
commit c0cb56a97d
3 changed files with 33 additions and 1 deletions

View File

@ -216,6 +216,29 @@ Note: it is advised that you keep local customizations to a minimum as if you
override builtin templates with your customized copies, you will have to keep override builtin templates with your customized copies, you will have to keep
your copies in sync with future changes we make to the builtin ones. your copies in sync with future changes we make to the builtin ones.
Custom templates
----------------
If you need to add some simple views, just showing some simple templates (like
e.g. if you have some footer links that link to these views to show some site-
specific content, some legalese, ...), do it like that:
* have a footer and a custom template directory like described in previous
section
* add files like main/custom/foo.html to that directory::
{% extends "base.html" %}
{% load bootstrap %}
{% block content %}
This is content rendered from template "foo.html".
{% endblock %}
* link to the view made from that template like this::
<a href="{% url 'custom' template='foo.html' %}">
link to custom foo.html view
</a>
Maintenance Maintenance
=========== ===========

View File

@ -8,7 +8,7 @@ from django.views.generic import TemplateView
from .views import ( from .views import (
HomeView, OverviewView, HostView, DeleteHostView, AboutView, GenerateSecretView, GenerateNSSecretView, HomeView, OverviewView, HostView, DeleteHostView, AboutView, GenerateSecretView, GenerateNSSecretView,
RobotsTxtView, DomainOverviewView, DomainView, DeleteDomainView, StatusView, JsUpdateView, RobotsTxtView, DomainOverviewView, DomainView, DeleteDomainView, StatusView, JsUpdateView,
UpdaterHostConfigOverviewView, UpdaterHostConfigView, DeleteUpdaterHostConfigView) UpdaterHostConfigOverviewView, UpdaterHostConfigView, DeleteUpdaterHostConfigView, CustomTemplateView)
from ..api.views import ( from ..api.views import (
myip_view, DetectIpView, AjaxGetIps, NicUpdateView, AuthorizedNicUpdateView, myip_view, DetectIpView, AjaxGetIps, NicUpdateView, AuthorizedNicUpdateView,
NicDeleteView, AuthorizedNicDeleteView) NicDeleteView, AuthorizedNicDeleteView)
@ -19,6 +19,7 @@ urlpatterns = patterns(
# interactive web ui # interactive web ui
url(r'^$', HomeView.as_view(), name="home"), url(r'^$', HomeView.as_view(), name="home"),
url(r'^about/$', AboutView.as_view(), name="about"), url(r'^about/$', AboutView.as_view(), name="about"),
url(r'^custom/(?P<template>[\w.]+)$', CustomTemplateView.as_view(), name="custom"),
url(r'^update$', JsUpdateView.as_view(), name='update'), url(r'^update$', JsUpdateView.as_view(), name='update'),
url(r'^overview/$', OverviewView.as_view(), name='overview'), url(r'^overview/$', OverviewView.as_view(), name='overview'),
url(r'^host/(?P<pk>\d+)/$', HostView.as_view(), name='host_view'), url(r'^host/(?P<pk>\d+)/$', HostView.as_view(), name='host_view'),

View File

@ -80,6 +80,14 @@ class AboutView(TemplateView):
return context return context
class CustomTemplateView(TemplateView):
# template_name is set in dispatch method
def dispatch(self, *args, **kwargs):
self.template_name = 'main/custom/%s' % kwargs.get('template')
return super(CustomTemplateView, self).dispatch(*args, **kwargs)
class HomeView(TemplateView): class HomeView(TemplateView):
template_name = "main/home.html" template_name = "main/home.html"