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() }
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, }