Beispiel #1
0
    def post(self, request, *args, **kwargs):
        context = self.get_context_data(**kwargs)
        
        formset = SubmissionFormset(self.request.POST)
        
        if formset.is_valid():

            response = None 
    
            for form in formset.forms:
                if form.is_valid():
                    submission = form.save(False)
                    
                    #does this request already have a response?
                    if response is None:
                        if len(submission.request.responses.all()) > 0:
                            response = submission.request.responses.all()[0]
                            break
                        else:
                            response = Response()
                    
                    #does this response link to the request?    
                    try:
                        response.request
                    except (Request.DoesNotExist):
                        response.request = submission.request
                        response.save()
                        
                    #do the terms in the form match the request?
                    try: 
                        response.request.terms.get(body=form.cleaned_data["term"].body)
                        submission.save()
                    except:
                        print "Term does not exist in request"
                        break

            context['humanity'] = {'delta':response.delta,'test':response.human}

        self.template_name = "trainer/receipt.html"
        
        context['formset'] = formset
        
        return self.render_to_response(context)
Beispiel #2
0
    def create(self,request):
        #formset = request.form
        
        formset = SubmissionFormset(request.POST)
        
        if not formset.is_valid():
            return None
        
        response = None
        
        for form in formset.forms:
            if form.is_valid():
                submission = form.save(False)
                
                #does this request already have a response?
                if response is None:
                    if len(submission.request.responses.all()) > 0:
                        response = submission.request.responses.all()[0]
                        break
                    else:
                        response = Response()
                
                #does this response link to the request?    
                try:
                    response.request
                except (Request.DoesNotExist):
                    response.request = submission.request
                    response.save()
                    
                #do the terms in the form match the request?
                try: 
                    response.request.terms.get(body=form.cleaned_data["term"].body)
                    submission.save()
                except:
                    print "Term does not exist in request"
                    break

                
        return response