Skip to content

Instantly share code, notes, and snippets.

@matthewryanscott
Created September 12, 2008 17:52
Show Gist options
  • Save matthewryanscott/10482 to your computer and use it in GitHub Desktop.
Save matthewryanscott/10482 to your computer and use it in GitHub Desktop.
# In schevo.entity:Entity...
@extentmethod
@with_selection
@with_label(u'Delete Selected')
def t_delete_selected(self, selection):
tx = schevo.transaction.Combination([
entity.t.delete() for entity in selection
])
# @with_selection indicates that the method operates on a selection of entities,
# passed in as a single argument that is an iterable.
#
# The method is decorated with an attribute that indicates that it is such
# a method.
#
# The method should return a single object of the type expected by other methods
# with the same prefix.
#
# If you have a 't' method, it must return a single Transaction.
# Typically this will be a Combination transaction but could be a custom
# transaction, e.g. one that accepted input, then executed a series of
# child transactions that updated selected entities based on that input.
#
# If you have a 'v' method, it must return a single View, e.g. a view that
# summarized information about a set of selected entities.
list(db.Something.t)
# -> ['create']
#
# Listing the 't' namespace of an extent does not show the with_selection
# methods.
list(db.Something.t('with_selection'))
# -> ['delete_selected']
#
# Calling the 't' namespace of an extent with the name of an attribute
# returns a variant of the namespace where iterating over it will return
# the names of methods where that attribute has been set to True.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment