Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     if 'user' in kwargs:
         self.user = kwargs.pop('user', None)
     else:
         self.user = None
     super(DonationForm, self).__init__(*args, **kwargs)
     # populate the user fields
     if self.user and self.user.id:
         self.fields['first_name'].initial = self.user.first_name
         self.fields['last_name'].initial = self.user.last_name
         self.fields['email'].initial = self.user.email
         try:
             profile = self.user.get_profile()
             if profile:
                 self.fields['company'].initial = profile.company
                 self.fields['address'].initial = profile.address
                 self.fields['address2'].initial = profile.address2
                 self.fields['city'].initial = profile.city
                 self.fields['state'].initial = profile.state
                 self.fields['zip_code'].initial = profile.zipcode
                 self.fields['country'].initial = profile.country
                 self.fields['phone'].initial = profile.phone
         except:
             pass
         
     self.fields['payment_method'].widget = forms.RadioSelect(choices=get_payment_method_choices(self.user))
     allocation_str = get_setting('module', 'donations', 'donationsallocations')
     if allocation_str:
         self.fields['allocation'].choices = get_allocation_choices(self.user, allocation_str)
     else:
         del self.fields['allocation']
     preset_amount_str = (get_setting('module', 'donations', 'donationspresetamounts')).strip('')
     if preset_amount_str:
         self.fields['donation_amount'] = forms.ChoiceField(choices=get_preset_amount_choices(preset_amount_str))
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        if 'user' in kwargs:
            self.user = kwargs.pop('user', None)
        else:
            self.user = None
        super(DonationAdminForm, self).__init__(*args, **kwargs)

        preset_amount_str = (get_setting('module', 'donations', 'donationspresetamounts')).strip('')
        if preset_amount_str:
            self.fields['donation_amount'] = forms.ChoiceField(choices=get_preset_amount_choices(preset_amount_str))