<s> from __future__ import unicode_literals <EOL> from django . forms . widgets import ( <EOL> CheckboxInput , ClearableFileInput , <EOL> HiddenInput , MultiWidget , Select <EOL> ) <EOL> from django . utils . encoding import force_text <EOL> from django . utils . html import conditional_escape , format_html <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . translation import ugettext_lazy <EOL> CENTERPOINT_CHOICES = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> class ClearableFileInputWithImagePreview ( ClearableFileInput ) : <EOL> ppoi_label = ugettext_lazy ( '<STR_LIT>' ) <EOL> template_with_clear = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> template_with_initial_and_imagepreview = """<STR_LIT>""" <EOL> def get_hidden_field_id ( self , name ) : <EOL> i = name . rindex ( '<STR_LIT:_>' ) <EOL> return "<STR_LIT>" % ( name [ : i ] , int ( name [ i + <NUM_LIT:1> : ] ) + <NUM_LIT:1> ) <EOL> def image_preview_id ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return name + '<STR_LIT>' <EOL> def get_ppoi_id ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return name + '<STR_LIT>' <EOL> def get_point_stage_id ( self , name ) : <EOL> return name + '<STR_LIT>' <EOL> def image_preview ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> value . create_on_demand = True <EOL> return ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) % { <EOL> '<STR_LIT>' : value . thumbnail [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : self . image_preview_id ( name ) , <EOL> '<STR_LIT>' : self . get_hidden_field_id ( name ) , <EOL> '<STR_LIT>' : self . get_point_stage_id ( name ) , <EOL> '<STR_LIT>' : self . get_ppoi_id ( name ) <EOL> } <EOL> def render ( self , name , value , attrs = None ) : <EOL> substitutions = { <EOL> '<STR_LIT>' : force_text ( self . initial_text ) , <EOL> '<STR_LIT>' : self . input_text , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . clear_checkbox_label , <EOL> '<STR_LIT>' : self . ppoi_label <EOL> } <EOL> template = '<STR_LIT>' <EOL> substitutions [ '<STR_LIT:input>' ] = super ( ClearableFileInput , self ) . render ( <EOL> name , <EOL> value , <EOL> attrs <EOL> ) <EOL> if value and hasattr ( value , "<STR_LIT:url>" ) : <EOL> substitutions [ '<STR_LIT>' ] = format_html ( '<STR_LIT>' , <EOL> value . url , <EOL> force_text ( value ) ) <EOL> substitutions [ '<STR_LIT>' ] = value . url <EOL> template = self . template_with_initial_and_imagepreview <EOL> point_stage_id = self . get_point_stage_id ( name ) <EOL> ppoi_id = self . get_ppoi_id ( name ) <EOL> substitutions [ '<STR_LIT>' ] = point_stage_id <EOL> substitutions [ '<STR_LIT>' ] = ppoi_id <EOL> substitutions [ '<STR_LIT>' ] = self . image_preview_id ( name ) <EOL> image_preview = self . image_preview ( <EOL> name , <EOL> value <EOL> ) <EOL> substitutions [ '<STR_LIT>' ] = image_preview <EOL> if value . field . blank : <EOL> checkbox_name = self . clear_checkbox_name ( name ) <EOL> checkbox_id = self . clear_checkbox_id ( checkbox_name ) <EOL> substitutions [ '<STR_LIT>' ] = conditional_escape ( <EOL> checkbox_name <EOL> ) <EOL> substitutions [ '<STR_LIT>' ] = conditional_escape ( <EOL> checkbox_id <EOL> ) <EOL> substitutions [ '<STR_LIT>' ] = CheckboxInput ( ) . render ( <EOL> checkbox_name , <EOL> False , <EOL> attrs = { '<STR_LIT:id>' : checkbox_id } <EOL> ) <EOL> substitutions [ '<STR_LIT>' ] = self . template_with_clear % substitutions <EOL> return mark_safe ( template % substitutions ) <EOL> class SizedImageCenterpointWidgetMixIn ( object ) : <EOL> def decompress ( self , value ) : <EOL> to_return = [ None , None ] <EOL> if value : <EOL> to_return = [ <EOL> value , <EOL> '<STR_LIT:x>' . join ( str ( num ) for num in value . ppoi ) <EOL> ] <EOL> return to_return <EOL> class VersatileImagePPOISelectWidget ( SizedImageCenterpointWidgetMixIn , <EOL> MultiWidget ) : <EOL> def __init__ ( self , widgets = None , attrs = None ) : <EOL> widgets = [ <EOL> ClearableFileInput ( attrs = None ) , <EOL> Select ( <EOL> attrs = attrs , <EOL> choices = CENTERPOINT_CHOICES <EOL> ) <EOL> ] <EOL> super ( VersatileImagePPOISelectWidget , self ) . __init__ ( widgets , attrs ) <EOL> class VersatileImagePPOIClickWidget ( SizedImageCenterpointWidgetMixIn , <EOL> MultiWidget ) : <EOL> image_preview_template = None <EOL> clear_checkbox_template = None <EOL> def __init__ ( self , widgets = None , attrs = None , image_preview_template = None ) : <EOL> widgets = ( <EOL> ClearableFileInputWithImagePreview ( <EOL> attrs = { '<STR_LIT:class>' : '<STR_LIT>' } , <EOL> ) , <EOL> HiddenInput ( <EOL> attrs = { '<STR_LIT:class>' : '<STR_LIT>' } <EOL> ) <EOL> ) <EOL> super ( VersatileImagePPOIClickWidget , self ) . __init__ ( widgets , attrs ) <EOL> class Media : <EOL> css = { <EOL> '<STR_LIT:all>' : ( '<STR_LIT>' , ) , <EOL> } <EOL> js = ( '<STR_LIT>' , ) <EOL> def render ( self , name , value , attrs = None ) : <EOL> rendered = super ( VersatileImagePPOIClickWidget , self ) . render ( <EOL> name , <EOL> value , <EOL> attrs <EOL> ) <EOL> to_return = '<STR_LIT>' + mark_safe ( rendered ) + '<STR_LIT>' <EOL> return mark_safe ( to_return ) <EOL> class SizedImageCenterpointClickDjangoAdminWidget ( <EOL> VersatileImagePPOIClickWidget ) : <EOL> class Media : <EOL> css = { <EOL> '<STR_LIT:all>' : ( '<STR_LIT>' , ) , <EOL> } <EOL> class SizedImageCenterpointClickBootstrap3Widget ( <EOL> VersatileImagePPOIClickWidget ) : <EOL> template_with_initial_and_imagepreview = """<STR_LIT>""" <EOL> template_with_clear = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class Media : <EOL> css = { <EOL> '<STR_LIT:all>' : ( '<STR_LIT>' , ) , <EOL> } </s>
