Esempio n. 1
0
def expedit(request, expid=None):
    '''
    controller for individual experiment edit page
    '''
    
    exp = get_object_or_404(Experiment, pk=expid)
        
    # get my urls
    urls = genurls()
    
    # Deal with response 
    if request.method == 'POST':
        cancel = request.POST.get('cancel', None)
        if cancel:
            # reroute back to view page
            urls['expview']=reverse('cimexpgen.apps.expgenapp.views.expview',args=(exp.id, ))
            return HttpResponseRedirect(urls['expview'])
        else:        
            if 'expform' in request.POST:
                expform = ExperimentForm(request.POST, instance=exp, prefix='exp', user=request.user) 
                if expform.is_valid():
                    #exp = expform.save(commit=False)
                    exp = expform.save()
                    exp.author = request.user
                    exp.save()
                    # assign permissions to access this experiment
                    assign('manage_exp', request.user, exp)
                    
                    return HttpResponseRedirect(urls['explist']) # Redirect to list page 
                else:
                    return render_to_response('page/expedit.html', {'expform': expform, 'urls':urls}, context_instance=RequestContext(request))
            elif 'reqform' in request.POST:
                reqform = RequirementForm(request.POST, 
                                          instance=NumericalRequirement(), 
                                          prefix='req') 
                if reqform.is_valid(): 
                    newreq = reqform.save()
                    exp.requirements.add(newreq)
            
                return HttpResponseRedirect(urls['explist']) # Redirect to list page
    else:
        expform = ExperimentForm(instance=exp, prefix='exp', user=request.user) # An unbound form
        reqform = RequirementForm(prefix='req') # An unbound form

    return render_to_response('page/expedit.html', 
                              {'expform': expform,               
                               'reqform': reqform, 
                               'urls':urls},
                                context_instance=RequestContext(request))
Esempio n. 2
0
def expadd(request):
    '''
    controller for experiment add page
    '''
    
    exp = Experiment()
        
    # get my urls
    urls = genurls()
    
    # Deal with response 
    if request.method == 'POST':
        cancel = request.POST.get('cancel', None)
        if cancel:
            return HttpResponseRedirect(urls['explist'])
        else:        
            if 'expform' in request.POST:
                expform = ExperimentForm(request.POST, instance=exp, prefix='exp', user=request.user) 
                if expform.is_valid(): 
                    exp = expform.save(commit=False)
                    exp.author = request.user
                    exp.save()
                    # assign permissions to access this experiment
                    assign('manage_exp', request.user, exp)
                    
                    return HttpResponseRedirect(urls['explist']) # Redirect to list page 
                else:
                    return render_to_response('page/expedit.html', {'expform': expform, 'urls':urls}, context_instance=RequestContext(request))
            elif 'reqform' in request.POST:
                reqform = RequirementForm(request.POST, 
                                          instance=NumericalRequirement(), 
                                          prefix='req') 
                if reqform.is_valid(): 
                    newreq = reqform.save()
                    exp.requirements.add(newreq)
            
                return HttpResponseRedirect(urls['explist']) # Redirect to list page
    else:
        expform = ExperimentForm(instance=exp, prefix='exp', user=request.user) # An unbound form
        reqform = RequirementForm(prefix='req') # An unbound form

    return render_to_response('page/expedit.html', 
                              {'expform': expform,               
                               'reqform': reqform, 
                               'urls':urls},
                                context_instance=RequestContext(request))