当前位置: 首页>>代码示例>>Python>>正文


Python lib.General类代码示例

本文整理汇总了Python中oasis.lib.General的典型用法代码示例。如果您正苦于以下问题:Python General类的具体用法?Python General怎么用?Python General使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了General类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_instance_generate_multif_answer

def test_instance_generate_multif_answer():
    """ Convert some html templates + variables into resulting instance HTML
        and make sure it's doing it right. Focus on multif choice "ANSWER"

        No side effects.
    """

    tmpl = "blah<ANSWER1 MULTIF f,g,h,i>blah"
    qvars = {'f': 7, 'g': "joe", "h": "3.4", "i": 33}
    html = """blah<table border=0><tr><td>Please choose one:</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='1' Oa_CHK_1_1>7</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='2' Oa_CHK_1_2>joe</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='3' Oa_CHK_1_3>3.4</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='4' Oa_CHK_1_4>33</td></tr></table><br />
blah"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html

    tmpl = "blah<ANSWER1 MULTIF f,g,h,i,j>blah"
    qvars = {'f': 7, 'g': "joe", "h": "3.4", "i": 33, "j": "&amp;"}
    html = """blah<table border=0><tr><td>Please choose one:</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='1' Oa_CHK_1_1>7</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='2' Oa_CHK_1_2>joe</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='3' Oa_CHK_1_3>3.4</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='4' Oa_CHK_1_4>33</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='5' Oa_CHK_1_5>&amp;</td></tr></table><br />
blah"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html

    tmpl = "blah<ANSWER1 MULTIF f,g,h,"
    qvars = {'f': 7, 'g': "joe", "h": "3.4", "i": 33, "j": "&amp;"}
    html = """blah<ANSWER1 MULTIF f,g,h,"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html

    tmpl = "blah<ANSWER1 MULTIF f,g,h,i,j>"
    qvars = {'f': 7, 'g': "joe"}
    html = """blah<table border=0><tr><td>Please choose one:</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='1' Oa_CHK_1_1>7</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='2' Oa_CHK_1_2>joe</td><FONT COLOR="red">ERROR IN QUESTION DATA</FONT><FONT COLOR="red">ERROR IN QUESTION DATA</FONT><FONT COLOR="red">ERROR IN QUESTION DATA</FONT></tr></table><br />\n"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html
开发者ID:tkanesh,项目名称:oasisqe,代码行数:32,代码来源:test_qengine.py

示例2: mark_q

def mark_q(user_id, topic_id, q_id, request):
    """Mark the question and return the results"""
    answers = {}
    for i in request.form.keys():
        part = re.search(r"^Q_(\d+)_ANS_(\d+)$", i)
        if part:
            newqid = int(part.groups()[0])
            part = int(part.groups()[1])
            if newqid == q_id:
                value = request.form[i]
                answers["G%d" % part] = value
                DB.save_guess(newqid, part, value)
            else:
                L.warn("received guess for wrong question? (%d,%d,%d,%s)" %
                       (user_id, topic_id, q_id, request.form))
    try:
        marks = General.mark_q(q_id, answers)
        DB.set_q_status(q_id, 3)    # 3 = marked
        DB.set_q_marktime(q_id)
    except OaMarkerError:
        L.warn("Marker Error - (%d, %d, %d, %s)" %
               (user_id, topic_id, q_id, request.form))
        marks = {}
    q_body = General.render_mark_results(q_id, marks)
    parts = [int(var[1:])
             for var in marks.keys()
             if re.search(r"^A([0-9]+)$", var) > 0]
    parts.sort()
    total = 0.0
    for part in parts:
        if 'M%d' % (part,) in marks:
            total += float(marks['M%d' % (part,)])
    DB.update_q_score(q_id, total)    # 3 = marked
    DB.set_q_status(q_id, 2)
    return q_body
开发者ID:colincoghill,项目名称:oasisqe,代码行数:35,代码来源:Practice.py

