clean up, merge the different kind of lists, merge BaseSection & Section

This commit is contained in:
bkfox 2016-05-26 21:45:11 +02:00
parent 7402fc49b6
commit 157914a0a1
10 changed files with 140 additions and 179 deletions

View File

@ -170,7 +170,6 @@ class Post (models.Model):
return self.route_url(routes.DetailRoute, return self.route_url(routes.DetailRoute,
{ 'pk': self.pk, 'slug': slugify(self.title) }) { 'pk': self.pk, 'slug': slugify(self.title) })
def get_object_list(self, request, object, **kwargs): def get_object_list(self, request, object, **kwargs):
type = ContentType.objects.get_for_model(object) type = ContentType.objects.get_for_model(object)
qs = Comment.objects.filter( qs = Comment.objects.filter(

View File

@ -0,0 +1,33 @@
{% extends "aircox/cms/section.html" %}
{% load i18n %}
{% load honeypot %}
{% block header %}
{% if comment_form %}
{% with comment_form as form %}
{{ form.non_field_errors }}
<form action="" method="POST" class="comment_form">
{% csrf_token %}
{% render_honeypot_field "hp_website" %}
<div>
{{ form.author.errors }}
{{ form.author }}
<input type="checkbox" value="1">
<div class="extra">
{{ form.email.errors }}
{{ form.email }}
{{ form.url.errors }}
{{ form.url }}
</div>
</div>
<div>
{{ form.content.errors }}
{{ form.content }}
<button type="submit">{% trans "Post!" %}</button>
</div>
</form>
{% endwith %}
{% endif %}
{% endblock %}

View File

@ -1,8 +0,0 @@
<{{ tag }} class="{{ classes }}"
{% for k, v in attrs.items %}{{ k }} = "{{ v|addslashes }}" {% endfor %} >
{% block content %}
{{ content|safe }}
{% endblock %}
</{{ tag }}>

View File

@ -1,53 +1,78 @@
{% extends "aircox/cms/website.html" %} {% extends base_template %}
{% load i18n %} {% load i18n %}
{% load thumbnail %} {% load thumbnail %}
{% block content %} {% block content %}
<div class="post_list {{ classes }} {% if embed %}embed{% endif %}"> <ul>
{% for post in object_list %} {% for item in object_list %}
<a class="post_item" <li {% if item.css_class %}class="{{ item.css_class }}"{% endif %}
href="{{ post.detail_url }}"> {% for k, v in item.attrs.items %}
{% if 'date' in view.fields or 'time' in view.fields %} {{ k }} = "{{ v|addslashes }}"
<time datetime="{{ post.date }}" class="post_datetime"> {% endfor %} >
{% if 'date' in view.fields %} {% if item.detail_url %}
<span class="post_date"> <a href="{{ item.detail_url }}">
{{ post.date|date:'D. d F' }} {% endif %}
{% if 'date' in list.fields or 'time' in list.fields or 'author' in list.fields %}
<div class="meta">
{% if item.date and 'date' in list.fields or 'time' in list.fields %}
<time datetime="{{ item.date }}">
{% if 'date' in list.fields %}
<span class="date">
{{ item.date|date:'D. d F' }}
</span> </span>
{% endif %} {% endif %}
{% if 'time' in view.fields %} {% if 'time' in list.fields %}
<span class="post_time"> <span class="time">
{{ post.date|date:'H:i' }} {{ item.date|date:'H:i' }}
</span> </span>
{% endif %} {% endif %}
</time> </time>
{% endif %} {% endif %}
{% if item.author and 'author' in list.fields %}
{% if 'image' in view.fields and post.image %} <span class="author">
<img src="{% thumbnail post.image view.icon_size crop %}" class="post_image"> {{ item.author }}
</span>
{% endif %} {% endif %}
{% if 'title' in view.fields %}
<h3 class="post_title">{{ post.title }}</h3>
{% endif %}
{% if 'content' in view.fields %}
<div class="post_content">
{{ post.content|safe|striptags|truncatechars:"64" }}
</div> </div>
{% endif %} {% endif %}
</a>
{% endfor %}
</div>
<nav> {% if 'image' in list.fields and item.image %}
{% if embed %} <img src="{% thumbnail item.image list.image_size crop %}">
{% with view.get_url as list_url %}
{% if list_url %}
<a href="{{list_url}}" title="More elements">&#8690;</a>
{% endif %} {% endif %}
{% endwith %}
{% if 'title' in list.fields %}
<h2 class="title">{{ item.title }}</h2>
{% endif %}
{% if 'content' in list.fields %}
<div class="content">
{% if list.truncate %}
{{ item.content|striptags|truncatewords:list.truncate }}
{% else %} {% else %}
{{ item.content|striptags }}
{% endif %}
</div>
{% endif %}
{% if item.detail_url %}
</a>
{% endif %}
{% empty %}
<div class="message empty">
{{ list.message_empty }}
</div>
{% endfor %}
</ul>
{% if page_obj or list.url %}
<nav>
{% if not page_obj or embed %}
<a href="{{list.url}}" title={% trans "More elements" %}>&#8690;</a>
{% else %}
{# FIXME: page numbers #}
{% if page_obj.has_previous %} {% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}">previous</a> <a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %} {% endif %}
@ -61,5 +86,6 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</nav> </nav>
{% endif %}
{% endblock %} {% endblock %}

View File

@ -1,10 +0,0 @@
<{{ tag }} class="menu menu_{{ position }} {{ classes }}" {% if name %}
name="{{ name }}"
id="{{ name }}"
{% endif %}>
{% for section in sections %}
{{ section|safe }}
{% endfor %}
</{{ tag }}>

View File

@ -1,34 +1,35 @@
{% extends "aircox/cms/content_object.html" %}
{% block content %} <{{ tag }} class="{{ css_class }}"
{% for k, v in list.attrs.items %}
{{ k }} = "{{ v|addslashes }}"
{% endfor %} >
{% block title %}
{% if title %} {% if title %}
<h1> <h1>
{% block section_title %}
{{ title }} {{ title }}
{% endblock %}
</h1> </h1>
{% endif %} {% endif %}
{% endblock %}
{% block header %}
{% if header %} {% if header %}
<header> <header>
{% block section_header %}
{{ header }} {{ header }}
{% endblock %}
</header> </header>
{% endif %} {% endif %}
{% endblock %}
<div class="content"> {% block content %}
{% block section_content %}
{{ content|safe }} {{ content|safe }}
{% endblock %} {% endblock %}
</div>
{% block footer %}
{% if footer %} {% if footer %}
<footer> <footer>
{% block section_footer %}
{{ footer }} {{ footer }}
{% endblock %}
</footer> </footer>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
</{{ tag }}>

View File

@ -1,52 +0,0 @@
{% extends "aircox/cms/section.html" %}
{% load i18n %}
{% load honeypot %}
{% block section_content %}
{{ form.non_field_errors }}
<form action="" method="POST" class="comment_form">
{% csrf_token %}
{% render_honeypot_field "hp_website" %}
<div>
{{ form.author.errors }}
{{ form.author }}
<input type="checkbox" value="1">
<div class="extra">
{{ form.email.errors }}
{{ form.email }}
{{ form.url.errors }}
{{ form.url }}
</div>
</div>
<div>
{{ form.content.errors }}
{{ form.content }}
<button type="submit">{% trans "Post!" %}</button>
</div>
</form>
<div class="comment_list">
{% for item in object_list %}
<div id="comment-{{ item.id }}" class="comment_item">
{{ item.content }}
<div class="metadata">
<a href="{% if item.url %}{{ item.url }}{% else
%}#{% endif %}" class="author">
{{ item.author }}
</a>
<time datetime="{{ item.date }}">
{{ item.date|date:'l d F Y' }},
{{ item.date|time:'H\hi' }}
</time>
<a href="#comment-{{ item.id }}">#{{ item.id }}</a>
</div>
</div>
{% endfor %}
</div>
{% endblock %}

View File

@ -1,28 +0,0 @@
{% extends "aircox/cms/section.html" %}
{% load thumbnail %}
{% block section_content %}
<ul style="padding:0; margin:0">
{% for item in object_list %}
<li class="{{item.css}}">
{% if item.url %}
<a href="{{item.url}}">
{% endif %}
{% if use_icons and item.icon %}
<img src="{% thumbnail item.icon icon_size crop %}" class="icon">
{% endif %}
{{ item.title }}
{% if item.text %}
<small>{{ item.text }}</small>
{% endif %}
{% if item.url %}
</a>
{% endif %}
</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -5,7 +5,10 @@ from django.views.generic.base import View
from django.utils.translation import ugettext as _, ugettext_lazy from django.utils.translation import ugettext as _, ugettext_lazy
from django.http import Http404 from django.http import Http404
from django.views.decorators.http import require_http_methods from honeypot.decorators import verify_honeypot_value
from aircox.cms.forms import CommentForm
class PostBaseView: class PostBaseView:
website = None # corresponding website website = None # corresponding website
@ -25,8 +28,9 @@ class PostBaseView:
} }
if not self.embed: if not self.embed:
object = self.object if hasattr(self, 'object') else None
context['menus'] = { context['menus'] = {
k: v.get(self.request, object = self.object, **kwargs) k: v.get(self.request, object = object, **kwargs)
for k, v in { for k, v in {
k: self.website.get_menu(k) k: self.website.get_menu(k)
for k in self.website.menu_layouts for k in self.website.menu_layouts
@ -53,8 +57,7 @@ class PostListView(PostBaseView, ListView):
model = None model = None
route = None route = None
fields = [ 'date', 'time', 'image', 'title', 'content' ] list = None
icon_size = '64x64'
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -93,28 +96,28 @@ class PostListView(PostBaseView, ListView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context.update(self.get_base_context(**kwargs)) context.update(self.get_base_context(**kwargs))
context.update({
'title': self.get_title(), title = self.title if self.title else \
}) self.route and self.route.get_title(self.model, self.request,
**self.kwargs)
context['title'] = title
context['base_template'] = 'aircox/cms/website.html'
if not self.list:
import aircox.cms.sections as sections
self.list = sections.List(
truncate = 64,
fields = [ 'date', 'time', 'image', 'title', 'content' ],
)
context['list'] = self.list
# FIXME: list.url = if self.route: self.model(self.route, self.kwargs) else ''
return context return context
def get_title(self):
if self.title:
return self.title
title = self.route and self.route.get_title(self.model, self.request,
**self.kwargs)
return title
def get_url(self): def get_url(self):
if self.route:
return self.model(self.route, self.kwargs)
return '' return ''
from honeypot.decorators import verify_honeypot_value
from aircox.cms.forms import CommentForm
class PostDetailView(DetailView, PostBaseView): class PostDetailView(DetailView, PostBaseView):
""" """
Detail view for posts and children Detail view for posts and children
@ -173,9 +176,8 @@ class PostDetailView(DetailView, PostBaseView):
return self.get(request, *args, **kwargs) return self.get(request, *args, **kwargs)
class Menu(View): class Menu(View):
template_name = 'aircox/cms/content_object.html' template_name = 'aircox/cms/section.html'
tag = 'nav' tag = 'nav'
classes = '' classes = ''
attrs = '' attrs = ''
@ -212,4 +214,3 @@ class Menu(View):
return render_to_string(self.template_name, context) return render_to_string(self.template_name, context)

View File

@ -74,7 +74,6 @@ class Actions:
if manual: if manual:
Diffusion.objects.bulk_create(items) Diffusion.objects.bulk_create(items)
else: else:
print('items: ', len(items))
for item in items: for item in items:
count[1] += cl.__check_conflicts(item, saved_items) count[1] += cl.__check_conflicts(item, saved_items)
if hasattr(item, 'do_not_save'): if hasattr(item, 'do_not_save'):