<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from past . builtins import cmp <EOL> from builtins import object <EOL> import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> from django . conf import settings <EOL> from django . db import models <EOL> from . utils import full_model_name as fmn <EOL> class DisableDeleteHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , model ) : <EOL> self . model = model <EOL> self . fklist = [ ] <EOL> def add_fk ( self , model , fk ) : <EOL> for m , fld in self . fklist : <EOL> if model is m : <EOL> return <EOL> self . fklist . append ( ( model , fk ) ) <EOL> def f ( a , b ) : <EOL> return cmp ( <EOL> fmn ( a [ <NUM_LIT:0> ] ) + '<STR_LIT:.>' + a [ <NUM_LIT:1> ] . name , fmn ( b [ <NUM_LIT:0> ] ) + '<STR_LIT:.>' + b [ <NUM_LIT:1> ] . name ) <EOL> from functools import cmp_to_key <EOL> self . fklist . sort ( key = cmp_to_key ( f ) ) <EOL> def __str__ ( self ) : <EOL> s = '<STR_LIT:U+002C>' . join ( [ m . __name__ + '<STR_LIT:.>' + fk . name for m , fk in self . fklist ] ) <EOL> return "<STR_LIT>" % ( self . model , s ) <EOL> def disable_delete_on_object ( self , obj , ignore_models = set ( ) ) : <EOL> """<STR_LIT>""" <EOL> for m , fk in self . fklist : <EOL> if m in ignore_models : <EOL> continue <EOL> if fk . name in m . allow_cascaded_delete : <EOL> continue <EOL> if fk . null and fk . rel . on_delete == models . SET_NULL : <EOL> continue <EOL> n = m . objects . filter ( ** { fk . name : obj } ) . count ( ) <EOL> if n : <EOL> return obj . delete_veto_message ( m , n ) <EOL> kernel = settings . SITE . kernel <EOL> for gfk , fk_field , qs in kernel . get_generic_related ( obj ) : <EOL> if gfk . name in qs . model . allow_cascaded_delete : <EOL> continue <EOL> if fk_field . null : <EOL> continue <EOL> n = qs . count ( ) <EOL> if n : <EOL> return obj . delete_veto_message ( qs . model , n ) <EOL> return None </s>
