Exemplo n.º 1
0
def molecule_detail(request, molecule):
    job_form = JobForm.get_form(request, molecule)
    mol_form = MoleculeForm(request.REQUEST)

    job_is_valid = job_form.is_valid(request.method)
    mol_is_valid = mol_form.is_valid()

    if job_is_valid and mol_is_valid:
        return job_form.get_results(request, molecule, mol_form)
    elif request.is_ajax():
        job_form_html = render_crispy_form(
            job_form, context=RequestContext(request))
        mol_form_html = render_crispy_form(
            mol_form, context=RequestContext(request))
        a = {
            "success": False,
            "job_form_html": job_form_html,
            "mol_form_html": mol_form_html,
        }
        return HttpResponse(json.dumps(a), content_type="application/json")

    a = get_molecule_info_status(molecule)
    a["job_form"] = job_form
    a["mol_form"] = MoleculeForm()
    return render(request, "chem/molecule_detail.html", a)
Exemplo n.º 2
0
def multi_molecule(request, string):
    if request.REQUEST.get("random"):
        amount = int(request.REQUEST.get("random"))
        string = ','.join(name_expansion(string, rand=amount))

    job_form = JobForm.get_form(request, "{{ name }}")
    mol_form = MoleculeForm(request.REQUEST)

    job_is_valid = job_form.is_valid(request.method)
    mol_is_valid = mol_form.is_valid()

    if job_is_valid and mol_is_valid:
        return job_form.get_results(request, string, mol_form)
    elif request.is_ajax():
        job_form_html = render_crispy_form(
            job_form, context=RequestContext(request))
        mol_form_html = render_crispy_form(
            mol_form, context=RequestContext(request))
        a = {
            "success": False,
            "job_form_html": job_form_html,
            "mol_form_html": mol_form_html,
        }
        return HttpResponse(json.dumps(a), content_type="application/json")

    c = {
        "pagename": string,
        "job_form": job_form,
        "mol_form": MoleculeForm(),
        "gjf": "checked",
        "autoflip": request.REQUEST.get("autoflip"),
    }
    return render(request, "chem/multi_molecule.html", c)
Exemplo n.º 3
0
def multi_molecule(request, string):
    if request.REQUEST.get("random"):
        amount = int(request.REQUEST.get("random"))
        string = ','.join(name_expansion(string, rand=amount))

    job_form = JobForm.get_form(request, "{{ name }}")
    mol_form = MoleculeForm(request.REQUEST)

    job_is_valid = job_form.is_valid(request.method)
    mol_is_valid = mol_form.is_valid()

    if job_is_valid and mol_is_valid:
        return job_form.get_results(request, string, mol_form)
    elif request.is_ajax():
        job_form_html = render_crispy_form(job_form,
                                           context=RequestContext(request))
        mol_form_html = render_crispy_form(mol_form,
                                           context=RequestContext(request))
        a = {
            "success": False,
            "job_form_html": job_form_html,
            "mol_form_html": mol_form_html,
        }
        return HttpResponse(json.dumps(a), content_type="application/json")

    c = {
        "pagename": string,
        "job_form": job_form,
        "mol_form": MoleculeForm(),
        "gjf": "checked",
        "autoflip": request.REQUEST.get("autoflip"),
    }
    return render(request, "chem/multi_molecule.html", c)
Exemplo n.º 4
0
def molecule_detail(request, molecule):
    job_form = JobForm.get_form(request, molecule)
    mol_form = MoleculeForm(request.REQUEST)

    job_is_valid = job_form.is_valid(request.method)
    mol_is_valid = mol_form.is_valid()

    if job_is_valid and mol_is_valid:
        return job_form.get_results(request, molecule, mol_form)
    elif request.is_ajax():
        job_form_html = render_crispy_form(job_form,
                                           context=RequestContext(request))
        mol_form_html = render_crispy_form(mol_form,
                                           context=RequestContext(request))
        a = {
            "success": False,
            "job_form_html": job_form_html,
            "mol_form_html": mol_form_html,
        }
        return HttpResponse(json.dumps(a), content_type="application/json")

    a = get_molecule_info_status(molecule)
    a["job_form"] = job_form
    a["mol_form"] = MoleculeForm()
    return render(request, "chem/molecule_detail.html", a)
Exemplo n.º 5
0
def write_png(request, molecule):
    mol_form = MoleculeForm(request.REQUEST)
    mol_form.is_valid()
    mol_settings = dict(mol_form.cleaned_data)

    out = gjfwriter.NamedMolecule(molecule, **mol_settings)
    response = HttpResponse(out.get_png(), content_type="image/png")
    response['Content-Disposition'] = 'filename=%s.png' % molecule
    return response
