<s> from cliquet import resource <EOL> from cliquet . events import ResourceChanged , ACTIONS <EOL> from pyramid . events import subscriber <EOL> from kinto . views import NameGenerator <EOL> class BucketSchema ( resource . ResourceSchema ) : <EOL> class Options : <EOL> preserve_unknown = True <EOL> @ resource . register ( name = '<STR_LIT>' , <EOL> collection_methods = ( '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' ) , <EOL> collection_path = '<STR_LIT>' , <EOL> record_path = '<STR_LIT>' ) <EOL> class Bucket ( resource . ShareableResource ) : <EOL> mapping = BucketSchema ( ) <EOL> permissions = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Bucket , self ) . __init__ ( * args , ** kwargs ) <EOL> self . model . id_generator = NameGenerator ( ) <EOL> def get_parent_id ( self , request ) : <EOL> return '<STR_LIT>' <EOL> @ subscriber ( ResourceChanged , <EOL> for_resources = ( '<STR_LIT>' , ) , <EOL> for_actions = ( ACTIONS . DELETE , ) ) <EOL> def on_buckets_deleted ( event ) : <EOL> """<STR_LIT>""" <EOL> storage = event . request . registry . storage <EOL> for change in event . impacted_records : <EOL> bucket = change [ '<STR_LIT>' ] <EOL> parent_id = '<STR_LIT>' % bucket [ '<STR_LIT:id>' ] <EOL> storage . delete_all ( collection_id = '<STR_LIT>' , <EOL> parent_id = parent_id , <EOL> with_deleted = False ) <EOL> storage . purge_deleted ( collection_id = '<STR_LIT>' , <EOL> parent_id = parent_id ) <EOL> deleted_collections = storage . delete_all ( collection_id = '<STR_LIT>' , <EOL> parent_id = parent_id , <EOL> with_deleted = False ) <EOL> storage . purge_deleted ( collection_id = '<STR_LIT>' , <EOL> parent_id = parent_id ) <EOL> for collection in deleted_collections : <EOL> parent_id = '<STR_LIT>' % ( bucket [ '<STR_LIT:id>' ] , <EOL> collection [ '<STR_LIT:id>' ] ) <EOL> storage . delete_all ( collection_id = '<STR_LIT>' , <EOL> parent_id = parent_id , <EOL> with_deleted = False ) <EOL> storage . purge_deleted ( collection_id = '<STR_LIT>' , <EOL> parent_id = parent_id ) </s>
