forms.py 1.02 KB
Newer Older
1
"""The forms defined by the activemembers module"""
2
from django import forms
3
from django.contrib.auth.models import Permission
4

5
from activemembers.models import MemberGroupMembership
6
from members.models import Member
7
8


9
10
class MemberGroupMembershipForm(forms.ModelForm):
    """Custom form for group memberships that orders the members"""
11
    member = forms.ModelChoiceField(
12
13
        queryset=Member.objects.order_by('first_name',
                                         'last_name'))
14
15

    class Meta:
16
        model = MemberGroupMembership
17
        exclude = ()
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32


class MemberGroupForm(forms.ModelForm):
    """
    Solely here for performance reasons.

    Needed because the `__str__()` of `Permission` (which is displayed in the
    permissions selection box) also prints the corresponding app and
    `content_type` for each permission.
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['permissions'].queryset = (
            Permission.objects.select_related('content_type'))