Exemplo n.º 1
0
def create_user_profile_and_supporter(sender, instance, created, **kw):
    if not created:
        return None
    profile = UserProfile(user=instance)
    profile.save()

    first_name = instance.first_name
    if not first_name:
        first_name = instance.username

    supporter = Supporter(first_name = first_name, last_name = instance.last_name, user_profile = profile, creator = instance)

    if instance.email:
        email = EmailAddress(email = instance.email, type = EmailAddressType.objects.all()[0])
        email.save()
        contact_profile = ContactProfile(primary_email = email)
        contact_profile.save()
        supporter.contact_profile = contact_profile

    supporter.save()
Exemplo n.º 2
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()
Exemplo n.º 3
0
    def save(self, request):
        supporter = Supporter(
            first_name=self.cleaned_data.get("first_name"),
            middle_name=self.cleaned_data.get("middle_name"),
            last_name=self.cleaned_data.get("last_name"),
            birthdate=self.cleaned_data.get("birthdate"),
            age=self.cleaned_data.get("age"),
            gender=self.cleaned_data.get("gender"),
            creator=request.user,
        )
        supporter.save()
        tags = self.cleaned_data.get("tags")
        if tags:
            tag_set = TagSet(
                creator=request.user,
                section=request.session["site"].active_section._path,
                action_type="add",
                action_context=supporter,
            )
            tag_set.save()
            for tag in tags:
                tagged_item = TaggedItem(tag_set=tag_set, tag=tag, supporter=supporter, active=True)
                tagged_item.save()

        address_type = self.cleaned_data.get("address_type")
        state = self.cleaned_data.get("state")

        contact_profile = None

        voter = self.cleaned_data.get("voter")
        if voter:
            if not contact_profile:
                contact_profile = ContactProfile()
                contact_profile.save()
            voter.contact_profile = contact_profile
            voter.save()

        if address_type and state:
            if not contact_profile:
                contact_profile = ContactProfile()
                contact_profile.save()
            try:
                contact_address = ContactAddress.objects.get(
                    "",
                    address_type=address_type,
                    address1=self.cleaned_data.get("address_line_1"),
                    address2=self.cleaned_data.get("address_line_2"),
                    address3=self.cleaned_data.get("address_line_3"),
                    city=self.cleaned_data.get("city"),
                    state=state,
                    zip=self.cleaned_data.get("zip"),
                )
            except:
                contact_address = ContactAddress(
                    address_type=address_type,
                    address1=self.cleaned_data.get("address_line_1"),
                    address2=self.cleaned_data.get("address_line_2"),
                    address3=self.cleaned_data.get("address_line_3"),
                    city=self.cleaned_data.get("city"),
                    state=state,
                    zip=self.cleaned_data.get("zip"),
                )
                contact_address.save()
            contact_profile.primary_address = contact_address

        organization = self.cleaned_data.get("organization")
        if organization:
            if not contact_profile:
                contact_profile = ContactProfile()
                contact_profile.save()
            contact_profile.organizations

        primary_phone = self.cleaned_data.get("primary_phone")
        primary_phone_type = self.cleaned_data.get("primary_phone_type")
        if primary_phone:
            if not contact_profile:
                contact_profile = ContactProfile()
                contact_profile.save()
            primary_phone_type = self.cleaned_data.get("primary_phone_type")
            try:
                primary_phone = PhoneNumber.objects.get(
                    number=primary_phone, type=self.cleaned_data.get("primary_phone_type")
                )
            except:
                primary_phone = PhoneNumber(number=primary_phone, type=self.cleaned_data.get("primary_phone_type"))
                primary_phone.save()
            if contact_profile.primary_phone != primary_phone:
                if contact_profile.primary_phone:
                    contact_profile.other_phones.add(contact_profile.primary_phone)
                contact_profile.primary_phone = primary_phone

        primary_email = self.cleaned_data.get("primary_email")
        primary_email_type = self.cleaned_data.get("primary_email_type")
        if primary_email:
            if not contact_profile:
                contact_profile = ContactProfile()
                contact_profile.save()
            primary_email_type = self.cleaned_data.get("primary_email_type")
            try:
                primary_email = EmailAddress.objects.get(
                    email=primary_email, type=self.cleaned_data.get("primary_email_type")
                )
            except:
                primary_email = EmailAddress(email=primary_email, type=self.cleaned_data.get("primary_email_type"))
                primary_email.save()
            if contact_profile.primary_email != primary_email:
                if contact_profile.primary_email:
                    contact_profile.other_emails.add(contact_profile.primary_email)
                contact_profile.primary_email = primary_email

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

        supporter.save()
        return supporter