<s> from django import forms <EOL> from django . conf import settings as site_settings <EOL> from django . contrib import admin <EOL> from django . forms . models import modelformset_factory , modelform_factory <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . functional import curry <EOL> from stories import settings <EOL> from . forms import StoryForm <EOL> from . models import Story <EOL> from . utils import load_widget <EOL> HAS_RELATIONS = '<STR_LIT>' in site_settings . INSTALLED_APPS and settings . RELATIONS <EOL> if HAS_RELATIONS : <EOL> from stories . relations . genericcollection import GenericCollectionTabularInline <EOL> from stories . relations . models import StoryRelation <EOL> class InlineStoryRelation ( GenericCollectionTabularInline ) : <EOL> model = StoryRelation <EOL> if settings . USE_REVERSION : <EOL> from reversion . admin import VersionAdmin <EOL> AdminModel = VersionAdmin <EOL> else : <EOL> AdminModel = admin . ModelAdmin <EOL> class ChangeStatus ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , status_val , status_name ) : <EOL> super ( ChangeStatus , self ) . __init__ ( ) <EOL> self . status_val = status_val <EOL> self . status_name = status_name . __unicode__ ( ) <EOL> self . __name__ = "<STR_LIT>" % self . status_name <EOL> def __call__ ( self , modeladmin , request , queryset ) : <EOL> rows_updated = queryset . update ( status = self . status_val ) <EOL> if rows_updated == <NUM_LIT:1> : <EOL> message_bit = "<STR_LIT>" <EOL> else : <EOL> message_bit = "<STR_LIT>" % rows_updated <EOL> modeladmin . message_user ( request , <EOL> "<STR_LIT>" % ( <EOL> message_bit , self . status_name ) ) <EOL> admin_actions = [ ChangeStatus ( x , y ) for x , y in settings . STATUS_CHOICES ] <EOL> class StoryAdmin ( AdminModel ) : <EOL> """<STR_LIT>""" <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_filter = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_per_page = settings . ADMIN_EXTRAS . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> list_editable = ( ) <EOL> quick_editable = settings . QUICKEDIT_FIELDS <EOL> search_fields = settings . ADMIN_EXTRAS . get ( '<STR_LIT>' , ( '<STR_LIT>' , ) ) <EOL> date_hierarchy = '<STR_LIT>' <EOL> prepopulated_fields = { '<STR_LIT>' : ( '<STR_LIT>' , ) } <EOL> form = StoryForm <EOL> actions = admin_actions <EOL> actions_on_bottom = True <EOL> raw_id_fields = settings . ADMIN_EXTRAS . get ( '<STR_LIT>' , ( ) ) <EOL> filter_horizontal = settings . ADMIN_EXTRAS . get ( <EOL> '<STR_LIT>' , ( '<STR_LIT>' , ) ) <EOL> if HAS_RELATIONS : <EOL> inlines = [ InlineStoryRelation , ] <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:body>' ) <EOL> } ) , <EOL> ( _ ( '<STR_LIT>' ) , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> } ) , ) <EOL> if settings . INCLUDE_PRINT : <EOL> fieldsets = fieldsets + ( _ ( '<STR_LIT>' ) , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> } ) <EOL> fieldsets = fieldsets + ( ( _ ( '<STR_LIT>' ) , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' , '<STR_LIT>' , ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> } ) , ) <EOL> change_list_template = '<STR_LIT>' <EOL> revision_form_template = '<STR_LIT>' <EOL> class Media : <EOL> js = ( '<STR_LIT>' , ) <EOL> if HAS_RELATIONS : <EOL> js += ( '<STR_LIT>' , ) <EOL> css = { '<STR_LIT:all>' : ( '<STR_LIT>' , ) } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( StoryAdmin , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fieldsets = list ( self . fieldsets ) <EOL> for extra_fs in settings . ADMIN_EXTRAS . get ( '<STR_LIT>' , ( ) ) : <EOL> fs = ( extra_fs . get ( '<STR_LIT:name>' , None ) , { <EOL> '<STR_LIT>' : extra_fs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : extra_fs . get ( '<STR_LIT>' , ( ) ) , <EOL> '<STR_LIT:description>' : extra_fs . get ( '<STR_LIT:description>' , None ) <EOL> } ) <EOL> if '<STR_LIT>' in extra_fs : <EOL> self . fieldsets . insert ( extra_fs . get ( '<STR_LIT>' ) , fs ) <EOL> else : <EOL> self . fieldsets . append ( fs ) <EOL> def _get_widget ( self ) : <EOL> attrs = settings . WIDGET_ATTRS <EOL> widget = load_widget ( settings . WIDGET ) or forms . Textarea <EOL> return widget ( attrs = attrs ) <EOL> def formfield_for_dbfield ( self , db_field , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if db_field . name in settings . WIDGET_FIELDS : <EOL> return db_field . formfield ( widget = self . _get_widget ( ) ) <EOL> return super ( StoryAdmin , self ) . formfield_for_dbfield ( db_field , ** kwargs ) <EOL> def queryset ( self , request ) : <EOL> """<STR_LIT>""" <EOL> qs = self . model . objects . get_query_set ( ) <EOL> ordering = self . ordering or ( ) <EOL> if ordering : <EOL> qs = qs . order_by ( * ordering ) <EOL> return qs <EOL> def changelist_view ( self , * args , ** kwargs ) : <EOL> self . list_editable = True <EOL> return super ( StoryAdmin , self ) . changelist_view ( * args , ** kwargs ) <EOL> def get_changelist_formset ( self , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> defaults = { <EOL> '<STR_LIT>' : curry ( <EOL> self . formfield_for_dbfield , <EOL> request = request ) , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> QEForm = modelform_factory ( self . model ) <EOL> return modelformset_factory ( <EOL> self . model , <EOL> QEForm , <EOL> extra = <NUM_LIT:0> , <EOL> fields = self . quick_editable , <EOL> ** defaults ) <EOL> admin . site . register ( Story , StoryAdmin ) </s>
