Пример #1
0
def party_view(request):
    """
    the view users use to order a ticket
    """
    _num_tickets = PartyTicket.get_num_tickets()
    _num_tickets_paid = PartyTicket.get_num_tickets_paid()

    class PersonalData(colander.MappingSchema):
        """
        colander schema for membership application form
        """
        locale_name = get_locale_name(request)
        firstname = colander.SchemaNode(
            colander.String(),
            title=_(u"Vorame"),
            oid="firstname",
        )
        lastname = colander.SchemaNode(
            colander.String(),
            title=_(u"Nachname"),
            oid="lastname",
        )
        email = colander.SchemaNode(
            colander.String(),
            title=_(u'Email'),
            validator=colander.Email(),
            oid="email",
        )
        # password = colander.SchemaNode(
        #     colander.String(),
        #     validator=colander.Length(min=3, max=100),
        #     widget=deform.widget.PasswordWidget(size=20),
        #     title=_(u"Password (to protect access to your data)"),
        #     description=_("We need a password to protect your data. After "
        #                   "verifying your email you will have to enter it."),
        #     oid="password",
        # )
        comment = colander.SchemaNode(
            colander.String(),
            title=_("Kommentare"),
            missing='',
            validator=colander.Length(max=250),
            widget=deform.widget.TextAreaWidget(rows=3, cols=50),
            description=_(u"Raum für Kommentare (255 Zeichen)"),
            oid="comment",
        )
        _LOCALE_ = colander.SchemaNode(
            colander.String(),
            widget=deform.widget.HiddenWidget(),
            default=locale_name
        )

    num_ticket_options = (
        ('10', _(u'10 tickets')),
        ('9', _(u'9 tickets')),
        ('8', _(u'8 tickets')),
        ('7', _(u'7 tickets')),
        ('6', _(u'6 tickets')),
        ('5', _(u'5 tickets')),
        ('4', _(u'4 tickets')),
        ('3', _(u'3 tickets')),
        ('2', _(u'2 tickets')),
        ('1', _(u'1 tickets')),
        #('0', _(u'no ticket')),
    )
    ticket_type_options = (
        (1, _(u'2. Klasse (5€: party, bands)')),
        (2, _(u'2. Klasse + Speisewagen (15€: party, bands, essen)')),
        (3, _(u'1. Klasse (50€: party, bands, essen, kaffee, shirt)')),
        (4, _(u'Grüne Mamba (100€: party, bands, essen, kaffee, jacke)')),
    )

    class PartyTickets(colander.MappingSchema):

        ticket_type = colander.SchemaNode(
            colander.Integer(),
            title=_(u"Ich reise in der folgenden Kategorie:"),
            description=_(
                u'Du kannst uns mit dem Kauf von Tickets unterstützen. '
                u'Überschüsse fliessen in die Büroausstattung.'),
            default="1",
            widget=deform.widget.RadioChoiceWidget(
                size=1, css_class='ticket_types_input',
                values=ticket_type_options,
                #inline=True
            ),
            oid="ticket_type"
        )
        num_tickets = colander.SchemaNode(
            colander.Integer(),
            title=_(u"Ich nehme die folgende Anzahl von Tickets"),
            description=_(
                u'Du kannst zwischen 1 und 10 Tickets bestellen. '
                u'Die Kosten variieren je nach Ticket-Kategorie.'),
            default="1",
            widget=deform.widget.SelectSliderWidget(
                #size=3, css_class='num_tickets_input',
                values=num_ticket_options),
            validator=colander.Range(
                min=1,
                max=10,
                min_err=_(u"Du brauchst mindestens ein Ticket, "
                          u"um die Reise anzutreten."),
                max_err=_(u"Höchstens 10 Tickets. (viel los!)"),
            ),
            oid="num_tickets")

    class TicketForm(colander.Schema):
        """
        The Form consists of
        - Personal Data
        - Ticketing Information
        - FoodInfo
        """
        person = PersonalData(
            title=_(u"Persönliche Daten"),
            #description=_(u"this is a test"),
            #css_class="thisisjustatest"
        )
        ticket_info = PartyTickets(
            title=_(u"Ticketinformationen")
        )
        #shares = FoodInfo(
        #    title=_(u"Food Stamps")
        #)

    schema = TicketForm()

    form = deform.Form(
        schema,
        buttons=[
            deform.Button('submit', _(u'Absenden')),
            deform.Button('reset', _(u'Zurücksetzen'))
        ],
        use_ajax=True,
        renderer=zpt_renderer
    )

    # if the form has NOT been used and submitted, remove error messages if any
    if not 'submit' in request.POST:
        request.session.pop_flash()

    # if the form has been used and SUBMITTED, check contents
    if 'submit' in request.POST:
        print "submitted!"
        controls = request.POST.items()
        print controls
        try:
            print 'about to validate form input'
            appstruct = form.validate(controls)
            print 'done validating form input'
            print("the appstruct from the form: %s \n") % appstruct
            for thing in appstruct:
                print("the thing: %s") % thing
                print("type: %s") % type(thing)

        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(),
                '_num_tickets': _num_tickets,
                '_num_tickets_paid': _num_tickets_paid,
            }

        # make confirmation code
        randomstring = make_random_string()

        # calculate the total sum
        the_value = {
            1: 5,
            2: 15,
            3: 50,
            4: 100,
        }
        _the_total = appstruct['ticket_info']['num_tickets'] * the_value.get(
            appstruct['ticket_info']['ticket_type'])
        appstruct['ticket_info']['the_total'] = _the_total
        print("_the_total: %s" % _the_total)
        # to store the data in the DB, an object is created
        ticket = PartyTicket(
            firstname=appstruct['person']['firstname'],
            lastname=appstruct['person']['lastname'],
            email=appstruct['person']['email'],
            password='',  # appstruct['person']['password'],
            locale=appstruct['person']['_LOCALE_'],
            email_is_confirmed=False,
            email_confirm_code=randomstring,
            date_of_submission=datetime.now(),
            num_tickets=appstruct['ticket_info']['num_tickets'],
            ticket_type=appstruct['ticket_info']['ticket_type'],
            the_total=_the_total,
            user_comment=appstruct['person']['comment'],
        )
        dbsession = DBSession
        try:
            print "about to add ticket"
            dbsession.add(ticket)
            print "adding ticket"
            appstruct['email_confirm_code'] = randomstring  # XXX
            appstruct['email_confirm_code'] = randomstring
        except InvalidRequestError, e:  # pragma: no cover
            print("InvalidRequestError! %s") % e
