admin.py 1.88 KB
Newer Older
Thom Wiggers's avatar
Thom Wiggers committed
1
from django.contrib import admin
2

3
from activemembers.forms import CommitteeMembershipForm
4
from utils.translation import TranslatedModelAdmin
Thom Wiggers's avatar
Thom Wiggers committed
5
6
from . import models

7

8
9
10
11
12
13
14
class CommitteeMembershipInline(admin.StackedInline):
    model = models.CommitteeMembership
    can_delete = False
    ordering = ('since',)
    extra = 0


Thom Wiggers's avatar
Thom Wiggers committed
15
@admin.register(models.Committee)
16
class CommitteeAdmin(TranslatedModelAdmin):
17
    inlines = (CommitteeMembershipInline,)
18
19
    list_display = ('name', 'since', 'until', 'active', 'email')
    list_filter = ('until', 'active',)
Joren Vrancken's avatar
Joren Vrancken committed
20
    search_fields = ('name', 'description')
21
    filter_horizontal = ('permissions',)
Thom Wiggers's avatar
Thom Wiggers committed
22

23
    fields = ('name', 'description', 'photo', 'permissions', 'since',
24
25
              'until', 'contact_mailinglist', 'contact_email',
              'wiki_namespace', 'active')
26

27
28
29
30
31
32
33
    def email(self, instance):
        if instance.contact_email:
            return instance.contact_email
        elif instance.contact_mailinglist:
            return instance.contact_mailinglist.name + '@thalia.nu'
        return None

Thom Wiggers's avatar
Thom Wiggers committed
34
35
36
37
38
39
    def get_queryset(self, request):
        qs = super().get_queryset(request)
        return qs.exclude(board__is_board=True)


@admin.register(models.Board)
40
class BoardAdmin(TranslatedModelAdmin):
41
    inlines = (CommitteeMembershipInline,)
Thom Wiggers's avatar
Thom Wiggers committed
42
    exclude = ('is_board',)
43
    filter_horizontal = ('permissions',)
Thom Wiggers's avatar
Thom Wiggers committed
44

45
46
    fields = ('name', 'description', 'photo', 'permissions',
              'contact_mailinglist', 'contact_email', 'since', 'until',)
47

Thom Wiggers's avatar
Thom Wiggers committed
48
49

@admin.register(models.CommitteeMembership)
50
class CommitteeMembershipAdmin(TranslatedModelAdmin):
51
    form = CommitteeMembershipForm
52
    list_display = ('member', 'committee', 'since', 'until', 'chair', 'role')
53
    list_filter = ('committee',)
54
55
    search_fields = ('member__first_name', 'member__last_name',
                     'member__email')
56
57
58
59
60


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