Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
lino.mixins.sequenced¶
Defines the model mixins Sequenced and Hierarchical.
A Sequenced is something which has a sequence number and thus a sort
order which can be manipulated by the end user using actions
MoveUp and MoveDown.
Hierarchical is a Sequenced with a parent field.
Classes
|
|
|
Model mixin for things that have a "parent" and "siblings". |
|
Move this row N rows upwards or downwards. |
|
Move this row one row downwards. |
|
Move this row one row upwards. |
|
Mixin for models that have a field |
- class lino.mixins.sequenced.MoveByN(label=None, **kwargs)¶
Bases:
ActionMove this row N rows upwards or downwards.
This action is available on any
Sequencedobject asSequenced.move_by_n.It is currently only used by React to allow for drag and drop reordering.
- class lino.mixins.sequenced.MoveUp(label=None, **kwargs)¶
Bases:
ActionMove this row one row upwards.
This action is available on any
Sequencedobject asSequenced.move_up.
- class lino.mixins.sequenced.MoveDown(label=None, **kwargs)¶
Bases:
ActionMove this row one row downwards.
This action is available on any
Sequencedobject asSequenced.move_down.
- class lino.mixins.sequenced.Sequenced(*args, **kwargs)¶
Bases:
ClonableMixin for models that have a field
seqnocontaining a “sequence number”.- seqno¶
The sequence number of this item with its parent.
- clone_row()¶
Create a duplicate of this row and insert the new row below this one.
Implemented by
CloneSequenced
- move_by_n¶
- move_action_names = ('move_up', 'move_down', 'clone_row')¶
The names of the actions to display in the move_buttons column.
Overridden by
lino.modlib.dashboard.Widgetwhere the clone_row button would be irritating.
- get_siblings()¶
Return a Django Queryset with all siblings of this, or None if this is a root element which cannot have any siblings.
Siblings are all objects that belong to a same sequence. This is needed for automatic management of the seqno field.
The queryset will of course include self.
The default implementation uses a global sequencing by returning all objects of self’s model.
A common case for overriding this method is when numbering restarts for each master. For example if you have a master model Product and a sequenced slave model Property with a ForeignKey field product which points to the Product, then you’ll define:
class Property(dd.Sequenced): def get_siblings(self): return Property.objects.filter( product=self.product)
Overridden e.g. in
lino_xl.lib.thirds.models.Thirdorlino_welfare.modlib.debts.models.Entry.
- set_seqno()¶
Initialize seqno to the seqno of eldest sibling + 1.
- seqno_changed(ar)¶
If the user manually assigns a seqno.
- dndreorder¶
A place holder column for drag and drop row reorder on React front end
CAUTION: Do NOT rename this field, for react works on checking the name as dndreorder.
- class lino.mixins.sequenced.Hierarchical(*args, **kwargs)¶
Bases:
ClonableModel mixin for things that have a “parent” and “siblings”.
Pronounciation: [hai’ra:kikl]
- children_summary¶
A comma-separated list of the children.
- get_parental_line()¶
Return an ordered list of all ancestors of this instance.
The last element of the list is this. A top-level project is its own root.
- whole_clan()¶
Return a set of this instance and all children and grandchildren.
- whole_tree()¶
Returns a tuple with two items (obj, children) representing the whole tree.
The first item is the top-most ancestor and the second item is a tuple of all the children of the ancestor. A child is wrappend inside another tuple where the first item is the child and second item is None when the child itself has no children otherwise the second item will be another tuple of children and so on.