def edit(request, ds_id): from neurolab.db.forms import DatasetForm from neurolab.db.models import * try: dset = Dataset.objects.with_id(ds_id) except Dataset.DoesNotExist: raise Http404 if request.method == 'POST': import json form = DatasetForm(request.POST) if form.is_valid(): for k in form.cleaned_data: setattr(dset, k, form.cleaned_data[k]) dset.save() return HttpResponse(json.dumps({ 'success': True, 'html': render_to_string( "partials/db/item.html", {'dataset': dset} ) }), mimetype="application/json") else: return HttpResponse(json.dumps(form.errors.copy()), mimetype="application/json") else: return render_to_response('partials/db/form.html', { 'form': DatasetForm({ 'name': dset.name, 'root': dset.root, 'blockname': dset.blockname, 'groupname': dset.groupname, }), 'dataset': dset, })
def new(request): from neurolab.db.forms import DatasetForm from neurolab.db.models import * try: file = SourceFile.objects.get(id=request.REQUEST['file']) except SourceFile.DoesNotExist, KeyError: raise Http404 if request.method == "POST": form = DatasetForm(request.POST) errors = {} if len(request.POST.getlist('components')) == 0: errors['components'] = ['You must select at least 1 component'] if form.is_valid() and not errors: dset = Dataset(**form.cleaned_data) dset.permit_user(request.user, 'admin') dset.components = [] for name in request.POST.getlist('components'): if name not in file.components: return HttpResponseBadRequest() base = file.components[name] componentform = Component.registry[base['type']].CriteriaForm(base) if not componentform.is_valid(): return HttpResponseBadRequest() template = ComponentTemplate.objects.create( name=base['name'],