Isolated individual admin files
This commit is contained in:
parent
0849cfa25a
commit
820ba17513
7 changed files with 163 additions and 107 deletions
|
|
@ -1,107 +0,0 @@
|
|||
from django.contrib import admin
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import ngettext
|
||||
from django.db.models import Sum, F
|
||||
from django.db.models.functions import Coalesce
|
||||
|
||||
from .models import Activity, House, Teacher, PointsEntry, UserEntry
|
||||
|
||||
|
||||
@admin.register(Activity)
|
||||
class ActivityAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
(None, {'fields': ['name']}),
|
||||
('Activity Information', {
|
||||
'fields': ['quota', 'time']}),
|
||||
]
|
||||
|
||||
list_display = ['name', 'time', 'quota', 'teacher', 'hawk_signups',
|
||||
'great_grey_signups', 'snowy_signups', 'eagle_signups']
|
||||
|
||||
@admin.display(description='Hawk Signups')
|
||||
def hawk_signups(self, obj):
|
||||
return str(UserEntry.hawk.filterActivity1(obj).count()) + " | " + str((UserEntry.hawk.filterActivity2(obj).count(), "-")[obj.time == 60])
|
||||
|
||||
@admin.display(description='Great Grey Signups')
|
||||
def great_grey_signups(self, obj):
|
||||
return str(UserEntry.great_grey.filterActivity1(obj).count()) + " | " + str((UserEntry.great_grey.filterActivity2(obj).count(), "-")[obj.time == 60])
|
||||
|
||||
@admin.display(description='Snowy Signups')
|
||||
def snowy_signups(self, obj):
|
||||
return str(UserEntry.snowy.filterActivity1(obj).count()) + " | " + str((UserEntry.snowy.filterActivity2(obj).count(), "-")[obj.time == 60])
|
||||
|
||||
@admin.display(description='Eagle Signups')
|
||||
def eagle_signups(self, obj):
|
||||
return str(UserEntry.eagle.filterActivity1(obj).count()) + " | " + str((UserEntry.eagle.filterActivity2(obj).count(), "-")[obj.time == 60])
|
||||
|
||||
|
||||
@admin.register(House)
|
||||
class HouseAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'points', 'current_points', 'total_points')
|
||||
actions = ['finalize_points']
|
||||
|
||||
@admin.display(description='Current Housewars Points')
|
||||
def current_points(self, obj):
|
||||
return obj.current_points
|
||||
|
||||
@admin.display(description='Total Points')
|
||||
def total_points(self, obj):
|
||||
return obj.total_points
|
||||
|
||||
@admin.action(description='Finalize selected house points')
|
||||
def finalize_points(self, request, queryset):
|
||||
updated = queryset.update(
|
||||
points=queryset.aggregate(points__sum=Coalesce(Sum('pointsentry__points'), 0)).get('points__sum') + F('points'))
|
||||
PointsEntry.objects.filter(pk__in=queryset).delete()
|
||||
self.message_user(request, ngettext(
|
||||
'%d story was successfully marked as published.',
|
||||
'%d stories were successfully marked as published.',
|
||||
1,
|
||||
) % 1, messages.SUCCESS)
|
||||
|
||||
|
||||
@ admin.register(Teacher)
|
||||
class TeacherAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
('Personal Information', {'fields': [
|
||||
'first_name', 'last_name']}),
|
||||
('House Wars Information', {
|
||||
'fields': ['grade', 'house', 'activity']}),
|
||||
]
|
||||
|
||||
list_display = ('first_name', 'last_name', 'grade', 'activity')
|
||||
|
||||
|
||||
@ admin.register(UserEntry)
|
||||
class EntryAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
('Personal Information', {'fields': [
|
||||
'first_name', 'last_name', 'email', 'grade']}),
|
||||
('House Wars Information', {
|
||||
'fields': ['house', 'activity1', 'activity2']}),
|
||||
]
|
||||
|
||||
list_display = ('first_name', 'last_name',
|
||||
'house', 'activity1', 'activity1_teacher', 'activity2', 'activity2_teacher')
|
||||
|
||||
list_filter = ['house', 'grade', 'activity1',
|
||||
'activity1__teacher', 'activity2', 'activity2__teacher']
|
||||
|
||||
@admin.display(description='Activity 1 Teacher')
|
||||
def activity1_teacher(self, obj):
|
||||
if (obj.activity1 == None):
|
||||
return None
|
||||
|
||||
return obj.activity1.teacher
|
||||
|
||||
@admin.display(description='Activity 2 Teacher')
|
||||
def activity2_teacher(self, obj):
|
||||
if (obj.activity2 == None):
|
||||
return None
|
||||
|
||||
return obj.activity2.teacher
|
||||
|
||||
|
||||
@admin.register(PointsEntry)
|
||||
class PointsEntryAdmin(admin.ModelAdmin):
|
||||
list_display = ('activity', 'name', 'house', 'points')
|
||||
39
housewars/admin/Activity.py
Normal file
39
housewars/admin/Activity.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from ..models import Activity, UserEntry
|
||||
|
||||
|
||||
@admin.register(Activity)
|
||||
class ActivityAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
(None, {'fields': ['name']}),
|
||||
('Activity Information', {
|
||||
'fields': ['quota', 'time']}),
|
||||
]
|
||||
|
||||
list_display = ['name', 'time', 'quota', 'teacher', 'password', 'hawk_signups',
|
||||
'great_grey_signups', 'snowy_signups', 'eagle_signups']
|
||||
|
||||
@admin.display(description='Hawk Signups')
|
||||
def hawk_signups(self, obj):
|
||||
if (obj.time == None):
|
||||
return "- | -"
|
||||
return str(UserEntry.hawk.filterActivity1(obj).count()) + " | " + str((UserEntry.hawk.filterActivity2(obj).count(), "-")[obj.time == 60])
|
||||
|
||||
@admin.display(description='Great Grey Signups')
|
||||
def great_grey_signups(self, obj):
|
||||
if (obj.time == None):
|
||||
return "- | -"
|
||||
return str(UserEntry.great_grey.filterActivity1(obj).count()) + " | " + str((UserEntry.great_grey.filterActivity2(obj).count(), "-")[obj.time == 60])
|
||||
|
||||
@admin.display(description='Snowy Signups')
|
||||
def snowy_signups(self, obj):
|
||||
if (obj.time == None):
|
||||
return "- | -"
|
||||
return str(UserEntry.snowy.filterActivity1(obj).count()) + " | " + str((UserEntry.snowy.filterActivity2(obj).count(), "-")[obj.time == 60])
|
||||
|
||||
@admin.display(description='Eagle Signups')
|
||||
def eagle_signups(self, obj):
|
||||
if (obj.time == None):
|
||||
return "- | -"
|
||||
return str(UserEntry.eagle.filterActivity1(obj).count()) + " | " + str((UserEntry.eagle.filterActivity2(obj).count(), "-")[obj.time == 60])
|
||||
31
housewars/admin/House.py
Normal file
31
housewars/admin/House.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from django.contrib import admin, messages
|
||||
from django.utils.translation import ngettext
|
||||
from django.db.models import Sum, F
|
||||
from django.db.models.functions import Coalesce
|
||||
|
||||
from ..models import House, PointsEntry
|
||||
|
||||
|
||||
@admin.register(House)
|
||||
class HouseAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'points', 'current_points', 'total_points')
|
||||
actions = ['finalize_points']
|
||||
|
||||
@admin.display(description='Current Housewars Points')
|
||||
def current_points(self, obj):
|
||||
return obj.current_points
|
||||
|
||||
@admin.display(description='Total Points')
|
||||
def total_points(self, obj):
|
||||
return obj.total_points
|
||||
|
||||
@admin.action(description='Finalize selected house points')
|
||||
def finalize_points(self, request, queryset):
|
||||
updated = queryset.update(
|
||||
points=queryset.aggregate(points__sum=Coalesce(Sum('pointsentry__points'), 0)).get('points__sum') + F('points'))
|
||||
PointsEntry.objects.filter(pk__in=queryset).delete()
|
||||
self.message_user(request, ngettext(
|
||||
'Finalized house points for %d house.',
|
||||
'Finalized house points for %d houses.',
|
||||
updated,
|
||||
) % updated, messages.SUCCESS)
|
||||
8
housewars/admin/PointsEntry.py
Normal file
8
housewars/admin/PointsEntry.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from ..models import PointsEntry
|
||||
|
||||
|
||||
@admin.register(PointsEntry)
|
||||
class PointsEntryAdmin(admin.ModelAdmin):
|
||||
list_display = ('activity', 'name', 'house', 'points')
|
||||
15
housewars/admin/Teacher.py
Normal file
15
housewars/admin/Teacher.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from ..models import Teacher
|
||||
|
||||
|
||||
@admin.register(Teacher)
|
||||
class TeacherAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
('Personal Information', {'fields': [
|
||||
'first_name', 'last_name']}),
|
||||
('House Wars Information', {
|
||||
'fields': ['grade', 'house', 'activity']}),
|
||||
]
|
||||
|
||||
list_display = ('first_name', 'last_name', 'house', 'grade', 'activity')
|
||||
65
housewars/admin/UserEntry.py
Normal file
65
housewars/admin/UserEntry.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
from django.contrib import admin
|
||||
from django.db.models import F, Value
|
||||
from django.db.models.functions import Concat
|
||||
|
||||
from ..models import UserEntry
|
||||
|
||||
|
||||
class MentorListFilter(admin.SimpleListFilter):
|
||||
title = 'mentor teacher'
|
||||
|
||||
# Parameter for the filter that will be used in the URL query.
|
||||
parameter_name = 'mentor'
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
"""
|
||||
Returns a list of tuples. The first element in each
|
||||
tuple is the coded value for the option that will
|
||||
appear in the URL query. The second element is the
|
||||
human-readable name for the option that will appear
|
||||
in the right sidebar.
|
||||
"""
|
||||
qs = model_admin.get_queryset(request).annotate(full_name=Concat(F(
|
||||
'house__teacher__first_name'), Value(' '), F('house__teacher__last_name'))).values_list('house__teacher', 'full_name').distinct()
|
||||
|
||||
return qs
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
if (self.value() == None):
|
||||
return queryset
|
||||
|
||||
return queryset.filter(house__teacher=self.value(), grade=F('house__teacher__grade'))
|
||||
|
||||
|
||||
@ admin.register(UserEntry)
|
||||
class UserEntryAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
('Personal Information', {'fields': [
|
||||
'first_name', 'last_name', 'email', 'grade']}),
|
||||
('House Wars Information', {
|
||||
'fields': ['house', 'activity1', 'activity2']}),
|
||||
]
|
||||
|
||||
list_display = ('first_name', 'last_name',
|
||||
'house', 'mentor_teacher', 'activity1', 'activity1_teacher', 'activity2', 'activity2_teacher')
|
||||
|
||||
list_filter = ['house', 'grade', MentorListFilter, 'activity1',
|
||||
'activity1__teacher', 'activity2', 'activity2__teacher']
|
||||
|
||||
@ admin.display(description='Activity 1 Teacher')
|
||||
def activity1_teacher(self, obj):
|
||||
if (obj.activity1 == None):
|
||||
return None
|
||||
|
||||
return obj.activity1.teacher
|
||||
|
||||
@ admin.display(description='Mentor Teacher')
|
||||
def mentor_teacher(self, obj):
|
||||
return obj.mentor
|
||||
|
||||
@ admin.display(description='Activity 2 Teacher')
|
||||
def activity2_teacher(self, obj):
|
||||
if (obj.activity2 == None):
|
||||
return None
|
||||
|
||||
return obj.activity2.teacher
|
||||
5
housewars/admin/__init__.py
Normal file
5
housewars/admin/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from .Activity import ActivityAdmin
|
||||
from .House import HouseAdmin
|
||||
from .Teacher import TeacherAdmin
|
||||
from .UserEntry import UserEntryAdmin
|
||||
from .PointsEntry import PointsEntryAdmin
|
||||
Reference in a new issue