<s> from django . contrib import admin <EOL> from django . contrib . sites . models import Site <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . translation import ugettext_noop , ungettext <EOL> from faq . settings import DRAFTED , PUBLISHED , REMOVED , STATUS_CHOICES <EOL> from faq . models import Topic , Question <EOL> from faq . forms import QuestionForm <EOL> def update_status ( modeladmin , request , queryset , status ) : <EOL> """<STR_LIT>""" <EOL> for obj in queryset : <EOL> obj . status = status <EOL> obj . save ( ) <EOL> log_message = ugettext_noop ( u'<STR_LIT>' % <EOL> obj . get_status_display ( ) ) <EOL> modeladmin . log_change ( request , obj , log_message ) <EOL> message_dict = { <EOL> '<STR_LIT:count>' : queryset . count ( ) , <EOL> '<STR_LIT:object>' : modeladmin . model . _meta . verbose_name , <EOL> '<STR_LIT>' : dict ( STATUS_CHOICES ) [ status ] , <EOL> } <EOL> if not message_dict [ '<STR_LIT:count>' ] == <NUM_LIT:1> : <EOL> message_dict [ '<STR_LIT:object>' ] = modeladmin . model . _meta . verbose_name_plural <EOL> user_message = ungettext ( <EOL> u'<STR_LIT>' , <EOL> u'<STR_LIT>' , <EOL> message_dict [ '<STR_LIT:count>' ] ) % message_dict <EOL> modeladmin . message_user ( request , user_message ) <EOL> return None <EOL> def draft ( modeladmin , request , queryset ) : <EOL> """<STR_LIT>""" <EOL> return update_status ( modeladmin , request , queryset , DRAFTED ) <EOL> draft . short_description = _ ( u'<STR_LIT>' ) <EOL> def publish ( modeladmin , request , queryset ) : <EOL> """<STR_LIT>""" <EOL> return update_status ( modeladmin , request , queryset , PUBLISHED ) <EOL> publish . short_description = _ ( u'<STR_LIT>' ) <EOL> def remove ( modeladmin , request , queryset ) : <EOL> """<STR_LIT>""" <EOL> return update_status ( modeladmin , request , queryset , REMOVED ) <EOL> remove . short_description = _ ( u'<STR_LIT>' ) <EOL> class QuestionInline ( admin . TabularInline ) : <EOL> extra = <NUM_LIT:1> <EOL> form = QuestionForm <EOL> model = Question <EOL> class FAQAdminBase ( admin . ModelAdmin ) : <EOL> actions = ( draft , publish , remove ) <EOL> actions_on_top = True <EOL> actions_on_bottom = True <EOL> list_per_page = <NUM_LIT:50> <EOL> class TopicAdmin ( FAQAdminBase ) : <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT:status>' , '<STR_LIT>' ) } ) , <EOL> ) <EOL> inlines = ( QuestionInline , ) <EOL> list_display = ( '<STR_LIT:title>' , '<STR_LIT:description>' , '<STR_LIT:status>' , '<STR_LIT>' ) <EOL> list_filter = ( '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> prepopulated_fields = { '<STR_LIT>' : ( '<STR_LIT:title>' , ) } <EOL> search_fields = ( '<STR_LIT:title>' , '<STR_LIT:description>' ) <EOL> def question_count ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> return obj . questions . count ( ) <EOL> question_count . short_description = _ ( u'<STR_LIT>' ) <EOL> class QuestionAdmin ( FAQAdminBase ) : <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:status>' , <EOL> '<STR_LIT>' ) } ) , <EOL> ) <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' ) <EOL> list_filter = ( '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> prepopulated_fields = { '<STR_LIT>' : ( '<STR_LIT>' , ) } <EOL> search_fields = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> admin . site . register ( Topic , TopicAdmin ) <EOL> admin . site . register ( Question , QuestionAdmin ) </s>
