0

我目前正在开发一个允许用户进行自我评估的项目。目前,我将评估标准存储在 MySQL 表中,并遍历该表以生成 FORM 对象,将下拉列表附加到每一行。尽管这很容易创建表单,但当我将插入命令放入表单接受条件块时,我在第一个使用下划线的字段分配中遇到语法错误。这是表格的代码:

db.define_table('Evaluation', Field('EvaluationId', 'integer', 'id'), 
Field('PersonBeingEvaluated', db.Person, 'integer'), 
Field('PersonEvaluating', 'integer'), 
Field('EvalDate', 'datetime'), 
Field('1_1A', 'integer'), Field('1_1B', 'integer'), Field('1_2', 'integer'),
Field('1_3', 'integer'), Field('1_4', 'integer'), Field('1_5', 'integer'), 
Field('1_6', 'integer'), Field('2_1', 'integer'), Field('2_2A', 'integer'),
Field('2_2B', 'integer'), Field('2_3A', 'integer'), Field('2_3B', 'integer'), 
Field('2_4', 'integer'), Field('2_5', 'integer'), Field('3_1', 'integer'), 
Field('3_2', 'integer'), Field('3_3', 'integer'), Field('3_4', 'integer'), 
Field('3_5A', 'integer'), Field('3_5B', 'integer'), Field('3_6', 'integer'), 
Field('3_7', 'integer'), Field('3_8', 'integer'), Field('3_9A', 'integer'), 
Field('3_9B', 'integer'), Field('3_9C', 'integer'), Field('4_1', 'integer'), 
Field('4_2', 'integer'), Field('4_3A', 'integer'), Field('4_3B', 'integer'), 
Field('4_4', 'integer'), Field('BeliefsScore', 'integer'), 
Field('CharacterScore', 'integer'), primarykey=['EvaluationId'])

我的方法的代码:

@auth.requires_login()
def Take_Eval(): 
    user = db(db.Person.auth_userUserId == auth.user.id).select().first().PersonId
    table = db(db.PageContent.ContentId > 0).select()

    accordion = DIV(_id="accordion")
    for row in table:
        accordion.append(H2(row['ContentDescription'], _style="padding-left: 10px;"))
        accordion.append(DIV(XML(row.ContentHTML), BR(), P(SELECT(OPTGROUP(OPTION('Does not Attempt', _value=0), 
        OPTION('Developing', _value=1), OPTION('Progressing', _value=2), OPTION('Established', _value=3), 
        OPTION('Advanced', _value=4), OPTION('Master', _value=5)), _id=row['QuestionNumber']), _style='text-align: center;')))


    form = FORM(accordion, BR(), P(INPUT(_type='submit', _value='Submit', _name='btnSubmit'), _style="text-align: center;"))

    if form.accepts(request, session):
        response.flash = 'Evaluation Saved Successfully on  ' + str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        db.Evaluation.insert(PersonBeingEvaluated=user, PersonEvaluating=0, EvalDate=datetime.now(), 
        1_1A = form.vars.1_1A, 1_1B = form.vars.1_1B, 1_2 = form.vars.1_2, 1_3 = form.vars.1_3, 
        1_4 = form.vars.1_4, 1_5 = form.vars.1_5, 1_6 = form.vars.1_6, 2_1 = form.vars.2_1, 
        2_2A = form.vars.2_2A, 2_2B = form.vars.2_2B, 2_3A = form.vars.2_3A, 2_3B = form.vars.2_3B, 
        2_4 = form.vars.2_4, 2_5 = form.vars.2_5, 3_1 = form.vars.3_1, 3_2 = form.vars.3_2, 
        3_3 = form.vars.3_3, 3_4 = form.vars.3_4, 3_5A = form.vars.3_5A, 3_5B = form.vars.3_5B, 
        3_6 = form.vars.3_6, 3_7 = form.vars.3_7, 3_8 = form.vars.3_8, 3_9A = form.vars.3_9A, 
        3_9B = form.vars.3_9B, 3_9C = form.vars.3_9C, 4_1 = form.vars.4_1, 4_2 = form.vars.4_2, 
        4_3A = form.vars.4_3A, 4_3B = form.vars.4_3B, 4_4 = form.vars.4_4, 
        BeliefsScore = form.vars.BeliefsScore, CharacterScore = form.vars.CharacterScore)

        redirect(URL('default', 'index'))
    elif form.errors:
            response.flash = 'Profile could not be submitted.  Please try again later. '   

    return locals()

为了解决这个问题,我重构了表单,认为我的命名约定对于下拉列表可能是错误的。但是,我不相信情况会如此。我也尝试过使用类似的东西:

1_1A = form.vars.1_1A.value

认为也许我正在分配下拉列表而不是其数值,但这也没有改变错误代码。这个问题的最佳解决方案是让代码正确编译,并让每个下拉列表在插入时向数据库提交一个整数。

谁能告诉我为什么我的插入方法的语法出错了?谢谢。

编辑

这是 HTML 页面:

{{extend 'layout.html'}}
<script>
    $(function() {
        $("#accordion").accordion({ 
            header: "h2",
            autoHeight: false
         });

    });  
</script>


<h1>Evaluation Info</h1>
<br />
<div id="contentPane">
    {{=form}}
</div>


<br />

实际页面本身有几千行;但是,我还抓住了一个选择标签的标记:

<p style="text-align: center;"><select id="Q1_1A"><optgroup>
    <option value="0">Does not Attempt</option>
    <option value="1">Developing</option>
    <option value="2">Progressing</option>
    <option value="3">Established</option>
    <option value="4">Advanced</option>
    <option value="5">Master</option>
</optgroup></select></p>

需要帮助请叫我。

4

0 回答 0