class ShopAuthFormMixin(EntangledModelFormMixin): form_type = ChoiceField( label=_("Rendered Form"), choices=[ft[:2] for ft in AUTH_FORM_TYPES], help_text=_("Select the appropriate form for various authentication purposes."), ) class Meta: entangled_fields = {'glossary': ['form_type']}
class ShopAuthForm(LinkForm): LINK_TYPE_CHOICES = (('cmspage', _("CMS Page")), ('RELOAD_PAGE', _("Reload Page")), ('DO_NOTHING', _("Do Nothing"))) form_type = ChoiceField(label=_("Rendered Form"), choices=(ft[:2] for ft in AUTH_FORM_TYPES), help_text=_("Select the appropriate form for various authentication purposes.")) def clean(self): cleaned_data = super(ShopAuthForm, self).clean() if self.is_valid(): cleaned_data['glossary'].update(form_type=cleaned_data['form_type']) return cleaned_data
class DuesForm(NgFormValidationMixin, Bootstrap3FormMixin, NgForm): required_css_class = 'required' merchant_id = CharField(widget=forms.HiddenInput(), initial=MERCHANT_ID) description = CharField(widget=forms.HiddenInput(), initial='membership fees.') merchantDefinedData1 = CharField(widget=forms.HiddenInput(), initial=PAYMENT_TYPE) merchantDefinedData2 = ChoiceField(required=True, label='Affiliation', choices=list(amount_choices())) merchantDefinedData3 = EmailField(required=True, label='Email') # For Participant-less users with JS enabled, this will be hidden & silently # set by an Angular directive that updates the amount based on the affiliation. # For users _without_ JavaScript, it will display as a Select widget. amount = ChoiceField( label='Please confirm membership level', required=True, help_text="(We're showing this because you have scripts disabled)", choices=list(amount_choices(value_is_amount=True)), ) def __init__(self, *args, **kwargs): participant = kwargs.pop('participant') super().__init__(*args, **kwargs) email = self.fields['merchantDefinedData3'] if participant: email.initial = participant.email self.fields[ 'merchantDefinedData2'].initial = participant.affiliation self.fields['amount'].initial = participant.annual_dues else: email.widget.attrs['placeholder'] = '*****@*****.**' # Without this, the default choice is 'Undergraduate student'. # This heading doesn't render as a choice, but it behaves like one. self.fields['amount'].initial = ''