<s> from __future__ import unicode_literals <EOL> from django . contrib import admin <EOL> from django . http import HttpResponseRedirect <EOL> from django . shortcuts import render_to_response <EOL> from . widgets import RelatedFieldWidgetWrapper <EOL> class EnhancedAdminMixin ( object ) : <EOL> enhance_exclude = ( ) <EOL> related_widget_wrapper = RelatedFieldWidgetWrapper <EOL> def formfield_for_dbfield ( self , db_field , ** kwargs ) : <EOL> formfield = super ( EnhancedAdminMixin , self ) . formfield_for_dbfield ( db_field , ** kwargs ) <EOL> if ( formfield and db_field . name not in self . enhance_exclude and <EOL> isinstance ( formfield . widget , admin . widgets . RelatedFieldWidgetWrapper ) ) : <EOL> request = kwargs . pop ( '<STR_LIT>' , None ) <EOL> related_modeladmin = self . admin_site . _registry . get ( db_field . rel . to ) <EOL> if related_modeladmin : <EOL> can_change_related = related_modeladmin . has_change_permission ( request ) <EOL> can_delete_related = related_modeladmin . has_delete_permission ( request ) <EOL> widget = self . related_widget_wrapper . wrap ( formfield . widget , <EOL> can_change_related , <EOL> can_delete_related ) <EOL> formfield . widget = widget <EOL> return formfield <EOL> def delete_view ( self , request , object_id , extra_context = None ) : <EOL> """<STR_LIT>""" <EOL> if not extra_context : <EOL> extra_context = { } <EOL> extra_context [ '<STR_LIT>' ] = request . REQUEST . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> return super ( EnhancedAdminMixin , self ) . delete_view ( request , object_id , extra_context ) <EOL> class EnhancedModelAdminMixin ( EnhancedAdminMixin ) : <EOL> def response_change ( self , request , obj ) : <EOL> if '<STR_LIT>' in request . REQUEST : <EOL> return render_to_response ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : obj } <EOL> ) <EOL> else : <EOL> return super ( EnhancedModelAdminMixin , self ) . response_change ( request , obj ) <EOL> def delete_view ( self , request , object_id , extra_context = None ) : <EOL> delete_view_response = super ( EnhancedModelAdminMixin , self ) . delete_view ( request , object_id , extra_context ) <EOL> if ( request . POST and '<STR_LIT>' in request . REQUEST and <EOL> isinstance ( delete_view_response , HttpResponseRedirect ) ) : <EOL> return render_to_response ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : object_id } <EOL> ) <EOL> else : <EOL> return delete_view_response </s>
