rename 'item' in list_item template into 'object' to be more django compliant

This commit is contained in:
bkfox
2016-07-06 14:40:09 +02:00
parent dd2ccac3c0
commit cfce035527
6 changed files with 40 additions and 43 deletions

View File

@ -317,6 +317,7 @@ class RelatedMeta (models.base.ModelBase):
elif rel.auto_create(instance) if callable(rel.auto_create) else \
rel.auto_create:
post = model(related = instance)
# TODO: hackish way: model.objects.filter(related=null,...).delete()
else:
return
post.rel_to_post()
@ -325,7 +326,6 @@ class RelatedMeta (models.base.ModelBase):
post_save.connect(handler_rel, model._relation.model, False)
def __new__ (cl, name, bases, attrs):
# TODO: allow proxy models and better inheritance
# TODO: check bindings
if name == 'RelatedPost':
return super().__new__(cl, name, bases, attrs)
@ -348,7 +348,6 @@ class RelatedMeta (models.base.ModelBase):
name = rel.model._meta.object_name
if name == model._meta.object_name:
model._meta.default_related_name = '{} Post'.format(name)
return model
@ -401,7 +400,7 @@ class RelatedPost (Post, metaclass = RelatedMeta):
bindings = None
"""
dict of `post_attr: rel_attr` that represent bindings of values
between the post and the related object. Field are updated according
between the post and the related object. Fields are updated according
to `post_to_rel` and `rel_to_post`.
If there is a post_attr "thread", the corresponding rel_attr is used
@ -413,6 +412,11 @@ class RelatedPost (Post, metaclass = RelatedMeta):
note: bound values can be any value, not only Django field.
"""
defaults = None
"""
dict of `post_attr: value` that gives default value for the given
fields.
"""
post_to_rel = False
"""
update related object when the post is saved, using bindings
@ -474,7 +478,6 @@ class RelatedPost (Post, metaclass = RelatedMeta):
if save:
self.related.save()
def rel_to_post(self, save = True):
"""
Change the post using the related object bound values. Save the
@ -508,13 +511,6 @@ class RelatedPost (Post, metaclass = RelatedMeta):
if has_changed and save:
self.save()
def __init__ (self, *kargs, **kwargs):
super().__init__(*kargs, **kwargs)
# we use this method for sync, in order to avoid intrusive code on other
# applications, e.g. using signals.
if self.pk and self._relation.rel_to_post:
self.rel_to_post(False)
def save (self, avoid_sync = False, save = True, *args, **kwargs):
"""
* avoid_sync: do not synchronise the post/related object;

View File

@ -288,9 +288,6 @@ class List(Section):
"""
Prepare objects before context is sent to the template renderer.
Return the object_list that is prepared.
Remember: since we are in a rendering process, the items should
not be saved.
"""
return object_list

View File

@ -7,7 +7,7 @@
{% block content %}
<ul class="content">
{% for item in object_list %}
{% for object in object_list %}
{% include "aircox/cms/list_item.html" %}
{% empty %}
<div class="message empty">

View File

@ -2,62 +2,62 @@
{% load i18n %}
{% load thumbnail %}
<li {% if item.css_class %}class="{{ item.css_class }}"{% endif %}
{% for k, v in item.attrs.items %}
<li {% if object.css_class %}class="{{ object.css_class }}"{% endif %}
{% for k, v in object.attrs.items %}
{{ k }} = "{{ v|addslashes }}"
{% endfor %} >
{% if item.url %}
<a class="url" href="{{ item.url }}">
{% if object.url %}
<a class="url" href="{{ object.url }}">
{% endif %}
{% if 'image' in list.fields and item.image %}
<img class="image" src="{% thumbnail item.image list.image_size crop %}">
{% if 'image' in list.fields and object.image %}
<img class="image" src="{% thumbnail object.image list.image_size crop %}">
{% endif %}
<div class="body">
{% if 'title' in list.fields and item.title %}
<h2 class="title">{{ item.title }}</h2>
{% if 'title' in list.fields and object.title %}
<h2 class="title">{{ object.title }}</h2>
{% endif %}
{% if 'content' in list.fields and item.content %}
{% if 'content' in list.fields and object.content %}
<div class="content">
{% if list.truncate %}
{{ item.content|striptags|truncatewords:list.truncate }}
{{ object.content|striptags|truncatewords:list.truncate }}
{% else %}
{{ item.content|striptags }}
{{ object.content|striptags }}
{% endif %}
</div>
{% endif %}
</div>
<div class="meta">
{% if item.date and 'date' in list.fields or 'time' in list.fields %}
<time datetime="{{ item.date }}">
{% if object.date and 'date' in list.fields or 'time' in list.fields %}
<time datetime="{{ object.date }}">
{% if 'date' in list.fields %}
<span class="date">
{{ item.date|date:'D. d F' }}
{{ object.date|date:'D. d F' }}
</span>
{% endif %}
{% if 'time' in list.fields %}
<span class="time">
{{ item.date|date:'H:i' }}
{{ object.date|date:'H:i' }}
</span>
{% endif %}
</time>
{% endif %}
{% if item.author and 'author' in list.fields %}
{% if object.author and 'author' in list.fields %}
<span class="author">
{{ item.author }}
{{ object.author }}
</span>
{% endif %}
{% if item.info and 'info' in list.fields %}
{% if object.info and 'info' in list.fields %}
<span class="info">
{{ item.info }}
{{ object.info }}
</span>
{% endif %}
</div>
{% if item.url %}
{% if object.url %}
</a>
{% endif %}
</li>