comparison gpp/bio/admin.py @ 347:69d0306a6fe7

Fixing #165: add a way to filter users in the admin by join date; add an admin action to approve a pending user; added a honeypot type field to the registration form.
author Brian Neal <bgneal@gmail.com>
date Wed, 02 Mar 2011 01:11:32 +0000
parents d424b8bae71d
children d1b11096595b
comparison
equal deleted inserted replaced
346:efa3b4901777 347:69d0306a6fe7
2 This file contains the admin definitions for the bio application. 2 This file contains the admin definitions for the bio application.
3 """ 3 """
4 import datetime 4 import datetime
5 5
6 from django.contrib import admin 6 from django.contrib import admin
7
8 import django.contrib.auth.models
9 import django.contrib.auth.admin
7 10
8 import bio.models 11 import bio.models
9 import bio.badges 12 import bio.badges
10 from comments.models import Comment 13 from comments.models import Comment
11 from forums.tools import delete_user_posts 14 from forums.tools import delete_user_posts
24 readonly_fields = ('status', 'status_date', 'update_date') 27 readonly_fields = ('status', 'status_date', 'update_date')
25 list_filter = ('status', ) 28 list_filter = ('status', )
26 date_hierarchy = 'status_date' 29 date_hierarchy = 'status_date'
27 inlines = (BadgeOwnerInline, ) 30 inlines = (BadgeOwnerInline, )
28 actions = ( 31 actions = (
29 'mark_active', 32 'mark_active',
30 'mark_resigned', 33 'mark_resigned',
31 'mark_removed', 34 'mark_removed',
32 'mark_suspended', 35 'mark_suspended',
33 'mark_spammer', 36 'mark_spammer',
34 'mark_stranger', 37 'mark_stranger',
38 return obj.get_status_display() 41 return obj.get_status_display()
39 get_status_display.short_description = 'Status' 42 get_status_display.short_description = 'Status'
40 43
41 def mark_user_status(self, request, qs, status): 44 def mark_user_status(self, request, qs, status):
42 """ 45 """
43 Common code for the admin actions. Updates the status field in the 46 Common code for the admin actions. Updates the status field in the
44 profiles to 'status'. Updates the status_date. Sets the is_active 47 profiles to 'status'. Updates the status_date. Sets the is_active
45 field to True if the status is STA_ACTIVE and False otherwise. 48 field to True if the status is STA_ACTIVE and False otherwise.
46 """ 49 """
47 now = datetime.datetime.now() 50 now = datetime.datetime.now()
48 for profile in qs: 51 for profile in qs:
49 profile.user.is_active = (status == bio.models.STA_ACTIVE or 52 profile.user.is_active = (status == bio.models.STA_ACTIVE or
118 flag.delete() 121 flag.delete()
119 122
120 accept_flags.short_description = "Accept selected flagged profiles" 123 accept_flags.short_description = "Accept selected flagged profiles"
121 124
122 125
123
124
125
126 class BadgeAdmin(admin.ModelAdmin): 126 class BadgeAdmin(admin.ModelAdmin):
127 list_display = ('name', 'html', 'order', 'numeric_id', 'description') 127 list_display = ('name', 'html', 'order', 'numeric_id', 'description')
128 list_editable = ('order', 'numeric_id') 128 list_editable = ('order', 'numeric_id')
129 129
130 130
131 # We like the User admin but would like a date hierarcy on date_joined.
132 class UserAdmin(django.contrib.auth.admin.UserAdmin):
133 date_hierarchy = 'date_joined'
134
135
131 admin.site.register(bio.models.UserProfile, UserProfileAdmin) 136 admin.site.register(bio.models.UserProfile, UserProfileAdmin)
132 admin.site.register(bio.models.UserProfileFlag, UserProfileFlagAdmin) 137 admin.site.register(bio.models.UserProfileFlag, UserProfileFlagAdmin)
133 admin.site.register(bio.models.Badge, BadgeAdmin) 138 admin.site.register(bio.models.Badge, BadgeAdmin)
139
140 # Unregister existing ModelAdmin for User, then register ours
141 admin.site.unregister(django.contrib.auth.models.User)
142 admin.site.register(django.contrib.auth.models.User, UserAdmin)