add 'parts' system + script; work on player; create list_item.html template; update on_air

This commit is contained in:
bkfox
2016-06-14 03:33:26 +02:00
parent 5da8762f77
commit 3936580275
12 changed files with 466 additions and 144 deletions

View File

@ -212,7 +212,7 @@ class Post (models.Model, Routable):
abstract = True
class RelatedPostBase (models.base.ModelBase):
class RelatedMeta (models.base.ModelBase):
"""
Metaclass for RelatedPost children.
"""
@ -310,7 +310,7 @@ class RelatedPostBase (models.base.ModelBase):
return model
class RelatedPost (Post, metaclass = RelatedPostBase):
class RelatedPost (Post, metaclass = RelatedMeta):
"""
Post linked to an object of other model. This object is accessible through
the field "related".
@ -346,29 +346,6 @@ class RelatedPost (Post, metaclass = RelatedPostBase):
"""
Relation descriptor used to generate and manage the related object.
* model: model of the related object
* bindings: values that are bound between the post and the related
object. When the post is saved, these fields are updated on it.
It is a dict of { post_attr: rel_attr }
If there is a post_attr "thread", the corresponding rel_attr is used
to update the post thread to the correct Post model (in order to
establish a parent-child relation between two models)
When a callable is set as bound value, it will be called to retrieve
the value, as: callable_func(post, related)
Note: bound values can be any value, not only Django field.
* post_to_rel: auto update related object when post is updated
* rel_to_post: auto update the post when related object is updated
* thread_model: generated by the metaclass, points to the RelatedPost
model generated for the bindings.thread object.
* field_args: dict of arguments to pass to the ForeignKey constructor,
such as: ForeignKey(related_model, **field_args)
* auto_create: automatically create a RelatedPost for each new item of
the related object and init it with bounded values. Use 'post_save'
signal. If auto_create is callable, use `auto_create(related_object)`.
Be careful with post_to_rel!
* There is no check of permissions when related object is synchronised
from the post, so be careful when enabling post_to_rel.
@ -376,12 +353,48 @@ class RelatedPost (Post, metaclass = RelatedPostBase):
(sub-)class thread_model, the related parent is set to None
"""
model = None
bindings = None # values to map { post_attr: rel_attr }
"""
model of the related object
"""
bindings = None
"""
dict of `post_attr: rel_attr` that represent bindings of values
between the post and the related object. Field are updated according
to `post_to_rel` and `rel_to_post`.
If there is a post_attr "thread", the corresponding rel_attr is used
to update the post thread to the correct Post model (in order to
establish a parent-child relation between two models)
When a callable is set as `rel_attr`, it will be called to retrieve
the value, as `rel_attr(post, related)`
note: bound values can be any value, not only Django field.
"""
post_to_rel = False
"""
update related object when the post is saved, using bindings
"""
rel_to_post = False
"""
update the post when related object is updated, using bindings
"""
thread_model = None
"""
generated by the metaclass, points to the RelatedPost model
generated for the bindings.thread object.
"""
field_args = None
"""
dict of arguments to pass to the ForeignKey constructor, such as
`ForeignKey(related_model, **field_args)`
"""
auto_create = False
"""
automatically create a RelatedPost for each new item of the related
object and init it with bounded values. Use 'post_save' signal. If
auto_create is callable, use `auto_create(related_object)`.
"""
def get_rel_attr(self, attr):
attr = self._relation.bindings.get(attr)