Exemple #1
0
def handle_form(request):
    if request.method == 'POST':
        form = SBMLUploadForm(request.POST, request.FILES)
        vars = dict(form = form)
        if form.is_valid():
            try:
                resp = HttpResponse(
                    content = convertSBML2EML(request.FILES['file'].read()).asString(),
                    mimetype = 'application/x-ecell-model'
                    )
                eml_file_name = os.path.splitext(
                    os.path.basename(request.FILES['file'].filename))[0] + '.eml'
                resp['Content-Disposition'] = 'attachment; filename=%s' % eml_file_name
                return resp
            except Exception, e:
                form._errors[NON_FIELD_ERRORS] = ErrorList([_(u'Conversion failed (attempt to convert a non-SBML file?)')])
        return render_to_response('sbml2eml/form.html', vars,
            context_instance = RequestContext(request))
Exemple #2
0
        form = SBMLUploadForm(request.POST, request.FILES)
        vars = dict(form = form)
        if form.is_valid():
            try:
                resp = HttpResponse(
                    content = convertSBML2EML(request.FILES['file'].read()).asString(),
                    mimetype = 'application/x-ecell-model'
                    )
                eml_file_name = os.path.splitext(
                    os.path.basename(request.FILES['file'].filename))[0] + '.eml'
                resp['Content-Disposition'] = 'attachment; filename=%s' % eml_file_name
                return resp
            except Exception, e:
                form._errors[NON_FIELD_ERRORS] = ErrorList([_(u'Conversion failed (attempt to convert a non-SBML file?)')])
        return render_to_response('sbml2eml/form.html', vars,
            context_instance = RequestContext(request))
    elif request.method == "PUT":
        try:
            return HttpResponse(
                content = convertSBML2EML(request.raw_post_data).asString(),
                mimetype = 'application/x-ecell-model',
                )
        except Exception, e:
            return HttpResponseServerError(
                content_type = 'text/plain; charset=%s' %
                    settings.DEFAULT_CHARSET,
                content = unicode(_(u'Conversion failed (attempt to convert a non-SBML file?)'))
                )
    else:
        return show_form(request)