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


Python DB.get_qt_att_mimetype方法代码示例

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


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

示例1: get_q_att_fname

# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import get_qt_att_mimetype [as 别名]
def get_q_att_fname(qid, name):
    """ Return (mimetype, filename) with the relevant filename.
        If it's not found in question, look in questiontemplate.
    """
    qtid = DB.get_q_parent(qid)
    variation = DB.get_q_variation(qid)
    version = DB.get_q_version(qid)
    # for the two biggies we hit the question first,
    # otherwise check the question template first
    if name == "image.gif" or name == "qtemplate.html":

        fname = DB.get_q_att_fname(qtid, name, variation, version)
        if fname:
            return DB.get_q_att_mimetype(qtid, name, variation, version), fname
        fname = DB.get_qt_att_fname(qtid, name, version)
        if fname:
            return DB.get_qt_att_mimetype(qtid, name, version), fname
    else:
        fname = DB.get_qt_att_fname(qtid, name, version)
        if fname:
            return DB.get_qt_att_mimetype(qtid, name, version), fname
        fname = DB.get_q_att_fname(qtid, name, variation, version)
        if fname:
            return DB.get_q_att_mimetype(qtid, name, variation, version), fname
    return None, None
开发者ID:tkanesh,项目名称:oasisqe,代码行数:27,代码来源:General.py

示例2: q_att_details

# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import get_qt_att_mimetype [as 别名]
def q_att_details(qtid, version, variation, name):
    """ Find a question attachment and return its details. """
    # for the two biggies we hit the question first,
    # otherwise check the question template first
    if name == "image.gif" or name == "qtemplate.html":
        fname = DB.get_q_att_fname(qtid, name, variation, version)
        if fname:
            return DB.get_q_att_mimetype(qtid, name, variation, version), fname
        fname = DB.get_qt_att_fname(qtid, name, version)
        if fname:
            return DB.get_qt_att_mimetype(qtid, name, version), fname
    else:
        fname = DB.get_qt_att_fname(qtid, name, version)
        if fname:
            return DB.get_qt_att_mimetype(qtid, name, version), fname
        fname = DB.get_q_att_fname(qtid, name, variation, version)
        if fname:
            return DB.get_q_att_mimetype(qtid, name, variation, version), fname
    return None, None
开发者ID:jamesdoherty,项目名称:oasisqe,代码行数:21,代码来源:Attach.py

示例3: get_q_att

# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import get_qt_att_mimetype [as 别名]
def get_q_att(qid, name):
    """ Return (mimetype, data) with the relevant attachment.
        If it's not found in question, look in questiontemplate.
    """
    qtid = DB.get_q_parent(qid)
    variation = DB.get_q_variation(qid)
    version = DB.get_q_version(qid)
    # for the two biggies we hit the question first,
    # otherwise check the question template first
    if name == "image.gif" or name == "qtemplate.html":
        data = DB.get_q_att(qtid, name, variation, version)
        if data:
            return DB.get_q_att_mimetype(qtid, name, variation, version), data
        data = DB.get_qt_att(qtid, name, version)
        if data:
            return DB.get_qt_att_mimetype(qtid, name, version), data
    else:
        data = DB.get_qt_att(qtid, name, version)
        if data:
            return DB.get_qt_att_mimetype(qtid, name, version), data
        data = DB.get_q_att(qtid, name, variation, version)
        if data:
            return DB.get_q_att_mimetype(qtid, name, variation, version), data
    return None, None
开发者ID:tkanesh,项目名称:oasisqe,代码行数:26,代码来源:General.py

示例4: qts_to_zip

# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import get_qt_att_mimetype [as 别名]
def qts_to_zip(qt_ids, fname="oa_export", extra_info = None):
    """ Take a list of QTemplate IDs and return a binary string containing
        them as an .oaq file.
        (a zip file in special format)
    """

    fname = os.path.basename(fname)
    qdir = tempfile.mkdtemp(prefix="oa")
    info = {
        'oasis': {
            'oa_version': "3.9.4",
            'qt_version': '0.9',
            'url': OaConfig.parentURL
        },
        'qtemplates': {},
        'extra': extra_info
    }

    arc = zipfile.ZipFile(os.path.join(qdir, "oasisqe.zip"),
                          'w',
                          zipfile.ZIP_DEFLATED)
    for qt_id in qt_ids:
        qtemplate = DB.get_qtemplate(qt_id)
        qtdir = os.path.join(qdir, str(qt_id))
        attachments = DB.get_qt_atts(qt_id)
        if not 'qtemplate.html' in attachments:
            attachments.append('qtemplate.html')
        if not 'datfile.txt' in attachments:
            attachments.append('datfile.txt')
        if not 'image.gif' in attachments:
            attachments.append('image.gif')
        os.mkdir(qtdir)
        os.mkdir(os.path.join(qtdir, "attach"))
        info["qtemplates"][qt_id] = {'qtemplate': qtemplate}
        info["qtemplates"][qt_id]["attachments"] = []

        for name in attachments:
            if not name:
                name='UNKNOWN'
            mtype = DB.get_qt_att_mimetype(qt_id, name)
            if not mtype:
                mtype = ""
            data = DB.get_qt_att(qt_id, name)
            if not data:
                data = ""
            info["qtemplates"][qt_id]["attachments"].append([name, mtype, len(data)])
            subdir = os.path.join(qtdir, "attach", name)
            outf = open(subdir, "wb")
            outf.write(data)
            outf.close()
            arc.write(subdir,
                      os.path.join("%s" % qt_id, "attach", name),
                      zipfile.ZIP_DEFLATED)

    infof = open(os.path.join(qdir, "info.json"), "wb")
    infof.write(json.dumps(info))
    infof.close()
    arc.write(os.path.join(qdir, "info.json"),
              os.path.join("info.json"),
              zipfile.ZIP_DEFLATED)
    arc.close()

    readback = open(os.path.join(qdir, "oasisqe.zip"), "rb")
    data = readback.read()
    readback.close()
    shutil.rmtree(qdir)
    return data
开发者ID:tkanesh,项目名称:oasisqe,代码行数:69,代码来源:External.py


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