Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

from django import forms 

from django.forms import inlineformset_factory 

 

from .models import EmailAddress, Member 

 

 

class BaseAddForm(forms.ModelForm): 

required_css_class = 'required' 

error_css_class = 'alert-danger' 

 

 

class MemberImportForm(forms.Form): 

docfile = forms.FileField( 

label='Select a file', 

help_text='max. 42 megabytes' 

) 

 

 

class MemberAddForm(BaseAddForm): 

class Meta: 

model = Member 

fields = ( 

'membership_type', 'membership_reduced', 'erfa', 'first_name', 'last_name', 'address_1', 'address_2', 

'address_3', 'address_country', 'notification_consent', 'wants_datenschleuder', 'comment', 

'membership_start' 

) 

widgets = { 

'membership_type': forms.Select(attrs={'class': 'form-control'}), 

'erfa': forms.Select(attrs={'class': 'form-control'}), 

'address_country': forms.Select(attrs={'class': 'form-control'}), 

'membership_start': forms.HiddenInput(), 

} 

 

 

class CashPointImportForm(forms.Form): 

docfile = forms.FileField( 

label='Select a file', 

help_text='max. 42 megabytes' 

) 

 

 

class EmailAddressFormSet(forms.BaseInlineFormSet): 

"""Change each form's behaviour to be required. No empty inline forms allowed.""" 

def __init__(self, *args, **kwargs): 

super(EmailAddressFormSet, self).__init__(*args, **kwargs) 

for form in self.forms: 

form.empty_permitted = False 

 

 

class EmailAddressForm(BaseAddForm): 

pass 

 

 

EmailFormset = inlineformset_factory( 

Member, EmailAddress, formset=EmailAddressFormSet, form=EmailAddressForm, 

fields=('email_address', 'gpg_key_id'), extra=1, 

widgets={'gpg_key_id': forms.TextInput( 

attrs={'oninput': r'this.value = this.value.replace(/\s+/g, '');'}) 

} 

)