コード例 #1
0
ファイル: test_utils.py プロジェクト: C3S/c3sPartyTicketing
 def tearDown(self):
     """
     clean up after a test case
     """
     DBSession.close()
     DBSession.remove()
     testing.tearDown()
     os.remove('test_utils.db')
コード例 #2
0
ファイル: test_utils.py プロジェクト: C3S/c3sPartyTicketing
    def setUp(self):
        """
        set up everything for a test case
        """
        self.config = testing.setUp()
        self.config.include('pyramid_mailer.testing')
        try:
            DBSession.close()
            DBSession.remove()
            #print("removing old DBSession ===================================")
        except:
            #print("no DBSession to remove ===================================")
            pass
        from sqlalchemy import create_engine
        engine = create_engine('sqlite:///test_utils.db')
        DBSession.configure(bind=engine)
        self.session = DBSession  # ()

        Base.metadata.create_all(engine)
        with transaction.manager:
            ticket1 = PartyTicket(  # german
                firstname=u'SomeFirstnäme',
                lastname=u'SomeLastnäme',
                email=u'*****@*****.**',
                locale=u"DE",
                email_is_confirmed=False,
                email_confirm_code=u'ABCDEFGBAR',
                password=u'arandompassword',
                date_of_submission=date.today(),
                num_tickets=5,
                ticket_type=2,
                the_total=75,
                user_comment=u"äh, was?"
            )
            DBSession.add(ticket1)
            DBSession.flush()
コード例 #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,
    }
コード例 #4
0
def staff_view(request):
    """
    This view lets admins edit staff/cashier personnel:
    who may act as cashier etc.?
    """
    _staffers = C3sStaff.get_all()

    class Cashier(colander.MappingSchema):
        login = colander.SchemaNode(
            colander.String(),
            title='login',
        )
        password = colander.SchemaNode(
            colander.String(),
            title='passwort',
        )

    schema = Cashier()

    cashierform = deform.Form(
        schema,
        buttons=[
            deform.Button('new_cashier', 'erstellen')
        ]
    )

    if 'action' in request.POST:
        print(request.POST['id'])
        #try:
        _cashier = C3sStaff.get_by_id(int(request.POST['id']))
        #except:
        #    print("exception!")
        #    return HTTPFound(location=request.route_url('staff'))
        #print(request.POST['action'])
        if request.POST['action'] == u'delete':
            print("will delete staff id %s" % _cashier.id)
            C3sStaff.delete_by_id(_cashier.id)
            print("deleted staff id %s" % _cashier.id)
            return HTTPFound(location=request.route_url('staff'))
        elif request.POST['action'] == 'edit':
            cashierform.set_appstruct(_cashier)

    if 'new_cashier' in request.POST:
        print "new cashier!?!"
        controls = request.POST.items()
        try:
            appstruct = cashierform.validate(controls)
            print('validated!')
        except ValidationFailure, e:
            return {
                'cashierform': e.render()
            }
        #try:
        # create an appstruct for persistence
        cashier = C3sStaff(
            login=appstruct['login'],
            password=appstruct['password'],
            email='',
        )
        cashier.groups = [Group.get_cashiers_group()]
        #print "about to add user"
        DBSession.add(cashier)
        DBSession.flush()
        print "added cashier"
            #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('staff')
        )