Example #1
0
def speedfunding_view(request):
    """
    this view is the default view or landing page: the main speedfunding form

    simple: one option, three buttons

    option: paypal or not

    buttons: [Donate]  [T-Shirt]  [Share(s)]
    """
    DEBUG = False
    # if another language was chosen by clicking on a flag
    # the add_locale_to_cookie subscriber has planted an attr on the request

    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))

    _the_total = TheTotal.get_total()
    try:
        _missing_sum = 70000 - int(_the_total.amount_actual)
    except TypeError, t:
        print("the error: %s" % t)
        #import pdb; pdb.set_trace()
        _missing_sum = "70000"
Example #2
0
def new_total(request):
    """
    This view lets accountants set the amount collected
    to be displayed on the front page
    """
    def sort_totals_reversed(objects):
        """
        show the objects in reverse order (highest id first)
        """
        return sorted(objects, key=lambda obj: obj.id, reverse=True)

    try:
        last_total = TheTotal.get_total()
        last_sum = last_total.amount_actual
        last_promised = last_total.amount_promised
        last_shirts = last_total.num_shirts
    except:
        last_sum = 0
        last_promised = 0
        last_shirts = 0

    class NewTotal(colander.MappingSchema):
        """
        colander schema for setting the collected sum
        """
        amount_collected = colander.SchemaNode(
            colander.Int(),
            title=_(
                u"Sum collected (Euro, Integer) "
                "(This amount will be deducted from 70000 and "
                "the result be displayed on the landing page)"),
            validator=colander.Range(0, 200000),
            default=last_sum,
            oid="sum",
        )
        amount_promised = colander.SchemaNode(
            colander.Int(),
            title=_(u"Sum promised (Euro, Integer)"),
            default=last_promised,
            oid="promised",
        )
        num_shirts = colander.SchemaNode(
            colander.Int(),
            title=_(u"Number of shirts (Integer)"),
            default=last_shirts,
            oid="shirts",
        )

    schema = NewTotal()

    form = deform.Form(
        schema,
        buttons=[
            deform.Button('submit', _(u'Submit')),
            deform.Button('reset', _(u'Reset'))
        ],
        #use_ajax=True,
        #renderer=zpt_renderer
    )

    # get and show the former totals
    _totals = TheTotal.get_listing(
        TheTotal.id.desc())

    # if the form has been used and SUBMITTED, check contents
    if 'submit' in request.POST:
        print("the form was submitted")
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
            print("the appstruct: %s" % appstruct)

            # time to save the data to the DB
            #{
            #    'num_shirts': 123,
            #    'amount_collected': 12345,
            #    'amount_promised': 23456
            #}

            _new_total = TheTotal(
                amount_actual=appstruct['amount_collected'],
                amount_promised=appstruct['amount_promised'],
                num_shirts=appstruct['num_shirts'],
            )
            try:
                DBSession.add(_new_total)
                DBSession.flush()
                _totals = TheTotal.get_listing(
                    TheTotal.id.desc())

            except:
                print("could not write to DB. Error: ")

        except ValidationFailure, e:
            print(e)

            request.session.flash(
                _(u"Please note: There were errors, "
                  "please check the form below."),
                'message_above_form',
                allow_duplicate=False)
            return{'form': e.render(),
                   'totals': {}}
def new_total(request):
    """
    This view lets accountants set the amount collected
    to be displayed on the front page
    """

    class NewTotal(colander.MappingSchema):
        """
        colander schema for setting the collected sum
        """
        amount_collected = colander.SchemaNode(
            colander.Int(),
            title=_(u"sum collected"),
            validator=colander.Range(0, 200000),
            oid="sum",
        )
        amount_promised = colander.SchemaNode(
            colander.Int(),
            title=_(u"promised"),
            oid="promised",
        )
        num_shirts = colander.SchemaNode(
            colander.Int(),
            title=_(u"shirts"),
            oid="shirts",
        )

    schema = NewTotal()

    form = deform.Form(
        schema,
        buttons=[
            deform.Button('submit', _(u'Submit')),
            deform.Button('reset', _(u'Reset'))
        ],
        #use_ajax=True,
        #renderer=zpt_renderer
    )

    # get and show the former totals
    _totals = TheTotal.get_listing(
        TheTotal.id.asc())

    # if the form has been used and SUBMITTED, check contents
    if 'submit' in request.POST:
        print("the form was submitted")
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
            print("the appstruct: %s" % appstruct)

            # time to save the data to the DB
            #{
            #    'num_shirts': 123,
            #    'amount_collected': 12345,
            #    'amount_promised': 23456
            #}

            _new_total = TheTotal(
                amount_actual=appstruct['amount_collected'],
                amount_promised=appstruct['amount_promised'],
                num_shirts=appstruct['num_shirts'],
            )
            try:
                DBSession.add(_new_total)
                DBSession.flush()
            except:
                print("could not write to DB. Error: ")

        except ValidationFailure, e:
            print(e)

            request.session.flash(
                _(u"Please note: There were errors, "
                  "please check the form below."),
                'message_above_form',
                allow_duplicate=False)
            return{'form': e.render(),
                   'totals': {}}