def make_hobo_view(request):
    """
    this view adds schwarzfahrers to the gästeliste
    """
    class PersonalData(colander.MappingSchema):
        """
        colander schema for membership application form
        """
        locale_name = 'de'
        firstname = colander.SchemaNode(
            colander.String(),
            title=_(u"Vorame"),
            oid="firstname",
        )
        lastname = colander.SchemaNode(
            colander.String(),
            title=_(u"Nachname"),
            oid="lastname",
        )
        email = colander.SchemaNode(
            colander.String(),
            title=_(u'Email'),
            validator=colander.Email(),
            oid="email",
        )
        comment = colander.SchemaNode(
            colander.String(),
            title=_("Warum Schwarzfahren?"),
            missing='',
            validator=colander.Length(max=250),
            widget=deform.widget.TextAreaWidget(rows=3, cols=50),
            description=_(u"(guter grund) (255 Zeichen)"),
            oid="comment",
        )
        _LOCALE_ = colander.SchemaNode(
            colander.String(),
            widget=deform.widget.HiddenWidget(),
            default=locale_name
        )

    class HoboForm(colander.Schema):
        """
        The Form consists of
        - Personal Data
        - Ticketing Information
        - FoodInfo
        """
        person = PersonalData(
            title=_(u"Persönliche Daten"),
            #description=_(u"this is a test"),
            #css_class="thisisjustatest"
        )

    schema = HoboForm()

    form = deform.Form(
        schema,
        buttons=[
            deform.Button('submit', _(u'Absenden')),
            deform.Button('reset', _(u'Zurücksetzen'))
        ],
        #use_ajax=True,
        renderer=zpt_renderer
    )

    if 'submit' in request.POST:
        print "new hobo!?!"
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
            print('validated!')
            the_total = 0  # nothing to pay
            # create an appstruct for persistence
            randomstring = make_random_string()
            hobo = PartyTicket(
                firstname=appstruct['person']['firstname'],
                lastname=appstruct['person']['lastname'],
                email=appstruct['person']['email'],
                password='',  # appstruct['person']['password'],
                locale=appstruct['person']['_LOCALE_'],
                email_is_confirmed=False,
                email_confirm_code=randomstring,
                date_of_submission=datetime.now(),
                num_tickets=1,
                ticket_type=5,
                the_total=the_total,
                user_comment=appstruct['person']['comment'],
            )
            hobo.payment_received = True
            dbsession = DBSession
            #try:
            print "about to add ticket"
            dbsession.add(hobo)
            dbsession.flush()
            print "added ticket"
            #except InvalidRequestError, e:  # pragma: no cover
            #    print("InvalidRequestError! %s") % e
            #except IntegrityError, ie:  # pragma: no cover
            #print("IntegrityError! %s") % ie
            return HTTPFound(
                request.route_url('detail',
                                  ticket_id=hobo.id)
            )

        except ValidationFailure, e:
            return {
                'hoboform': e.render()
            }
