Ñò Š„[Jc@s©dZddklZddklZdgZd d„Zd„Zd„Z d„Z d „Z d e fd „ƒYZ ed jo#dd kZeideiƒnd S(s A custom list that manages index/position information for its children. ``orderinglist`` is a custom list collection implementation for mapped relations that keeps an arbitrary "position" attribute on contained objects in sync with each object's position in the Python list. The collection acts just like a normal Python ``list``, with the added behavior that as you manipulate the list (via ``insert``, ``pop``, assignment, deletion, what have you), each of the objects it contains is updated as needed to reflect its position. This is very useful for managing ordered relations which have a user-defined, serialized order:: >>> from sqlalchemy import MetaData, Table, Column, Integer, String, ForeignKey >>> from sqlalchemy.orm import mapper, relation >>> from sqlalchemy.ext.orderinglist import ordering_list A simple model of users their "top 10" things:: >>> metadata = MetaData() >>> users = Table('users', metadata, ... Column('id', Integer, primary_key=True)) >>> blurbs = Table('user_top_ten_list', metadata, ... Column('id', Integer, primary_key=True), ... Column('user_id', Integer, ForeignKey('users.id')), ... Column('position', Integer), ... Column('blurb', String(80))) >>> class User(object): ... pass ... >>> class Blurb(object): ... def __init__(self, blurb): ... self.blurb = blurb ... >>> mapper(User, users, properties={ ... 'topten': relation(Blurb, collection_class=ordering_list('position'), ... order_by=[blurbs.c.position])}) >>> mapper(Blurb, blurbs) Acts just like a regular list:: >>> u = User() >>> u.topten.append(Blurb('Number one!')) >>> u.topten.append(Blurb('Number two!')) But the ``.position`` attibute is set automatically behind the scenes:: >>> assert [blurb.position for blurb in u.topten] == [0, 1] The objects will be renumbered automaticaly after any list-changing operation, for example an ``insert()``:: >>> u.topten.insert(1, Blurb('I am the new Number Two.')) >>> assert [blurb.position for blurb in u.topten] == [0, 1, 2] >>> assert u.topten[1].blurb == 'I am the new Number Two.' >>> assert u.topten[1].position == 1 Numbering and serialization are both highly configurable. See the docstrings in this module and the main SQLAlchemy documentation for more information and examples. The :class:`~sqlalchemy.ext.orderinglist.ordering_list` factory function is the ORM-compatible constructor for `OrderingList` instances. iÿÿÿÿ(t collection(tutilt ordering_listc s"td|ˆ‰‡‡fd†S(s”Prepares an OrderingList factory for use in mapper definitions. Returns an object suitable for use as an argument to a Mapper relation's ``collection_class`` option. Arguments are: attr Name of the mapped attribute to use for storage and retrieval of ordering information count_from (optional) 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. Passes along any keyword arguments to ``OrderingList`` constructor. t count_fromcs tˆˆS((t OrderingList((tkwtattr(s?/usr/lib/python2.6/site-packages/sqlalchemy/ext/orderinglist.pyt]s(t_unsugar_count_from(RRR((RRs?/usr/lib/python2.6/site-packages/sqlalchemy/ext/orderinglist.pyRIscCs|S(s7Numbering function: consecutive integers starting at 0.((tindexR((s?/usr/lib/python2.6/site-packages/sqlalchemy/ext/orderinglist.pyt count_from_0`scCs|dS(s7Numbering function: consecutive integers starting at 1.i((R R((s?/usr/lib/python2.6/site-packages/sqlalchemy/ext/orderinglist.pyt count_from_1escs:‡fd†}ydˆ|_Wntj onX|S(sENumbering function: consecutive integers starting at arbitrary start.cs|ˆS(N((R R(tstart(s?/usr/lib/python2.6/site-packages/sqlalchemy/ext/orderinglist.pytfmss count_from_%i(t__name__t TypeError(R R ((R s?/usr/lib/python2.6/site-packages/sqlalchemy/ext/orderinglist.pytcount_from_n_factoryjs cKs†|iddƒ}|iddƒdjoW|dj oJ|djot|dBs     ’