Module Expr Str ImportFrom alias alias ImportFrom alias Assign NameStore ListLoad Str FunctionDef arguments args NameParam NameParam defaults NameLoad kwarg body Expr Str Assign NameStore Call NameLoad keyword NameLoad NameLoad Return Lambda arguments args defaults Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return BinOpAdd NameLoad Num decorator_list FunctionDef arguments args NameParam defaults body Expr Str FunctionDef arguments args NameParam NameParam defaults body Return BinOpAdd NameLoad NameLoad decorator_list TryExcept body Assign AttributeStore NameLoad attr BinOpMod Str NameLoad handlers ExceptHandler type NameLoad body Pass Return NameLoad decorator_list FunctionDef arguments args defaults kwarg body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Str NameLoad If BoolOpAnd CompareIs Call AttributeLoad NameLoad attr Str NameLoad NameLoad CompareIsNot NameLoad NameLoad body If CompareEq NameLoad Num body Assign SubscriptStore NameLoad Index Str NameLoad orelse If CompareEq NameLoad Num body Assign SubscriptStore NameLoad Index Str NameLoad orelse Assign SubscriptStore NameLoad Index Str Call NameLoad NameLoad Return NameLoad decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad NameLoad NameLoad body Expr Str Assign AttributeStore NameLoad attr NameLoad If CompareIs NameLoad NameLoad body Assign NameStore NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Call NameLoad NameLoad AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Call NameLoad NameLoad AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str For TupleStore NameStore NameStore Call NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad decorator_list Assign NameStore NameLoad FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad If BoolOpAnd CompareIsNot NameLoad NameLoad UnaryOpNot NameLoad body Return Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad If CompareNotEq NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr BinOpSub Call NameLoad NameLoad Num NameLoad AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad decorator_list Assign NameStore Call Call AttributeLoad NameLoad attr Num NameLoad FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad Assign NameStore Call NameLoad NameLoad If BoolOpAnd NameLoad AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults Num body Assign NameStore Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body If Call NameLoad NameLoad NameLoad body Assign NameStore BoolOpOr AttributeLoad NameLoad attr Num Assign NameStore BoolOpOr AttributeLoad NameLoad attr Num If CompareLt NameLoad Num body AugAssignAdd NameStore Call NameLoad NameLoad Assign NameStore BoolOpOr AttributeLoad NameLoad attr Call NameLoad NameLoad If CompareLt NameLoad Num body AugAssignAdd NameStore Call NameLoad NameLoad For NameStore Call NameLoad NameLoad NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad SubscriptLoad NameLoad Index NameLoad orelse Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return TupleLoad NameLoad TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Call NameLoad NameLoad decorator_list For TupleStore NameStore NameStore Call NameLoad Call AttributeLoad Call NameLoad attr body If BoolOpAnd Call AttributeLoad NameLoad attr NameLoad CompareEq AttributeLoad NameLoad attr NameLoad UnaryOpNot AttributeLoad NameLoad attr Call NameLoad NameLoad NameLoad body Assign AttributeStore NameLoad attr AttributeLoad Call NameLoad NameLoad NameLoad attr Delete NameDel NameDel decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad Return NameLoad decorator_list
N/A N/A A custom list that manages index/position information for contained
elements.

:author: Jason Kirtland

``orderinglist`` is a helper for mutable ordered relationships.  It will
intercept list operations performed on a :func:`.relationship`-managed
collection and
automatically synchronize changes in list position onto a target scalar
attribute.

Example: A ``slide`` table, where each row refers to zero or more entries
in a related ``bullet`` table.   The bullets within a slide are
displayed in order based on the value of the ``position`` column in the
``bullet`` table.   As entries are reordered in memory, the value of the
``position`` attribute should be updated to reflect the new sort order::


    Base = declarative_base()

    class Slide(Base):
        __tablename__ = 'slide'

        id = Column(Integer, primary_key=True)
        name = Column(String)

        bullets = relationship("Bullet", order_by="Bullet.position")

    class Bullet(Base):
        __tablename__ = 'bullet'
        id = Column(Integer, primary_key=True)
        slide_id = Column(Integer, ForeignKey('slide.id'))
        position = Column(Integer)
        text = Column(String)

