Greetings list!

I have just checked in a new elixir extension called `acts_as_list`.
I'll include the docstring below.  I'd appreciate some additional
testing, and eyes on the code.  Any ideas would also be appreciated.

Here is the docstring for the module:

'''
An ordered-list plugin for Elixir to help you make an entity be
able to be managed in a list-like way. Much inspiration comes from
the Ruby on Rails acts_as_list plugin, which is currently more
full-featured than this plugin.

Once you flag an entity with an `acts_as_list()` statement, a
column will be added to the entity called `position` which will
be an integer column that is managed for you by the plugin. In
addition, your entity will get a series of new methods attached to
it, including:

+----------------------+--------------------------------------+
| Method Name          | Description                          |
+======================+======================================+
| ``move_lower``       | Move the item lower in the list      |
+----------------------+--------------------------------------+
| ``move_higher``      | Move the item higher in the list     |
+----------------------+--------------------------------------+
| ``move_to_bottom``   | Move the item to the bottom of the   |
|                      | list                                 |
+----------------------+--------------------------------------+
| ``move_to_top``      | Move the item to the top of the list |
+----------------------+--------------------------------------+
| ``move_to``          | Move the item to a specific position |
|                      | in the list                          |
+----------------------+--------------------------------------+


Sometimes, your entities that represent list items will be a part
of different lists. To implement this behavior, simply pass the
`acts_as_list` statement a callable that returns a "qualifier"
SQLAlchemy expression. This expression will be added to the
generated WHERE clauses used by the plugin.


Example model usage:

     from elixir import *
     from elixir.ext.list import acts_as_list

     class ToDo(Entity):
         subject = Field(String(128))
         owner = ManyToOne('Person')

         def qualify(self):
             return ToDo.owner_id == self.owner_id

         acts_as_list(qualify)

     class Person(Entity):
         name = Field(String(64))
         todos = OneToMany('ToDo', order_by='position')


The above example can then be used to manage ordered todo lists
for people. Note that you must set the `order_by` property on the
`Person.todo` relation in order for the relation to respect the
ordering. Here is an example of using this model in practice:

     p = Person.query.filter_by(name='Jonathan').one()
     p.todos.append(ToDo(subject='Three'))
     p.todos.append(ToDo(subject='Two'))
     p.todos.append(ToDo(subject='One'))
     session.flush(); session.clear()

     p = Person.query.filter_by(name='Jonathan').one()
     p.todos[0].move_to_bottom()
     p.todos[2].move_to_top()
     session.flush(); session.clear()

     p = Person.query.filter_by(name='Jonathan').one()
     assert p.todos[0].subject == 'One'
     assert p.todos[1].subject == 'Two'
     assert p.todos[2].subject == 'Three'

For more examples, refer to the unit tests for this plugin.
'''

--
Jonathan LaCour
http://cleverdevil.org




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to