Пример #3
0
def new_ticket(request):
    """
    This view lets cachiers make/issue new tickets

    a form permits checkin of people, up to the amount of tickets
    """
    logged_in = authenticated_userid(request)
    print("authenticated_userid: " + str(logged_in))

    print("the request.POST: %s" % request.POST)
    add_cond = ('persons' in request.POST)
    if add_cond:
        _num = request.POST['persons']
        if 'type1' in request.POST:
            _type = request.POST['type1']
            _type_int = 1
            _type_cost = 5
        elif 'type2' in request.POST:
            _type = request.POST['type2']
            _type_int = 2
            _type_cost = 15
        elif 'type3' in request.POST:
            _type = request.POST['type3']
            _type_int = 3
            _type_cost = 50
        elif 'type4' in request.POST:
            _type = request.POST['type4']
            _type_int = 4
            _type_cost = 100
        log.info(
            "%s tickets(s) of cat. %s sold by %s" % (_num, _type, logged_in))
        _new = PartyTicket(
            firstname='anon',
            lastname='anon',
            email='anon',
            password='******',
            locale='de',
            email_is_confirmed=False,
            email_confirm_code='cash',
            num_tickets=int(_num),
            ticket_type=_type_int,
            the_total=int(_num)*_type_cost,
            user_comment='got ticket at entry',
            date_of_submission=datetime.now(),
            payment_received=True
        )
        #try:
        dbsession = DBSession()
        _new.payment_received = True
        #import pdb
        #pdb.set_trace()
        _new.checked_persons = int(_num)
        _new.payment_received_date = datetime.now()
        _new.email_confirm_code = 'CASHDESK' + make_random_string()
        _new.accountant_comment = 'issued by %s' % logged_in
        dbsession.add(_new)

        #except:
        #    print("new_ticket: something went wrong")
            #pass
    _num_passengers = PartyTicket.num_passengers()
    _num_open_tickets = int(
        PartyTicket.get_num_tickets()) - int(_num_passengers)

    return {
        'logged_in': logged_in,
        'num_passengers': _num_passengers,
        'num_open_tickets': _num_open_tickets,
    }