示例3: test_html_esc

def test_html_esc():
    """ Check that our HTML escaping works ok. ( & -> &amp;  etc)
    """

    assert "&amp;" == General.htmlesc("&")
    assert "&lt;" == General.htmlesc("<")
    assert "&gt;" == General.htmlesc(">")
开发者ID:tkanesh,项目名称:oasisqe,代码行数:7,代码来源:test_qengine.py

示例4: mark_exam

def mark_exam(user_id, exam_id):
    """ Submit the assessment and mark it.
        Returns True if it went well, or False if a problem.
    """
    numquestions = Exams.get_num_questions(exam_id)
    status = Exams.get_user_status(user_id, exam_id)
    L.info("Marking assessment %s for %s, status is %s" % (exam_id, user_id, status))
    examtotal = 0.0
    errors = 0
    for position in range(1, numquestions + 1):
        q_id = General.get_exam_q(exam_id, position, user_id)
        if not q_id:
            L.critical("Unable to retrieve exam question page %s, exam %s, for user %s" % (position, exam_id, user_id
                                                                                           )
                       )
            errors += 1
            continue
        answers = DB.get_q_guesses(q_id)
        # There's a small chance they got here without ever seeing a question,
        # make sure it exists.
        DB.add_exam_q(user_id, exam_id, q_id, position)

        # First, mark the question
        try:
            marks = General.mark_q(q_id, answers)
            DB.set_q_status(q_id, 3)    # 3 = marked
            DB.set_q_marktime(q_id)
        except OaMarkerError:
            L.warn("Marker Error in question %s, exam %s, student %s!" %
                   (q_id, exam_id, user_id))
            return False
        parts = [int(var[1:])
                 for var in marks.keys()
                 if re.search("^A([0-9]+)$", var) > 0]
        parts.sort()

        # Then calculate the mark
        total = 0.0
        for part in parts:
            try:
                mark = float(marks['M%d' % (part,)])
            except (KeyError, ValueError):
                mark = 0
            total += mark
            DB.update_q_score(q_id, total)
        examtotal += total
    if not errors:
        Exams.set_user_status(user_id, exam_id, 5)
        Exams.set_submit_time(user_id, exam_id)
        Exams.save_score(exam_id, user_id, examtotal)
        Exams.touchuserexam(exam_id, user_id)

    if errors:
        return False
    L.info("user %s scored %s total on exam %s" %
           (user_id, examtotal, exam_id))
    return True
开发者ID:colincoghill,项目名称:oasisqe,代码行数:57,代码来源:Assess.py

示例5: test_date_ops

def test_date_ops():
    """ Test our various date operations
    """

    a = datetime.date(2013, 12, 1)
    b = datetime.date(2013, 12, 2)
    c = datetime.date(2013, 11, 1)
    d = datetime.date(2012, 11, 1)

    assert General.is_between(a, c, b) is True
    assert General.is_between(a, b, c) is True
    assert General.is_between(a, c, d) is False
开发者ID:tkanesh,项目名称:oasisqe,代码行数:12,代码来源:test_qengine.py

示例6: cadmin_exam_viewmarked

def cadmin_exam_viewmarked(course_id, exam_id, student_uid):
    """  Show a student's marked assessment results """

    course = Courses2.get_course(course_id)
    try:
        exam = Exams.get_exam_struct(exam_id, course_id)
    except KeyError:
        exam = {}
        abort(404)
    results, examtotal = Assess.render_own_marked_exam(student_uid, exam_id)

    if examtotal is False:
        status = 0
    else:
        status = 1
    marktime = Exams.get_mark_time(exam_id, student_uid)
    firstview = Exams.get_student_start_time(exam_id, student_uid)
    submittime = Exams.get_submit_time(exam_id, student_uid)

    try:
        datemarked = General.human_date(marktime)
    except AttributeError:
        datemarked = None
    try:
        datefirstview = General.human_date(firstview)
    except AttributeError:
        datefirstview = None
    try:
        datesubmit = General.human_date(submittime)
    except AttributeError:
        datesubmit = None

    user = Users2.get_user(student_uid)

    if submittime and firstview:
        taken = submittime-firstview
        takenmins = (taken.seconds/60)
    else:
        takenmins = None

    return render_template(
        "cadmin_markedresult.html",
        course=course,
        exam=exam,
        results=results,
        examtotal=examtotal,
        datesubmit=datesubmit,
        datemarked=datemarked,
        datefirstview=datefirstview,
        taken=takenmins,
        user=user,
        status=status
    )
