<s> from django import forms , template <EOL> from django . forms . formsets import all_valid <EOL> from django . forms . models import modelform_factory , modelformset_factory , inlineformset_factory <EOL> from django . forms . models import BaseInlineFormSet <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . admin import widgets <EOL> from django . contrib . admin import helpers <EOL> from django . contrib . admin . util import unquote , flatten_fieldsets , get_deleted_objects , model_ngettext , model_format_dict <EOL> from django . contrib import messages <EOL> from django . views . decorators . csrf import csrf_protect <EOL> from django . core . exceptions import PermissionDenied , ValidationError <EOL> from django . db import models , transaction <EOL> from django . db . models . related import RelatedObject <EOL> from django . db . models . fields import BLANK_CHOICE_DASH , FieldDoesNotExist <EOL> from django . db . models . sql . constants import LOOKUP_SEP , QUERY_TERMS <EOL> from django . http import Http404 , HttpResponse , HttpResponseRedirect <EOL> from django . shortcuts import get_object_or_404 , render_to_response <EOL> from django . utils . decorators import method_decorator <EOL> from django . utils . datastructures import SortedDict <EOL> from django . utils . functional import update_wrapper <EOL> from django . utils . html import escape , escapejs <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . functional import curry <EOL> from django . utils . text import capfirst , get_text_list <EOL> from django . utils . translation import ugettext as _ <EOL> from django . utils . translation import ungettext , ugettext_lazy <EOL> from django . utils . encoding import force_unicode <EOL> HORIZONTAL , VERTICAL = <NUM_LIT:1> , <NUM_LIT:2> <EOL> get_ul_class = lambda x : '<STR_LIT>' % ( ( x == HORIZONTAL ) and '<STR_LIT>' or '<STR_LIT>' ) <EOL> class IncorrectLookupParameters ( Exception ) : <EOL> pass <EOL> FORMFIELD_FOR_DBFIELD_DEFAULTS = { <EOL> models . DateTimeField : { <EOL> '<STR_LIT>' : forms . SplitDateTimeField , <EOL> '<STR_LIT>' : widgets . AdminSplitDateTime <EOL> } , <EOL> models . DateField : { '<STR_LIT>' : widgets . AdminDateWidget } , <EOL> models . TimeField : { '<STR_LIT>' : widgets . AdminTimeWidget } , <EOL> models . TextField : { '<STR_LIT>' : widgets . AdminTextareaWidget } , <EOL> models . URLField : { '<STR_LIT>' : widgets . AdminURLFieldWidget } , <EOL> models . IntegerField : { '<STR_LIT>' : widgets . AdminIntegerFieldWidget } , <EOL> models . BigIntegerField : { '<STR_LIT>' : widgets . AdminIntegerFieldWidget } , <EOL> models . CharField : { '<STR_LIT>' : widgets . AdminTextInputWidget } , <EOL> models . ImageField : { '<STR_LIT>' : widgets . AdminFileWidget } , <EOL> models . FileField : { '<STR_LIT>' : widgets . AdminFileWidget } , <EOL> } <EOL> csrf_protect_m = method_decorator ( csrf_protect ) <EOL> class BaseModelAdmin ( object ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = forms . MediaDefiningClass <EOL> raw_id_fields = ( ) <EOL> fields = None <EOL> exclude = None <EOL> fieldsets = None <EOL> form = forms . ModelForm <EOL> filter_vertical = ( ) <EOL> filter_horizontal = ( ) <EOL> radio_fields = { } <EOL> prepopulated_fields = { } <EOL> formfield_overrides = { } <EOL> readonly_fields = ( ) <EOL> def __init__ ( self ) : <EOL> overrides = FORMFIELD_FOR_DBFIELD_DEFAULTS . copy ( ) <EOL> overrides . update ( self . formfield_overrides ) <EOL> self . formfield_overrides = overrides <EOL> def formfield_for_dbfield ( self , db_field , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> request = kwargs . pop ( "<STR_LIT>" , None ) <EOL> if db_field . choices : <EOL> return self . formfield_for_choice_field ( db_field , request , ** kwargs ) <EOL> if isinstance ( db_field , ( models . ForeignKey , models . ManyToManyField ) ) : <EOL> if db_field . __class__ in self . formfield_overrides : <EOL> kwargs = dict ( self . formfield_overrides [ db_field . __class__ ] , ** kwargs ) <EOL> if isinstance ( db_field , models . ForeignKey ) : <EOL> formfield = self . formfield_for_foreignkey ( db_field , request , ** kwargs ) <EOL> elif isinstance ( db_field , models . ManyToManyField ) : <EOL> formfield = self . formfield_for_manytomany ( db_field , request , ** kwargs ) <EOL> if formfield and db_field . name not in self . raw_id_fields : <EOL> formfield . widget = widgets . RelatedFieldWidgetWrapper ( formfield . widget , db_field . rel , self . admin_site ) <EOL> return formfield <EOL> for klass in db_field . __class__ . mro ( ) : <EOL> if klass in self . formfield_overrides : <EOL> kwargs = dict ( self . formfield_overrides [ klass ] , ** kwargs ) <EOL> return db_field . formfield ( ** kwargs ) <EOL> return db_field . formfield ( ** kwargs ) <EOL> def formfield_for_choice_field ( self , db_field , request = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if db_field . name in self . radio_fields : <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = widgets . AdminRadioSelect ( attrs = { <EOL> '<STR_LIT:class>' : get_ul_class ( self . radio_fields [ db_field . name ] ) , <EOL> } ) <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = db_field . get_choices ( <EOL> include_blank = db_field . blank , <EOL> blank_choice = [ ( '<STR_LIT>' , _ ( '<STR_LIT:None>' ) ) ] <EOL> ) <EOL> return db_field . formfield ( ** kwargs ) <EOL> def formfield_for_foreignkey ( self , db_field , request = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> db = kwargs . get ( '<STR_LIT>' ) <EOL> if db_field . name in self . raw_id_fields : <EOL> kwargs [ '<STR_LIT>' ] = widgets . ForeignKeyRawIdWidget ( db_field . rel , using = db ) <EOL> elif db_field . name in self . radio_fields : <EOL> kwargs [ '<STR_LIT>' ] = widgets . AdminRadioSelect ( attrs = { <EOL> '<STR_LIT:class>' : get_ul_class ( self . radio_fields [ db_field . name ] ) , <EOL> } ) <EOL> kwargs [ '<STR_LIT>' ] = db_field . blank and _ ( '<STR_LIT:None>' ) or None <EOL> return db_field . formfield ( ** kwargs ) <EOL> def formfield_for_manytomany ( self , db_field , request = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not db_field . rel . through . _meta . auto_created : <EOL> return None <EOL> db = kwargs . get ( '<STR_LIT>' ) <EOL> if db_field . name in self . raw_id_fields : <EOL> kwargs [ '<STR_LIT>' ] = widgets . ManyToManyRawIdWidget ( db_field . rel , using = db ) <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> elif db_field . name in ( list ( self . filter_vertical ) + list ( self . filter_horizontal ) ) : <EOL> kwargs [ '<STR_LIT>' ] = widgets . FilteredSelectMultiple ( db_field . verbose_name , ( db_field . name in self . filter_vertical ) ) <EOL> return db_field . formfield ( ** kwargs ) <EOL> def _declared_fieldsets ( self ) : <EOL> if self . fieldsets : <EOL> return self . fieldsets <EOL> elif self . fields : <EOL> return [ ( None , { '<STR_LIT>' : self . fields } ) ] <EOL> return None <EOL> declared_fieldsets = property ( _declared_fieldsets ) <EOL> def get_readonly_fields ( self , request , obj = None ) : <EOL> return self . readonly_fields <EOL> def lookup_allowed ( self , lookup , value ) : <EOL> model = self . model <EOL> for l in model . _meta . related_fkey_lookups : <EOL> for k , v in widgets . url_params_from_lookup_dict ( l ) . items ( ) : <EOL> if k == lookup and v == value : <EOL> return True <EOL> parts = lookup . split ( LOOKUP_SEP ) <EOL> if len ( parts ) > <NUM_LIT:1> and parts [ - <NUM_LIT:1> ] in QUERY_TERMS : <EOL> parts . pop ( ) <EOL> pk_attr_name = None <EOL> for part in parts [ : - <NUM_LIT:1> ] : <EOL> field , _ , _ , _ = model . _meta . get_field_by_name ( part ) <EOL> if hasattr ( field , '<STR_LIT>' ) : <EOL> model = field . rel . to <EOL> pk_attr_name = model . _meta . pk . name <EOL> elif isinstance ( field , RelatedObject ) : <EOL> model = field . model <EOL> pk_attr_name = model . _meta . pk . name <EOL> else : <EOL> pk_attr_name = None <EOL> if pk_attr_name and len ( parts ) > <NUM_LIT:1> and parts [ - <NUM_LIT:1> ] == pk_attr_name : <EOL> parts . pop ( ) <EOL> try : <EOL> self . model . _meta . get_field_by_name ( parts [ <NUM_LIT:0> ] ) <EOL> except FieldDoesNotExist : <EOL> return True <EOL> else : <EOL> if len ( parts ) == <NUM_LIT:1> : <EOL> return True <EOL> clean_lookup = LOOKUP_SEP . join ( parts ) <EOL> return clean_lookup in self . list_filter or clean_lookup == self . date_hierarchy <EOL> class ModelAdmin ( BaseModelAdmin ) : <EOL> "<STR_LIT>" <EOL> list_display = ( '<STR_LIT>' , ) <EOL> list_display_links = ( ) <EOL> list_filter = ( ) <EOL> list_select_related = False <EOL> list_per_page = <NUM_LIT:100> <EOL> list_editable = ( ) <EOL> search_fields = ( ) <EOL> date_hierarchy = None <EOL> save_as = False <EOL> save_on_top = False <EOL> ordering = None <EOL> inlines = [ ] <EOL> add_form_template = None <EOL> change_form_template = None <EOL> change_list_template = None <EOL> delete_confirmation_template = None <EOL> delete_selected_confirmation_template = None <EOL> object_history_template = None <EOL> actions = [ ] <EOL> action_form = helpers . ActionForm <EOL> actions_on_top = True <EOL> actions_on_bottom = False <EOL> actions_selection_counter = True <EOL> def __init__ ( self , model , admin_site ) : <EOL> self . model = model <EOL> self . opts = model . _meta <EOL> self . admin_site = admin_site <EOL> self . inline_instances = [ ] <EOL> for inline_class in self . inlines : <EOL> inline_instance = inline_class ( self . model , self . admin_site ) <EOL> self . inline_instances . append ( inline_instance ) <EOL> if '<STR_LIT>' not in self . list_display and self . actions is not None : <EOL> self . list_display = [ '<STR_LIT>' ] + list ( self . list_display ) <EOL> if not self . list_display_links : <EOL> for name in self . list_display : <EOL> if name != '<STR_LIT>' : <EOL> self . list_display_links = [ name ] <EOL> break <EOL> super ( ModelAdmin , self ) . __init__ ( ) <EOL> def get_urls ( self ) : <EOL> from django . conf . urls . defaults import patterns , url <EOL> def wrap ( view ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> return self . admin_site . admin_view ( view ) ( * args , ** kwargs ) <EOL> return update_wrapper ( wrapper , view ) <EOL> info = self . model . _meta . app_label , self . model . _meta . module_name <EOL> urlpatterns = patterns ( '<STR_LIT>' , <EOL> url ( r'<STR_LIT>' , <EOL> wrap ( self . changelist_view ) , <EOL> name = '<STR_LIT>' % info ) , <EOL> url ( r'<STR_LIT>' , <EOL> wrap ( self . add_view ) , <EOL> name = '<STR_LIT>' % info ) , <EOL> url ( r'<STR_LIT>' , <EOL> wrap ( self . history_view ) , <EOL> name = '<STR_LIT>' % info ) , <EOL> url ( r'<STR_LIT>' , <EOL> wrap ( self . delete_view ) , <EOL> name = '<STR_LIT>' % info ) , <EOL> url ( r'<STR_LIT>' , <EOL> wrap ( self . change_view ) , <EOL> name = '<STR_LIT>' % info ) , <EOL> ) <EOL> return urlpatterns <EOL> def urls ( self ) : <EOL> return self . get_urls ( ) <EOL> urls = property ( urls ) <EOL> def _media ( self ) : <EOL> from django . conf import settings <EOL> js = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> if self . actions is not None : <EOL> js . extend ( [ '<STR_LIT>' ] ) <EOL> if self . prepopulated_fields : <EOL> js . append ( '<STR_LIT>' ) <EOL> js . append ( '<STR_LIT>' ) <EOL> if self . opts . get_ordered_objects ( ) : <EOL> js . extend ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> return forms . Media ( js = [ '<STR_LIT>' % ( settings . ADMIN_MEDIA_PREFIX , url ) for url in js ] ) <EOL> media = property ( _media ) <EOL> def has_add_permission ( self , request ) : <EOL> """<STR_LIT>""" <EOL> opts = self . opts <EOL> return request . user . has_perm ( opts . app_label + '<STR_LIT:.>' + opts . get_add_permission ( ) ) <EOL> def has_change_permission ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> opts = self . opts <EOL> return request . user . has_perm ( opts . app_label + '<STR_LIT:.>' + opts . get_change_permission ( ) ) <EOL> def has_delete_permission ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> opts = self . opts <EOL> return request . user . has_perm ( opts . app_label + '<STR_LIT:.>' + opts . get_delete_permission ( ) ) <EOL> def get_model_perms ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> '<STR_LIT>' : self . has_add_permission ( request ) , <EOL> '<STR_LIT>' : self . has_change_permission ( request ) , <EOL> '<STR_LIT>' : self . has_delete_permission ( request ) , <EOL> } <EOL> def queryset ( self , request ) : <EOL> """<STR_LIT>""" <EOL> qs = self . model . _default_manager . get_query_set ( ) <EOL> ordering = self . ordering or ( ) <EOL> if ordering : <EOL> qs = qs . order_by ( * ordering ) <EOL> return qs <EOL> def get_fieldsets ( self , request , obj = None ) : <EOL> "<STR_LIT>" <EOL> if self . declared_fieldsets : <EOL> return self . declared_fieldsets <EOL> form = self . get_form ( request , obj ) <EOL> fields = form . base_fields . keys ( ) + list ( self . get_readonly_fields ( request , obj ) ) <EOL> return [ ( None , { '<STR_LIT>' : fields } ) ] <EOL> def get_form ( self , request , obj = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . declared_fieldsets : <EOL> fields = flatten_fieldsets ( self . declared_fieldsets ) <EOL> else : <EOL> fields = None <EOL> if self . exclude is None : <EOL> exclude = [ ] <EOL> else : <EOL> exclude = list ( self . exclude ) <EOL> exclude . extend ( kwargs . get ( "<STR_LIT>" , [ ] ) ) <EOL> exclude . extend ( self . get_readonly_fields ( request , obj ) ) <EOL> exclude = exclude or None <EOL> defaults = { <EOL> "<STR_LIT>" : self . form , <EOL> "<STR_LIT>" : fields , <EOL> "<STR_LIT>" : exclude , <EOL> "<STR_LIT>" : curry ( self . formfield_for_dbfield , request = request ) , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return modelform_factory ( self . model , ** defaults ) <EOL> def get_changelist ( self , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> from django . contrib . admin . views . main import ChangeList <EOL> return ChangeList <EOL> def get_object ( self , request , object_id ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . queryset ( request ) <EOL> model = queryset . model <EOL> try : <EOL> object_id = model . _meta . pk . to_python ( object_id ) <EOL> return queryset . get ( pk = object_id ) <EOL> except ( model . DoesNotExist , ValidationError ) : <EOL> return None <EOL> def get_changelist_form ( self , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> defaults = { <EOL> "<STR_LIT>" : curry ( self . formfield_for_dbfield , request = request ) , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return modelform_factory ( self . model , ** defaults ) <EOL> def get_changelist_formset ( self , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> defaults = { <EOL> "<STR_LIT>" : curry ( self . formfield_for_dbfield , request = request ) , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return modelformset_factory ( self . model , <EOL> self . get_changelist_form ( request ) , extra = <NUM_LIT:0> , <EOL> fields = self . list_editable , ** defaults ) <EOL> def get_formsets ( self , request , obj = None ) : <EOL> for inline in self . inline_instances : <EOL> yield inline . get_formset ( request , obj ) <EOL> def log_addition ( self , request , object ) : <EOL> """<STR_LIT>""" <EOL> from django . contrib . admin . models import LogEntry , ADDITION <EOL> LogEntry . objects . log_action ( <EOL> user_id = request . user . pk , <EOL> content_type_id = ContentType . objects . get_for_model ( object ) . pk , <EOL> object_id = object . pk , <EOL> object_repr = force_unicode ( object ) , <EOL> action_flag = ADDITION <EOL> ) <EOL> def log_change ( self , request , object , message ) : <EOL> """<STR_LIT>""" <EOL> from django . contrib . admin . models import LogEntry , CHANGE <EOL> LogEntry . objects . log_action ( <EOL> user_id = request . user . pk , <EOL> content_type_id = ContentType . objects . get_for_model ( object ) . pk , <EOL> object_id = object . pk , <EOL> object_repr = force_unicode ( object ) , <EOL> action_flag = CHANGE , <EOL> change_message = message <EOL> ) <EOL> def log_deletion ( self , request , object , object_repr ) : <EOL> """<STR_LIT>""" <EOL> from django . contrib . admin . models import LogEntry , DELETION <EOL> LogEntry . objects . log_action ( <EOL> user_id = request . user . id , <EOL> content_type_id = ContentType . objects . get_for_model ( self . model ) . pk , <EOL> object_id = object . pk , <EOL> object_repr = object_repr , <EOL> action_flag = DELETION <EOL> ) <EOL> def action_checkbox ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> return helpers . checkbox . render ( helpers . ACTION_CHECKBOX_NAME , force_unicode ( obj . pk ) ) <EOL> action_checkbox . short_description = mark_safe ( '<STR_LIT>' ) <EOL> action_checkbox . allow_tags = True <EOL> def get_actions ( self , request ) : <EOL> """<STR_LIT>""" <EOL> if self . actions is None : <EOL> return SortedDict ( ) <EOL> actions = [ ] <EOL> for ( name , func ) in self . admin_site . actions : <EOL> description = getattr ( func , '<STR_LIT>' , name . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) ) <EOL> actions . append ( ( func , name , description ) ) <EOL> for klass in self . __class__ . mro ( ) [ : : - <NUM_LIT:1> ] : <EOL> class_actions = getattr ( klass , '<STR_LIT>' , [ ] ) <EOL> if not class_actions : <EOL> continue <EOL> actions . extend ( [ self . get_action ( action ) for action in class_actions ] ) <EOL> actions = filter ( None , actions ) <EOL> actions . sort ( lambda a , b : cmp ( a [ <NUM_LIT:2> ] . lower ( ) , b [ <NUM_LIT:2> ] . lower ( ) ) ) <EOL> actions = SortedDict ( [ <EOL> ( name , ( func , name , desc ) ) <EOL> for func , name , desc in actions <EOL> ] ) <EOL> return actions <EOL> def get_action_choices ( self , request , default_choices = BLANK_CHOICE_DASH ) : <EOL> """<STR_LIT>""" <EOL> choices = [ ] + default_choices <EOL> for func , name , description in self . get_actions ( request ) . itervalues ( ) : <EOL> choice = ( name , description % model_format_dict ( self . opts ) ) <EOL> choices . append ( choice ) <EOL> return choices <EOL> def get_action ( self , action ) : <EOL> """<STR_LIT>""" <EOL> if callable ( action ) : <EOL> func = action <EOL> action = action . __name__ <EOL> elif hasattr ( self . __class__ , action ) : <EOL> func = getattr ( self . __class__ , action ) <EOL> else : <EOL> try : <EOL> func = self . admin_site . get_action ( action ) <EOL> except KeyError : <EOL> return None <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> description = func . short_description <EOL> else : <EOL> description = capfirst ( action . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) ) <EOL> return func , action , description <EOL> def construct_change_message ( self , request , form , formsets ) : <EOL> """<STR_LIT>""" <EOL> change_message = [ ] <EOL> if form . changed_data : <EOL> change_message . append ( _ ( '<STR_LIT>' ) % get_text_list ( form . changed_data , _ ( '<STR_LIT>' ) ) ) <EOL> if formsets : <EOL> for formset in formsets : <EOL> for added_object in formset . new_objects : <EOL> change_message . append ( _ ( '<STR_LIT>' ) <EOL> % { '<STR_LIT:name>' : force_unicode ( added_object . _meta . verbose_name ) , <EOL> '<STR_LIT:object>' : force_unicode ( added_object ) } ) <EOL> for changed_object , changed_fields in formset . changed_objects : <EOL> change_message . append ( _ ( '<STR_LIT>' ) <EOL> % { '<STR_LIT:list>' : get_text_list ( changed_fields , _ ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT:name>' : force_unicode ( changed_object . _meta . verbose_name ) , <EOL> '<STR_LIT:object>' : force_unicode ( changed_object ) } ) <EOL> for deleted_object in formset . deleted_objects : <EOL> change_message . append ( _ ( '<STR_LIT>' ) <EOL> % { '<STR_LIT:name>' : force_unicode ( deleted_object . _meta . verbose_name ) , <EOL> '<STR_LIT:object>' : force_unicode ( deleted_object ) } ) <EOL> change_message = '<STR_LIT:U+0020>' . join ( change_message ) <EOL> return change_message or _ ( '<STR_LIT>' ) <EOL> def message_user ( self , request , message ) : <EOL> """<STR_LIT>""" <EOL> messages . info ( request , message ) <EOL> def save_form ( self , request , form , change ) : <EOL> """<STR_LIT>""" <EOL> return form . save ( commit = False ) <EOL> def save_model ( self , request , obj , form , change ) : <EOL> """<STR_LIT>""" <EOL> obj . save ( ) <EOL> def save_formset ( self , request , form , formset , change ) : <EOL> """<STR_LIT>""" <EOL> formset . save ( ) <EOL> def render_change_form ( self , request , context , add = False , change = False , form_url = '<STR_LIT>' , obj = None ) : <EOL> opts = self . model . _meta <EOL> app_label = opts . app_label <EOL> ordered_objects = opts . get_ordered_objects ( ) <EOL> context . update ( { <EOL> '<STR_LIT>' : add , <EOL> '<STR_LIT>' : change , <EOL> '<STR_LIT>' : self . has_add_permission ( request ) , <EOL> '<STR_LIT>' : self . has_change_permission ( request , obj ) , <EOL> '<STR_LIT>' : self . has_delete_permission ( request , obj ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : hasattr ( self . model , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ordered_objects , <EOL> '<STR_LIT>' : mark_safe ( form_url ) , <EOL> '<STR_LIT>' : opts , <EOL> '<STR_LIT>' : ContentType . objects . get_for_model ( self . model ) . id , <EOL> '<STR_LIT>' : self . save_as , <EOL> '<STR_LIT>' : self . save_on_top , <EOL> '<STR_LIT>' : self . admin_site . root_path , <EOL> } ) <EOL> if add and self . add_form_template is not None : <EOL> form_template = self . add_form_template <EOL> else : <EOL> form_template = self . change_form_template <EOL> context_instance = template . RequestContext ( request , current_app = self . admin_site . name ) <EOL> return render_to_response ( form_template or [ <EOL> "<STR_LIT>" % ( app_label , opts . object_name . lower ( ) ) , <EOL> "<STR_LIT>" % app_label , <EOL> "<STR_LIT>" <EOL> ] , context , context_instance = context_instance ) <EOL> def response_add ( self , request , obj , post_url_continue = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> opts = obj . _meta <EOL> pk_value = obj . _get_pk_val ( ) <EOL> msg = _ ( '<STR_LIT>' ) % { '<STR_LIT:name>' : force_unicode ( opts . verbose_name ) , '<STR_LIT>' : force_unicode ( obj ) } <EOL> if request . POST . has_key ( "<STR_LIT>" ) : <EOL> self . message_user ( request , msg + '<STR_LIT:U+0020>' + _ ( "<STR_LIT>" ) ) <EOL> if request . POST . has_key ( "<STR_LIT>" ) : <EOL> post_url_continue += "<STR_LIT>" <EOL> return HttpResponseRedirect ( post_url_continue % pk_value ) <EOL> if request . POST . has_key ( "<STR_LIT>" ) : <EOL> return HttpResponse ( '<STR_LIT>' % <EOL> ( escape ( pk_value ) , escapejs ( obj ) ) ) <EOL> elif request . POST . has_key ( "<STR_LIT>" ) : <EOL> self . message_user ( request , msg + '<STR_LIT:U+0020>' + ( _ ( "<STR_LIT>" ) % force_unicode ( opts . verbose_name ) ) ) <EOL> return HttpResponseRedirect ( request . path ) <EOL> else : <EOL> self . message_user ( request , msg ) <EOL> if self . has_change_permission ( request , None ) : <EOL> post_url = '<STR_LIT>' <EOL> else : <EOL> post_url = '<STR_LIT>' <EOL> return HttpResponseRedirect ( post_url ) <EOL> def response_change ( self , request , obj ) : <EOL> """<STR_LIT>""" <EOL> opts = obj . _meta <EOL> pk_value = obj . _get_pk_val ( ) <EOL> msg = _ ( '<STR_LIT>' ) % { '<STR_LIT:name>' : force_unicode ( opts . verbose_name ) , '<STR_LIT>' : force_unicode ( obj ) } <EOL> if request . POST . has_key ( "<STR_LIT>" ) : <EOL> self . message_user ( request , msg + '<STR_LIT:U+0020>' + _ ( "<STR_LIT>" ) ) <EOL> if request . REQUEST . has_key ( '<STR_LIT>' ) : <EOL> return HttpResponseRedirect ( request . path + "<STR_LIT>" ) <EOL> else : <EOL> return HttpResponseRedirect ( request . path ) <EOL> elif request . POST . has_key ( "<STR_LIT>" ) : <EOL> msg = _ ( '<STR_LIT>' ) % { '<STR_LIT:name>' : force_unicode ( opts . verbose_name ) , '<STR_LIT>' : obj } <EOL> self . message_user ( request , msg ) <EOL> return HttpResponseRedirect ( "<STR_LIT>" % pk_value ) <EOL> elif request . POST . has_key ( "<STR_LIT>" ) : <EOL> self . message_user ( request , msg + '<STR_LIT:U+0020>' + ( _ ( "<STR_LIT>" ) % force_unicode ( opts . verbose_name ) ) ) <EOL> return HttpResponseRedirect ( "<STR_LIT>" ) <EOL> else : <EOL> self . message_user ( request , msg ) <EOL> return HttpResponseRedirect ( "<STR_LIT>" ) <EOL> def response_action ( self , request , queryset ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> action_index = int ( request . POST . get ( '<STR_LIT:index>' , <NUM_LIT:0> ) ) <EOL> except ValueError : <EOL> action_index = <NUM_LIT:0> <EOL> data = request . POST . copy ( ) <EOL> data . pop ( helpers . ACTION_CHECKBOX_NAME , None ) <EOL> data . pop ( "<STR_LIT:index>" , None ) <EOL> try : <EOL> data . update ( { '<STR_LIT:action>' : data . getlist ( '<STR_LIT:action>' ) [ action_index ] } ) <EOL> except IndexError : <EOL> pass <EOL> action_form = self . action_form ( data , auto_id = None ) <EOL> action_form . fields [ '<STR_LIT:action>' ] . choices = self . get_action_choices ( request ) <EOL> if action_form . is_valid ( ) : <EOL> action = action_form . cleaned_data [ '<STR_LIT:action>' ] <EOL> select_across = action_form . cleaned_data [ '<STR_LIT>' ] <EOL> func , name , description = self . get_actions ( request ) [ action ] <EOL> selected = request . POST . getlist ( helpers . ACTION_CHECKBOX_NAME ) <EOL> if not selected and not select_across : <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . message_user ( request , msg ) <EOL> return None <EOL> if not select_across : <EOL> queryset = queryset . filter ( pk__in = selected ) <EOL> response = func ( self , request , queryset ) <EOL> if isinstance ( response , HttpResponse ) : <EOL> return response <EOL> else : <EOL> return HttpResponseRedirect ( request . get_full_path ( ) ) <EOL> else : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> self . message_user ( request , msg ) <EOL> return None <EOL> @ csrf_protect_m <EOL> @ transaction . commit_on_success <EOL> def add_view ( self , request , form_url = '<STR_LIT>' , extra_context = None ) : <EOL> "<STR_LIT>" <EOL> model = self . model <EOL> opts = model . _meta <EOL> if not self . has_add_permission ( request ) : <EOL> raise PermissionDenied <EOL> ModelForm = self . get_form ( request ) <EOL> formsets = [ ] <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = ModelForm ( request . POST , request . FILES ) <EOL> if form . is_valid ( ) : <EOL> new_object = self . save_form ( request , form , change = False ) <EOL> form_validated = True <EOL> else : <EOL> form_validated = False <EOL> new_object = self . model ( ) <EOL> prefixes = { } <EOL> for FormSet , inline in zip ( self . get_formsets ( request ) , self . inline_instances ) : <EOL> prefix = FormSet . get_default_prefix ( ) <EOL> prefixes [ prefix ] = prefixes . get ( prefix , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> if prefixes [ prefix ] != <NUM_LIT:1> : <EOL> prefix = "<STR_LIT>" % ( prefix , prefixes [ prefix ] ) <EOL> formset = FormSet ( data = request . POST , files = request . FILES , <EOL> instance = new_object , <EOL> save_as_new = request . POST . has_key ( "<STR_LIT>" ) , <EOL> prefix = prefix , queryset = inline . queryset ( request ) ) <EOL> formsets . append ( formset ) <EOL> if all_valid ( formsets ) and form_validated : <EOL> self . save_model ( request , new_object , form , change = False ) <EOL> form . save_m2m ( ) <EOL> for formset in formsets : <EOL> self . save_formset ( request , form , formset , change = False ) <EOL> self . log_addition ( request , new_object ) <EOL> return self . response_add ( request , new_object ) <EOL> else : <EOL> initial = dict ( request . GET . items ( ) ) <EOL> for k in initial : <EOL> try : <EOL> f = opts . get_field ( k ) <EOL> except models . FieldDoesNotExist : <EOL> continue <EOL> if isinstance ( f , models . ManyToManyField ) : <EOL> initial [ k ] = initial [ k ] . split ( "<STR_LIT:U+002C>" ) <EOL> form = ModelForm ( initial = initial ) <EOL> prefixes = { } <EOL> for FormSet , inline in zip ( self . get_formsets ( request ) , <EOL> self . inline_instances ) : <EOL> prefix = FormSet . get_default_prefix ( ) <EOL> prefixes [ prefix ] = prefixes . get ( prefix , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> if prefixes [ prefix ] != <NUM_LIT:1> : <EOL> prefix = "<STR_LIT>" % ( prefix , prefixes [ prefix ] ) <EOL> formset = FormSet ( instance = self . model ( ) , prefix = prefix , <EOL> queryset = inline . queryset ( request ) ) <EOL> formsets . append ( formset ) <EOL> adminForm = helpers . AdminForm ( form , list ( self . get_fieldsets ( request ) ) , <EOL> self . prepopulated_fields , self . get_readonly_fields ( request ) , <EOL> model_admin = self ) <EOL> media = self . media + adminForm . media <EOL> inline_admin_formsets = [ ] <EOL> for inline , formset in zip ( self . inline_instances , formsets ) : <EOL> fieldsets = list ( inline . get_fieldsets ( request ) ) <EOL> readonly = list ( inline . get_readonly_fields ( request ) ) <EOL> inline_admin_formset = helpers . InlineAdminFormSet ( inline , formset , <EOL> fieldsets , readonly , model_admin = self ) <EOL> inline_admin_formsets . append ( inline_admin_formset ) <EOL> media = media + inline_admin_formset . media <EOL> context = { <EOL> '<STR_LIT:title>' : _ ( '<STR_LIT>' ) % force_unicode ( opts . verbose_name ) , <EOL> '<STR_LIT>' : adminForm , <EOL> '<STR_LIT>' : request . REQUEST . has_key ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : mark_safe ( media ) , <EOL> '<STR_LIT>' : inline_admin_formsets , <EOL> '<STR_LIT>' : helpers . AdminErrorList ( form , formsets ) , <EOL> '<STR_LIT>' : self . admin_site . root_path , <EOL> '<STR_LIT>' : opts . app_label , <EOL> } <EOL> context . update ( extra_context or { } ) <EOL> return self . render_change_form ( request , context , form_url = form_url , add = True ) <EOL> @ csrf_protect_m <EOL> @ transaction . commit_on_success <EOL> def change_view ( self , request , object_id , extra_context = None ) : <EOL> "<STR_LIT>" <EOL> model = self . model <EOL> opts = model . _meta <EOL> obj = self . get_object ( request , unquote ( object_id ) ) <EOL> if not self . has_change_permission ( request , obj ) : <EOL> raise PermissionDenied <EOL> if obj is None : <EOL> raise Http404 ( _ ( '<STR_LIT>' ) % { '<STR_LIT:name>' : force_unicode ( opts . verbose_name ) , '<STR_LIT:key>' : escape ( object_id ) } ) <EOL> if request . method == '<STR_LIT:POST>' and request . POST . has_key ( "<STR_LIT>" ) : <EOL> return self . add_view ( request , form_url = '<STR_LIT>' ) <EOL> ModelForm = self . get_form ( request , obj ) <EOL> formsets = [ ] <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = ModelForm ( request . POST , request . FILES , instance = obj ) <EOL> if form . is_valid ( ) : <EOL> form_validated = True <EOL> new_object = self . save_form ( request , form , change = True ) <EOL> else : <EOL> form_validated = False <EOL> new_object = obj <EOL> prefixes = { } <EOL> for FormSet , inline in zip ( self . get_formsets ( request , new_object ) , <EOL> self . inline_instances ) : <EOL> prefix = FormSet . get_default_prefix ( ) <EOL> prefixes [ prefix ] = prefixes . get ( prefix , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> if prefixes [ prefix ] != <NUM_LIT:1> : <EOL> prefix = "<STR_LIT>" % ( prefix , prefixes [ prefix ] ) <EOL> formset = FormSet ( request . POST , request . FILES , <EOL> instance = new_object , prefix = prefix , <EOL> queryset = inline . queryset ( request ) ) <EOL> formsets . append ( formset ) <EOL> if all_valid ( formsets ) and form_validated : <EOL> self . save_model ( request , new_object , form , change = True ) <EOL> form . save_m2m ( ) <EOL> for formset in formsets : <EOL> self . save_formset ( request , form , formset , change = True ) <EOL> change_message = self . construct_change_message ( request , form , formsets ) <EOL> self . log_change ( request , new_object , change_message ) <EOL> return self . response_change ( request , new_object ) <EOL> else : <EOL> form = ModelForm ( instance = obj ) <EOL> prefixes = { } <EOL> for FormSet , inline in zip ( self . get_formsets ( request , obj ) , self . inline_instances ) : <EOL> prefix = FormSet . get_default_prefix ( ) <EOL> prefixes [ prefix ] = prefixes . get ( prefix , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> if prefixes [ prefix ] != <NUM_LIT:1> : <EOL> prefix = "<STR_LIT>" % ( prefix , prefixes [ prefix ] ) <EOL> formset = FormSet ( instance = obj , prefix = prefix , <EOL> queryset = inline . queryset ( request ) ) <EOL> formsets . append ( formset ) <EOL> adminForm = helpers . AdminForm ( form , self . get_fieldsets ( request , obj ) , <EOL> self . prepopulated_fields , self . get_readonly_fields ( request , obj ) , <EOL> model_admin = self ) <EOL> media = self . media + adminForm . media <EOL> inline_admin_formsets = [ ] <EOL> for inline , formset in zip ( self . inline_instances , formsets ) : <EOL> fieldsets = list ( inline . get_fieldsets ( request , obj ) ) <EOL> readonly = list ( inline . get_readonly_fields ( request , obj ) ) <EOL> inline_admin_formset = helpers . InlineAdminFormSet ( inline , formset , <EOL> fieldsets , readonly , model_admin = self ) <EOL> inline_admin_formsets . append ( inline_admin_formset ) <EOL> media = media + inline_admin_formset . media <EOL> context = { <EOL> '<STR_LIT:title>' : _ ( '<STR_LIT>' ) % force_unicode ( opts . verbose_name ) , <EOL> '<STR_LIT>' : adminForm , <EOL> '<STR_LIT>' : object_id , <EOL> '<STR_LIT>' : obj , <EOL> '<STR_LIT>' : request . REQUEST . has_key ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : mark_safe ( media ) , <EOL> '<STR_LIT>' : inline_admin_formsets , <EOL> '<STR_LIT>' : helpers . AdminErrorList ( form , formsets ) , <EOL> '<STR_LIT>' : self . admin_site . root_path , <EOL> '<STR_LIT>' : opts . app_label , <EOL> } <EOL> context . update ( extra_context or { } ) <EOL> return self . render_change_form ( request , context , change = True , obj = obj ) <EOL> @ csrf_protect_m <EOL> def changelist_view ( self , request , extra_context = None ) : <EOL> "<STR_LIT>" <EOL> from django . contrib . admin . views . main import ERROR_FLAG <EOL> opts = self . model . _meta <EOL> app_label = opts . app_label <EOL> if not self . has_change_permission ( request , None ) : <EOL> raise PermissionDenied <EOL> actions = self . get_actions ( request ) <EOL> list_display = list ( self . list_display ) <EOL> if not actions : <EOL> try : <EOL> list_display . remove ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> pass <EOL> ChangeList = self . get_changelist ( request ) <EOL> try : <EOL> cl = ChangeList ( request , self . model , list_display , self . list_display_links , self . list_filter , <EOL> self . date_hierarchy , self . search_fields , self . list_select_related , self . list_per_page , self . list_editable , self ) <EOL> except IncorrectLookupParameters : <EOL> if ERROR_FLAG in request . GET . keys ( ) : <EOL> return render_to_response ( '<STR_LIT>' , { '<STR_LIT:title>' : _ ( '<STR_LIT>' ) } ) <EOL> return HttpResponseRedirect ( request . path + '<STR_LIT:?>' + ERROR_FLAG + '<STR_LIT>' ) <EOL> action_failed = False <EOL> selected = request . POST . getlist ( helpers . ACTION_CHECKBOX_NAME ) <EOL> if ( actions and request . method == '<STR_LIT:POST>' and <EOL> '<STR_LIT:index>' in request . POST and '<STR_LIT>' not in request . POST ) : <EOL> if selected : <EOL> response = self . response_action ( request , queryset = cl . get_query_set ( ) ) <EOL> if response : <EOL> return response <EOL> else : <EOL> action_failed = True <EOL> else : <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . message_user ( request , msg ) <EOL> action_failed = True <EOL> if ( actions and request . method == '<STR_LIT:POST>' and <EOL> helpers . ACTION_CHECKBOX_NAME in request . POST and <EOL> '<STR_LIT:index>' not in request . POST and '<STR_LIT>' not in request . POST ) : <EOL> if selected : <EOL> response = self . response_action ( request , queryset = cl . get_query_set ( ) ) <EOL> if response : <EOL> return response <EOL> else : <EOL> action_failed = True <EOL> formset = cl . formset = None <EOL> if ( request . method == "<STR_LIT:POST>" and self . list_editable and <EOL> '<STR_LIT>' in request . POST and not action_failed ) : <EOL> FormSet = self . get_changelist_formset ( request ) <EOL> formset = cl . formset = FormSet ( request . POST , request . FILES , queryset = cl . result_list ) <EOL> if formset . is_valid ( ) : <EOL> changecount = <NUM_LIT:0> <EOL> for form in formset . forms : <EOL> if form . has_changed ( ) : <EOL> obj = self . save_form ( request , form , change = True ) <EOL> self . save_model ( request , obj , form , change = True ) <EOL> form . save_m2m ( ) <EOL> change_msg = self . construct_change_message ( request , form , None ) <EOL> self . log_change ( request , obj , change_msg ) <EOL> changecount += <NUM_LIT:1> <EOL> if changecount : <EOL> if changecount == <NUM_LIT:1> : <EOL> name = force_unicode ( opts . verbose_name ) <EOL> else : <EOL> name = force_unicode ( opts . verbose_name_plural ) <EOL> msg = ungettext ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> changecount ) % { '<STR_LIT:count>' : changecount , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : force_unicode ( obj ) } <EOL> self . message_user ( request , msg ) <EOL> return HttpResponseRedirect ( request . get_full_path ( ) ) <EOL> elif self . list_editable : <EOL> FormSet = self . get_changelist_formset ( request ) <EOL> formset = cl . formset = FormSet ( queryset = cl . result_list ) <EOL> if formset : <EOL> media = self . media + formset . media <EOL> else : <EOL> media = self . media <EOL> if actions : <EOL> action_form = self . action_form ( auto_id = None ) <EOL> action_form . fields [ '<STR_LIT:action>' ] . choices = self . get_action_choices ( request ) <EOL> else : <EOL> action_form = None <EOL> selection_note_all = ungettext ( '<STR_LIT>' , <EOL> '<STR_LIT>' , cl . result_count ) <EOL> context = { <EOL> '<STR_LIT>' : force_unicode ( opts . verbose_name_plural ) , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) % { '<STR_LIT>' : len ( cl . result_list ) } , <EOL> '<STR_LIT>' : selection_note_all % { '<STR_LIT>' : cl . result_count } , <EOL> '<STR_LIT:title>' : cl . title , <EOL> '<STR_LIT>' : cl . is_popup , <EOL> '<STR_LIT>' : cl , <EOL> '<STR_LIT>' : media , <EOL> '<STR_LIT>' : self . has_add_permission ( request ) , <EOL> '<STR_LIT>' : self . admin_site . root_path , <EOL> '<STR_LIT>' : app_label , <EOL> '<STR_LIT>' : action_form , <EOL> '<STR_LIT>' : self . actions_on_top , <EOL> '<STR_LIT>' : self . actions_on_bottom , <EOL> '<STR_LIT>' : self . actions_selection_counter , <EOL> } <EOL> context . update ( extra_context or { } ) <EOL> context_instance = template . RequestContext ( request , current_app = self . admin_site . name ) <EOL> return render_to_response ( self . change_list_template or [ <EOL> '<STR_LIT>' % ( app_label , opts . object_name . lower ( ) ) , <EOL> '<STR_LIT>' % app_label , <EOL> '<STR_LIT>' <EOL> ] , context , context_instance = context_instance ) <EOL> @ csrf_protect_m <EOL> def delete_view ( self , request , object_id , extra_context = None ) : <EOL> "<STR_LIT>" <EOL> opts = self . model . _meta <EOL> app_label = opts . app_label <EOL> obj = self . get_object ( request , unquote ( object_id ) ) <EOL> if not self . has_delete_permission ( request , obj ) : <EOL> raise PermissionDenied <EOL> if obj is None : <EOL> raise Http404 ( _ ( '<STR_LIT>' ) % { '<STR_LIT:name>' : force_unicode ( opts . verbose_name ) , '<STR_LIT:key>' : escape ( object_id ) } ) <EOL> ( deleted_objects , perms_needed ) = get_deleted_objects ( ( obj , ) , opts , request . user , self . admin_site ) <EOL> if request . POST : <EOL> if perms_needed : <EOL> raise PermissionDenied <EOL> obj_display = force_unicode ( obj ) <EOL> self . log_deletion ( request , obj , obj_display ) <EOL> obj . delete ( ) <EOL> self . message_user ( request , _ ( '<STR_LIT>' ) % { '<STR_LIT:name>' : force_unicode ( opts . verbose_name ) , '<STR_LIT>' : force_unicode ( obj_display ) } ) <EOL> if not self . has_change_permission ( request , None ) : <EOL> return HttpResponseRedirect ( "<STR_LIT>" ) <EOL> return HttpResponseRedirect ( "<STR_LIT>" ) <EOL> context = { <EOL> "<STR_LIT:title>" : _ ( "<STR_LIT>" ) , <EOL> "<STR_LIT:object_name>" : force_unicode ( opts . verbose_name ) , <EOL> "<STR_LIT:object>" : obj , <EOL> "<STR_LIT>" : deleted_objects , <EOL> "<STR_LIT>" : perms_needed , <EOL> "<STR_LIT>" : opts , <EOL> "<STR_LIT>" : self . admin_site . root_path , <EOL> "<STR_LIT>" : app_label , <EOL> } <EOL> context . update ( extra_context or { } ) <EOL> context_instance = template . RequestContext ( request , current_app = self . admin_site . name ) <EOL> return render_to_response ( self . delete_confirmation_template or [ <EOL> "<STR_LIT>" % ( app_label , opts . object_name . lower ( ) ) , <EOL> "<STR_LIT>" % app_label , <EOL> "<STR_LIT>" <EOL> ] , context , context_instance = context_instance ) <EOL> def history_view ( self , request , object_id , extra_context = None ) : <EOL> "<STR_LIT>" <EOL> from django . contrib . admin . models import LogEntry <EOL> model = self . model <EOL> opts = model . _meta <EOL> app_label = opts . app_label <EOL> action_list = LogEntry . objects . filter ( <EOL> object_id = object_id , <EOL> content_type__id__exact = ContentType . objects . get_for_model ( model ) . id <EOL> ) . select_related ( ) . order_by ( '<STR_LIT>' ) <EOL> obj = get_object_or_404 ( model , pk = unquote ( object_id ) ) <EOL> context = { <EOL> '<STR_LIT:title>' : _ ( '<STR_LIT>' ) % force_unicode ( obj ) , <EOL> '<STR_LIT>' : action_list , <EOL> '<STR_LIT>' : capfirst ( force_unicode ( opts . verbose_name_plural ) ) , <EOL> '<STR_LIT:object>' : obj , <EOL> '<STR_LIT>' : self . admin_site . root_path , <EOL> '<STR_LIT>' : app_label , <EOL> } <EOL> context . update ( extra_context or { } ) <EOL> context_instance = template . RequestContext ( request , current_app = self . admin_site . name ) <EOL> return render_to_response ( self . object_history_template or [ <EOL> "<STR_LIT>" % ( app_label , opts . object_name . lower ( ) ) , <EOL> "<STR_LIT>" % app_label , <EOL> "<STR_LIT>" <EOL> ] , context , context_instance = context_instance ) <EOL> def __call__ ( self , request , url ) : <EOL> """<STR_LIT>""" <EOL> if url is None : <EOL> return self . changelist_view ( request ) <EOL> elif url == "<STR_LIT>" : <EOL> return self . add_view ( request ) <EOL> elif url . endswith ( '<STR_LIT>' ) : <EOL> return self . history_view ( request , unquote ( url [ : - <NUM_LIT:8> ] ) ) <EOL> elif url . endswith ( '<STR_LIT>' ) : <EOL> return self . delete_view ( request , unquote ( url [ : - <NUM_LIT:7> ] ) ) <EOL> else : <EOL> return self . change_view ( request , unquote ( url ) ) <EOL> class InlineModelAdmin ( BaseModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> model = None <EOL> fk_name = None <EOL> formset = BaseInlineFormSet <EOL> extra = <NUM_LIT:3> <EOL> max_num = None <EOL> template = None <EOL> verbose_name = None <EOL> verbose_name_plural = None <EOL> can_delete = True <EOL> def __init__ ( self , parent_model , admin_site ) : <EOL> self . admin_site = admin_site <EOL> self . parent_model = parent_model <EOL> self . opts = self . model . _meta <EOL> super ( InlineModelAdmin , self ) . __init__ ( ) <EOL> if self . verbose_name is None : <EOL> self . verbose_name = self . model . _meta . verbose_name <EOL> if self . verbose_name_plural is None : <EOL> self . verbose_name_plural = self . model . _meta . verbose_name_plural <EOL> def _media ( self ) : <EOL> from django . conf import settings <EOL> js = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if self . prepopulated_fields : <EOL> js . append ( '<STR_LIT>' ) <EOL> js . append ( '<STR_LIT>' ) <EOL> if self . filter_vertical or self . filter_horizontal : <EOL> js . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> return forms . Media ( js = [ '<STR_LIT>' % ( settings . ADMIN_MEDIA_PREFIX , url ) for url in js ] ) <EOL> media = property ( _media ) <EOL> def get_formset ( self , request , obj = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . declared_fieldsets : <EOL> fields = flatten_fieldsets ( self . declared_fieldsets ) <EOL> else : <EOL> fields = None <EOL> if self . exclude is None : <EOL> exclude = [ ] <EOL> else : <EOL> exclude = list ( self . exclude ) <EOL> exclude . extend ( kwargs . get ( "<STR_LIT>" , [ ] ) ) <EOL> exclude . extend ( self . get_readonly_fields ( request , obj ) ) <EOL> exclude = exclude or None <EOL> defaults = { <EOL> "<STR_LIT>" : self . form , <EOL> "<STR_LIT>" : self . formset , <EOL> "<STR_LIT>" : self . fk_name , <EOL> "<STR_LIT>" : fields , <EOL> "<STR_LIT>" : exclude , <EOL> "<STR_LIT>" : curry ( self . formfield_for_dbfield , request = request ) , <EOL> "<STR_LIT>" : self . extra , <EOL> "<STR_LIT>" : self . max_num , <EOL> "<STR_LIT>" : self . can_delete , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return inlineformset_factory ( self . parent_model , self . model , ** defaults ) <EOL> def get_fieldsets ( self , request , obj = None ) : <EOL> if self . declared_fieldsets : <EOL> return self . declared_fieldsets <EOL> form = self . get_formset ( request ) . form <EOL> fields = form . base_fields . keys ( ) + list ( self . get_readonly_fields ( request , obj ) ) <EOL> return [ ( None , { '<STR_LIT>' : fields } ) ] <EOL> def queryset ( self , request ) : <EOL> return self . model . _default_manager . all ( ) <EOL> class StackedInline ( InlineModelAdmin ) : <EOL> template = '<STR_LIT>' <EOL> class TabularInline ( InlineModelAdmin ) : <EOL> template = '<STR_LIT>' </s>
