Beispiel #1
0
    def form_valid(self, form):
        retorno = super(DiscussionCreateView, self).form_valid(form)        
        cleaned_data = form.cleaned_data

        if not cleaned_data.get("automatically_generate", False) and cleaned_data["theses"]:
            for t in cleaned_data["theses"]:
                thesis = Thesis(description=t["description"], discussion=self.object)
                thesis.full_clean()
                thesis.save()
                    
        return retorno
Beispiel #2
0
 def process(self, request, *args, **kwargs):
     pk = kwargs.get('pk', None)
     # get discussion
     try:
         discussion = Discussion.objects.get(pk=pk)
     except Discussion.DoesNotExist:
         raise ValidationError('Discussion not found')
     
     data = request.POST.get('data', None)
     if not data:
         raise ValidationError('Invalid POST request')
     
     data = json.loads(data)
     for t in data:
         thesis = Thesis(description=t["description"], valid=t["valid"], discussion=discussion)
         thesis.full_clean()
         thesis.save()
         print t["valid"]
         print t["description"]