开发者ID:tkanesh,项目名称:oasisqe,代码行数:53,代码来源:views_cadmin.py

示例7: get_q_list

def get_q_list(topic_id):
    """
    Return a list of questions, sorted by position.
    """
    # TODO: Duplicated in General.get_q_list ?

    def cmp_question_position(a, b):
        """Order questions by the absolute value of their positions
           since we use -'ve to indicate hidden.
        """
        return cmp(abs(a['position']), abs(b['position']))

    questionlist = General.get_q_list(topic_id, None, False)
    if questionlist:
        # At the moment we use -'ve positions to indicate that a question is
        # hidden but when displaying them we want to maintain the sort order.
        for question in questionlist:
            # Usually questions with position 0 are broken or uninteresting
            # so put them at the bottom.
            if question['position'] == 0:
                question['position'] = -10000
        questionlist.sort(cmp_question_position)
    else:
        questionlist = []

    return questionlist
开发者ID:colincoghill,项目名称:oasisqe,代码行数:26,代码来源:API.py

示例8: get_next_prev

def get_next_prev(qt_id, topic_id):
    """ Find the "next" and "previous" qtemplates, by topic, position. """
    if not topic_id:
        return None, None
        # This is very inefficient, but with the way questions are stored,
        # I didn't see a better way. Could maybe be revisited some time?
    questionlist = General.get_q_list(topic_id, numdone=False)
    if questionlist:
        # Filter out the questions without a positive position
        questionlist = [question
                        for question in questionlist
                        if question['position'] > 0]
    else:
        questionlist = []
        # We need to step through the list finding the "next and previous" id's
    nextid = None
    foundprev = None
    previd = None
    foundcurrent = None
    for i in questionlist:
        if foundcurrent:
            nextid = int(i['qtid'])
            break
        if int(i['qtid']) == int(qt_id):
            foundprev = True
            foundcurrent = True
        if not foundprev:
            previd = int(i['qtid'])
        # previd and nextid should now contain the correct values
    # or None, if they are not valid (current_qtid is the first or
    # last question)
    return previd, nextid
开发者ID:tkanesh,项目名称:oasisqe,代码行数:32,代码来源:Practice.py

示例9: get_sorted_questions

def get_sorted_questions(course_id, topic_id, user_id=None):
    """ Return a list of questions, sorted by position
    """

    def cmp_question_position(a, b):
        """Order questions by the absolute value of their positions
           since we use -'ve to indicate hidden.
        """
        return cmp(abs(a['position']), abs(b['position']))

    questionlist = General.get_q_list(topic_id, user_id, numdone=False)
    if questionlist:
        # Filter out the questions without a positive position unless
        # the user has prevew permission.
        canpreview = check_perm(user_id, course_id, "questionpreview")
        if not canpreview:
            questionlist = [question for question in questionlist
                            if question['position'] > 0]
        else:
            # At the moment we use -'ve positions to indicate that a question
            # is hidden but when displaying them we want to maintain the sort
            # order.
            for question in questionlist:
                # Usually questions with position 0 are broken or
                # uninteresting so put them at the bottom.
                if question['position'] == 0:
                    question['position'] = -10000
            questionlist.sort(cmp_question_position)
    else:
        questionlist = []
    return questionlist
开发者ID:colincoghill,项目名称:oasisqe,代码行数:31,代码来源:Practice.py

