<s> from functools import partial <EOL> from django . contrib import admin <EOL> from fluent_contents import extensions <EOL> from fluent_contents . admin . placeholdereditor import PlaceholderEditorInline , PlaceholderEditorAdmin <EOL> from fluent_contents . models import PlaceholderData <EOL> from fluent_contents . models . fields import PlaceholderField <EOL> class PlaceholderFieldInline ( PlaceholderEditorInline ) : <EOL> """<STR_LIT>""" <EOL> template = "<STR_LIT>" <EOL> class PlaceholderFieldAdmin ( PlaceholderEditorAdmin ) : <EOL> """<STR_LIT>""" <EOL> placeholder_inline = PlaceholderFieldInline <EOL> def get_form ( self , request , obj = None , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = partial ( <EOL> self . formfield_for_dbfield , request = request , obj = obj ) <EOL> return super ( PlaceholderFieldAdmin , self ) . get_form ( <EOL> request , obj = obj , ** kwargs ) <EOL> def formfield_for_dbfield ( self , db_field , ** kwargs ) : <EOL> obj = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if isinstance ( db_field , PlaceholderField ) : <EOL> kwargs [ '<STR_LIT>' ] = obj <EOL> return super ( PlaceholderFieldAdmin , self ) . formfield_for_dbfield ( <EOL> db_field , ** kwargs ) <EOL> def get_placeholder_data ( self , request , obj = None ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self . model , '<STR_LIT>' ) : <EOL> return [ ] <EOL> data = [ ] <EOL> for name , field in self . model . _meta_placeholder_fields . items ( ) : <EOL> assert isinstance ( field , PlaceholderField ) <EOL> data . append ( PlaceholderData ( <EOL> slot = field . slot , <EOL> title = field . verbose_name . capitalize ( ) , <EOL> fallback_language = None , <EOL> ) ) <EOL> return data <EOL> def get_all_allowed_plugins ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self . model , '<STR_LIT>' ) : <EOL> return [ ] <EOL> plugins = [ ] <EOL> for name , field in self . model . _meta_placeholder_fields . items ( ) : <EOL> assert isinstance ( field , PlaceholderField ) <EOL> if field . plugins is None : <EOL> return extensions . plugin_pool . get_plugins ( ) <EOL> else : <EOL> plugins += field . plugins <EOL> return list ( set ( plugins ) ) </s>
