Ejemplo n.º 1
0
    def test_make_donation_confirmation_emailbody_en(self):
        from speedfunding.utils import make_donation_confirmation_emailbody
        _item = Speedfundings.get_by_id(1)

        result = make_donation_confirmation_emailbody(_item)
        self.assertTrue('your pledge' in result)
        self.assertTrue('appreciate your donation' in result)
Ejemplo n.º 2
0
 def test_make_donation_confirmation_emailbody_de(self):
     from speedfunding.utils import make_donation_confirmation_emailbody
     _item = Speedfundings.get_by_id(2)
     self.assertIsNotNone(_item)
     result = make_donation_confirmation_emailbody(_item)
     self.assertTrue('Deine Spende' in result)
Ejemplo n.º 3
0
def donate_view(request):
    """
    this view handles donations
    """
    DEBUG = False
    if hasattr(request, '_REDIRECT_'):
        _query = request._REDIRECT_
        request.response.set_cookie('_LOCALE_', _query)
        request._LOCALE_ = locale_name = _query
        return HTTPFound(location=request.route_url('speedfund'),
                         headers=request.response.headers)
    else:
        locale_name = get_locale_name(request)
    #if hasattr(request, '_paypal'):
    #    print("hasattr(request, '_paypal') !!!")
    #import pdb;pdb.set_trace()
    # set default of Country select widget according to locale
    LOCALE_COUNTRY_MAPPING = {
        'de': 'DE',
        #'da': 'DK',
        'en': 'GB',
        #'es': 'ES',
        #'fr': 'FR',
    }

    if 'paypal' in request.params:
        request.session.pop_flash('message_above_form')
        return {
            'form': '',  # if paypal was chosen, don't show the form
            'paypal': True}  # but the paypal button (see templates/donate.pt)
    else:
        paypal = False

    #print("DEBUG: paypal in donate_view is %s" % paypal)

    country_default = LOCALE_COUNTRY_MAPPING.get(locale_name)
    if DEBUG:  # pragma: no cover
        print("== locale is :" + str(locale_name))
        print("== choosing :" + str(country_default))

    donation_amount_choice = (
        ('10', u'5000,00 €'),
        ('9', u'2500,00 €'),
        ('8', u'1000,00 €'),
        ('7', u'500,00 €'),
        ('6', u'250,00 €'),
        ('5', u'100,00 €'),
        ('4', u'50,00 €'),
        ('3', u'25,00 €'),
        ('2', u'10,00 €'),
        ('1', u'5,00 €'),
    )

    # declare a data set
    class DonationOption(colander.MappingSchema):
        """
        a class for the donation choices in our speedfunding
        """
        the_amount = colander.SchemaNode(
            colander.String(),
            title=_(u'I want to support C3S with my donation:'),
            default='1',  # default: '1' ==> '5€'
            widget=deform.widget.SelectSliderWidget(
                #widget=deform.widget.SelectWidget(
                values=donation_amount_choice),
            oid="donation_choice",
        )

    class PersonalData(colander.MappingSchema):
        email = colander.SchemaNode(
            colander.String(),
            title=_(u'Email'),
            validator=colander.Email(),
            oid="email",
        )

    class DonationForm(colander.Schema):
        """
        a donation
        """
        donation = DonationOption(
            title=_('The Donation')
        )
        #if True:
        personalData = PersonalData(
            title=_(u'Please tell us your email address in case we need '
                    'to contact you:')
        )

    # now construct the form schema from the parts above
    schema = DonationForm()

    form = deform.Form(
        schema,
        buttons=[
            deform.Button('donate', _(u'Yes, I want to donate!')),
            deform.Button('go_back', _(u'Go back, let me start over again.')),
        ],
        renderer=zpt_renderer)

    # if the form has been used and SUBMITTED, check contents
    submitted = (('donate' in request.POST) or ('go_back' in request.POST))

    if not submitted:
        request.session.pop_flash('message_above_form')

    if submitted:
        if ('go_back' in request.POST):
            return HTTPFound(
                location=request.route_url('speedfund'),
            )
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
            #print("the form did validate!")
            #print("the appstruct: %s" % appstruct)
            # if the form validated correctly, use the data given
            _donation = Speedfundings(
                firstname='',
                lastname='',
                email=appstruct['personalData']['email'],
                address1='',
                address2='',
                postcode='',
                city='',
                country='',
                locale=locale_name,
                donation=appstruct['donation']['the_amount'],
                shirt_size='',
                comment='',
            )
            try:
                DBSession.add(_donation)
                DBSession.flush()
                #print("speedfunding entry was persisted.")
            except:
                print("failed to persist")
            #try:
            message = Message(
                subject=_("[fund C3S!] thanks for your donation!"),
                sender="*****@*****.**",
                recipients=[_donation.email, ],
                body=make_donation_confirmation_emailbody(_donation)
            )
            mailer = get_mailer(request)
            mailer.send(message)
            #except:
            #    print("failed to send the mail")

        except deform.ValidationFailure, e:
            print(e)
            request.session.flash(
                _(u"Please note: There were errors, "
                  "please check the form below."),
                'message_above_form',
                allow_duplicate=False)
            # if there were errors, present the form with error messages
            return{
                'form': e.render(),
                'paypal': paypal,
            }

        #print("the appstruct: %s" % appstruct)
        request.session.pop_flash()  # delete old error messages
        return HTTPFound(
            location=request.route_url('success'),
        )