<s> from django . contrib import admin <EOL> from django import forms <EOL> from . settings import preferences_settings <EOL> from . registries import global_preferences_registry <EOL> from . models import GlobalPreferenceModel , UserPreferenceModel <EOL> from . forms import GlobalSinglePreferenceForm , UserSinglePreferenceForm , SinglePerInstancePreferenceForm <EOL> class DynamicPreferenceAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> readonly_fields = ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> if preferences_settings . ADMIN_ENABLE_CHANGELIST_FORM : <EOL> list_editable = ( '<STR_LIT>' , ) <EOL> search_fields = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> list_filter = ( '<STR_LIT>' , ) <EOL> if preferences_settings . ADMIN_ENABLE_CHANGELIST_FORM : <EOL> def get_changelist_form ( self , request , ** kwargs ) : <EOL> return self . changelist_form <EOL> class GlobalPreferenceAdmin ( DynamicPreferenceAdmin ) : <EOL> form = GlobalSinglePreferenceForm <EOL> changelist_form = GlobalSinglePreferenceForm <EOL> def get_queryset ( self , * args , ** kwargs ) : <EOL> manager = global_preferences_registry . manager ( ) <EOL> manager . all ( ) <EOL> return super ( GlobalPreferenceAdmin , self ) . get_queryset ( * args , ** kwargs ) <EOL> admin . site . register ( GlobalPreferenceModel , GlobalPreferenceAdmin ) <EOL> class PerInstancePreferenceAdmin ( DynamicPreferenceAdmin ) : <EOL> list_display = ( '<STR_LIT>' , ) + DynamicPreferenceAdmin . list_display <EOL> raw_id_fields = ( '<STR_LIT>' , ) <EOL> form = SinglePerInstancePreferenceForm <EOL> list_select_related = True <EOL> class UserPreferenceAdmin ( PerInstancePreferenceAdmin ) : <EOL> search_fields = [ '<STR_LIT>' ] + DynamicPreferenceAdmin . search_fields <EOL> form = UserSinglePreferenceForm <EOL> changelist_form = UserSinglePreferenceForm <EOL> def get_queryset ( self , request , * args , ** kwargs ) : <EOL> getattr ( request . user , preferences_settings . MANAGER_ATTRIBUTE ) . all ( ) <EOL> return super ( UserPreferenceAdmin , self ) . get_queryset ( request , * args , ** kwargs ) <EOL> if preferences_settings . ENABLE_USER_PREFERENCES : <EOL> admin . site . register ( UserPreferenceModel , UserPreferenceAdmin ) </s>
