admin.py 2.05 KB
Newer Older
Thom Wiggers's avatar
Thom Wiggers committed
1
from django.contrib import admin
Thom Wiggers's avatar
Thom Wiggers committed
2
from django.forms import ModelForm
3

4
from activemembers.forms import CommitteeMembershipForm
Thom Wiggers's avatar
Thom Wiggers committed
5
from members.models import Member
6
from utils.translation import TranslatedModelAdmin
Thom Wiggers's avatar
Thom Wiggers committed
7
8
from . import models

9

Thom Wiggers's avatar
Thom Wiggers committed
10
11
12
13
14
15
16
17
18
19
20
21
22
class CommitteeMembershipInlineForm(ModelForm):
    """
    Form for the Committee Membership inline

    Doesn't do anything fancy, but we need it for speed.
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Get the related fields in advance
        self.fields['member'].queryset = Member.objects.select_related('user')


23
24
class CommitteeMembershipInline(admin.StackedInline):
    model = models.CommitteeMembership
Thom Wiggers's avatar
Thom Wiggers committed
25
    form = CommitteeMembershipInlineForm
26
27
28
29
30
    can_delete = False
    ordering = ('since',)
    extra = 0


Thom Wiggers's avatar
Thom Wiggers committed
31
@admin.register(models.Committee)
32
class CommitteeAdmin(TranslatedModelAdmin):
33
    inlines = (CommitteeMembershipInline,)
Thom Wiggers's avatar
Thom Wiggers committed
34
    list_filter = ('until',)
Joren Vrancken's avatar
Joren Vrancken committed
35
    search_fields = ('name', 'description')
36
    filter_horizontal = ('permissions',)
Thom Wiggers's avatar
Thom Wiggers committed
37

38
    fields = ('name', 'description', 'photo', 'permissions', 'since',
39
40
              'until', 'contact_mailinglist', 'contact_email',
              'wiki_namespace', 'active')
41

Thom Wiggers's avatar
Thom Wiggers committed
42
43
44
45
46
47
    def get_queryset(self, request):
        qs = super().get_queryset(request)
        return qs.exclude(board__is_board=True)


@admin.register(models.Board)
48
class BoardAdmin(TranslatedModelAdmin):
49
    inlines = (CommitteeMembershipInline,)
Thom Wiggers's avatar
Thom Wiggers committed
50
    exclude = ('is_board',)
51
    filter_horizontal = ('permissions',)
Thom Wiggers's avatar
Thom Wiggers committed
52

53
54
    fields = ('name', 'photo', 'permissions', 'contact_mailinglist',
              'contact_email', 'since', 'until',)
55

Thom Wiggers's avatar
Thom Wiggers committed
56
57

@admin.register(models.CommitteeMembership)
58
class CommitteeMembershipAdmin(TranslatedModelAdmin):
59
    form = CommitteeMembershipForm
60
    list_display = ('member', 'committee', 'since', 'until', 'chair', 'role')
61
62
63
    list_filter = ('committee',)
    search_fields = ('member__user__first_name', 'member__user__last_name',
                     'member__user__email')
64
65
66
67
68


@admin.register(models.Mentorship)
class MentorsAdmin(admin.ModelAdmin):
    pass