コード例 #1
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()
コード例 #2
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')
        )