<s> from __future__ import absolute_import , unicode_literals <EOL> import json <EOL> from django . template . loader import render_to_string <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from wagtail . wagtailadmin . widgets import AdminChooser <EOL> class AdminSnippetChooser ( AdminChooser ) : <EOL> def __init__ ( self , model , ** kwargs ) : <EOL> self . target_model = model <EOL> name = self . target_model . _meta . verbose_name <EOL> self . choose_one_text = _ ( '<STR_LIT>' ) % name <EOL> self . choose_another_text = _ ( '<STR_LIT>' ) % name <EOL> self . link_to_chosen_text = _ ( '<STR_LIT>' ) % name <EOL> super ( AdminSnippetChooser , self ) . __init__ ( ** kwargs ) <EOL> def render_html ( self , name , value , attrs ) : <EOL> instance , value = self . get_instance_and_id ( self . target_model , value ) <EOL> original_field_html = super ( AdminSnippetChooser , self ) . render_html ( name , value , attrs ) <EOL> return render_to_string ( "<STR_LIT>" , { <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : self . target_model . _meta , <EOL> '<STR_LIT>' : original_field_html , <EOL> '<STR_LIT>' : attrs , <EOL> '<STR_LIT:value>' : value , <EOL> '<STR_LIT>' : instance , <EOL> } ) <EOL> def render_js_init ( self , id_ , name , value ) : <EOL> model = self . target_model <EOL> return "<STR_LIT>" . format ( <EOL> id = json . dumps ( id_ ) , <EOL> model = json . dumps ( '<STR_LIT>' . format ( <EOL> app = model . _meta . app_label , <EOL> model = model . _meta . model_name ) ) ) </s>