The standard relationship mapping will produce a list-like attribute on each
``Slide`` containing all related ``Bullet`` objects,
but coping with changes in ordering is not handled automatically.
When appending a ``Bullet`` into ``Slide.bullets``, the ``Bullet.position``
attribute will remain unset until manually assigned.   When the ``Bullet``
is inserted into the middle of the list, the following ``Bullet`` objects
will also need to be renumbered.

The :class:`.OrderingList` object automates this task, managing the
``position`` attribute on all ``Bullet`` objects in the collection.  It is
constructed using the :func:`.ordering_list` factory::

    from sqlalchemy.ext.orderinglist import ordering_list

    Base = declarative_base()

    class Slide(Base):
        __tablename__ = 'slide'

        id = Column(Integer, primary_key=True)
        name = Column(String)

        bullets = relationship("Bullet", order_by="Bullet.position",
                                collection_class=ordering_list('position'))

    class Bullet(Base):
        __tablename__ = 'bullet'
        id = Column(Integer, primary_key=True)
        slide_id = Column(Integer, ForeignKey('slide.id'))
        position = Column(Integer)
        text = Column(String)

With the above mapping the ``Bullet.position`` attribute is managed::

    s = Slide()
    s.bullets.append(Bullet())
    s.bullets.append(Bullet())
    s.bullets[1].position
    >>> 1
    s.bullets.insert(1, Bullet())
    s.bullets[2].position
    >>> 2

The :class:`.OrderingList` construct only works with **changes** to a
collection, and not the initial load from the database, and requires that the
list be sorted when loaded.  Therefore, be sure to specify ``order_by`` on the
:func:`.relationship` against the target ordering attribute, so that the
ordering is correct when first loaded.

.. warning::

  :class:`.OrderingList` only provides limited functionality when a primary
  key column or unique column is the target of the sort.  Operations
  that are unsupported or are problematic include:

    * two entries must trade values.  This is not supported directly in the
      case of a primary key or unique constraint because it means at least
      one row would need to be temporarily removed first, or changed to
      a third, neutral value while the switch occurs.

    * an entry must be deleted in order to make room for a new entry.
      SQLAlchemy's unit of work performs all INSERTs before DELETEs within a
      single flush.  In the case of a primary key, it will trade
      an INSERT/DELETE of the same primary key for an UPDATE statement in order
      to lessen the impact of this limitation, however this does not take place
      for a UNIQUE column.
      A future feature will allow the "DELETE before INSERT" behavior to be
      possible, allevating this limitation, though this feature will require
      explicit configuration at the mapper level for sets of columns that
      are to be handled in this way.

