<s> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . db import models <EOL> from django . utils . html import escape <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . text import capfirst <EOL> from django . utils . encoding import force_unicode <EOL> from django . utils . translation import ungettext , ugettext as _ <EOL> from django . core . urlresolvers import reverse , NoReverseMatch <EOL> def quote ( s ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( s , basestring ) : <EOL> return s <EOL> res = list ( s ) <EOL> for i in range ( len ( res ) ) : <EOL> c = res [ i ] <EOL> if c in """<STR_LIT>""" : <EOL> res [ i ] = '<STR_LIT>' % ord ( c ) <EOL> return '<STR_LIT>' . join ( res ) <EOL> def unquote ( s ) : <EOL> """<STR_LIT>""" <EOL> mychr = chr <EOL> myatoi = int <EOL> list = s . split ( '<STR_LIT:_>' ) <EOL> res = [ list [ <NUM_LIT:0> ] ] <EOL> myappend = res . append <EOL> del list [ <NUM_LIT:0> ] <EOL> for item in list : <EOL> if item [ <NUM_LIT:1> : <NUM_LIT:2> ] : <EOL> try : <EOL> myappend ( mychr ( myatoi ( item [ : <NUM_LIT:2> ] , <NUM_LIT:16> ) ) + item [ <NUM_LIT:2> : ] ) <EOL> except ValueError : <EOL> myappend ( '<STR_LIT:_>' + item ) <EOL> else : <EOL> myappend ( '<STR_LIT:_>' + item ) <EOL> return "<STR_LIT>" . join ( res ) <EOL> def flatten_fieldsets ( fieldsets ) : <EOL> """<STR_LIT>""" <EOL> field_names = [ ] <EOL> for name , opts in fieldsets : <EOL> for field in opts [ '<STR_LIT>' ] : <EOL> if type ( field ) == tuple : <EOL> field_names . extend ( field ) <EOL> else : <EOL> field_names . append ( field ) <EOL> return field_names <EOL> def _nest_help ( obj , depth , val ) : <EOL> current = obj <EOL> for i in range ( depth ) : <EOL> current = current [ - <NUM_LIT:1> ] <EOL> current . append ( val ) <EOL> def get_change_view_url ( app_label , module_name , pk , admin_site , levels_to_root ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return reverse ( '<STR_LIT>' % ( admin_site . name , app_label , module_name ) , None , ( pk , ) ) <EOL> except NoReverseMatch : <EOL> return '<STR_LIT>' % ( '<STR_LIT>' * levels_to_root , app_label , module_name , pk ) <EOL> def get_deleted_objects ( deleted_objects , perms_needed , user , obj , opts , current_depth , admin_site , levels_to_root = <NUM_LIT:4> ) : <EOL> """<STR_LIT>""" <EOL> nh = _nest_help <EOL> if current_depth > <NUM_LIT:16> : <EOL> return <EOL> opts_seen = [ ] <EOL> for related in opts . get_all_related_objects ( ) : <EOL> has_admin = related . model in admin_site . _registry <EOL> if related . opts in opts_seen : <EOL> continue <EOL> opts_seen . append ( related . opts ) <EOL> rel_opts_name = related . get_accessor_name ( ) <EOL> if isinstance ( related . field . rel , models . OneToOneRel ) : <EOL> try : <EOL> sub_obj = getattr ( obj , rel_opts_name ) <EOL> except ObjectDoesNotExist : <EOL> pass <EOL> else : <EOL> if has_admin : <EOL> p = '<STR_LIT>' % ( related . opts . app_label , related . opts . get_delete_permission ( ) ) <EOL> if not user . has_perm ( p ) : <EOL> perms_needed . add ( related . opts . verbose_name ) <EOL> continue <EOL> if not has_admin : <EOL> nh ( deleted_objects , current_depth , <EOL> [ u'<STR_LIT>' % ( capfirst ( related . opts . verbose_name ) , force_unicode ( sub_obj ) ) , [ ] ] ) <EOL> else : <EOL> nh ( deleted_objects , current_depth , [ mark_safe ( u'<STR_LIT>' % <EOL> ( escape ( capfirst ( related . opts . verbose_name ) ) , <EOL> get_change_view_url ( related . opts . app_label , <EOL> related . opts . object_name . lower ( ) , <EOL> sub_obj . _get_pk_val ( ) , <EOL> admin_site , <EOL> levels_to_root ) , <EOL> escape ( sub_obj ) ) ) , [ ] ] ) <EOL> get_deleted_objects ( deleted_objects , perms_needed , user , sub_obj , related . opts , current_depth + <NUM_LIT:2> , admin_site ) <EOL> else : <EOL> has_related_objs = False <EOL> for sub_obj in getattr ( obj , rel_opts_name ) . all ( ) : <EOL> has_related_objs = True <EOL> if not has_admin : <EOL> nh ( deleted_objects , current_depth , <EOL> [ u'<STR_LIT>' % ( capfirst ( related . opts . verbose_name ) , force_unicode ( sub_obj ) ) , [ ] ] ) <EOL> else : <EOL> nh ( deleted_objects , current_depth , [ mark_safe ( u'<STR_LIT>' % <EOL> ( escape ( capfirst ( related . opts . verbose_name ) ) , <EOL> get_change_view_url ( related . opts . app_label , <EOL> related . opts . object_name . lower ( ) , <EOL> sub_obj . _get_pk_val ( ) , <EOL> admin_site , <EOL> levels_to_root ) , <EOL> escape ( sub_obj ) ) ) , [ ] ] ) <EOL> get_deleted_objects ( deleted_objects , perms_needed , user , sub_obj , related . opts , current_depth + <NUM_LIT:2> , admin_site ) <EOL> if has_admin and has_related_objs : <EOL> p = '<STR_LIT>' % ( related . opts . app_label , related . opts . get_delete_permission ( ) ) <EOL> if not user . has_perm ( p ) : <EOL> perms_needed . add ( related . opts . verbose_name ) <EOL> for related in opts . get_all_related_many_to_many_objects ( ) : <EOL> has_admin = related . model in admin_site . _registry <EOL> if related . opts in opts_seen : <EOL> continue <EOL> opts_seen . append ( related . opts ) <EOL> rel_opts_name = related . get_accessor_name ( ) <EOL> has_related_objs = False <EOL> if rel_opts_name : <EOL> rel_objs = getattr ( obj , rel_opts_name , None ) <EOL> if rel_objs : <EOL> has_related_objs = True <EOL> if has_related_objs : <EOL> for sub_obj in rel_objs . all ( ) : <EOL> if not has_admin : <EOL> nh ( deleted_objects , current_depth , [ _ ( '<STR_LIT>' ) % { '<STR_LIT>' : force_unicode ( related . field . verbose_name ) , '<STR_LIT:name>' : force_unicode ( related . opts . verbose_name ) , '<STR_LIT>' : escape ( sub_obj ) } , [ ] ] ) <EOL> else : <EOL> nh ( deleted_objects , current_depth , [ <EOL> mark_safe ( ( _ ( '<STR_LIT>' ) % { '<STR_LIT>' : escape ( force_unicode ( related . field . verbose_name ) ) , '<STR_LIT:name>' : escape ( force_unicode ( related . opts . verbose_name ) ) } ) + ( u'<STR_LIT>' % ( get_change_view_url ( related . opts . app_label , <EOL> related . opts . object_name . lower ( ) , <EOL> sub_obj . _get_pk_val ( ) , <EOL> admin_site , <EOL> levels_to_root ) , <EOL> escape ( sub_obj ) ) ) ) , [ ] ] ) <EOL> if has_admin and has_related_objs : <EOL> p = u'<STR_LIT>' % ( related . opts . app_label , related . opts . get_change_permission ( ) ) <EOL> if not user . has_perm ( p ) : <EOL> perms_needed . add ( related . opts . verbose_name ) <EOL> def model_format_dict ( obj ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj , ( models . Model , models . base . ModelBase ) ) : <EOL> opts = obj . _meta <EOL> elif isinstance ( obj , models . query . QuerySet ) : <EOL> opts = obj . model . _meta <EOL> else : <EOL> opts = obj <EOL> return { <EOL> '<STR_LIT>' : force_unicode ( opts . verbose_name ) , <EOL> '<STR_LIT>' : force_unicode ( opts . verbose_name_plural ) <EOL> } <EOL> def model_ngettext ( obj , n = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj , models . query . QuerySet ) : <EOL> if n is None : <EOL> n = obj . count ( ) <EOL> obj = obj . model <EOL> d = model_format_dict ( obj ) <EOL> singular , plural = d [ "<STR_LIT>" ] , d [ "<STR_LIT>" ] <EOL> return ungettext ( singular , plural , n or <NUM_LIT:0> ) </s>