示例10: test_do_question

    def test_do_question(self):
        """ Do a question"""

        course_id = Courses.create("TEST102", "Test question logic", 1, 1)
        self.assertGreater(course_id, 0)
        topic1_id = Topics.create(course_id, "TESTQUESTIONS1", 1, 2)
        self.assertGreater(topic1_id, 0)

        qt1_id = DB.create_qt(1, "TESTQ9", "Test question 9", 0, 5.0, 1, topic_id=topic1_id)
        self.assertIsNotNone(qt1_id)

        ver = DB.get_qt_version(qt1_id)
        self.assertGreater(ver, 0)

        data = "2\n|1\n|2\n"
        qvars = [{'A1': "2"}, {'A1': "3"}]
        for row in range(0, len(qvars)):
            DB.add_qt_variation(qt1_id, row + 1, qvars[row], ver)
        DB.create_qt_att(qt1_id, "datfile.dat", "text/plain", data , ver)
        DB.create_qt_att(qt1_id, "qtemplate.html", "text/html", "What is <VAL A1>? <ANSWER 1>", ver)

        q_id = DB.get_q_by_qt_student(qt1_id, 1)
        self.assertFalse(q_id)  # Not generated yet

        q_id = General.gen_q(qt1_id, 1)
        self.assertGreater(q_id, 0)

        q_id = DB.get_q_by_qt_student(qt1_id, 1)
        self.assertTrue(qt1_id)  # Better be there now

        DB.update_qt_maxscore(qt1_id, 7.0)
        score = DB.get_qt_maxscore(qt1_id)
        self.assertEqual(score, 7.0)
        DB.set_q_viewtime(q_id)
        self.assertIsNotNone(DB.get_q_viewtime(q_id))
开发者ID:colincoghill,项目名称:oasisqe,代码行数:35,代码来源:test_topics.py

示例11: mark_q

def mark_q(user_id, qtid, request):
    """Mark the question and show a page containing marking results."""

    if "OaQID" in request.form:
        qid = int(request.form["OaQID"])
    else:
        qid = None

    out = u""
    answers = {}
    for i in request.form.keys():
        part = re.search(r"^Q_(\d+)_ANS_(\d+)$", i)
        if part:
            newqid = int(part.groups()[0])
            part = int(part.groups()[1])

            value = request.form[i]
            answers["G%d" % part] = value
            DB.save_guess(newqid, part, value)

    if qid:
        try:
            marks = General.mark_q(qid, answers)
            DB.set_q_status(qid, 3)    # 3 = marked
            DB.set_q_marktime(qid)
        except OaMarkerError:
            log(INFO,
                "getMarkQuestionPage(%d, %d, %s) Marker ERROR" %
                (user_id, qtid, request.form))
            marks = {}

        out += General.render_mark_results(qid, marks)
        parts = [int(var[1:])
                 for var in marks.keys()
                 if re.search("^A([0-9]+)$", var) > 0]
        parts.sort()
        total = 0.0
        for part in parts:
            if marks.has_key('M%d' % (part,)):
                total += float(marks['M%d' % (part,)])

    return out
开发者ID:jamesdoherty,项目名称:oasisqe,代码行数:42,代码来源:Embed.py

示例12: test_instance_generate_multi_answer

def test_instance_generate_multi_answer():
    """ Convert some html templates + variables into resulting instance HTML
        and make sure it's doing it right. Focus on multi "ANSWER MULTI"

        No side effects.
    """

    tmpl = "blah<ANSWER1 MULTI f,g,h,i>blah"
    qvars = {'f': 7, 'g': "joe", "h": "3.4", "i": 33}
    html = """<table border=0><tr><th>Please choose one:</th><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='1' Oa_CHK_1_1> 7</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='2' Oa_CHK_1_2> joe</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='3' Oa_CHK_1_3> 3.4</td><td CLASS='multichoicecell'><INPUT class='auto_save' TYPE='radio' NAME='ANS_1' VALUE='4' Oa_CHK_1_4> 33</td></tr></table><br />\n"""
    res = General.handle_multi(tmpl, 1, qvars, shuffle=False)[1]
    assert res == html
