Example #1
0
def tbimport():
    t = db.study
    key = "uploaded_nexml_%s" % auth.user.id
    contributor = "%s %s" % (auth.user.first_name, auth.user.last_name)
    status = None
    tbid = request.args(0)
    if tbid:
        try:
            e = treebase.fetch_study(tbid)
            nexml = treebase.parse_nexml(e)
        except:
            nexml = {}
            status = "Valid study id required"
        if nexml:
            nexml.meta['contributor'] = contributor
            cache.ram.clear(key)
            x = cache.ram(key, lambda: nexml, time_expire=10000)
            redirect(URL('study', 'tbimport2', args=tbid))
    uploadfolder = request.folder + 'uploads'
    fields = [
        Field("study_id", "string", default=tbid),
        Field("nexml_file", "upload", uploadfolder=uploadfolder)
    ]
    form = SQLFORM.factory(*fields)
    if form.accepts(request.vars, session, dbio=False):
        if form.vars.study_id:
            try:
                e = treebase.fetch_study(form.vars.study_id)
                nexml = treebase.parse_nexml(e)
            except:
                nexml = {}
                status = "Valid study id required"
        elif form.vars.nexml_file:
            ## print form.vars.nexml_file
            path = os.path.join(uploadfolder, form.vars.nexml_file)
            ## form.vars.nexml_file_newfilename)
            nexml = treebase.parse_nexml(path)
            os.remove(path)
        else:
            nexml = {}
            request.flash = "Valid study id or nexml file required"
        if nexml:
            nexml.meta['contributor'] = contributor
            cache.ram.clear(key)
            x = cache.ram(key, lambda: nexml, time_expire=10000)
            redirect(URL('study', 'tbimport2', args=tbid))

    return dict(form=form, status=status)
Example #2
0
def tbimport():
    t = db.study
    key = "uploaded_nexml_%s" % auth.user.id
    contributor = "%s %s" % (auth.user.first_name, auth.user.last_name)
    status = None
    tbid = request.args(0)
    if tbid:
        try:
            e = treebase.fetch_study(tbid)
            nexml = treebase.parse_nexml(e)
        except:
            nexml = { }
            status = "Valid study id required"
        if nexml:
            nexml.meta['contributor'] = contributor
            cache.ram.clear(key)
            x = cache.ram(key, lambda:nexml, time_expire=10000)
            redirect(URL('study','tbimport2',args=tbid))
    uploadfolder = request.folder+'uploads'
    fields = [Field("study_id", "string", default=tbid),
              Field("nexml_file", "upload", uploadfolder=uploadfolder)]
    form = SQLFORM.factory(*fields)
    if form.accepts(request.vars, session, dbio=False):
        if form.vars.study_id:
            try:
                e = treebase.fetch_study(form.vars.study_id)
                nexml = treebase.parse_nexml(e)
            except:
                nexml = { }
                status = "Valid study id required"
        elif form.vars.nexml_file:
            ## print form.vars.nexml_file
            path = os.path.join(uploadfolder,
                                form.vars.nexml_file)
                                ## form.vars.nexml_file_newfilename)
            nexml = treebase.parse_nexml(path)
            os.remove(path)
        else:
            nexml = {}
            request.flash = "Valid study id or nexml file required"
        if nexml:
            nexml.meta['contributor'] = contributor
            cache.ram.clear(key)
            x = cache.ram(key, lambda:nexml, time_expire=10000)
            redirect(URL('study','tbimport2',args=tbid))

    return dict(form=form, status=status )
Example #3
0
def fetch_treebase_nexml():
    sid = request.args(0)
    e = treebase.fetch_study(sid)
    response.headers["Content-Type"] = "text/xml"
    s = "attachment; filename=TB-study-%s.nexml" % sid
    response.headers["Content-Disposition"] = s
    buf = StringIO()
    e.write(buf, pretty_print=True)
    return buf.getvalue()
Example #4
0
def fetch_treebase_nexml():
    sid = request.args(0)
    e = treebase.fetch_study(sid)
    response.headers["Content-Type"] = "text/xml"
    s = "attachment; filename=TB-study-%s.nexml" % sid
    response.headers["Content-Disposition"] = s
    buf = StringIO()
    e.write(buf, pretty_print=True)
    return buf.getvalue()