2012-08-08 13:03:28 +03:00
# coding: utf-8
2009-01-05 14:30:08 +02:00
from django . contrib import admin
2009-11-03 14:28:35 +02:00
from django . contrib . auth import admin as auth_admin
from django . contrib . auth . models import User
2012-07-30 10:49:59 +03:00
from django . utils . translation import ugettext_lazy as _
2009-04-08 20:43:29 +03:00
2012-07-30 10:44:50 +03:00
from djangobb_forum . models import Category , Forum , Topic , Post , Profile , Reputation , \
2012-08-10 11:12:52 +03:00
Report , Ban , Attachment , Poll , PollChoice
2009-04-08 20:43:29 +03:00
2009-01-05 14:30:08 +02:00
2012-08-08 13:03:28 +03:00
class BaseModelAdmin ( admin . ModelAdmin ) :
def get_actions ( self , request ) :
# disabled, because delete_selected ignoring delete model method
actions = super ( BaseModelAdmin , self ) . get_actions ( request )
if ' delete_selected ' in actions :
del actions [ ' delete_selected ' ]
return actions
class CategoryAdmin ( BaseModelAdmin ) :
2009-01-05 14:30:08 +02:00
list_display = [ ' name ' , ' position ' , ' forum_count ' ]
2012-08-08 13:03:28 +03:00
class ForumAdmin ( BaseModelAdmin ) :
2009-01-05 14:30:08 +02:00
list_display = [ ' name ' , ' category ' , ' position ' , ' topic_count ' ]
2010-01-05 15:56:19 +02:00
raw_id_fields = [ ' moderators ' , ' last_post ' ]
2009-01-05 14:30:08 +02:00
2012-08-08 13:03:28 +03:00
class TopicAdmin ( BaseModelAdmin ) :
2012-07-30 10:49:59 +03:00
def subscribers2 ( self , obj ) :
return " , " . join ( [ user . username for user in obj . subscribers . all ( ) ] )
subscribers2 . short_description = _ ( " subscribers " )
list_display = [ ' name ' , ' forum ' , ' created ' , ' head ' , ' post_count ' , ' subscribers2 ' ]
2009-01-05 14:30:08 +02:00
search_fields = [ ' name ' ]
2009-06-30 10:12:21 +03:00
raw_id_fields = [ ' user ' , ' subscribers ' , ' last_post ' ]
2009-01-05 14:30:08 +02:00
2012-08-08 13:03:28 +03:00
class PostAdmin ( BaseModelAdmin ) :
2009-01-05 14:30:08 +02:00
list_display = [ ' topic ' , ' user ' , ' created ' , ' updated ' , ' summary ' ]
search_fields = [ ' body ' ]
2010-02-17 13:05:48 +02:00
raw_id_fields = [ ' topic ' , ' user ' , ' updated_by ' ]
2009-01-05 14:30:08 +02:00
2012-08-08 13:03:28 +03:00
class ProfileAdmin ( BaseModelAdmin ) :
2009-01-05 14:30:08 +02:00
list_display = [ ' user ' , ' status ' , ' time_zone ' , ' location ' , ' language ' ]
2009-07-02 16:01:22 +03:00
raw_id_fields = [ ' user ' ]
2009-01-05 14:30:08 +02:00
2012-08-08 13:03:28 +03:00
class ReputationAdmin ( BaseModelAdmin ) :
2010-02-23 14:19:20 +02:00
list_display = [ ' from_user ' , ' to_user ' , ' post ' , ' sign ' , ' time ' , ' reason ' ]
raw_id_fields = [ ' from_user ' , ' to_user ' , ' post ' ]
2009-06-30 10:12:21 +03:00
2012-08-08 13:03:28 +03:00
class ReportAdmin ( BaseModelAdmin ) :
2009-01-05 14:30:08 +02:00
list_display = [ ' reported_by ' , ' post ' , ' zapped ' , ' zapped_by ' , ' created ' , ' reason ' ]
2009-06-30 10:12:21 +03:00
raw_id_fields = [ ' reported_by ' , ' post ' ]
2012-08-08 13:03:28 +03:00
class BanAdmin ( BaseModelAdmin ) :
2009-04-08 20:43:29 +03:00
list_display = [ ' user ' , ' ban_start ' , ' ban_end ' , ' reason ' ]
2009-06-30 10:12:21 +03:00
raw_id_fields = [ ' user ' ]
2009-04-08 20:43:29 +03:00
2009-11-03 14:28:35 +02:00
class UserAdmin ( auth_admin . UserAdmin ) :
2009-12-29 22:59:17 +02:00
list_display = [ ' username ' , ' email ' , ' first_name ' , ' last_name ' , ' is_staff ' , ' is_active ' ]
2012-08-08 13:03:28 +03:00
2009-11-03 14:28:35 +02:00
def get_urls ( self ) :
from django . conf . urls . defaults import patterns , url
return patterns ( ' ' ,
url ( r ' ^( \ d+)/password/$ ' , self . admin_site . admin_view ( self . user_change_password ) , name = ' user_change_password ' ) ,
) + super ( auth_admin . UserAdmin , self ) . get_urls ( )
2009-01-05 14:30:08 +02:00
2012-08-08 13:03:28 +03:00
class AttachmentAdmin ( BaseModelAdmin ) :
2012-07-30 10:44:50 +03:00
list_display = [ ' id ' , ' name ' , ' size ' , ' path ' , ' hash ' , ]
search_fields = [ ' name ' ]
list_display_links = ( ' name ' , )
list_filter = ( " content_type " , )
2009-11-03 14:28:35 +02:00
2012-08-10 11:12:52 +03:00
class PollChoiceInline ( admin . TabularInline ) :
model = PollChoice
extra = 3
class PollAdmin ( admin . ModelAdmin ) :
list_display = ( " question " , " active " , )
list_display_links = ( " question " , )
list_editable = ( " active " , )
list_filter = ( " active " , )
inlines = [ PollChoiceInline ]
2009-11-03 14:28:35 +02:00
2012-08-10 11:12:52 +03:00
admin . site . unregister ( User )
2009-11-03 14:28:35 +02:00
admin . site . register ( User , UserAdmin )
2012-08-10 11:12:52 +03:00
2009-01-05 14:30:08 +02:00
admin . site . register ( Category , CategoryAdmin )
admin . site . register ( Forum , ForumAdmin )
admin . site . register ( Topic , TopicAdmin )
admin . site . register ( Post , PostAdmin )
admin . site . register ( Profile , ProfileAdmin )
admin . site . register ( Reputation , ReputationAdmin )
admin . site . register ( Report , ReportAdmin )
2009-10-20 14:01:50 +03:00
admin . site . register ( Ban , BanAdmin )
2012-07-30 10:44:50 +03:00
admin . site . register ( Attachment , AttachmentAdmin )
2012-08-10 11:12:52 +03:00
admin . site . register ( Poll , PollAdmin )
2009-10-20 14:01:50 +03:00