Exemple #1
0
    def process_add_donation(self, request):
        if request.method == "POST":
            form = AddDonationForm(request.POST)
            if form.is_valid():
                donation = Donation(
                    supporter=self.detail.obj,
                    creator=request.user,
                    amount=form.cleaned_data["amount"],
                    status=form.cleaned_data["status"],
                    campaign=form.cleaned_data["campaign"],
                    date_transaction=datetime.now(),
                )
                donation.save()

                response = {}
                response["success"] = True
                response["location"] = self.detail.subsection.get_full_path()

                encoder = simplejson.JSONEncoder()
                json = encoder.encode(response)
                return HttpResponse(json)
        else:
            form = AddDonationForm()

        t = get_template("core/render_uni_form.html")
        context = {}
        context["section"] = self
        context["form"] = form
        form_html = t.render(Context(context))

        response = {}
        response["success"] = False
        response["form_html"] = form_html

        encoder = simplejson.JSONEncoder()
        json = encoder.encode(response)
        return HttpResponse(json)
Exemple #2
0
    def process_add_donation(self, request):
        if request.method == 'POST':
            form = AddDonationForm(request.POST)
            if form.is_valid():
                donation = Donation(
                    organization = self.detail.obj,
                    creator = request.user,
                    amount = form.cleaned_data['amount'],
                    status = form.cleaned_data['status'],
                    campaign = form.cleaned_data['campaign'],
                    date_transaction = datetime.now(),
                )
                donation.save()

                response = {}
                response['success'] = True
                response['location'] = self.detail.subsection.get_full_path()

                encoder = simplejson.JSONEncoder()
                json = encoder.encode(response)
                return HttpResponse(json)
        else:
            form = AddDonationForm()

        t = get_template('core/render_uni_form.html')
        context = {}
        context['section'] = self
        context['form'] = form
        form_html = t.render(Context(context))

        response = {}
        response['success'] = False
        response['form_html'] = form_html

        encoder = simplejson.JSONEncoder()
        json = encoder.encode(response)
        return HttpResponse(json)
Exemple #3
0
def process_paypal_donation(sender, **kwargs):
    ipn_obj = sender
            
    if ipn_obj.payment_status == u'Completed':
        try:
            custom = simplejson.loads(ipn_obj.custom)
        except:
            custom = {}
       
        creator = None 
        if custom.has_key('creator'):
            try:
                supporter = Supporter.objects.get(id = custom['creator'])
                if supporter.user_profile:
                    creator = supporter.user_profile.user
            except Supporter.DoesNotExist:
                pass
        if not creator:
            creator = get_default_creator()
            
        # Lookup Supporter
        try:
            supporter = Supporter.objects.get(
                first_name = ipn_obj.first_name,
                last_name = ipn_obj.last_name,
                contact_profile__primary_address__address1 = ipn_obj.address_street,
                contact_profile__primary_address__zip = ipn_obj.address_zip,
            )
            contact_profile = supporter.contact_profile
            
        except Supporter.DoesNotExist:
            supporter = Supporter(
                first_name = ipn_obj.first_name,
                last_name = ipn_obj.last_name,
                creator = creator,
            )
            supporter.save()
            contact_profile = None

        if not contact_profile:
            contact_profile = ContactProfile()
            contact_profile.save()
            supporter.contact_profile = contact_profile
            supporter.save()

        if not contact_profile.primary_address or contact_profile.primary_address.address1 != ipn_obj.address_street or contact_profile.primary_address.zip != ipn_obj.address_zip:
            address_info = {
                'address1': ipn_obj.address_street,
                'city': ipn_obj.address_city,
                'state': ipn_obj.address_state,
                'zip': ipn_obj.address_zip,
            }
            address = get_or_create_address(address_info)
            if contact_profile.primary_address:
                contact_profile.other_addresses.add(contact_profile.primary_address)
            contact_profile.primary_address = address

        if not contact_profile.primary_email or contact_profile.primary_email.email != ipn_obj.payer_email:
            try:
                email = EmailAddress.objects.get(email = ipn_obj.payer_email)
            except EmailAddress.DoesNotExist:
                email = EmailAddress(
                    email = ipn_obj.payer_email,
                    type = get_default_email_type(),
                )
                email.save()
            if contact_profile.primary_email:
                contact_profile.other_emails.add(contact_profile.primary_email)
            contact_profile.primary_email = email
            
        contact_profile.save()

        campaign = None
        if custom.has_key('campaign'):
            try:
                campaign = Campaign.objects.get(id = custom['campaign'])
            except Campaign.DoesNotExist:
                pass

        donation = Donation(
            supporter = supporter,
            creator = creator,
            campaign = campaign,
            date_transaction = ipn_obj.payment_date,
            status = 'received',
            amount = ipn_obj.mc_gross,            
        )
        donation.save()