Beispiel #1
0
def bipartite_view_genbank(request):
    context = RequestContext(request)
    context.update(csrf(request))
    if request.method == 'POST':
        request_data = request.POST
    elif request.method == 'GET':
        request_data = request.GET
    else:
        request_data = None

    if request_data:
        form = BipartiteForm3(request_data)
        if form.is_valid():
            seq = assemble_parts(form.cleaned_data, ['part_1', 'part_2'])
            response = HttpResponse(seq.format('genbank'),
                                    content_type='text/plain')
            filename = seq.name + '.gb'
            response['Content-Disposition'] = 'attachment; '
            response['Content-Disposition'] += 'filename="{0}"'.format(filename)
            return response
    return HttpResponseBadRequest()
Beispiel #2
0
def bipartite_view_add(request):
    context = RequestContext(request)
    context.update(csrf(request))
    request_data = request.POST
    if not request_data:
        return render_to_response('goldenbraid_info.html',
                               {'info': "Not enougth data to add the feature"},
                                context_instance=RequestContext(request))
    name = request_data['name']
    vector_name = request_data['Vector']
    used_parts = {'Vector': vector_name,
                  'part_1': request_data['part_1'],
                  'part_2': request_data['part_2']}
    seq = assemble_parts(used_parts, ['part_1', 'part_2'])
    props = {'Description': [request_data['description']],
             'Reference': [request_data['reference']]}
    temp_fhand = NamedTemporaryFile(prefix='{0}.'.format(seq.id), suffix='.gb')
    temp_fhand.write(seq.format('gb'))
    temp_fhand.flush()
    temp_fhand.seek(0)
    try:
        feature = add_feature(name=name, type_name=MODULE_TYPE_NAME,
                              vector=vector_name, genbank=temp_fhand, props=props,
                              owner=request.user, is_public=False)

    except IntegrityError as error:
        print error
        if 'feature already in db' in str(error):
            # TODO choose a template
            return render_to_response('feature_exists.html',
                                      {},
                            context_instance=RequestContext(request))
        else:
            return HttpResponseServerError()
    except Exception as error:
        print error
        return HttpResponseServerError(error)
    # if everithing os fine we show the just added feature
    return redirect(feature.url)