forked from rc/aircox
		
	work on sections
This commit is contained in:
		@ -1,10 +1,41 @@
 | 
			
		||||
body { padding: 0; margin: 0; }
 | 
			
		||||
 | 
			
		||||
nav.menu_top {
 | 
			
		||||
    width: 100%
 | 
			
		||||
    position: absolute;
 | 
			
		||||
    border-bottom: 1px grey solid;
 | 
			
		||||
body {
 | 
			
		||||
    padding: 0;
 | 
			
		||||
    margin: 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
.page {
 | 
			
		||||
    display: flex;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    .page .menu {
 | 
			
		||||
        width: 15em;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    .page .menu_left { margin-right: 0.5em; }
 | 
			
		||||
    .page .menu_right { margin-left: 0.5em; }
 | 
			
		||||
 | 
			
		||||
    .page main {
 | 
			
		||||
        flex-grow: 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
main .section {
 | 
			
		||||
    width: calc(50% - 1em);
 | 
			
		||||
    float: left;
 | 
			
		||||
    padding: 0.5em;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    main .section .section_content {
 | 
			
		||||
        font-size: 0.95em;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    main .section h1 {
 | 
			
		||||
        font-size: 1.2em;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    main .section * {
 | 
			
		||||
        max-width: 100%;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								aircox_cms/templates/aircox_cms/base_section.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								aircox_cms/templates/aircox_cms/base_section.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
 | 
			
		||||
<{{ tag }} class="section {{ classes }}"
 | 
			
		||||
    {% for key, value in attrs.items %}{{ key }} = "{{ value|addslashes }}"
 | 
			
		||||
    {% endfor %} >
 | 
			
		||||
{% block content %}
 | 
			
		||||
{{ content|safe }}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
</{{ tag }}>
 | 
			
		||||
 | 
			
		||||
@ -8,22 +8,23 @@
 | 
			
		||||
        <meta name="description" content="{{ website.description }}">
 | 
			
		||||
        <meta name="keywords" content="{{ website.tags }}">
 | 
			
		||||
 | 
			
		||||
        <link rel="stylesheet" href="{% static "aircox_aircox_cms/styles.css" %}" type="text/css">
 | 
			
		||||
        <link rel="stylesheet" href="{% static "aircox_cms/styles.css" %}" type="text/css">
 | 
			
		||||
        {% if website.styles %}
 | 
			
		||||
        <link rel="stylesheet" href="{% static website.styles %}" type="text/css">
 | 
			
		||||
        {% endif %}
 | 
			
		||||
        <title>{{ website.name }} {% if title %}- {{ title }} {% endif %}</title>
 | 
			
		||||
    </head>
 | 
			
		||||
    <body>
 | 
			
		||||
        {% block header %}
 | 
			
		||||
            {% if menus.header %}
 | 
			
		||||
            {{ menus.header|safe }}
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        {% endblock %}
 | 
			
		||||
 | 
			
		||||
        {% if menus.top %}
 | 
			
		||||
            {{ menus.top|safe }}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
 | 
			
		||||
        {% block header %}
 | 
			
		||||
            {% if menus.header %}
 | 
			
		||||
            <header>
 | 
			
		||||
                {{ menus.header|safe }}
 | 
			
		||||
            </header>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        {% endblock %}
 | 
			
		||||
 | 
			
		||||
        <div class="page">
 | 
			
		||||
            {% if menus.left %}
 | 
			
		||||
                {{ menus.left|safe }}
 | 
			
		||||
@ -50,11 +51,13 @@
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        {% if menus.page_bottom %}
 | 
			
		||||
            {{ menus.page_bottom|safe }}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
 | 
			
		||||
        {% block footer %}
 | 
			
		||||
            {% if menus.footer %}
 | 
			
		||||
            <footer>
 | 
			
		||||
                {{ menus.footer|safe }}
 | 
			
		||||
            </footer>
 | 
			
		||||
            {{ menus.footer|safe }}
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        {% endblock %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,10 @@
 | 
			
		||||
 | 
			
		||||
<nav class="menu menu_{{ position }} {{ classes }}" {% if name %}
 | 
			
		||||
        name="menu_{{ name }}"
 | 
			
		||||
        id="menu_{{ name }}"
 | 
			
		||||
<{{ tag }} class="menu menu_{{ position }} {{ classes }}" {% if name %}
 | 
			
		||||
        name="{{ name }}"
 | 
			
		||||
        id="{{ name }}"
 | 
			
		||||
    {% endif %}>
 | 
			
		||||
    {% for section in sections %}
 | 
			
		||||
    {{ section|safe }}
 | 
			
		||||
    {% endfor %}
 | 
			
		||||
</nav>
 | 
			
		||||
</{{ tag }}>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,33 +1,34 @@
 | 
			
		||||
<div class="section {{ classes }}">
 | 
			
		||||
    {% if title %}
 | 
			
		||||
    <h1>
 | 
			
		||||
        {% block section_title %}
 | 
			
		||||
        {{ title }}
 | 
			
		||||
        {% endblock %}
 | 
			
		||||
    </h1>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
{% extends "aircox_cms/base_section.html" %}
 | 
			
		||||
 | 
			
		||||
    {% if header %}
 | 
			
		||||
    <header class="section_header">
 | 
			
		||||
        {% block section_header %}
 | 
			
		||||
        {{ header }}
 | 
			
		||||
        {% endblock %}
 | 
			
		||||
    </header>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
{% block content %}
 | 
			
		||||
{% if title %}
 | 
			
		||||
<h1>
 | 
			
		||||
    {% block section_title %}
 | 
			
		||||
    {{ title }}
 | 
			
		||||
    {% endblock %}
 | 
			
		||||
</h1>
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
    <div class="section_content">
 | 
			
		||||
        {% block section_content %}
 | 
			
		||||
        {{ content|safe }}
 | 
			
		||||
        {% endblock %}
 | 
			
		||||
    </div>
 | 
			
		||||
{% if header %}
 | 
			
		||||
<header class="section_header">
 | 
			
		||||
    {% block section_header %}
 | 
			
		||||
    {{ header }}
 | 
			
		||||
    {% endblock %}
 | 
			
		||||
</header>
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
    {% if bottom %}
 | 
			
		||||
    <div class="section_bottom">
 | 
			
		||||
        {% block section_bottom %}
 | 
			
		||||
        {{ bottom }}
 | 
			
		||||
        {% endblock %}
 | 
			
		||||
    </div>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
<div class="section_content">
 | 
			
		||||
    {% block section_content %}
 | 
			
		||||
    {{ content|safe }}
 | 
			
		||||
    {% endblock %}
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
{% if bottom %}
 | 
			
		||||
<div class="section_bottom">
 | 
			
		||||
    {% block section_bottom %}
 | 
			
		||||
    {{ bottom }}
 | 
			
		||||
    {% endblock %}
 | 
			
		||||
</div>
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,14 @@
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
from django.templatetags.static import static
 | 
			
		||||
from django.shortcuts import render
 | 
			
		||||
from django.template.loader import render_to_string
 | 
			
		||||
from django.views.generic import ListView, DetailView
 | 
			
		||||
from django.views.generic.base import View, TemplateResponseMixin
 | 
			
		||||
from django.core import serializers
 | 
			
		||||
from django.utils.translation import ugettext as _, ugettext_lazy
 | 
			
		||||
from django.utils.html import escape
 | 
			
		||||
 | 
			
		||||
import aircox_cms.routes as routes
 | 
			
		||||
 | 
			
		||||
@ -29,12 +34,8 @@ class PostBaseView:
 | 
			
		||||
            context['menus'] = {
 | 
			
		||||
                k: v.get(self.request)
 | 
			
		||||
                for k, v in {
 | 
			
		||||
                    'top': self.website.get_menu('top'),
 | 
			
		||||
                    'left': self.website.get_menu('left'),
 | 
			
		||||
                    'bottom': self.website.get_menu('bottom'),
 | 
			
		||||
                    'right': self.website.get_menu('right'),
 | 
			
		||||
                    'header': self.website.get_menu('header'),
 | 
			
		||||
                    'footer': self.website.get_menu('footer'),
 | 
			
		||||
                    k: self.website.get_menu(k)
 | 
			
		||||
                    for k in self.website.menu_layouts
 | 
			
		||||
                }.items() if v
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -162,6 +163,179 @@ class PostDetailView (DetailView, PostBaseView):
 | 
			
		||||
        return context
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Menu (View):
 | 
			
		||||
    template_name = 'aircox_cms/menu.html'
 | 
			
		||||
 | 
			
		||||
    name = ''
 | 
			
		||||
    tag = 'nav'
 | 
			
		||||
    enabled = True
 | 
			
		||||
    classes = ''
 | 
			
		||||
    position = ''   # top, left, bottom, right, header, footer, page_top, page_bottom
 | 
			
		||||
    sections = None
 | 
			
		||||
 | 
			
		||||
    def __init__ (self, *args, **kwargs):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.name = self.name or ('menu_' + self.position)
 | 
			
		||||
 | 
			
		||||
    def get_context_data (self, **kwargs):
 | 
			
		||||
        return {
 | 
			
		||||
            'name': self.name,
 | 
			
		||||
            'tag': self.tag,
 | 
			
		||||
            'classes': self.classes,
 | 
			
		||||
            'position': self.position,
 | 
			
		||||
            'sections': [
 | 
			
		||||
                section.get(self.request, object = None)
 | 
			
		||||
                    for section in self.sections
 | 
			
		||||
            ]
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def get (self, request, **kwargs):
 | 
			
		||||
        self.request = request
 | 
			
		||||
        context = self.get_context_data(**kwargs)
 | 
			
		||||
        return render_to_string(self.template_name, context)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BaseSection (View):
 | 
			
		||||
    """
 | 
			
		||||
    Base class for sections. Sections are view that can be used in detail view
 | 
			
		||||
    in order to have extra content about a post, or in menus.
 | 
			
		||||
    """
 | 
			
		||||
    template_name = 'aircox_cms/base_section.html'
 | 
			
		||||
    tag = 'div'        # container tags
 | 
			
		||||
    classes = ''    # container classes
 | 
			
		||||
    attrs = ''      # container extra attributes
 | 
			
		||||
    content = ''    # content
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def get_context_data (self, **kwargs):
 | 
			
		||||
        return {
 | 
			
		||||
            'tag': self.tag,
 | 
			
		||||
            'classes': self.classes,
 | 
			
		||||
            'attrs': self.attrs,
 | 
			
		||||
            'content': self.content,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def get (self, request, **kwargs):
 | 
			
		||||
        self.request = request
 | 
			
		||||
        context = self.get_context_data(**kwargs)
 | 
			
		||||
        return render_to_string(self.template_name, context)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Section (BaseSection):
 | 
			
		||||
    template_name = 'aircox_cms/section.html'
 | 
			
		||||
    require_object = False
 | 
			
		||||
    object = None
 | 
			
		||||
    title = ''
 | 
			
		||||
    header = ''
 | 
			
		||||
    bottom = ''
 | 
			
		||||
 | 
			
		||||
    def get_context_data (self, **kwargs):
 | 
			
		||||
        context = super().get_context_data(**kwargs)
 | 
			
		||||
        context.update({
 | 
			
		||||
            'title': self.title,
 | 
			
		||||
            'header': self.header,
 | 
			
		||||
            'bottom': self.bottom,
 | 
			
		||||
        })
 | 
			
		||||
        return context
 | 
			
		||||
 | 
			
		||||
    def get (self, request, **kwargs):
 | 
			
		||||
        self.object = kwargs.get('object') or self.object
 | 
			
		||||
        return super().get(request, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Sections:
 | 
			
		||||
    class Image (BaseSection):
 | 
			
		||||
        url = None # relative url to the image
 | 
			
		||||
 | 
			
		||||
        @property
 | 
			
		||||
        def content (self):
 | 
			
		||||
            return '<img src="{}">'.format(
 | 
			
		||||
                        static(self.url),
 | 
			
		||||
                    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    class PostContent (Section):
 | 
			
		||||
        @property
 | 
			
		||||
        def content (self):
 | 
			
		||||
            content = escape(self.object.content)
 | 
			
		||||
            content = re.sub(r'(^|\n\n)((\n?[^\n])+)', r'<p>\2</p>', content)
 | 
			
		||||
            content = re.sub(r'\n', r'<br>', content)
 | 
			
		||||
            return content
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    class PostImage (Section):
 | 
			
		||||
        @property
 | 
			
		||||
        def content (self):
 | 
			
		||||
            return '<img src="{}" class="post_image">'.format(
 | 
			
		||||
                        self.object.image.url
 | 
			
		||||
                    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    class List (Section):
 | 
			
		||||
        """
 | 
			
		||||
        Section to render list. The context item 'object_list' is used as list of
 | 
			
		||||
        items to render.
 | 
			
		||||
        """
 | 
			
		||||
        class Item:
 | 
			
		||||
            icon = None
 | 
			
		||||
            title = None
 | 
			
		||||
            text = None
 | 
			
		||||
 | 
			
		||||
            def __init__ (self, icon, title = None, text = None):
 | 
			
		||||
                self.icon = icon
 | 
			
		||||
                self.title = title
 | 
			
		||||
                self.text = text
 | 
			
		||||
 | 
			
		||||
        use_icons = True
 | 
			
		||||
        icon_size = '32x32'
 | 
			
		||||
        template_name = 'aircox_cms/section_list.html'
 | 
			
		||||
 | 
			
		||||
        def get_object_list (self):
 | 
			
		||||
            return []
 | 
			
		||||
 | 
			
		||||
        def get_context_data (self, **kwargs):
 | 
			
		||||
            context = super().get_context_data(**kwargs)
 | 
			
		||||
            context.update({
 | 
			
		||||
                'classes': context.get('classes') + ' section_list',
 | 
			
		||||
                'icon_size': self.icon_size,
 | 
			
		||||
                'object_list': self.get_object_list(),
 | 
			
		||||
            })
 | 
			
		||||
            return context
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    class UrlList (List):
 | 
			
		||||
        classes = 'section_urls'
 | 
			
		||||
        targets = None
 | 
			
		||||
 | 
			
		||||
        def get_object_list (self, request, **kwargs):
 | 
			
		||||
            return [
 | 
			
		||||
                List.Item(
 | 
			
		||||
                    target.image or None,
 | 
			
		||||
                    '<a href="{}">{}</a>'.format(target.detail_url(), target.title)
 | 
			
		||||
                )
 | 
			
		||||
                for target in self.targets
 | 
			
		||||
            ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    class PostList (PostListView):
 | 
			
		||||
        route = None
 | 
			
		||||
        model = None
 | 
			
		||||
        embed = True
 | 
			
		||||
 | 
			
		||||
        def __init__ (self, *args, **kwargs):
 | 
			
		||||
            super().__init__(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
        def get_kwargs (self, request, **kwargs):
 | 
			
		||||
            return kwargs
 | 
			
		||||
 | 
			
		||||
        def dispatch (self, request, *args, **kwargs):
 | 
			
		||||
            kwargs = self.get_kwargs(kwargs)
 | 
			
		||||
            response = super().dispatch(request, *args, **kwargs)
 | 
			
		||||
            return str(response.content)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ViewSet:
 | 
			
		||||
    """
 | 
			
		||||
    A ViewSet is a class helper that groups detail and list views that can be
 | 
			
		||||
@ -173,7 +347,10 @@ class ViewSet:
 | 
			
		||||
    list_routes = []
 | 
			
		||||
 | 
			
		||||
    detail_view = PostDetailView
 | 
			
		||||
    detail_sections = []
 | 
			
		||||
    detail_sections = [
 | 
			
		||||
        Sections.PostContent,
 | 
			
		||||
        Sections.PostImage,
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    def __init__ (self, website = None):
 | 
			
		||||
        self.detail_sections = [
 | 
			
		||||
@ -195,131 +372,3 @@ class ViewSet:
 | 
			
		||||
                      [ routes.DetailRoute.as_url(self.model, self.detail_view ) ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Menu (View):
 | 
			
		||||
    template_name = 'aircox_cms/menu.html'
 | 
			
		||||
 | 
			
		||||
    name = ''
 | 
			
		||||
    enabled = True
 | 
			
		||||
    classes = ''
 | 
			
		||||
    position = ''   # top, left, bottom, right, header, footer
 | 
			
		||||
    sections = None
 | 
			
		||||
 | 
			
		||||
    def __init__ (self, *args, **kwargs):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.name = self.name or ('menu_' + self.position)
 | 
			
		||||
 | 
			
		||||
    def get_context_data (self, **kwargs):
 | 
			
		||||
        return {
 | 
			
		||||
            'name': self.name,
 | 
			
		||||
            'classes': self.classes,
 | 
			
		||||
            'position': self.position,
 | 
			
		||||
            'sections': [
 | 
			
		||||
                section.get(self.request, object = None)
 | 
			
		||||
                    for section in self.sections
 | 
			
		||||
            ]
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def get (self, request, **kwargs):
 | 
			
		||||
        self.request = request
 | 
			
		||||
        context = self.get_context_data(**kwargs)
 | 
			
		||||
        return render_to_string(self.template_name, context)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Section (View):
 | 
			
		||||
    """
 | 
			
		||||
    Base class for sections. Sections are view that can be used in detail view
 | 
			
		||||
    in order to have extra content about a post.
 | 
			
		||||
    """
 | 
			
		||||
    template_name = 'aircox_cms/section.html'
 | 
			
		||||
    require_object = False
 | 
			
		||||
    object = None
 | 
			
		||||
    classes = ''
 | 
			
		||||
    title = ''
 | 
			
		||||
    content = ''
 | 
			
		||||
    header = ''
 | 
			
		||||
    bottom = ''
 | 
			
		||||
 | 
			
		||||
    def get_context_data (self, **kwargs):
 | 
			
		||||
        context = {
 | 
			
		||||
            'title': self.title,
 | 
			
		||||
            'header': self.header,
 | 
			
		||||
            'content': self.content,
 | 
			
		||||
            'bottom': self.bottom,
 | 
			
		||||
            'classes': self.classes,
 | 
			
		||||
        }
 | 
			
		||||
        return context
 | 
			
		||||
 | 
			
		||||
    def get (self, request, **kwargs):
 | 
			
		||||
        self.object = kwargs.get('object') or self.object
 | 
			
		||||
        self.request = request
 | 
			
		||||
        context = self.get_context_data(**kwargs)
 | 
			
		||||
        return render_to_string(self.template_name, context)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ListSection (Section):
 | 
			
		||||
    """
 | 
			
		||||
    Section to render list. The context item 'object_list' is used as list of
 | 
			
		||||
    items to render.
 | 
			
		||||
    """
 | 
			
		||||
    class Item:
 | 
			
		||||
        icon = None
 | 
			
		||||
        title = None
 | 
			
		||||
        text = None
 | 
			
		||||
 | 
			
		||||
        def __init__ (self, icon, title = None, text = None):
 | 
			
		||||
            self.icon = icon
 | 
			
		||||
            self.title = title
 | 
			
		||||
            self.text = text
 | 
			
		||||
 | 
			
		||||
    use_icons = True
 | 
			
		||||
    icon_size = '32x32'
 | 
			
		||||
    template_name = 'aircox_cms/section_list.html'
 | 
			
		||||
 | 
			
		||||
    def get_object_list (self):
 | 
			
		||||
        return []
 | 
			
		||||
 | 
			
		||||
    def get_context_data (self, **kwargs):
 | 
			
		||||
        context = super().get_context_data(**kwargs)
 | 
			
		||||
        context.update({
 | 
			
		||||
            'classes': context.get('classes') + ' section_list',
 | 
			
		||||
            'icon_size': self.icon_size,
 | 
			
		||||
            'object_list': self.get_object_list(),
 | 
			
		||||
        })
 | 
			
		||||
        return context
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class UrlListSection (ListSection):
 | 
			
		||||
    classes = 'section_urls'
 | 
			
		||||
    targets = None
 | 
			
		||||
 | 
			
		||||
    def get_object_list (self, request, **kwargs):
 | 
			
		||||
        return [
 | 
			
		||||
            ListSection.Item(
 | 
			
		||||
                target.image or None,
 | 
			
		||||
                '<a href="{}">{}</a>'.format(target.detail_url(), target.title)
 | 
			
		||||
            )
 | 
			
		||||
            for target in self.targets
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PostListSection (PostListView):
 | 
			
		||||
    route = None
 | 
			
		||||
    model = None
 | 
			
		||||
    embed = True
 | 
			
		||||
 | 
			
		||||
    def __init__ (self, *args, **kwargs):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_kwargs (self, request, **kwargs):
 | 
			
		||||
        return kwargs
 | 
			
		||||
 | 
			
		||||
    def dispatch (self, request, *args, **kwargs):
 | 
			
		||||
        kwargs = self.get_kwargs(kwargs)
 | 
			
		||||
        response = super().dispatch(request, *args, **kwargs)
 | 
			
		||||
        return str(response.content)
 | 
			
		||||
 | 
			
		||||
# TODO:
 | 
			
		||||
# - get_title: pass object / queryset
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,38 +6,46 @@ class Website:
 | 
			
		||||
    description = 'An aircox website'   # public description (used in meta info)
 | 
			
		||||
    tags = 'aircox,radio,music'         # public keywords (used in meta info)
 | 
			
		||||
 | 
			
		||||
    logo = None
 | 
			
		||||
    menus = None
 | 
			
		||||
    styles = ''                         # relative url to stylesheet file
 | 
			
		||||
    menus = None                        # list of menus
 | 
			
		||||
    menu_layouts = ['top', 'left',      # available positions
 | 
			
		||||
                    'right', 'bottom',
 | 
			
		||||
                    'header', 'footer']
 | 
			
		||||
    router = None
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def urls (self):
 | 
			
		||||
        return self.router.get_urlpatterns()
 | 
			
		||||
 | 
			
		||||
    def __init__ (self, **kwargs):
 | 
			
		||||
        self.__dict__.update(kwargs)
 | 
			
		||||
        if not self.router:
 | 
			
		||||
            self.router = routes.Router()
 | 
			
		||||
 | 
			
		||||
    def register_set (self, view_set):
 | 
			
		||||
        """
 | 
			
		||||
        Register a ViewSet (or subclass) to the router,
 | 
			
		||||
        and connect it to self.
 | 
			
		||||
        """
 | 
			
		||||
        view_set = view_set(website = self)
 | 
			
		||||
        self.router.register_set(view_set)
 | 
			
		||||
 | 
			
		||||
    def get_menu (self, position):
 | 
			
		||||
        """
 | 
			
		||||
        Get an enabled menu by its position
 | 
			
		||||
        """
 | 
			
		||||
        for menu in self.menus:
 | 
			
		||||
            if menu.enabled and menu.position == position:
 | 
			
		||||
                self.check_menu_tag(menu)
 | 
			
		||||
                return menu
 | 
			
		||||
 | 
			
		||||
    def get_top_menu (self):
 | 
			
		||||
        return self.get_menu('top')
 | 
			
		||||
 | 
			
		||||
    def get_left_menu (self):
 | 
			
		||||
        return self.get_menu('left')
 | 
			
		||||
 | 
			
		||||
    def get_bottom_menu (self):
 | 
			
		||||
        return self.get_menu('bottom')
 | 
			
		||||
 | 
			
		||||
    def get_right_menu (self):
 | 
			
		||||
        return self.get_menu('right')
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def urls (self):
 | 
			
		||||
        return self.router.get_urlpatterns()
 | 
			
		||||
    def check_menu_tag (self, menu):
 | 
			
		||||
        """
 | 
			
		||||
        Update menu tag if it is a footer or a header
 | 
			
		||||
        """
 | 
			
		||||
        if menu.position in ('footer','header'):
 | 
			
		||||
            menu.tag = menu.position
 | 
			
		||||
        if menu.position in ('left', 'right'):
 | 
			
		||||
            menu.tag = 'side'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user