Skip to content
This repository
tree: 1fcabb30de
Fetching contributors…

Cannot retrieve contributors at this time

file 35 lines (27 sloc) 1.335 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _
from users.models import UserProfile
from django.views.generic.list import ListView


class CensoredUserAdmin(UserAdmin):
    "UserAdmin that does not show a user's email address or password hash"

    list_display = ('username', 'first_name', 'last_name', 'is_staff')
    search_fields = ('username', 'first_name', 'last_name')
    fieldsets = (
        (None, {'fields': ('username',)}),
        (_('Personal info'), {'fields': ('first_name', 'last_name')}),
        (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
                                       'user_permissions')}),
        (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
        (_('Groups'), {'fields': ('groups',)}),
    )

    def get_readonly_fields(self, request, obj=None):
        if not request.user.is_superuser:
            return self.readonly_fields + ('is_staff', 'is_superuser',)
        return self.readonly_fields


admin.site.unregister(User)
admin.site.register(User, CensoredUserAdmin)


class SubscribedList(ListView):
    queryset = UserProfile.objects.filter(subscribed=True)
    template_name = 'users/subscribed_list.html'
Something went wrong with that request. Please try again.