Exemplo n.º 6
0
def write_svg(request, molecule):
    mol_form = MoleculeForm(request.REQUEST)
    mol_form.is_valid()
    mol_settings = dict(mol_form.cleaned_data)

    out = gjfwriter.NamedMolecule(molecule, **mol_settings)
    response = HttpResponse(out.get_svg(), content_type="image/svg+xml")
    response['Content-Disposition'] = 'filename=%s.svg' % molecule
    return response
Exemplo n.º 7
0
def write_mol2(request, molecule):
    mol_form = MoleculeForm(request.REQUEST)
    mol_form.is_valid()
    add = "" if request.REQUEST.get("view") else "attachment; "

    mol_settings = dict(mol_form.cleaned_data)
    out = gjfwriter.NamedMolecule(molecule, **mol_settings)
    response = HttpResponse(out.get_mol2(), content_type="text/plain")
    response['Content-Disposition'] = add + 'filename=%s.mol2' % molecule
    return response
Exemplo n.º 8
0
def write_mol2(request, molecule):
    mol_form = MoleculeForm(request.REQUEST)
    mol_form.is_valid()
    add = "" if request.REQUEST.get("view") else "attachment; "

    mol_settings = dict(mol_form.cleaned_data)
    out = gjfwriter.NamedMolecule(molecule, **mol_settings)
    response = HttpResponse(out.get_mol2(), content_type="text/plain")
    response['Content-Disposition'] = add + 'filename=%s.mol2' % molecule
    return response
Exemplo n.º 9
0
def multi_molecule_zip(request, string):
    try:
        autoflip = request.REQUEST.get("autoflip")
        molecules, warnings, errors, news = get_multi_molecule_status(
            string, autoflip=autoflip)
    except ValueError as e:
        logger.warn(str(e))
        c = {
            "error": str(e)
        }
        return render(request, "chem/multi_molecule.html", c)

    mol_form = MoleculeForm(request.REQUEST)
    mol_form.is_valid()
    if request.REQUEST.get("job"):
        job_form = JobForm.get_form(request, "{{ name }}")
        if not job_form.is_valid():
            f = lambda x: 'checked' if request.REQUEST.get(x) else ''
            c = {
                "pagename": string,
                "job_form": job_form,
                "mol_form": mol_form,
                "gjf": f("gjf"),
                "mol2": f("mol2"),
                "image": f("image"),
                "job": f("job"),
            }
            return render(request, "chem/multi_molecule.html", c)
    else:
        job_form = None

    selection = ("image", "mol2", "job", "gjf")
    options = [x for x in selection if request.REQUEST.get(x)]
    if request.REQUEST.get("new", ''):
        molecules = [x for i, x in enumerate(molecules) if news[i]]
    ret_zip = get_multi_molecule(molecules, options, mol_form, job_form)

    response = HttpResponse(ret_zip, content_type="application/zip")
    response["Content-Disposition"] = "attachment; filename=molecules.zip"
    return response
Exemplo n.º 10
0
def multi_molecule_zip(request, string):
    try:
        autoflip = request.REQUEST.get("autoflip")
        molecules, warnings, errors, news = get_multi_molecule_status(
            string, autoflip=autoflip)
    except ValueError as e:
        logger.warn(str(e))
        c = {"error": str(e)}
        return render(request, "chem/multi_molecule.html", c)

    mol_form = MoleculeForm(request.REQUEST)
    mol_form.is_valid()
    if request.REQUEST.get("job"):
        job_form = JobForm.get_form(request, "{{ name }}")
        if not job_form.is_valid():
            f = lambda x: 'checked' if request.REQUEST.get(x) else ''
            c = {
                "pagename": string,
                "job_form": job_form,
                "mol_form": mol_form,
                "gjf": f("gjf"),
                "mol2": f("mol2"),
                "image": f("image"),
                "job": f("job"),
            }
            return render(request, "chem/multi_molecule.html", c)
    else:
        job_form = None

    selection = ("image", "mol2", "job", "gjf")
    options = [x for x in selection if request.REQUEST.get(x)]
    if request.REQUEST.get("new", ''):
        molecules = [x for i, x in enumerate(molecules) if news[i]]
    ret_zip = get_multi_molecule(molecules, options, mol_form, job_form)

    response = HttpResponse(ret_zip, content_type="application/zip")
    response["Content-Disposition"] = "attachment; filename=molecules.zip"
    return response