Skip to content

Commit

Permalink
Merge pull request #1307 from akvo/1265_donations
Browse files Browse the repository at this point in the history
[#1265] Donations
  • Loading branch information
loicsans committed Mar 12, 2015
2 parents d8927e5 + a58e11b commit 2c49c52
Show file tree
Hide file tree
Showing 19 changed files with 983 additions and 181 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ tramp
# SASS
akvo/rsr/static/rsr/v3/css/src/.sass-cache
akvo/rsr/static/rsr/v3/css/src/*.map

*.codekit
52 changes: 51 additions & 1 deletion akvo/rsr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.sites.models import get_current_site
from django.db.models import get_model
from django.utils.translation import ugettext_lazy as _

from mollie.ideal.utils import get_mollie_banklist

from registration.models import RegistrationProfile

from urlparse import urlsplit, urlunsplit

from .models import Country, Organisation, ProjectUpdate, ProjectUpdateLocation
from .models import Country, Invoice, Organisation, ProjectUpdate, ProjectUpdateLocation

from akvo import settings

Expand Down Expand Up @@ -318,3 +321,50 @@ class UserAvatarForm(forms.ModelForm):
class Meta:
model = get_user_model()
fields = ('avatar',)


class InvoiceForm(forms.ModelForm):
def __init__(self, project, engine, *args, **kwargs):
super(InvoiceForm, self).__init__(*args, **kwargs)
self.project = project
self.engine = engine
if engine == 'ideal':
self.fields['bank'] = forms.CharField(max_length=4,
widget=forms.Select(choices=get_mollie_banklist()))

"""HACK:
Ideally the name and email fields in the Invoice model
should be required. They are not because of the original (legacy)
design of the Invoice model.
The fields below *override* the model to ensure data consistency.
"""
amount = forms.IntegerField(min_value=2)
name = forms.CharField(label="Full name")
email = forms.EmailField(label="Email address")
email2 = forms.EmailField(label="Email address (repeat)")
campaign_code = forms.CharField(required=False, label="Campaign code (optional)")
is_public = forms.BooleanField(required=False, label="List name next to donation")

class Meta:
model = get_model('rsr', 'invoice')
fields = ('amount', 'name', 'email', 'email2',
'campaign_code', 'is_public')

def over_donated(self):
donation = self.cleaned_data.get('amount', 0)
if self.engine == Invoice.PAYMENT_ENGINE_PAYPAL:
if self.project.amount_needed_to_fully_fund_via_paypal() < donation:
return True
else:
if self.project.amount_needed_to_fully_fund_via_ideal() < donation:
return True
return False

def clean(self):
if self.over_donated():
raise forms.ValidationError(_('You cannot donate more than the project actually needs!'))
cd = self.cleaned_data
if 'email' in cd and 'email2' in cd:
if cd['email'] != cd['email2']:
raise forms.ValidationError(_('You must type the same email address each time!'))
return cd
Binary file modified akvo/rsr/static/rsr/main/img/donate/ideal-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2c49c52

Please sign in to comment.