<s> """<STR_LIT>""" <EOL> import django . utils . copycompat as copy <EOL> from django import forms <EOL> from django . forms . widgets import RadioFieldRenderer <EOL> from django . forms . util import flatatt <EOL> from django . utils . html import escape <EOL> from django . utils . text import truncate_words <EOL> from django . utils . translation import ugettext as _ <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . encoding import force_unicode <EOL> from django . conf import settings <EOL> from django . core . urlresolvers import reverse , NoReverseMatch <EOL> class FilteredSelectMultiple ( forms . SelectMultiple ) : <EOL> """<STR_LIT>""" <EOL> class Media : <EOL> js = ( settings . ADMIN_MEDIA_PREFIX + "<STR_LIT>" , <EOL> settings . ADMIN_MEDIA_PREFIX + "<STR_LIT>" , <EOL> settings . ADMIN_MEDIA_PREFIX + "<STR_LIT>" ) <EOL> def __init__ ( self , verbose_name , is_stacked , attrs = None , choices = ( ) ) : <EOL> self . verbose_name = verbose_name <EOL> self . is_stacked = is_stacked <EOL> super ( FilteredSelectMultiple , self ) . __init__ ( attrs , choices ) <EOL> def render ( self , name , value , attrs = None , choices = ( ) ) : <EOL> if attrs is None : attrs = { } <EOL> attrs [ '<STR_LIT:class>' ] = '<STR_LIT>' <EOL> if self . is_stacked : attrs [ '<STR_LIT:class>' ] += '<STR_LIT>' <EOL> output = [ super ( FilteredSelectMultiple , self ) . render ( name , value , attrs , choices ) ] <EOL> output . append ( u'<STR_LIT>' ) <EOL> output . append ( u'<STR_LIT>' % ( name , self . verbose_name . replace ( '<STR_LIT:">' , '<STR_LIT>' ) , int ( self . is_stacked ) , settings . ADMIN_MEDIA_PREFIX ) ) <EOL> return mark_safe ( u'<STR_LIT>' . join ( output ) ) <EOL> class AdminDateWidget ( forms . DateInput ) : <EOL> class Media : <EOL> js = ( settings . ADMIN_MEDIA_PREFIX + "<STR_LIT>" , <EOL> settings . ADMIN_MEDIA_PREFIX + "<STR_LIT>" ) <EOL> def __init__ ( self , attrs = { } , format = None ) : <EOL> super ( AdminDateWidget , self ) . __init__ ( attrs = { '<STR_LIT:class>' : '<STR_LIT>' , '<STR_LIT:size>' : '<STR_LIT>' } , format = format ) <EOL> class AdminTimeWidget ( forms . TimeInput ) : <EOL> class Media : <EOL> js = ( settings . ADMIN_MEDIA_PREFIX + "<STR_LIT>" , <EOL> settings . ADMIN_MEDIA_PREFIX + "<STR_LIT>" ) <EOL> def __init__ ( self , attrs = { } , format = None ) : <EOL> super ( AdminTimeWidget , self ) . __init__ ( attrs = { '<STR_LIT:class>' : '<STR_LIT>' , '<STR_LIT:size>' : '<STR_LIT>' } , format = format ) <EOL> class AdminSplitDateTime ( forms . SplitDateTimeWidget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> widgets = [ AdminDateWidget , AdminTimeWidget ] <EOL> forms . MultiWidget . __init__ ( self , widgets , attrs ) <EOL> def format_output ( self , rendered_widgets ) : <EOL> return mark_safe ( u'<STR_LIT>' % ( _ ( '<STR_LIT>' ) , rendered_widgets [ <NUM_LIT:0> ] , _ ( '<STR_LIT>' ) , rendered_widgets [ <NUM_LIT:1> ] ) ) <EOL> class AdminRadioFieldRenderer ( RadioFieldRenderer ) : <EOL> def render ( self ) : <EOL> """<STR_LIT>""" <EOL> return mark_safe ( u'<STR_LIT>' % ( <EOL> flatatt ( self . attrs ) , <EOL> u'<STR_LIT:\n>' . join ( [ u'<STR_LIT>' % force_unicode ( w ) for w in self ] ) ) <EOL> ) <EOL> class AdminRadioSelect ( forms . RadioSelect ) : <EOL> renderer = AdminRadioFieldRenderer <EOL> class AdminFileWidget ( forms . ClearableFileInput ) : <EOL> template_with_initial = ( u'<STR_LIT>' <EOL> % forms . ClearableFileInput . template_with_initial ) <EOL> template_with_clear = ( u'<STR_LIT>' <EOL> % forms . ClearableFileInput . template_with_clear ) <EOL> def url_params_from_lookup_dict ( lookups ) : <EOL> """<STR_LIT>""" <EOL> params = { } <EOL> if lookups and hasattr ( lookups , '<STR_LIT>' ) : <EOL> items = [ ] <EOL> for k , v in lookups . items ( ) : <EOL> if isinstance ( v , list ) : <EOL> v = u'<STR_LIT:U+002C>' . join ( [ str ( x ) for x in v ] ) <EOL> elif isinstance ( v , bool ) : <EOL> v = ( '<STR_LIT:0>' , '<STR_LIT:1>' ) [ v ] <EOL> else : <EOL> v = unicode ( v ) <EOL> items . append ( ( k , v ) ) <EOL> params . update ( dict ( items ) ) <EOL> return params <EOL> class ForeignKeyRawIdWidget ( forms . TextInput ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rel , attrs = None , using = None ) : <EOL> self . rel = rel <EOL> self . db = using <EOL> super ( ForeignKeyRawIdWidget , self ) . __init__ ( attrs ) <EOL> def render ( self , name , value , attrs = None ) : <EOL> if attrs is None : <EOL> attrs = { } <EOL> related_url = '<STR_LIT>' % ( self . rel . to . _meta . app_label , self . rel . to . _meta . object_name . lower ( ) ) <EOL> params = self . url_parameters ( ) <EOL> if params : <EOL> url = u'<STR_LIT:?>' + u'<STR_LIT>' . join ( [ u'<STR_LIT>' % ( k , v ) for k , v in params . items ( ) ] ) <EOL> else : <EOL> url = u'<STR_LIT>' <EOL> if "<STR_LIT:class>" not in attrs : <EOL> attrs [ '<STR_LIT:class>' ] = '<STR_LIT>' <EOL> output = [ super ( ForeignKeyRawIdWidget , self ) . render ( name , value , attrs ) ] <EOL> output . append ( u'<STR_LIT>' % ( related_url , url , name ) ) <EOL> output . append ( u'<STR_LIT>' % ( settings . ADMIN_MEDIA_PREFIX , _ ( '<STR_LIT>' ) ) ) <EOL> if value : <EOL> output . append ( self . label_for_value ( value ) ) <EOL> return mark_safe ( u'<STR_LIT>' . join ( output ) ) <EOL> def base_url_parameters ( self ) : <EOL> return url_params_from_lookup_dict ( self . rel . limit_choices_to ) <EOL> def url_parameters ( self ) : <EOL> from django . contrib . admin . views . main import TO_FIELD_VAR <EOL> params = self . base_url_parameters ( ) <EOL> params . update ( { TO_FIELD_VAR : self . rel . get_related_field ( ) . name } ) <EOL> return params <EOL> def label_for_value ( self , value ) : <EOL> key = self . rel . get_related_field ( ) . name <EOL> try : <EOL> obj = self . rel . to . _default_manager . using ( self . db ) . get ( ** { key : value } ) <EOL> return '<STR_LIT>' % escape ( truncate_words ( obj , <NUM_LIT> ) ) <EOL> except ( ValueError , self . rel . to . DoesNotExist ) : <EOL> return '<STR_LIT>' <EOL> class ManyToManyRawIdWidget ( ForeignKeyRawIdWidget ) : <EOL> """<STR_LIT>""" <EOL> def render ( self , name , value , attrs = None ) : <EOL> if attrs is None : <EOL> attrs = { } <EOL> attrs [ '<STR_LIT:class>' ] = '<STR_LIT>' <EOL> if value : <EOL> value = '<STR_LIT:U+002C>' . join ( [ force_unicode ( v ) for v in value ] ) <EOL> else : <EOL> value = '<STR_LIT>' <EOL> return super ( ManyToManyRawIdWidget , self ) . render ( name , value , attrs ) <EOL> def url_parameters ( self ) : <EOL> return self . base_url_parameters ( ) <EOL> def label_for_value ( self , value ) : <EOL> return '<STR_LIT>' <EOL> def value_from_datadict ( self , data , files , name ) : <EOL> value = data . get ( name ) <EOL> if value : <EOL> return value . split ( '<STR_LIT:U+002C>' ) <EOL> def _has_changed ( self , initial , data ) : <EOL> if initial is None : <EOL> initial = [ ] <EOL> if data is None : <EOL> data = [ ] <EOL> if len ( initial ) != len ( data ) : <EOL> return True <EOL> for pk1 , pk2 in zip ( initial , data ) : <EOL> if force_unicode ( pk1 ) != force_unicode ( pk2 ) : <EOL> return True <EOL> return False <EOL> class RelatedFieldWidgetWrapper ( forms . Widget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , widget , rel , admin_site , can_add_related = None ) : <EOL> self . is_hidden = widget . is_hidden <EOL> self . needs_multipart_form = widget . needs_multipart_form <EOL> self . attrs = widget . attrs <EOL> self . choices = widget . choices <EOL> self . widget = widget <EOL> self . rel = rel <EOL> if can_add_related is None : <EOL> can_add_related = rel . to in admin_site . _registry <EOL> self . can_add_related = can_add_related <EOL> self . admin_site = admin_site <EOL> def __deepcopy__ ( self , memo ) : <EOL> obj = copy . copy ( self ) <EOL> obj . widget = copy . deepcopy ( self . widget , memo ) <EOL> obj . attrs = self . widget . attrs <EOL> memo [ id ( self ) ] = obj <EOL> return obj <EOL> def _media ( self ) : <EOL> return self . widget . media <EOL> media = property ( _media ) <EOL> def render ( self , name , value , * args , ** kwargs ) : <EOL> rel_to = self . rel . to <EOL> info = ( rel_to . _meta . app_label , rel_to . _meta . object_name . lower ( ) ) <EOL> try : <EOL> related_url = reverse ( '<STR_LIT>' % info , current_app = self . admin_site . name ) <EOL> except NoReverseMatch : <EOL> info = ( self . admin_site . root_path , rel_to . _meta . app_label , rel_to . _meta . object_name . lower ( ) ) <EOL> related_url = '<STR_LIT>' % info <EOL> self . widget . choices = self . choices <EOL> output = [ self . widget . render ( name , value , * args , ** kwargs ) ] <EOL> if self . can_add_related : <EOL> output . append ( u'<STR_LIT>' % ( related_url , name ) ) <EOL> output . append ( u'<STR_LIT>' % ( settings . ADMIN_MEDIA_PREFIX , _ ( '<STR_LIT>' ) ) ) <EOL> return mark_safe ( u'<STR_LIT>' . join ( output ) ) <EOL> def build_attrs ( self , extra_attrs = None , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> self . attrs = self . widget . build_attrs ( extra_attrs = None , ** kwargs ) <EOL> return self . attrs <EOL> def value_from_datadict ( self , data , files , name ) : <EOL> return self . widget . value_from_datadict ( data , files , name ) <EOL> def _has_changed ( self , initial , data ) : <EOL> return self . widget . _has_changed ( initial , data ) <EOL> def id_for_label ( self , id_ ) : <EOL> return self . widget . id_for_label ( id_ ) <EOL> class AdminTextareaWidget ( forms . Textarea ) : <EOL> def __init__ ( self , attrs = None ) : <EOL> final_attrs = { '<STR_LIT:class>' : '<STR_LIT>' } <EOL> if attrs is not None : <EOL> final_attrs . update ( attrs ) <EOL> super ( AdminTextareaWidget , self ) . __init__ ( attrs = final_attrs ) <EOL> class AdminTextInputWidget ( forms . TextInput ) : <EOL> def __init__ ( self , attrs = None ) : <EOL> final_attrs = { '<STR_LIT:class>' : '<STR_LIT>' } <EOL> if attrs is not None : <EOL> final_attrs . update ( attrs ) <EOL> super ( AdminTextInputWidget , self ) . __init__ ( attrs = final_attrs ) <EOL> class AdminURLFieldWidget ( forms . TextInput ) : <EOL> def __init__ ( self , attrs = None ) : <EOL> final_attrs = { '<STR_LIT:class>' : '<STR_LIT>' } <EOL> if attrs is not None : <EOL> final_attrs . update ( attrs ) <EOL> super ( AdminURLFieldWidget , self ) . __init__ ( attrs = final_attrs ) <EOL> class AdminIntegerFieldWidget ( forms . TextInput ) : <EOL> def __init__ ( self , attrs = None ) : <EOL> final_attrs = { '<STR_LIT:class>' : '<STR_LIT>' } <EOL> if attrs is not None : <EOL> final_attrs . update ( attrs ) <EOL> super ( AdminIntegerFieldWidget , self ) . __init__ ( attrs = final_attrs ) <EOL> class AdminCommaSeparatedIntegerFieldWidget ( forms . TextInput ) : <EOL> def __init__ ( self , attrs = None ) : <EOL> final_attrs = { '<STR_LIT:class>' : '<STR_LIT>' } <EOL> if attrs is not None : <EOL> final_attrs . update ( attrs ) <EOL> super ( AdminCommaSeparatedIntegerFieldWidget , self ) . __init__ ( attrs = final_attrs ) </s>
