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


Python General.is_now方法代码示例

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


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

示例1: get_exam_struct

# 需要导入模块: import General [as 别名]
# 或者: from General import is_now [as 别名]
def get_exam_struct(exam_id, user_id=None, include_qtemplates=False,
                    include_stats=False):
    """ Return a dictionary of useful data about the given exam for the user.
        Including stats is a performance hit so don't unless you need them.
    """
    assert isinstance(exam_id, int)
    assert isinstance(user_id, int) \
        or user_id is None
    assert isinstance(include_qtemplates, bool)
    assert isinstance(include_stats, bool)
    key = "exam-%s-struct" % exam_id
    obj = MC.get(key)
    if obj:
        exam = _deserialize_examstruct(obj)
    else:
        sql = """SELECT "title", "owner", "type", "start", "end",
                        "description", "comments", "course", "archived",
                        "duration", "markstatus", "instant", "code"
                 FROM "exams" WHERE "exam" = %s LIMIT 1;"""
        params = (exam_id, )
        ret = run_sql(sql, params)
        if not ret:
            raise KeyError("Exam %s not found." % exam_id)
        row = ret[0]
        exam = {'id': exam_id,
                'title': row[0],
                'owner': row[1],
                'type': row[2],
                'start': row[3],
                'end': row[4],
                'instructions': row[5],
                'comments': row[6],
                'cid': row[7],
                'archived': row[8],
                'duration': row[9],
                'markstatus': row[10],
                'instant': row[11],
                'code': row[12]
        }

        MC.set(key, _serialize_examstruct(exam),
               60)  # 60 second cache. to take the edge off exam start peak load
    course = Courses2.get_course(exam['cid'])
    exam['future'] = General.is_future(exam['start'])
    exam['past'] = General.is_past(exam['end'])
    exam['soon'] = General.is_soon(exam['start'])
    exam['recent'] = General.is_recent(exam['end'])
    exam['active'] = General.is_now(exam['start'], exam['end'])
    exam['start_epoch'] = int(exam['start'].strftime("%s"))  # used to sort
    exam['period'] = General.human_dates(exam['start'], exam['end'])
    exam['course'] = course
    exam['start_human'] = exam['start'].strftime("%a %d %b")

    if include_qtemplates:
        exam['qtemplates'] = get_qts(exam_id)
        exam['num_questions'] = len(exam['qtemplates'])
    if include_stats:
        exam['coursedone'] = get_num_done(exam_id, exam['cid'])
        exam['notcoursedone'] = get_num_done(exam_id), exam['coursedone']
    if user_id:
        exam['is_done'] = is_done_by(user_id, exam_id)
        exam['can_preview'] = check_perm(user_id, exam['cid'], "exampreview")

    return exam
开发者ID:jamesdoherty,项目名称:oasisqe,代码行数:66,代码来源:Exams.py


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