<s> from __future__ import unicode_literals <EOL> import copy <EOL> import json <EOL> import operator <EOL> from collections import OrderedDict <EOL> from functools import partial , reduce , update_wrapper <EOL> from django import forms <EOL> from django . conf import settings <EOL> from django . contrib import messages <EOL> from django . contrib . admin import helpers , widgets <EOL> from django . contrib . admin . checks import ( <EOL> BaseModelAdminChecks , InlineModelAdminChecks , ModelAdminChecks , <EOL> ) <EOL> from django . contrib . admin . exceptions import DisallowedModelAdminToField <EOL> from django . contrib . admin . templatetags . admin_urls import add_preserved_filters <EOL> from django . contrib . admin . utils import ( <EOL> NestedObjects , flatten_fieldsets , get_deleted_objects , <EOL> lookup_needs_distinct , model_format_dict , quote , unquote , <EOL> ) <EOL> from django . contrib . auth import get_permission_codename <EOL> from django . core . exceptions import ( <EOL> FieldDoesNotExist , FieldError , PermissionDenied , ValidationError , <EOL> ) <EOL> from django . core . paginator import Paginator <EOL> from django . db import models , router , transaction <EOL> from django . db . models . constants import LOOKUP_SEP <EOL> from django . db . models . fields import BLANK_CHOICE_DASH <EOL> from django . forms . formsets import DELETION_FIELD_NAME , all_valid <EOL> from django . forms . models import ( <EOL> BaseInlineFormSet , inlineformset_factory , modelform_defines_fields , <EOL> modelform_factory , modelformset_factory , <EOL> ) <EOL> from django . forms . widgets import CheckboxSelectMultiple , SelectMultiple <EOL> from django . http import Http404 , HttpResponseRedirect <EOL> from django . http . response import HttpResponseBase <EOL> from django . template . response import SimpleTemplateResponse , TemplateResponse <EOL> from django . urls import reverse <EOL> from django . utils import six <EOL> from django . utils . decorators import method_decorator <EOL> from django . utils . encoding import force_text , python_2_unicode_compatible <EOL> from django . utils . html import escape , format_html <EOL> from django . utils . http import urlencode , urlquote <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . text import capfirst , get_text_list <EOL> from django . utils . translation import ( <EOL> override as translation_override , string_concat , ugettext as _ , ungettext , <EOL> ) <EOL> from django . views . decorators . csrf import csrf_protect <EOL> from django . views . generic import RedirectView <EOL> IS_POPUP_VAR = '<STR_LIT>' <EOL> TO_FIELD_VAR = '<STR_LIT>' <EOL> HORIZONTAL , VERTICAL = <NUM_LIT:1> , <NUM_LIT:2> <EOL> def get_content_type_for_model ( obj ) : <EOL> from django . contrib . contenttypes . models import ContentType <EOL> return ContentType . objects . get_for_model ( obj , for_concrete_model = False ) <EOL> def get_ul_class ( radio_style ) : <EOL> return '<STR_LIT>' if radio_style == VERTICAL else '<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 . AdminBigIntegerFieldWidget } , <EOL> models . CharField : { '<STR_LIT>' : widgets . AdminTextInputWidget } , <EOL> models . ImageField : { '<STR_LIT>' : widgets . AdminFileWidget } , <EOL> models . FileField : { '<STR_LIT>' : widgets . AdminFileWidget } , <EOL> models . EmailField : { '<STR_LIT>' : widgets . AdminEmailInputWidget } , <EOL> } <EOL> csrf_protect_m = method_decorator ( csrf_protect ) <EOL> class BaseModelAdmin ( six . with_metaclass ( forms . MediaDefiningClass ) ) : <EOL> """<STR_LIT>""" <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> ordering = None <EOL> view_on_site = True <EOL> show_full_result_count = True <EOL> checks_class = BaseModelAdminChecks <EOL> def check ( self , ** kwargs ) : <EOL> return self . checks_class ( ) . check ( self , ** kwargs ) <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 , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if db_field . choices : <EOL> return self . formfield_for_choice_field ( db_field , request , ** kwargs ) <EOL> if db_field . many_to_many or isinstance ( db_field , models . ForeignKey ) : <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 db_field . many_to_many : <EOL> formfield = self . formfield_for_manytomany ( db_field , request , ** kwargs ) <EOL> if formfield and db_field . name not in self . raw_id_fields : <EOL> related_modeladmin = self . admin_site . _registry . get ( db_field . remote_field . model ) <EOL> wrapper_kwargs = { } <EOL> if related_modeladmin : <EOL> wrapper_kwargs . update ( <EOL> can_add_related = related_modeladmin . has_add_permission ( request ) , <EOL> can_change_related = related_modeladmin . has_change_permission ( request ) , <EOL> can_delete_related = related_modeladmin . has_delete_permission ( request ) , <EOL> ) <EOL> formfield . widget = widgets . RelatedFieldWidgetWrapper ( <EOL> formfield . widget , db_field . remote_field , self . admin_site , ** wrapper_kwargs <EOL> ) <EOL> return formfield <EOL> for klass in db_field . __class__ . mro ( ) : <EOL> if klass in self . formfield_overrides : <EOL> kwargs = dict ( copy . deepcopy ( 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 , ** 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 get_field_queryset ( self , db , db_field , request ) : <EOL> """<STR_LIT>""" <EOL> related_admin = self . admin_site . _registry . get ( db_field . remote_field . model ) <EOL> if related_admin is not None : <EOL> ordering = related_admin . get_ordering ( request ) <EOL> if ordering is not None and ordering != ( ) : <EOL> return db_field . remote_field . model . _default_manager . using ( db ) . order_by ( * ordering ) <EOL> return None <EOL> def formfield_for_foreignkey ( self , db_field , request , ** 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 . remote_field , self . admin_site , 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>' ] = _ ( '<STR_LIT:None>' ) if db_field . blank else None <EOL> if '<STR_LIT>' not in kwargs : <EOL> queryset = self . get_field_queryset ( db , db_field , request ) <EOL> if queryset is not None : <EOL> kwargs [ '<STR_LIT>' ] = queryset <EOL> return db_field . formfield ( ** kwargs ) <EOL> def formfield_for_manytomany ( self , db_field , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not db_field . remote_field . 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 . remote_field , self . admin_site , using = db ) <EOL> elif db_field . name in ( list ( self . filter_vertical ) + list ( self . filter_horizontal ) ) : <EOL> kwargs [ '<STR_LIT>' ] = widgets . FilteredSelectMultiple ( <EOL> db_field . verbose_name , <EOL> db_field . name in self . filter_vertical <EOL> ) <EOL> if '<STR_LIT>' not in kwargs : <EOL> queryset = self . get_field_queryset ( db , db_field , request ) <EOL> if queryset is not None : <EOL> kwargs [ '<STR_LIT>' ] = queryset <EOL> form_field = db_field . formfield ( ** kwargs ) <EOL> if isinstance ( form_field . widget , SelectMultiple ) and not isinstance ( form_field . widget , CheckboxSelectMultiple ) : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> help_text = form_field . help_text <EOL> form_field . help_text = string_concat ( help_text , '<STR_LIT:U+0020>' , msg ) if help_text else msg <EOL> return form_field <EOL> def get_view_on_site_url ( self , obj = None ) : <EOL> if obj is None or not self . view_on_site : <EOL> return None <EOL> if callable ( self . view_on_site ) : <EOL> return self . view_on_site ( obj ) <EOL> elif self . view_on_site and hasattr ( obj , '<STR_LIT>' ) : <EOL> return reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : get_content_type_for_model ( obj ) . pk , <EOL> '<STR_LIT>' : obj . pk <EOL> } ) <EOL> def get_empty_value_display ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return mark_safe ( self . empty_value_display ) <EOL> except AttributeError : <EOL> return mark_safe ( self . admin_site . empty_value_display ) <EOL> def get_fields ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> return self . fields <EOL> def get_fieldsets ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> if self . fieldsets : <EOL> return self . fieldsets <EOL> return [ ( None , { '<STR_LIT>' : self . get_fields ( request , obj ) } ) ] <EOL> def get_ordering ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return self . ordering or ( ) <EOL> def get_readonly_fields ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> return self . readonly_fields <EOL> def get_prepopulated_fields ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> return self . prepopulated_fields <EOL> def get_queryset ( self , request ) : <EOL> """<STR_LIT>""" <EOL> qs = self . model . _default_manager . get_queryset ( ) <EOL> ordering = self . get_ordering ( request ) <EOL> if ordering : <EOL> qs = qs . order_by ( * ordering ) <EOL> return qs <EOL> def lookup_allowed ( self , lookup , value ) : <EOL> from django . contrib . admin . filters import SimpleListFilter <EOL> model = self . model <EOL> for l in model . _meta . related_fkey_lookups : <EOL> if callable ( l ) : <EOL> l = l ( ) <EOL> for k , v in widgets . url_params_from_lookup_dict ( l ) . items ( ) : <EOL> if k == lookup and v == value : <EOL> return True <EOL> relation_parts = [ ] <EOL> prev_field = None <EOL> for part in lookup . split ( LOOKUP_SEP ) : <EOL> try : <EOL> field = model . _meta . get_field ( part ) <EOL> except FieldDoesNotExist : <EOL> break <EOL> if not prev_field or ( prev_field . concrete and <EOL> field not in prev_field . get_path_info ( ) [ - <NUM_LIT:1> ] . target_fields ) : <EOL> relation_parts . append ( part ) <EOL> if not getattr ( field , '<STR_LIT>' , None ) : <EOL> break <EOL> prev_field = field <EOL> model = field . get_path_info ( ) [ - <NUM_LIT:1> ] . to_opts . model <EOL> if len ( relation_parts ) <= <NUM_LIT:1> : <EOL> return True <EOL> clean_lookup = LOOKUP_SEP . join ( relation_parts ) <EOL> valid_lookups = [ self . date_hierarchy ] <EOL> for filter_item in self . list_filter : <EOL> if isinstance ( filter_item , type ) and issubclass ( filter_item , SimpleListFilter ) : <EOL> valid_lookups . append ( filter_item . parameter_name ) <EOL> elif isinstance ( filter_item , ( list , tuple ) ) : <EOL> valid_lookups . append ( filter_item [ <NUM_LIT:0> ] ) <EOL> else : <EOL> valid_lookups . append ( filter_item ) <EOL> return clean_lookup in valid_lookups <EOL> def to_field_allowed ( self , request , to_field ) : <EOL> """<STR_LIT>""" <EOL> opts = self . model . _meta <EOL> try : <EOL> field = opts . get_field ( to_field ) <EOL> except FieldDoesNotExist : <EOL> return False <EOL> if field . primary_key : <EOL> return True <EOL> for many_to_many in opts . many_to_many : <EOL> if many_to_many . m2m_target_field_name ( ) == to_field : <EOL> return True <EOL> registered_models = set ( ) <EOL> for model , admin in self . admin_site . _registry . items ( ) : <EOL> registered_models . add ( model ) <EOL> for inline in admin . inlines : <EOL> registered_models . add ( inline . model ) <EOL> related_objects = ( <EOL> f for f in opts . get_fields ( include_hidden = True ) <EOL> if ( f . auto_created and not f . concrete ) <EOL> ) <EOL> for related_object in related_objects : <EOL> related_model = related_object . related_model <EOL> remote_field = related_object . field . remote_field <EOL> if ( any ( issubclass ( model , related_model ) for model in registered_models ) and <EOL> hasattr ( remote_field , '<STR_LIT>' ) and <EOL> remote_field . get_related_field ( ) == field ) : <EOL> return True <EOL> return False <EOL> def has_add_permission ( self , request ) : <EOL> """<STR_LIT>""" <EOL> opts = self . opts <EOL> codename = get_permission_codename ( '<STR_LIT>' , opts ) <EOL> return request . user . has_perm ( "<STR_LIT>" % ( opts . app_label , codename ) ) <EOL> def has_change_permission ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> opts = self . opts <EOL> codename = get_permission_codename ( '<STR_LIT>' , opts ) <EOL> return request . user . has_perm ( "<STR_LIT>" % ( opts . app_label , codename ) ) <EOL> def has_delete_permission ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> opts = self . opts <EOL> codename = get_permission_codename ( '<STR_LIT>' , opts ) <EOL> return request . user . has_perm ( "<STR_LIT>" % ( opts . app_label , codename ) ) <EOL> def has_module_permission ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return request . user . has_module_perms ( self . opts . app_label ) <EOL> @ python_2_unicode_compatible <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_max_show_all = <NUM_LIT:200> <EOL> list_editable = ( ) <EOL> search_fields = ( ) <EOL> date_hierarchy = None <EOL> save_as = False <EOL> save_as_continue = True <EOL> save_on_top = False <EOL> paginator = Paginator <EOL> preserve_filters = True <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> checks_class = ModelAdminChecks <EOL> def __init__ ( self , model , admin_site ) : <EOL> self . model = model <EOL> self . opts = model . _meta <EOL> self . admin_site = admin_site <EOL> super ( ModelAdmin , self ) . __init__ ( ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . model . _meta . app_label , self . __class__ . __name__ ) <EOL> def get_inline_instances ( self , request , obj = None ) : <EOL> inline_instances = [ ] <EOL> for inline_class in self . inlines : <EOL> inline = inline_class ( self . model , self . admin_site ) <EOL> if request : <EOL> if not ( inline . has_add_permission ( request ) or <EOL> inline . has_change_permission ( request , obj ) or <EOL> inline . has_delete_permission ( request , obj ) ) : <EOL> continue <EOL> if not inline . has_add_permission ( request ) : <EOL> inline . max_num = <NUM_LIT:0> <EOL> inline_instances . append ( inline ) <EOL> return inline_instances <EOL> def get_urls ( self ) : <EOL> from django . conf . urls import url <EOL> def wrap ( view ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> return self . admin_site . admin_view ( view ) ( * args , ** kwargs ) <EOL> wrapper . model_admin = self <EOL> return update_wrapper ( wrapper , view ) <EOL> info = self . model . _meta . app_label , self . model . _meta . model_name <EOL> urlpatterns = [ <EOL> url ( r'<STR_LIT>' , wrap ( self . changelist_view ) , name = '<STR_LIT>' % info ) , <EOL> url ( r'<STR_LIT>' , wrap ( self . add_view ) , name = '<STR_LIT>' % info ) , <EOL> url ( r'<STR_LIT>' , wrap ( self . history_view ) , name = '<STR_LIT>' % info ) , <EOL> url ( r'<STR_LIT>' , wrap ( self . delete_view ) , name = '<STR_LIT>' % info ) , <EOL> url ( r'<STR_LIT>' , wrap ( self . change_view ) , name = '<STR_LIT>' % info ) , <EOL> url ( r'<STR_LIT>' , wrap ( RedirectView . as_view ( <EOL> pattern_name = '<STR_LIT>' % ( ( self . admin_site . name , ) + info ) <EOL> ) ) ) , <EOL> ] <EOL> return urlpatterns <EOL> def urls ( self ) : <EOL> return self . get_urls ( ) <EOL> urls = property ( urls ) <EOL> @ property <EOL> def media ( self ) : <EOL> extra = '<STR_LIT>' if settings . DEBUG else '<STR_LIT>' <EOL> js = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % extra , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % extra , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % extra , <EOL> '<STR_LIT>' , <EOL> ] <EOL> return forms . Media ( js = [ '<STR_LIT>' % url for url in js ] ) <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 get_fields ( self , request , obj = None ) : <EOL> if self . fields : <EOL> return self . fields <EOL> form = self . get_form ( request , obj , fields = None ) <EOL> return list ( form . base_fields ) + list ( self . get_readonly_fields ( request , obj ) ) <EOL> def get_form ( self , request , obj = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in kwargs : <EOL> fields = kwargs . pop ( '<STR_LIT>' ) <EOL> else : <EOL> fields = flatten_fieldsets ( self . get_fieldsets ( request , obj ) ) <EOL> if self . exclude is None : <EOL> exclude = [ ] <EOL> else : <EOL> exclude = list ( self . exclude ) <EOL> readonly_fields = self . get_readonly_fields ( request , obj ) <EOL> exclude . extend ( readonly_fields ) <EOL> if self . exclude is None and hasattr ( self . form , '<STR_LIT>' ) and self . form . _meta . exclude : <EOL> exclude . extend ( self . form . _meta . exclude ) <EOL> exclude = exclude or None <EOL> new_attrs = OrderedDict ( <EOL> ( f , None ) for f in readonly_fields <EOL> if f in self . form . declared_fields <EOL> ) <EOL> form = type ( self . form . __name__ , ( self . form , ) , new_attrs ) <EOL> defaults = { <EOL> "<STR_LIT>" : form , <EOL> "<STR_LIT>" : fields , <EOL> "<STR_LIT>" : exclude , <EOL> "<STR_LIT>" : partial ( self . formfield_for_dbfield , request = request ) , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> if defaults [ '<STR_LIT>' ] is None and not modelform_defines_fields ( defaults [ '<STR_LIT>' ] ) : <EOL> defaults [ '<STR_LIT>' ] = forms . ALL_FIELDS <EOL> try : <EOL> return modelform_factory ( self . model , ** defaults ) <EOL> except FieldError as e : <EOL> raise FieldError ( <EOL> '<STR_LIT>' <EOL> % ( e , self . __class__ . __name__ ) <EOL> ) <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 , from_field = None ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . get_queryset ( request ) <EOL> model = queryset . model <EOL> field = model . _meta . pk if from_field is None else model . _meta . get_field ( from_field ) <EOL> try : <EOL> object_id = field . to_python ( object_id ) <EOL> return queryset . get ( ** { field . name : object_id } ) <EOL> except ( model . DoesNotExist , ValidationError , ValueError ) : <EOL> return None <EOL> def get_changelist_form ( self , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> defaults = { <EOL> "<STR_LIT>" : partial ( self . formfield_for_dbfield , request = request ) , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> if defaults . get ( '<STR_LIT>' ) is None and not modelform_defines_fields ( defaults . get ( '<STR_LIT>' ) ) : <EOL> defaults [ '<STR_LIT>' ] = forms . ALL_FIELDS <EOL> return modelform_factory ( self . model , ** defaults ) <EOL> def get_changelist_formset ( self , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> defaults = { <EOL> "<STR_LIT>" : partial ( self . formfield_for_dbfield , request = request ) , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return modelformset_factory ( <EOL> self . model , self . get_changelist_form ( request ) , extra = <NUM_LIT:0> , <EOL> fields = self . list_editable , ** defaults <EOL> ) <EOL> def get_formsets_with_inlines ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> for inline in self . get_inline_instances ( request , obj ) : <EOL> yield inline . get_formset ( request , obj ) , inline <EOL> def get_paginator ( self , request , queryset , per_page , orphans = <NUM_LIT:0> , allow_empty_first_page = True ) : <EOL> return self . paginator ( queryset , per_page , orphans , allow_empty_first_page ) <EOL> def log_addition ( self , request , object , message ) : <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 = get_content_type_for_model ( object ) . pk , <EOL> object_id = object . pk , <EOL> object_repr = force_text ( object ) , <EOL> action_flag = ADDITION , <EOL> change_message = message , <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 = get_content_type_for_model ( object ) . pk , <EOL> object_id = object . pk , <EOL> object_repr = force_text ( 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 . pk , <EOL> content_type_id = get_content_type_for_model ( object ) . 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_text ( obj . pk ) ) <EOL> action_checkbox . short_description = mark_safe ( '<STR_LIT>' ) <EOL> def get_actions ( self , request ) : <EOL> """<STR_LIT>""" <EOL> if self . actions is None or IS_POPUP_VAR in request . GET : <EOL> return OrderedDict ( ) <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 = OrderedDict ( <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 six . itervalues ( self . get_actions ( request ) ) : <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 get_list_display ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return self . list_display <EOL> def get_list_display_links ( self , request , list_display ) : <EOL> """<STR_LIT>""" <EOL> if self . list_display_links or self . list_display_links is None or not list_display : <EOL> return self . list_display_links <EOL> else : <EOL> return list ( list_display ) [ : <NUM_LIT:1> ] <EOL> def get_list_filter ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return self . list_filter <EOL> def get_list_select_related ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return self . list_select_related <EOL> def get_search_fields ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return self . search_fields <EOL> def get_search_results ( self , request , queryset , search_term ) : <EOL> """<STR_LIT>""" <EOL> def construct_search ( field_name ) : <EOL> if field_name . startswith ( '<STR_LIT>' ) : <EOL> return "<STR_LIT>" % field_name [ <NUM_LIT:1> : ] <EOL> elif field_name . startswith ( '<STR_LIT:=>' ) : <EOL> return "<STR_LIT>" % field_name [ <NUM_LIT:1> : ] <EOL> elif field_name . startswith ( '<STR_LIT:@>' ) : <EOL> return "<STR_LIT>" % field_name [ <NUM_LIT:1> : ] <EOL> else : <EOL> return "<STR_LIT>" % field_name <EOL> use_distinct = False <EOL> search_fields = self . get_search_fields ( request ) <EOL> if search_fields and search_term : <EOL> orm_lookups = [ construct_search ( str ( search_field ) ) <EOL> for search_field in search_fields ] <EOL> for bit in search_term . split ( ) : <EOL> or_queries = [ models . Q ( ** { orm_lookup : bit } ) <EOL> for orm_lookup in orm_lookups ] <EOL> queryset = queryset . filter ( reduce ( operator . or_ , or_queries ) ) <EOL> if not use_distinct : <EOL> for search_spec in orm_lookups : <EOL> if lookup_needs_distinct ( self . opts , search_spec ) : <EOL> use_distinct = True <EOL> break <EOL> return queryset , use_distinct <EOL> def get_preserved_filters ( self , request ) : <EOL> """<STR_LIT>""" <EOL> match = request . resolver_match <EOL> if self . preserve_filters and match : <EOL> opts = self . model . _meta <EOL> current_url = '<STR_LIT>' % ( match . app_name , match . url_name ) <EOL> changelist_url = '<STR_LIT>' % ( opts . app_label , opts . model_name ) <EOL> if current_url == changelist_url : <EOL> preserved_filters = request . GET . urlencode ( ) <EOL> else : <EOL> preserved_filters = request . GET . get ( '<STR_LIT>' ) <EOL> if preserved_filters : <EOL> return urlencode ( { '<STR_LIT>' : preserved_filters } ) <EOL> return '<STR_LIT>' <EOL> @ translation_override ( None ) <EOL> def construct_change_message ( self , request , form , formsets , add = False ) : <EOL> """<STR_LIT>""" <EOL> change_message = [ ] <EOL> if add : <EOL> change_message . append ( { '<STR_LIT>' : { } } ) <EOL> elif form . changed_data : <EOL> change_message . append ( { '<STR_LIT>' : { '<STR_LIT>' : form . changed_data } } ) <EOL> if formsets : <EOL> for formset in formsets : <EOL> for added_object in formset . new_objects : <EOL> change_message . append ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : force_text ( added_object . _meta . verbose_name ) , <EOL> '<STR_LIT:object>' : force_text ( added_object ) , <EOL> } <EOL> } ) <EOL> for changed_object , changed_fields in formset . changed_objects : <EOL> change_message . append ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : force_text ( changed_object . _meta . verbose_name ) , <EOL> '<STR_LIT:object>' : force_text ( changed_object ) , <EOL> '<STR_LIT>' : changed_fields , <EOL> } <EOL> } ) <EOL> for deleted_object in formset . deleted_objects : <EOL> change_message . append ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : force_text ( deleted_object . _meta . verbose_name ) , <EOL> '<STR_LIT:object>' : force_text ( deleted_object ) , <EOL> } <EOL> } ) <EOL> return change_message <EOL> def message_user ( self , request , message , level = messages . INFO , extra_tags = '<STR_LIT>' , <EOL> fail_silently = False ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( level , int ) : <EOL> try : <EOL> level = getattr ( messages . constants , level . upper ( ) ) <EOL> except AttributeError : <EOL> levels = messages . constants . DEFAULT_TAGS . values ( ) <EOL> levels_repr = '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' % l for l in levels ) <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> % ( level , levels_repr ) <EOL> ) <EOL> messages . add_message ( request , level , message , extra_tags = extra_tags , fail_silently = fail_silently ) <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 delete_model ( self , request , obj ) : <EOL> """<STR_LIT>""" <EOL> obj . delete ( ) <EOL> def save_formset ( self , request , form , formset , change ) : <EOL> """<STR_LIT>""" <EOL> formset . save ( ) <EOL> def save_related ( self , request , form , formsets , change ) : <EOL> """<STR_LIT>""" <EOL> form . save_m2m ( ) <EOL> for formset in formsets : <EOL> self . save_formset ( request , form , formset , change = change ) <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> preserved_filters = self . get_preserved_filters ( request ) <EOL> form_url = add_preserved_filters ( { '<STR_LIT>' : preserved_filters , '<STR_LIT>' : opts } , form_url ) <EOL> view_on_site_url = self . get_view_on_site_url ( obj ) <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>' : view_on_site_url is not None , <EOL> '<STR_LIT>' : view_on_site_url , <EOL> '<STR_LIT>' : form_url , <EOL> '<STR_LIT>' : opts , <EOL> '<STR_LIT>' : get_content_type_for_model ( self . model ) . pk , <EOL> '<STR_LIT>' : self . save_as , <EOL> '<STR_LIT>' : self . save_on_top , <EOL> '<STR_LIT>' : TO_FIELD_VAR , <EOL> '<STR_LIT>' : IS_POPUP_VAR , <EOL> '<STR_LIT>' : app_label , <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> request . current_app = self . admin_site . name <EOL> return TemplateResponse ( request , form_template or [ <EOL> "<STR_LIT>" % ( app_label , opts . model_name ) , <EOL> "<STR_LIT>" % app_label , <EOL> "<STR_LIT>" <EOL> ] , context ) <EOL> def response_add ( self , request , obj , post_url_continue = None ) : <EOL> """<STR_LIT>""" <EOL> opts = obj . _meta <EOL> pk_value = obj . _get_pk_val ( ) <EOL> preserved_filters = self . get_preserved_filters ( request ) <EOL> obj_url = reverse ( <EOL> '<STR_LIT>' % ( opts . app_label , opts . model_name ) , <EOL> args = ( quote ( pk_value ) , ) , <EOL> current_app = self . admin_site . name , <EOL> ) <EOL> if self . has_change_permission ( request , obj ) : <EOL> obj_repr = format_html ( '<STR_LIT>' , urlquote ( obj_url ) , obj ) <EOL> else : <EOL> obj_repr = force_text ( obj ) <EOL> msg_dict = { <EOL> '<STR_LIT:name>' : force_text ( opts . verbose_name ) , <EOL> '<STR_LIT>' : obj_repr , <EOL> } <EOL> if IS_POPUP_VAR in request . POST : <EOL> to_field = request . POST . get ( TO_FIELD_VAR ) <EOL> if to_field : <EOL> attr = str ( to_field ) <EOL> else : <EOL> attr = obj . _meta . pk . attname <EOL> value = obj . serializable_value ( attr ) <EOL> popup_response_data = json . dumps ( { <EOL> '<STR_LIT:value>' : six . text_type ( value ) , <EOL> '<STR_LIT>' : six . text_type ( obj ) , <EOL> } ) <EOL> return SimpleTemplateResponse ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : popup_response_data , <EOL> } ) <EOL> elif "<STR_LIT>" in request . POST or ( <EOL> "<STR_LIT>" in request . POST and self . save_as_continue and <EOL> self . has_change_permission ( request , obj ) <EOL> ) : <EOL> msg = format_html ( <EOL> _ ( '<STR_LIT>' ) , <EOL> ** msg_dict <EOL> ) <EOL> self . message_user ( request , msg , messages . SUCCESS ) <EOL> if post_url_continue is None : <EOL> post_url_continue = obj_url <EOL> post_url_continue = add_preserved_filters ( <EOL> { '<STR_LIT>' : preserved_filters , '<STR_LIT>' : opts } , <EOL> post_url_continue <EOL> ) <EOL> return HttpResponseRedirect ( post_url_continue ) <EOL> elif "<STR_LIT>" in request . POST : <EOL> msg = format_html ( <EOL> _ ( '<STR_LIT>' ) , <EOL> ** msg_dict <EOL> ) <EOL> self . message_user ( request , msg , messages . SUCCESS ) <EOL> redirect_url = request . path <EOL> redirect_url = add_preserved_filters ( { '<STR_LIT>' : preserved_filters , '<STR_LIT>' : opts } , redirect_url ) <EOL> return HttpResponseRedirect ( redirect_url ) <EOL> else : <EOL> msg = format_html ( <EOL> _ ( '<STR_LIT>' ) , <EOL> ** msg_dict <EOL> ) <EOL> self . message_user ( request , msg , messages . SUCCESS ) <EOL> return self . response_post_save_add ( request , obj ) <EOL> def response_change ( self , request , obj ) : <EOL> """<STR_LIT>""" <EOL> if IS_POPUP_VAR in request . POST : <EOL> to_field = request . POST . get ( TO_FIELD_VAR ) <EOL> attr = str ( to_field ) if to_field else obj . _meta . pk . attname <EOL> value = request . resolver_match . args [ <NUM_LIT:0> ] <EOL> new_value = obj . serializable_value ( attr ) <EOL> popup_response_data = json . dumps ( { <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : six . text_type ( value ) , <EOL> '<STR_LIT>' : six . text_type ( obj ) , <EOL> '<STR_LIT>' : six . text_type ( new_value ) , <EOL> } ) <EOL> return SimpleTemplateResponse ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : popup_response_data , <EOL> } ) <EOL> opts = self . model . _meta <EOL> pk_value = obj . _get_pk_val ( ) <EOL> preserved_filters = self . get_preserved_filters ( request ) <EOL> msg_dict = { <EOL> '<STR_LIT:name>' : force_text ( opts . verbose_name ) , <EOL> '<STR_LIT>' : format_html ( '<STR_LIT>' , urlquote ( request . path ) , obj ) , <EOL> } <EOL> if "<STR_LIT>" in request . POST : <EOL> msg = format_html ( <EOL> _ ( '<STR_LIT>' ) , <EOL> ** msg_dict <EOL> ) <EOL> self . message_user ( request , msg , messages . SUCCESS ) <EOL> redirect_url = request . path <EOL> redirect_url = add_preserved_filters ( { '<STR_LIT>' : preserved_filters , '<STR_LIT>' : opts } , redirect_url ) <EOL> return HttpResponseRedirect ( redirect_url ) <EOL> elif "<STR_LIT>" in request . POST : <EOL> msg = format_html ( <EOL> _ ( '<STR_LIT>' ) , <EOL> ** msg_dict <EOL> ) <EOL> self . message_user ( request , msg , messages . SUCCESS ) <EOL> redirect_url = reverse ( '<STR_LIT>' % <EOL> ( opts . app_label , opts . model_name ) , <EOL> args = ( pk_value , ) , <EOL> current_app = self . admin_site . name ) <EOL> redirect_url = add_preserved_filters ( { '<STR_LIT>' : preserved_filters , '<STR_LIT>' : opts } , redirect_url ) <EOL> return HttpResponseRedirect ( redirect_url ) <EOL> elif "<STR_LIT>" in request . POST : <EOL> msg = format_html ( <EOL> _ ( '<STR_LIT>' ) , <EOL> ** msg_dict <EOL> ) <EOL> self . message_user ( request , msg , messages . SUCCESS ) <EOL> redirect_url = reverse ( '<STR_LIT>' % <EOL> ( opts . app_label , opts . model_name ) , <EOL> current_app = self . admin_site . name ) <EOL> redirect_url = add_preserved_filters ( { '<STR_LIT>' : preserved_filters , '<STR_LIT>' : opts } , redirect_url ) <EOL> return HttpResponseRedirect ( redirect_url ) <EOL> else : <EOL> msg = format_html ( <EOL> _ ( '<STR_LIT>' ) , <EOL> ** msg_dict <EOL> ) <EOL> self . message_user ( request , msg , messages . SUCCESS ) <EOL> return self . response_post_save_change ( request , obj ) <EOL> def response_post_save_add ( self , request , obj ) : <EOL> """<STR_LIT>""" <EOL> opts = self . model . _meta <EOL> if self . has_change_permission ( request , None ) : <EOL> post_url = reverse ( '<STR_LIT>' % <EOL> ( opts . app_label , opts . model_name ) , <EOL> current_app = self . admin_site . name ) <EOL> preserved_filters = self . get_preserved_filters ( request ) <EOL> post_url = add_preserved_filters ( { '<STR_LIT>' : preserved_filters , '<STR_LIT>' : opts } , post_url ) <EOL> else : <EOL> post_url = reverse ( '<STR_LIT>' , <EOL> current_app = self . admin_site . name ) <EOL> return HttpResponseRedirect ( post_url ) <EOL> def response_post_save_change ( self , request , obj ) : <EOL> """<STR_LIT>""" <EOL> opts = self . model . _meta <EOL> if self . has_change_permission ( request , None ) : <EOL> post_url = reverse ( '<STR_LIT>' % <EOL> ( opts . app_label , opts . model_name ) , <EOL> current_app = self . admin_site . name ) <EOL> preserved_filters = self . get_preserved_filters ( request ) <EOL> post_url = add_preserved_filters ( { '<STR_LIT>' : preserved_filters , '<STR_LIT>' : opts } , post_url ) <EOL> else : <EOL> post_url = reverse ( '<STR_LIT>' , <EOL> current_app = self . admin_site . name ) <EOL> return HttpResponseRedirect ( post_url ) <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 = self . get_actions ( request ) [ action ] [ <NUM_LIT:0> ] <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 , messages . WARNING ) <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 , HttpResponseBase ) : <EOL> return response <EOL> else : <EOL> return HttpResponseRedirect ( request . get_full_path ( ) ) <EOL> else : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> self . message_user ( request , msg , messages . WARNING ) <EOL> return None <EOL> def response_delete ( self , request , obj_display , obj_id ) : <EOL> """<STR_LIT>""" <EOL> opts = self . model . _meta <EOL> if IS_POPUP_VAR in request . POST : <EOL> popup_response_data = json . dumps ( { <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : str ( obj_id ) , <EOL> } ) <EOL> return SimpleTemplateResponse ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : popup_response_data , <EOL> } ) <EOL> self . message_user ( <EOL> request , <EOL> _ ( '<STR_LIT>' ) % { <EOL> '<STR_LIT:name>' : force_text ( opts . verbose_name ) , <EOL> '<STR_LIT>' : force_text ( obj_display ) , <EOL> } , <EOL> messages . SUCCESS , <EOL> ) <EOL> if self . has_change_permission ( request , None ) : <EOL> post_url = reverse ( <EOL> '<STR_LIT>' % ( opts . app_label , opts . model_name ) , <EOL> current_app = self . admin_site . name , <EOL> ) <EOL> preserved_filters = self . get_preserved_filters ( request ) <EOL> post_url = add_preserved_filters ( <EOL> { '<STR_LIT>' : preserved_filters , '<STR_LIT>' : opts } , post_url <EOL> ) <EOL> else : <EOL> post_url = reverse ( '<STR_LIT>' , current_app = self . admin_site . name ) <EOL> return HttpResponseRedirect ( post_url ) <EOL> def render_delete_form ( self , request , context ) : <EOL> opts = self . model . _meta <EOL> app_label = opts . app_label <EOL> request . current_app = self . admin_site . name <EOL> context . update ( <EOL> to_field_var = TO_FIELD_VAR , <EOL> is_popup_var = IS_POPUP_VAR , <EOL> media = self . media , <EOL> ) <EOL> return TemplateResponse ( <EOL> request , <EOL> self . delete_confirmation_template or [ <EOL> "<STR_LIT>" . format ( app_label , opts . model_name ) , <EOL> "<STR_LIT>" . format ( app_label ) , <EOL> "<STR_LIT>" , <EOL> ] , <EOL> context , <EOL> ) <EOL> def get_inline_formsets ( self , request , formsets , inline_instances , obj = None ) : <EOL> inline_admin_formsets = [ ] <EOL> for inline , formset in zip ( inline_instances , formsets ) : <EOL> fieldsets = list ( inline . get_fieldsets ( request , obj ) ) <EOL> readonly = list ( inline . get_readonly_fields ( request , obj ) ) <EOL> prepopulated = dict ( inline . get_prepopulated_fields ( request , obj ) ) <EOL> inline_admin_formset = helpers . InlineAdminFormSet ( <EOL> inline , formset , fieldsets , prepopulated , readonly , <EOL> model_admin = self , <EOL> ) <EOL> inline_admin_formsets . append ( inline_admin_formset ) <EOL> return inline_admin_formsets <EOL> def get_changeform_initial_data ( self , request ) : <EOL> """<STR_LIT>""" <EOL> initial = dict ( request . GET . items ( ) ) <EOL> for k in initial : <EOL> try : <EOL> f = self . model . _meta . get_field ( k ) <EOL> except FieldDoesNotExist : <EOL> continue <EOL> if f . many_to_many : <EOL> initial [ k ] = initial [ k ] . split ( "<STR_LIT:U+002C>" ) <EOL> return initial <EOL> @ csrf_protect_m <EOL> @ transaction . atomic <EOL> def changeform_view ( self , request , object_id = None , form_url = '<STR_LIT>' , extra_context = None ) : <EOL> to_field = request . POST . get ( TO_FIELD_VAR , request . GET . get ( TO_FIELD_VAR ) ) <EOL> if to_field and not self . to_field_allowed ( request , to_field ) : <EOL> raise DisallowedModelAdminToField ( "<STR_LIT>" % to_field ) <EOL> model = self . model <EOL> opts = model . _meta <EOL> if request . method == '<STR_LIT:POST>' and '<STR_LIT>' in request . POST : <EOL> object_id = None <EOL> add = object_id is None <EOL> if add : <EOL> if not self . has_add_permission ( request ) : <EOL> raise PermissionDenied <EOL> obj = None <EOL> else : <EOL> obj = self . get_object ( request , unquote ( object_id ) , to_field ) <EOL> if not self . has_change_permission ( request , obj ) : <EOL> raise PermissionDenied <EOL> if obj is None : <EOL> raise Http404 ( _ ( '<STR_LIT>' ) % { <EOL> '<STR_LIT:name>' : force_text ( opts . verbose_name ) , '<STR_LIT:key>' : escape ( object_id ) } ) <EOL> ModelForm = self . get_form ( request , obj ) <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 = not add ) <EOL> else : <EOL> form_validated = False <EOL> new_object = form . instance <EOL> formsets , inline_instances = self . _create_formsets ( request , new_object , change = not add ) <EOL> if all_valid ( formsets ) and form_validated : <EOL> self . save_model ( request , new_object , form , not add ) <EOL> self . save_related ( request , form , formsets , not add ) <EOL> change_message = self . construct_change_message ( request , form , formsets , add ) <EOL> if add : <EOL> self . log_addition ( request , new_object , change_message ) <EOL> return self . response_add ( request , new_object ) <EOL> else : <EOL> self . log_change ( request , new_object , change_message ) <EOL> return self . response_change ( request , new_object ) <EOL> else : <EOL> form_validated = False <EOL> else : <EOL> if add : <EOL> initial = self . get_changeform_initial_data ( request ) <EOL> form = ModelForm ( initial = initial ) <EOL> formsets , inline_instances = self . _create_formsets ( request , form . instance , change = False ) <EOL> else : <EOL> form = ModelForm ( instance = obj ) <EOL> formsets , inline_instances = self . _create_formsets ( request , obj , change = True ) <EOL> adminForm = helpers . AdminForm ( <EOL> form , <EOL> list ( self . get_fieldsets ( request , obj ) ) , <EOL> self . get_prepopulated_fields ( request , obj ) , <EOL> self . get_readonly_fields ( request , obj ) , <EOL> model_admin = self ) <EOL> media = self . media + adminForm . media <EOL> inline_formsets = self . get_inline_formsets ( request , formsets , inline_instances , obj ) <EOL> for inline_formset in inline_formsets : <EOL> media = media + inline_formset . media <EOL> context = dict ( <EOL> self . admin_site . each_context ( request ) , <EOL> title = ( _ ( '<STR_LIT>' ) if add else _ ( '<STR_LIT>' ) ) % force_text ( opts . verbose_name ) , <EOL> adminform = adminForm , <EOL> object_id = object_id , <EOL> original = obj , <EOL> is_popup = ( IS_POPUP_VAR in request . POST or <EOL> IS_POPUP_VAR in request . GET ) , <EOL> to_field = to_field , <EOL> media = media , <EOL> inline_admin_formsets = inline_formsets , <EOL> errors = helpers . AdminErrorList ( form , formsets ) , <EOL> preserved_filters = self . get_preserved_filters ( request ) , <EOL> ) <EOL> if request . method == '<STR_LIT:POST>' and not form_validated and "<STR_LIT>" in request . POST : <EOL> context [ '<STR_LIT>' ] = False <EOL> context [ '<STR_LIT>' ] = False <EOL> add = False <EOL> context . update ( extra_context or { } ) <EOL> return self . render_change_form ( request , context , add = add , change = not add , obj = obj , form_url = form_url ) <EOL> def add_view ( self , request , form_url = '<STR_LIT>' , extra_context = None ) : <EOL> return self . changeform_view ( request , None , form_url , extra_context ) <EOL> def change_view ( self , request , object_id , form_url = '<STR_LIT>' , extra_context = None ) : <EOL> return self . changeform_view ( request , object_id , form_url , extra_context ) <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> list_display = self . get_list_display ( request ) <EOL> list_display_links = self . get_list_display_links ( request , list_display ) <EOL> list_filter = self . get_list_filter ( request ) <EOL> search_fields = self . get_search_fields ( request ) <EOL> list_select_related = self . get_list_select_related ( request ) <EOL> actions = self . get_actions ( request ) <EOL> if actions : <EOL> list_display = [ '<STR_LIT>' ] + list ( list_display ) <EOL> ChangeList = self . get_changelist ( request ) <EOL> try : <EOL> cl = ChangeList ( <EOL> request , self . model , list_display , <EOL> list_display_links , list_filter , self . date_hierarchy , <EOL> search_fields , list_select_related , self . list_per_page , <EOL> self . list_max_show_all , self . list_editable , self , <EOL> ) <EOL> except IncorrectLookupParameters : <EOL> if ERROR_FLAG in request . GET . keys ( ) : <EOL> return SimpleTemplateResponse ( '<STR_LIT>' , { <EOL> '<STR_LIT:title>' : _ ( '<STR_LIT>' ) , <EOL> } ) <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_queryset ( request ) ) <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 , messages . WARNING ) <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_queryset ( request ) ) <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 cl . 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 = self . get_queryset ( request ) ) <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> self . save_related ( request , form , formsets = [ ] , change = True ) <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_text ( opts . verbose_name ) <EOL> else : <EOL> name = force_text ( opts . verbose_name_plural ) <EOL> msg = ungettext ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> changecount <EOL> ) % { <EOL> '<STR_LIT:count>' : changecount , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : force_text ( obj ) , <EOL> } <EOL> self . message_user ( request , msg , messages . SUCCESS ) <EOL> return HttpResponseRedirect ( request . get_full_path ( ) ) <EOL> elif cl . 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 ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> cl . result_count <EOL> ) <EOL> context = dict ( <EOL> self . admin_site . each_context ( request ) , <EOL> module_name = force_text ( opts . verbose_name_plural ) , <EOL> selection_note = _ ( '<STR_LIT>' ) % { '<STR_LIT>' : len ( cl . result_list ) } , <EOL> selection_note_all = selection_note_all % { '<STR_LIT>' : cl . result_count } , <EOL> title = cl . title , <EOL> is_popup = cl . is_popup , <EOL> to_field = cl . to_field , <EOL> cl = cl , <EOL> media = media , <EOL> has_add_permission = self . has_add_permission ( request ) , <EOL> opts = cl . opts , <EOL> action_form = action_form , <EOL> actions_on_top = self . actions_on_top , <EOL> actions_on_bottom = self . actions_on_bottom , <EOL> actions_selection_counter = self . actions_selection_counter , <EOL> preserved_filters = self . get_preserved_filters ( request ) , <EOL> ) <EOL> context . update ( extra_context or { } ) <EOL> request . current_app = self . admin_site . name <EOL> return TemplateResponse ( request , self . change_list_template or [ <EOL> '<STR_LIT>' % ( app_label , opts . model_name ) , <EOL> '<STR_LIT>' % app_label , <EOL> '<STR_LIT>' <EOL> ] , context ) <EOL> @ csrf_protect_m <EOL> @ transaction . atomic <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> to_field = request . POST . get ( TO_FIELD_VAR , request . GET . get ( TO_FIELD_VAR ) ) <EOL> if to_field and not self . to_field_allowed ( request , to_field ) : <EOL> raise DisallowedModelAdminToField ( "<STR_LIT>" % to_field ) <EOL> obj = self . get_object ( request , unquote ( object_id ) , to_field ) <EOL> if not self . has_delete_permission ( request , obj ) : <EOL> raise PermissionDenied <EOL> if obj is None : <EOL> raise Http404 ( <EOL> _ ( '<STR_LIT>' ) % <EOL> { '<STR_LIT:name>' : force_text ( opts . verbose_name ) , '<STR_LIT:key>' : escape ( object_id ) } <EOL> ) <EOL> using = router . db_for_write ( self . model ) <EOL> ( deleted_objects , model_count , perms_needed , protected ) = get_deleted_objects ( <EOL> [ obj ] , opts , request . user , self . admin_site , using ) <EOL> if request . POST and not protected : <EOL> if perms_needed : <EOL> raise PermissionDenied <EOL> obj_display = force_text ( obj ) <EOL> attr = str ( to_field ) if to_field else opts . pk . attname <EOL> obj_id = obj . serializable_value ( attr ) <EOL> self . log_deletion ( request , obj , obj_display ) <EOL> self . delete_model ( request , obj ) <EOL> return self . response_delete ( request , obj_display , obj_id ) <EOL> object_name = force_text ( opts . verbose_name ) <EOL> if perms_needed or protected : <EOL> title = _ ( "<STR_LIT>" ) % { "<STR_LIT:name>" : object_name } <EOL> else : <EOL> title = _ ( "<STR_LIT>" ) <EOL> context = dict ( <EOL> self . admin_site . each_context ( request ) , <EOL> title = title , <EOL> object_name = object_name , <EOL> object = obj , <EOL> deleted_objects = deleted_objects , <EOL> model_count = dict ( model_count ) . items ( ) , <EOL> perms_lacking = perms_needed , <EOL> protected = protected , <EOL> opts = opts , <EOL> app_label = app_label , <EOL> preserved_filters = self . get_preserved_filters ( request ) , <EOL> is_popup = ( IS_POPUP_VAR in request . POST or <EOL> IS_POPUP_VAR in request . GET ) , <EOL> to_field = to_field , <EOL> ) <EOL> context . update ( extra_context or { } ) <EOL> return self . render_delete_form ( request , context ) <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> obj = self . get_object ( request , unquote ( object_id ) ) <EOL> if obj is None : <EOL> raise Http404 ( _ ( '<STR_LIT>' ) % { <EOL> '<STR_LIT:name>' : force_text ( model . _meta . verbose_name ) , <EOL> '<STR_LIT:key>' : escape ( object_id ) , <EOL> } ) <EOL> if not self . has_change_permission ( request , obj ) : <EOL> raise PermissionDenied <EOL> opts = model . _meta <EOL> app_label = opts . app_label <EOL> action_list = LogEntry . objects . filter ( <EOL> object_id = unquote ( object_id ) , <EOL> content_type = get_content_type_for_model ( model ) <EOL> ) . select_related ( ) . order_by ( '<STR_LIT>' ) <EOL> context = dict ( <EOL> self . admin_site . each_context ( request ) , <EOL> title = _ ( '<STR_LIT>' ) % force_text ( obj ) , <EOL> action_list = action_list , <EOL> module_name = capfirst ( force_text ( opts . verbose_name_plural ) ) , <EOL> object = obj , <EOL> opts = opts , <EOL> preserved_filters = self . get_preserved_filters ( request ) , <EOL> ) <EOL> context . update ( extra_context or { } ) <EOL> request . current_app = self . admin_site . name <EOL> return TemplateResponse ( request , self . object_history_template or [ <EOL> "<STR_LIT>" % ( app_label , opts . model_name ) , <EOL> "<STR_LIT>" % app_label , <EOL> "<STR_LIT>" <EOL> ] , context ) <EOL> def _create_formsets ( self , request , obj , change ) : <EOL> "<STR_LIT>" <EOL> formsets = [ ] <EOL> inline_instances = [ ] <EOL> prefixes = { } <EOL> get_formsets_args = [ request ] <EOL> if change : <EOL> get_formsets_args . append ( obj ) <EOL> for FormSet , inline in self . get_formsets_with_inlines ( * get_formsets_args ) : <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> or not prefix : <EOL> prefix = "<STR_LIT>" % ( prefix , prefixes [ prefix ] ) <EOL> formset_params = { <EOL> '<STR_LIT>' : obj , <EOL> '<STR_LIT>' : prefix , <EOL> '<STR_LIT>' : inline . get_queryset ( request ) , <EOL> } <EOL> if request . method == '<STR_LIT:POST>' : <EOL> formset_params . update ( { <EOL> '<STR_LIT:data>' : request . POST , <EOL> '<STR_LIT>' : request . FILES , <EOL> '<STR_LIT>' : '<STR_LIT>' in request . POST <EOL> } ) <EOL> formsets . append ( FormSet ( ** formset_params ) ) <EOL> inline_instances . append ( inline ) <EOL> return formsets , inline_instances <EOL> class InlineModelAdmin ( BaseModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> model = None <EOL> fk_name = None <EOL> formset = BaseInlineFormSet <EOL> extra = <NUM_LIT:3> <EOL> min_num = None <EOL> max_num = None <EOL> template = None <EOL> verbose_name = None <EOL> verbose_name_plural = None <EOL> can_delete = True <EOL> show_change_link = False <EOL> checks_class = InlineModelAdminChecks <EOL> classes = None <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> self . has_registered_model = admin_site . is_registered ( self . model ) <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> @ property <EOL> def media ( self ) : <EOL> extra = '<STR_LIT>' if settings . DEBUG else '<STR_LIT>' <EOL> js = [ '<STR_LIT>' % extra , '<STR_LIT>' , <EOL> '<STR_LIT>' % extra ] <EOL> if self . filter_vertical or self . filter_horizontal : <EOL> js . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if self . classes and '<STR_LIT>' in self . classes : <EOL> js . append ( '<STR_LIT>' % extra ) <EOL> return forms . Media ( js = [ '<STR_LIT>' % url for url in js ] ) <EOL> def get_extra ( self , request , obj = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . extra <EOL> def get_min_num ( self , request , obj = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . min_num <EOL> def get_max_num ( self , request , obj = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . max_num <EOL> def get_formset ( self , request , obj = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in kwargs : <EOL> fields = kwargs . pop ( '<STR_LIT>' ) <EOL> else : <EOL> fields = flatten_fieldsets ( self . get_fieldsets ( request , obj ) ) <EOL> if self . exclude is None : <EOL> exclude = [ ] <EOL> else : <EOL> exclude = list ( self . exclude ) <EOL> exclude . extend ( self . get_readonly_fields ( request , obj ) ) <EOL> if self . exclude is None and hasattr ( self . form , '<STR_LIT>' ) and self . form . _meta . exclude : <EOL> exclude . extend ( self . form . _meta . exclude ) <EOL> exclude = exclude or None <EOL> can_delete = self . can_delete and self . has_delete_permission ( request , obj ) <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>" : partial ( self . formfield_for_dbfield , request = request ) , <EOL> "<STR_LIT>" : self . get_extra ( request , obj , ** kwargs ) , <EOL> "<STR_LIT>" : self . get_min_num ( request , obj , ** kwargs ) , <EOL> "<STR_LIT>" : self . get_max_num ( request , obj , ** kwargs ) , <EOL> "<STR_LIT>" : can_delete , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> base_model_form = defaults [ '<STR_LIT>' ] <EOL> class DeleteProtectedModelForm ( base_model_form ) : <EOL> def hand_clean_DELETE ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . cleaned_data . get ( DELETION_FIELD_NAME , False ) : <EOL> using = router . db_for_write ( self . _meta . model ) <EOL> collector = NestedObjects ( using = using ) <EOL> if self . instance . pk is None : <EOL> return <EOL> collector . collect ( [ self . instance ] ) <EOL> if collector . protected : <EOL> objs = [ ] <EOL> for p in collector . protected : <EOL> objs . append ( <EOL> _ ( '<STR_LIT>' ) % { <EOL> '<STR_LIT>' : p . _meta . verbose_name , <EOL> '<STR_LIT>' : p } <EOL> ) <EOL> params = { '<STR_LIT>' : self . _meta . model . _meta . verbose_name , <EOL> '<STR_LIT>' : self . instance , <EOL> '<STR_LIT>' : get_text_list ( objs , _ ( '<STR_LIT>' ) ) } <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> raise ValidationError ( msg , code = '<STR_LIT>' , params = params ) <EOL> def is_valid ( self ) : <EOL> result = super ( DeleteProtectedModelForm , self ) . is_valid ( ) <EOL> self . hand_clean_DELETE ( ) <EOL> return result <EOL> defaults [ '<STR_LIT>' ] = DeleteProtectedModelForm <EOL> if defaults [ '<STR_LIT>' ] is None and not modelform_defines_fields ( defaults [ '<STR_LIT>' ] ) : <EOL> defaults [ '<STR_LIT>' ] = forms . ALL_FIELDS <EOL> return inlineformset_factory ( self . parent_model , self . model , ** defaults ) <EOL> def get_fields ( self , request , obj = None ) : <EOL> if self . fields : <EOL> return self . fields <EOL> form = self . get_formset ( request , obj , fields = None ) . form <EOL> return list ( form . base_fields ) + list ( self . get_readonly_fields ( request , obj ) ) <EOL> def get_queryset ( self , request ) : <EOL> queryset = super ( InlineModelAdmin , self ) . get_queryset ( request ) <EOL> if not self . has_change_permission ( request ) : <EOL> queryset = queryset . none ( ) <EOL> return queryset <EOL> def has_add_permission ( self , request ) : <EOL> if self . opts . auto_created : <EOL> return self . has_change_permission ( request ) <EOL> return super ( InlineModelAdmin , self ) . has_add_permission ( request ) <EOL> def has_change_permission ( self , request , obj = None ) : <EOL> opts = self . opts <EOL> if opts . auto_created : <EOL> for field in opts . fields : <EOL> if field . remote_field and field . remote_field . model != self . parent_model : <EOL> opts = field . remote_field . model . _meta <EOL> break <EOL> codename = get_permission_codename ( '<STR_LIT>' , opts ) <EOL> return request . user . has_perm ( "<STR_LIT>" % ( opts . app_label , codename ) ) <EOL> def has_delete_permission ( self , request , obj = None ) : <EOL> if self . opts . auto_created : <EOL> return self . has_change_permission ( request , obj ) <EOL> return super ( InlineModelAdmin , self ) . has_delete_permission ( request , obj ) <EOL> class StackedInline ( InlineModelAdmin ) : <EOL> template = '<STR_LIT>' <EOL> class TabularInline ( InlineModelAdmin ) : <EOL> template = '<STR_LIT>' </s>
