Esempio n. 1
0
    def test_make_shirt_confirmation_email_en(self):
        from speedfunding.utils import make_shirt_confirmation_emailbody
        _item = Speedfundings.get_by_id(1)

        result = make_shirt_confirmation_emailbody(_item)
        self.assertTrue('shirt' in result)
        self.assertTrue('You have chosen a t-shirt' in result)
Esempio n. 2
0
 def test_make_shirt_confirmation_email_de(self):
     from speedfunding.utils import make_shirt_confirmation_emailbody
     _item = Speedfundings.get_by_id(2)
     result = make_shirt_confirmation_emailbody(_item)
     self.assertTrue(u'Du hast ein T-Shirt gewählt' in result)
Esempio n. 3
0
def shirt_view(request):
    """
    this view is the default view: the speedfunding form
    """
    DEBUG = True

    if 'paypal' in request.params:
        #print("paypal option")
        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/shirt.pt)
    else:
        paypal = False

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

    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)

    # set default of Country select widget according to locale
    LOCALE_COUNTRY_MAPPING = {
        'de': 'DE',
        #'da': 'DK',
        'en': 'GB',
        #'es': 'ES',
        #'fr': 'FR',
    }
    country_default = LOCALE_COUNTRY_MAPPING.get(locale_name)
    if DEBUG:  # pragma: no cover
        print("== locale is :" + str(locale_name))
        print("== choosing :" + str(country_default))

    # declare a form
    class TShirt(colander.MappingSchema):
        """
        what size and fit for the shirt?
        """
        shirt_option = colander.SchemaNode(
            colander.String(),
            title=_(u"I want to support the C3S by wearing my own t-shirt! "
                    "Here's my choice:"),
            #widget=deform.widget.RadioChoiceWidget(
            #            widget=deform.widget.SelectSliderWidget(
            widget=deform.widget.Select2Widget(
                values=(
                    (u'S', _(u'S €35,00 EUR')),
                    (u'M', _(u'M €35,00 EUR')),
                    (u'L', _(u'L €35,00 EUR')),
                    (u'XL', _(u'XL €35,00 EUR')),
                    (u'XXL', _(u'XXL €35,00 EUR')),
                    (u'S (Ladyfit)', _(u'S (Ladyfit) €35,00 EUR')),
                    (u'M (Ladyfit)', _(u'M (Ladyfit) €35,00 EUR')),
                    (u'L (Ladyfit)', _(u'L (Ladyfit) €35,00 EUR')),
                    (u'XL (Ladyfit)', _(u'XL (Ladyfit) €35,00 EUR')),
                    (u'XXL (Ladyfit)', _(u'XXL (Ladyfit) €35,00 EUR')),
                )
            )
        )

    class PersonalData(colander.MappingSchema):
        """
        people who want a shirt need to give us some address information
        """
        firstname = colander.SchemaNode(
            colander.String(),
            widget=deform.widget.TextInputWidget(
                css_class='deformWidgetWithStyle'),
            title=_(u'First Name')
        )
        lastname = colander.SchemaNode(
            colander.String(),
            title=_(u"Last Name")
        )
        email = colander.SchemaNode(
            colander.String(),
            validator=colander.Email(),
            title=_(u"Email (just in case we need to check back with you)")
        )
        address1 = colander.SchemaNode(
            colander.String(),
            title=_(u'Address Line 1')
        )
        address2 = colander.SchemaNode(
            colander.String(),
            missing=unicode(''),
            title=_(u"Address Line 2")
        )
        postcode = colander.SchemaNode(
            colander.String(),
            title=_(u'Zip Code'),
            oid="postcode"
        )
        city = colander.SchemaNode(
            colander.String(),
            title=_(u'City'),
            oid="city",
        )
        country = colander.SchemaNode(
            colander.String(),
            title=_(u'Country'),
            default=country_default,
            widget=deform.widget.SelectWidget(
                values=country_codes),
            oid="country",
        )

    class TShirtForm(colander.Schema):
        """
        the shirt form comprises shirt option and personal data
        """
        shirt_data = TShirt(
            title=_(u'Choose a Shirt')
        )
        personalData = PersonalData(
            title=_('Personal Data')
        )

    schema = TShirtForm()

    form = deform.Form(
        schema,
        buttons=[
            deform.Button('order_shirt', _(u'Yes, I want this T-Shirt!')),
            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 = (('order_shirt' 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 validated!")
            # XXX TODO: persist
            _shirt = Speedfundings(
                firstname=appstruct['personalData']['firstname'],
                lastname=appstruct['personalData']['lastname'],
                email=appstruct['personalData']['email'],
                address1=appstruct['personalData']['address1'],
                address2=appstruct['personalData']['address2'],
                postcode=appstruct['personalData']['postcode'],
                city=appstruct['personalData']['city'],
                country=appstruct['personalData']['country'],
                locale=locale_name,
                donation='',
                shirt_size=appstruct['shirt_data']['shirt_option'],
                comment='',
            )
            # persist
            try:
                DBSession.add(_shirt)
                DBSession.flush()
            except:
                print("failed to persist")
            # mail out
            message = Message(
                subject=_("[fund C3S!] thank you for choosing a shirt!"),
                sender="*****@*****.**",
                recipients=[_shirt.email],
                body=make_shirt_confirmation_emailbody(_shirt)
            )
            mailer = get_mailer(request)
            mailer.send(message)
            print("message sent!")

        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
            #print("DEBUG: paypal in shirt_view is %s" % paypal)
            return{'form': e.render(),
                   'paypal': paypal}

        # if the form validated correctly, use the data given
        #print("the appstruct: %s" % appstruct)
        request.session.pop_flash()  # delete old error messages
        return HTTPFound(
            location=request.route_url('success'),  # XXX transport info there
        )