:func:`.ordering_list` takes the name of the related object's ordering
attribute as an argument.  By default, the zero-based integer index of the
object's position in the :func:`.ordering_list` is synchronized with the
ordering attribute: index 0 will get position 0, index 1 position 1, etc.  To
start numbering at 1 or some other integer, provide ``count_from=1``.


 orm.collections collection collection_adapter N/A util N/A __all__ N/A ordering_list ordering_list N/A N/A attr count_from N/A None kw N/A N/A Prepares an :class:`OrderingList` factory for use in mapper definitions.

    Returns an object suitable for use as an argument to a Mapper
    relationship's ``collection_class`` option.  e.g.::

        from sqlalchemy.ext.orderinglist import ordering_list

        class Slide(Base):
            __tablename__ = 'slide'

            id = Column(Integer, primary_key=True)
            name = Column(String)

            bullets = relationship("Bullet", order_by="Bullet.position",
                                    collection_class=ordering_list('position'))

    :param attr:
      Name of the mapped attribute to use for storage and retrieval of
      ordering information

    :param count_from:
      Set up an integer-based ordering, starting at ``count_from``.  For
      example, ``ordering_list('pos', count_from=1)`` would create a 1-based
      list in SQL, storing the value in the 'pos' column.  Ignored if
      ``ordering_func`` is supplied.

    Additional arguments are passed to the :class:`.OrderingList` constructor.

     N/A kw N/A _unsugar_count_from count_from count_from kw N/A N/A N/A N/A N/A N/A OrderingList attr kw N/A count_from_0 N/A N/A index collection N/A N/A N/A Numbering function: consecutive integers starting at 0. N/A index N/A count_from_1 N/A N/A index collection N/A N/A N/A Numbering function: consecutive integers starting at 1. N/A N/A index 1 N/A count_from_n_factory N/A N/A start N/A N/A N/A Numbering function: consecutive integers starting at arbitrary start. f N/A N/A index collection N/A N/A N/A N/A index start N/A N/A N/A N/A N/A f __name__ N/A count_from_%i start N/A N/A N/A TypeError N/A N/A N/A f N/A _unsugar_count_from N/A N/A N/A kw N/A N/A Builds counting functions from keyword arguments.

    Keyword argument filter, prepares a simple ``ordering_func`` from a
    ``count_from`` argument, otherwise passes ``ordering_func`` on unchanged.
     N/A count_from N/A N/A kw pop count_from None N/A N/A N/A N/A N/A kw get ordering_func None None N/A count_from None N/A N/A N/A count_from 0 N/A N/A N/A kw N/A ordering_func count_from_0 N/A N/A N/A count_from 1 N/A N/A N/A kw N/A ordering_func count_from_1 N/A N/A N/A kw N/A ordering_func N/A count_from_n_factory count_from N/A kw N/A OrderingList N/A list N/A N/A A custom list that manages position information for its children.

    The :class:`.OrderingList` object is normally set up using the
    :func:`.ordering_list` factory function, used in conjunction with
    the :func:`.relationship` function.

     __init__ N/A N/A self ordering_attr ordering_func reorder_on_append N/A None None False N/A N/A A custom list that manages position information for its children.

        ``OrderingList`` is a ``collection_class`` list implementation that
        syncs position in a Python list with a position attribute on the
        mapped objects.

        This implementation relies on the list starting in the proper order,
        so be **sure** to put an ``order_by`` on your relationship.

        :param ordering_attr:
          Name of the attribute that stores the object's order in the
          relationship.

        :param ordering_func: Optional.  A function that maps the position in
          the Python list to a value to store in the
          ``ordering_attr``.  Values returned are usually (but need not be!)
          integers.

          An ``ordering_func`` is called with two positional parameters: the
          index of the element in the list, and the list itself.

          If omitted, Python list indexes are used for the attribute values.
          Two basic pre-built numbering functions are provided in this module:
          ``count_from_0`` and ``count_from_1``.  For more exotic examples
          like stepped numbering, alphabetical and Fibonacci numbering, see
          the unit tests.

        :param reorder_on_append:
          Default False.  When appending an object with an existing (non-None)
          ordering value, that value will be left untouched unless
          ``reorder_on_append`` is true.  This is an optimization to avoid a
          variety of dangerous unexpected database writes.

          SQLAlchemy will add instances to the list via append() when your
          object loads.  If for some reason the result set from the database
          skips a step in the ordering (say, row '1' is missing but you get
          '2', '3', and '4'), reorder_on_append=True would immediately
          renumber the items to '1', '2', '3'.  If you have multiple sessions
          making changes, any of whom happen to load this collection even in
          passing, all of the sessions would try to "clean up" the numbering
          in their commits, possibly causing all but one to fail with a
          concurrent modification error.

          Recommend leaving this with the default of False, and just call
          ``reorder()`` if you're doing ``append()`` operations with
          previously ordered instances or when doing some housekeeping after
          manual sql operations.

         N/A N/A self ordering_attr ordering_attr N/A N/A ordering_func None N/A N/A ordering_func count_from_0 N/A N/A self ordering_func ordering_func N/A N/A self reorder_on_append reorder_on_append N/A _get_order_value N/A N/A self entity N/A N/A N/A N/A getattr entity N/A self ordering_attr N/A _set_order_value N/A N/A self entity value N/A N/A N/A N/A setattr entity N/A self ordering_attr value N/A reorder N/A N/A self N/A N/A N/A Synchronize ordering for the entire collection.

        Sweeps through the list and ensures that each object has accurate
        ordering information set.

         N/A N/A index entity N/A enumerate self N/A N/A N/A N/A self _order_entity index entity True N/A N/A _reorder reorder _order_entity N/A N/A self index entity reorder N/A True N/A N/A have N/A N/A self _get_order_value entity N/A N/A N/A have None N/A reorder N/A N/A N/A should_be N/A N/A self ordering_func index self N/A N/A have should_be N/A N/A N/A N/A self _set_order_value entity should_be N/A append N/A N/A self entity N/A N/A N/A N/A N/A N/A super OrderingList self append entity N/A N/A N/A self _order_entity N/A N/A len self 1 entity N/A self reorder_on_append N/A _raw_append N/A N/A self entity N/A N/A N/A Append without any ordering behavior. N/A N/A N/A N/A super OrderingList self append entity N/A N/A _raw_append N/A N/A N/A collection adds 1 _raw_append insert N/A N/A self index entity N/A N/A N/A N/A N/A N/A super OrderingList self insert index entity N/A N/A N/A self _reorder N/A remove N/A N/A self entity N/A N/A N/A N/A N/A N/A super OrderingList self remove entity N/A adapter N/A collection_adapter self N/A N/A adapter N/A adapter _referenced_by_owner N/A N/A N/A N/A self _reorder N/A pop N/A N/A self index N/A -1 N/A N/A entity N/A N/A N/A super OrderingList self pop index N/A N/A N/A self _reorder N/A entity N/A __setitem__ N/A N/A self index entity N/A N/A N/A N/A isinstance index slice N/A N/A step N/A N/A index step 1 N/A start N/A N/A index start 0 N/A N/A start 0 N/A N/A start N/A len self N/A stop N/A N/A index stop N/A len self N/A N/A stop 0 N/A N/A stop N/A len self N/A i N/A range start stop step N/A N/A N/A N/A self __setitem__ i N/A entity N/A i N/A N/A N/A N/A self _order_entity index entity True N/A N/A N/A N/A super OrderingList self __setitem__ index entity N/A __delitem__ N/A N/A self index N/A N/A N/A N/A N/A N/A super OrderingList self __delitem__ index N/A N/A N/A self _reorder N/A __setslice__ N/A N/A self start end values N/A N/A N/A N/A N/A N/A super OrderingList self __setslice__ start end values N/A N/A N/A self _reorder N/A __delslice__ N/A N/A self start end N/A N/A N/A N/A N/A N/A super OrderingList self __delslice__ start end N/A N/A N/A self _reorder N/A __reduce__ N/A N/A self N/A N/A N/A N/A _reconstitute N/A N/A self __class__ N/A self __dict__ N/A list self N/A N/A N/A func_name func N/A list N/A N/A N/A locals items N/A N/A N/A N/A N/A util callable func N/A N/A func __name__ func_name N/A N/A func __doc__ N/A hasattr list func_name N/A N/A N/A func __doc__ N/A N/A getattr list func_name __doc__ N/A func_name func N/A _reconstitute N/A N/A cls dict_ items N/A N/A N/A  Reconstitute an :class:`.OrderingList`.

    This is the adjoint to :meth:`.OrderingList.__reduce__`.  It is used for
    unpickling :class:`.OrderingList` objects.

     N/A obj N/A N/A cls __new__ cls N/A N/A N/A N/A obj __dict__ update dict_ N/A N/A N/A list extend obj items N/A obj N/A