示例#1
0
    def new_choice():
        'input choice question'

        if request.method == 'POST':
            db = dbwrap.session()

            multi = 0
            if len(request.POST.type.strip()) > 0:
                multi = 1

            choice_list = request.POST.itema.strip() \
                + '@' + request.POST.itemb.strip() \
                + '@' + request.POST.itemc.strip() \
                + '@' + request.POST.itemd.strip()
            q = model.ChoiceQuestion(
                    descr=request.POST.descr.strip(),
                    multi=multi, choice_list=choice_list,
                    note=request.POST.note.strip())
            db.add(q)
            db.commit()

            redirect(app.get_url('question', qid=q.id))

        #  any local variables can be used in the template
        return locals()
    def setUp(self):
        dbwrap.connect(connect='sqlite:///:memory:')
        dbwrap.Base.metadata.create_all()

        db = dbwrap.session()
        model.create_sample_data()
        self.db = db
示例#3
0
    def new_truefalse():
        'input true-false question'

        if request.method == 'POST':
            db = dbwrap.session()

        #  any local variables can be used in the template
        return locals()
示例#4
0
    def new_snapshot():
        'input snapshot question'

        if request.method == 'POST':
            db = dbwrap.session()

        #  any local variables can be used in the template
        return locals()
示例#5
0
    def user_list():
        'A simple page from a dabase.'

        db = dbwrap.session()

        users = db.query(model.User).order_by(model.User.name)

        #  any local variables can be used in the template
        return locals()
示例#6
0
    def question_list():
        'A simple page from a dabase.'

        db = dbwrap.session()

        questions = db.query(model.ChoiceQuestion).order_by(model.ChoiceQuestion.id)

        #  any local variables can be used in the template
        return locals()
    def user_list():
        'A simple page from a dabase.'

        db = dbwrap.session()

        users = db.query(model.User).order_by(model.User.name)

        #  any local variables can be used in the template
        return locals()
    def setUp(self):
        dbwrap.connect(connect='sqlite:///:memory:')
        dbwrap.Base.metadata.create_all()

        db = dbwrap.session()
        model.create_sample_data()
        self.db = db

        from webtest import TestApp
        from bottle import TEMPLATE_PATH
        TEMPLATE_PATH.insert(0, '../views')
        self.app = website.build_application()
        self.harness = TestApp(self.app)
示例#9
0
    def new_essay():
        'input essay question'

        if request.method == 'POST':
            db = dbwrap.session()

            descr = request.POST.descr.strip()
            q = model.EssayQuestion(
                    descr=descr,
                    note=request.POST.note.strip())
            db.add(q)
            db.commit()

        #  any local variables can be used in the template
        return locals()
    def new_user():
        'A sample of interacting with a form and a database.'

        form = NewUserFormProcessor(request.forms.decode())

        if request.method == 'POST' and form.validate():
            db = dbwrap.session()

            sean = model.User(
                    full_name=form.full_name.data, name=form.name.data,
                    email_address=form.email_address.data)
            db.add(sean)
            db.commit()

            redirect(app.get_url('user', username=form.name.data))

        #  any local variables can be used in the template
        return locals()
示例#11
0
    def new_user():
        'A sample of interacting with a form and a database.'

        form = NewUserFormProcessor(request.forms.decode())

        if request.method == 'POST' and form.validate():
            db = dbwrap.session()

            sean = model.User(full_name=form.full_name.data,
                              name=form.name.data,
                              email_address=form.email_address.data)
            db.add(sean)
            db.commit()

            redirect(app.get_url('user', username=form.name.data))

        #  any local variables can be used in the template
        return locals()
示例#12
0
def create_sample_data():
    from bottledbwrap import dbwrap

    dbwrap.connect()
    dbwrap.Base.metadata.create_all()
    db = dbwrap.session()

    sean = User(
            full_name='Sean Reifschneider', name='sean',
            email_address='*****@*****.**')
    db.add(sean)
    evi = User(
            full_name='Evi Nemeth', name='evi',
            email_address='*****@*****.**')
    db.add(evi)
    dmr = User(
            full_name='Dennis Ritchie', name='dmr',
            email_address='*****@*****.**')
    db.add(dmr)

    dmr = User(
            full_name='Peichao Wang', name='pwang',
            email_address='*****@*****.**')
    db.add(dmr)

    db.commit()


    q = TrueFalseQuestion(descr=u'幻想与一般的创造想象区别在于,幻想中所创造的形象总是体现着个人的愿望,并指向未来。',
        note=u'对')

    db.add(q)

    q = ChoiceQuestion(multi=1, descr=u'教育目的就其表述和内容而言具有( )特征。',
        choice_list=u'抽象性@理想性@可操作性@终极性', note=u'ABD')
    db.add(q)

    q = ChoiceQuestion(multi=1, descr=u'下列关于复式教学叙述正确的是( )。',
        choice_list=u'复式教学就是对两个以上年级的学生进行教学的一种教学组织形式@复式教学适用于学生多、教室少的情况下教学@复式教学课堂教师的教学和学生的自学或做作业同时进行@复式教学情景下的学生的基本技能和自学能力相对较弱',
        note=u'ABC')
    db.add(q)

    db.commit()
示例#13
0
def create_sample_data():
    from bottledbwrap import dbwrap

    dbwrap.connect()
    dbwrap.Base.metadata.create_all()
    db = dbwrap.session()

    sean = User(full_name='Sean Reifschneider',
                name='sean',
                email_address='*****@*****.**')
    db.add(sean)
    evi = User(full_name='Evi Nemeth',
               name='evi',
               email_address='*****@*****.**')
    db.add(evi)
    dmr = User(full_name='Dennis Ritchie',
               name='dmr',
               email_address='*****@*****.**')
    db.add(dmr)

    db.commit()
示例#14
0
def create_sample_data():
    from bottledbwrap import dbwrap

    dbwrap.connect()
    dbwrap.Base.metadata.create_all()
    db = dbwrap.session()

    sean = User(
            full_name='Sean Reifschneider', name='sean',
            email_address='*****@*****.**')
    db.add(sean)
    evi = User(
            full_name='Evi Nemeth', name='evi',
            email_address='*****@*****.**')
    db.add(evi)
    dmr = User(
            full_name='Dennis Ritchie', name='dmr',
            email_address='*****@*****.**')
    db.add(dmr)

    db.commit()
示例#15
0
def question_by_id(qid):
    from bottledbwrap import dbwrap
    db = dbwrap.session()
    q = db.query(ChoiceQuestion).filter_by(id=qid).first()
    return q
示例#16
0
def user_by_name(name):
    from bottledbwrap import dbwrap
    db = dbwrap.session()
    user = db.query(User).filter_by(name=name).first()
    return user
示例#17
0
def user_by_name(name):
    from bottledbwrap import dbwrap
    db = dbwrap.session()
    user = db.query(User).filter_by(name=name).first()
    return user