<s> from . scope import Scope <EOL> class SoftDeletingScope ( Scope ) : <EOL> _extensions = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def apply ( self , builder , model ) : <EOL> """<STR_LIT>""" <EOL> builder . where_null ( model . get_qualified_deleted_at_column ( ) ) <EOL> self . extend ( builder ) <EOL> def extend ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> for extension in self . _extensions : <EOL> getattr ( self , '<STR_LIT>' % extension ) ( builder ) <EOL> builder . on_delete ( self . _on_delete ) <EOL> def _on_delete ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> column = self . _get_deleted_at_column ( builder ) <EOL> return builder . update ( { <EOL> column : builder . get_model ( ) . fresh_timestamp ( ) <EOL> } ) <EOL> def _get_deleted_at_column ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> if len ( builder . get_query ( ) . joins ) > <NUM_LIT:0> : <EOL> return builder . get_model ( ) . get_qualified_deleted_at_column ( ) <EOL> else : <EOL> return builder . get_model ( ) . get_deleted_at_column ( ) <EOL> def _add_force_delete ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> builder . macro ( '<STR_LIT>' , self . _force_delete ) <EOL> def _force_delete ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> return builder . get_query ( ) . delete ( ) <EOL> def _add_restore ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> builder . macro ( '<STR_LIT>' , self . _restore ) <EOL> def _restore ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> builder . with_trashed ( ) <EOL> return builder . update ( { <EOL> builder . get_model ( ) . get_deleted_at_column ( ) : None <EOL> } ) <EOL> def _add_with_trashed ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> builder . macro ( '<STR_LIT>' , self . _with_trashed ) <EOL> def _with_trashed ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> builder . remove_global_scope ( self ) <EOL> return builder <EOL> def _add_only_trashed ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> builder . macro ( '<STR_LIT>' , self . _only_trashed ) <EOL> def _only_trashed ( self , builder ) : <EOL> """<STR_LIT>""" <EOL> model = builder . get_model ( ) <EOL> builder . without_global_scope ( self ) <EOL> builder . get_query ( ) . where_not_null ( model . get_qualified_deleted_at_column ( ) ) <EOL> return builder </s>
