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

DuplicateSequenced([label])

Duplicate this row.

Hierarchical(*args, **kwargs)

Model mixin for things that have a "parent" and "siblings".

MoveByN([label])

Move this row N rows upwards or downwards.

MoveDown([label])

Move this row one row downwards.

MoveUp([label])

Move this row one row upwards.

Sequenced(*args, **kwargs)

Mixin for models that have a field seqno containing a "sequence number".

class lino.mixins.sequenced.MoveByN(label=None, **kwargs)

Bases: Action

Move this row N rows upwards or downwards.

This action is available on any Sequenced object as Sequenced.move_by_n.

It is currently only used by React to allow for drag and drop reording.

class lino.mixins.sequenced.MoveUp(label=None, **kwargs)

Bases: Action

Move this row one row upwards.

This action is available on any Sequenced object as Sequenced.move_up.

class lino.mixins.sequenced.MoveDown(label=None, **kwargs)

Bases: Action

Move this row one row downwards.

This action is available on any Sequenced object as Sequenced.move_down.

class lino.mixins.sequenced.DuplicateSequenced(label=None, **kwargs)

Bases: Duplicate

Duplicate this row.

class lino.mixins.sequenced.Sequenced(*args, **kwargs)

Bases: Duplicable

Mixin for models that have a field seqno containing a “sequence number”.

seqno

The sequence number of this item with its parent.

duplicate()

Create a duplicate of this object and insert the new object below this one.

Implemented by DuplicateSequenced

move_up

Exchange the seqno of this item and the previous item.

move_down

Exchange the seqno of this item and the next item.

move_buttons

Displays buttons for certain actions on this row:

move_by_n
move_action_names = ('move_up', 'move_down', 'duplicate')

The names of the actions to display in the move_buttons column.

Overridden by lino.modlib.dashboard.Widget where the duplicate 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.Third or lino_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.

class lino.mixins.sequenced.Hierarchical(*args, **kwargs)

Bases: Duplicable

Model 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.