예제 #1
0
def update(request, ds_id):
    import json
    from neurolab.db.forms import DatasourceForm
    from neurolab.db.models import Datasource
    
    try:
        ds = Datasource.objects.with_id(ds_id)
    except Datasource.DoesNotExist:
        raise Http404
    
    form = DatasourceForm(request.POST)
    if form.is_valid():
        data = form.cleaned_data
        for k in ('pathlevels', 'treelevels'):
            data[k] = filter(None, data[k].split('\n'))
        
        for k in data:
            setattr(ds, k, data[k])
        ds.save()
        return HttpResponse(json.dumps({
            'success': True,
            'html': render_to_string(
                "partials/datasources/item.html",
                {'datasource': ds}
            )
        }), mimetype="application/json")
    else:
        return HttpResponse(json.dumps(form.errors.copy()), mimetype="application/json")
예제 #2
0
def create(request):
    import json
    from neurolab.db.forms import DatasourceForm
    from neurolab.db.models import Datasource
    
    form = DatasourceForm(request.POST)
    if form.is_valid():
        data = form.cleaned_data
        for k in ('pathlevels', 'treelevels'):
            data[k] = filter(None, data[k].split('\n'))
        
        dset = Datasource(**data)
        dset.permit_user(request.user, 'admin')
        dset.save()
        
        return HttpResponse(json.dumps({
            'success': True,
            'html': render_to_string(
                "partials/datasources/item.html",
                {'datasource': dset}
            )
        }), mimetype="application/json")
    else:
        return HttpResponse(json.dumps(form.errors.copy()), mimetype="application/json")