开发者ID:tkanesh,项目名称:oasisqe,代码行数:12,代码来源:test_qengine.py

示例13: test_instance_generate_listbox_answer

def test_instance_generate_listbox_answer():
    """ Convert some html templates + variables into resulting instance HTML
        and make sure it's doing it right. Focus on listbox "ANSWER SELECT"

        No side effects.
    """

    tmpl = "blah<ANSWER1 SELECT f,g,h,i>blah"
    qvars = {'f': 7, 'g': "joe", "h": "3.4", "i": 33}
    html = """<SELECT class='auto_save' NAME='ANS_1'>Please choose:<OPTION VALUE='None'>--Choose--</OPTION><OPTION VALUE='1' Oa_SEL_1_1>7</OPTION><OPTION VALUE='2' Oa_SEL_1_2>joe</OPTION><OPTION VALUE='3' Oa_SEL_1_3>3.4</OPTION><OPTION VALUE='4' Oa_SEL_1_4>33</OPTION></SELECT>\n"""
    res = General.handle_listbox(tmpl, 1, qvars, shuffle=False)[1]
    assert res == html
开发者ID:tkanesh,项目名称:oasisqe,代码行数:12,代码来源:test_qengine.py

示例14: test_instance_generate_simple_answer

def test_instance_generate_simple_answer():
    """ Convert some html templates + variables into resulting instance HTML
        and make sure it's doing it right. Focus on simple "ANSWER"

        No side effects.
    """

    tmpl = "blah<ANSWER1>blah"
    qvars = {}
    html = """blah<INPUT class='auto_save' TYPE='text' NAME='ANS_1' VALUE="VAL_1"/>blah"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html

    tmpl = "blah<ANSWER2>blah"
    qvars = {}
    html = """blah<INPUT class='auto_save' TYPE='text' NAME='ANS_2' VALUE="VAL_2"/>blah"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html

    tmpl = "foo<ANSWER1>blah<ANSWER2>blah"
    qvars = {}
    html = """foo<INPUT class='auto_save' TYPE='text' NAME='ANS_1' VALUE="VAL_1"/>blah<INPUT class='auto_save' TYPE='text' NAME='ANS_2' VALUE="VAL_2"/>blah"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html
开发者ID:tkanesh,项目名称:oasisqe,代码行数:24,代码来源:test_qengine.py

示例15: test_instance_generate_variable

def test_instance_generate_variable():
    """ Convert some html templates + variables into resulting instance HTML
        and make sure it's doing it right. Focus on variable subs.

        No side effects.
    """

    tmpl = "The value is <VAL A>"
    qvars = {"A": 7, "a": 5, "Arthur": 3}
    html = """The value is 7"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html

    tmpl = "The value is <VAL A> <VAL Arthur>"
    qvars = {"A": 7, "a": 5, "Arthur": 3}
    html = """The value is 7 3"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html

    tmpl = "The value is <VAL A> <VAL Arthur>"
    qvars = {"A": "&amp;", "a": 5, "Arthur": 3}
    html = """The value is &amp; 3"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html

    tmpl = "The value is <VAL A> <VAL Arthur>"
    qvars = {"A": "<blink>annoying</blink>", "a": 5, "Arthur": 3}
    html = """The value is <blink>annoying</blink> 3"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html

    tmpl = "The value is <VAL A> <VAL Arthur>"
    qvars = {"A": u"\x9f", "a": 5, "Arthur": 3}
    html = u"""The value is \x9f 3"""
    res = General.gen_q_html(qvars, tmpl)
    assert res == html
开发者ID:tkanesh,项目名称:oasisqe,代码行数:36,代码来源:test_qengine.py


注:本文中的oasis.lib.General类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。