コード例 #1
0
ファイル: views.py プロジェクト: nikolas/open_fmri
    def form_valid(self, form):
        dataset = form.save()

        investigator_formset = InvestigatorFormSet(self.request.POST, self.request.FILES, instance=dataset)
        if investigator_formset.is_valid():
            investigator_formset.save()

        link_formset = LinkFormSet(self.request.POST, instance=dataset)
        if link_formset.is_valid():
            link_formset.save()

        publication_document_formset = PublicationDocumentFormSet(
            self.request.POST, self.request.FILES, instance=dataset
        )
        if publication_document_formset.is_valid():
            publication_document_formset.save()

        publication_pubmed_link_formset = PublicationPubMedLinkFormSet(self.request.POST, instance=dataset)
        if publication_pubmed_link_formset.is_valid():
            publication_pubmed_link_formset.save()

        revision_formset = RevisionFormSet(self.request.POST, instance=dataset)
        if revision_formset.is_valid():
            revision_formset.save()

        task_formset = TaskFormSet(self.request.POST, self.request.FILES, instance=dataset)
        if task_formset.is_valid():
            task_formset.save()

        return super(DatasetCreate, self).form_valid(form)
コード例 #2
0
ファイル: views.py プロジェクト: nikolas/open_fmri
    def form_valid(self, form):
        dataset = form.save()

        investigator_formset = InvestigatorFormSet(self.request.POST, self.request.FILES, instance=self.object)
        if investigator_formset.is_valid():
            investigator_formset.save()

        link_formset = LinkFormSet(self.request.POST, instance=self.object)
        if link_formset.is_valid():
            link_formset.save()

        publication_document_formset = PublicationDocumentFormSet(
            self.request.POST, self.request.FILES, instance=self.object
        )
        if publication_document_formset.is_valid():
            publication_document_formset.save()

        publication_pubmed_link_formset = PublicationPubMedLinkFormSet(self.request.POST, instance=self.object)
        if publication_pubmed_link_formset.is_valid():
            publication_pubmed_link_formset.save()

        revision_formset = RevisionFormSet(self.request.POST, instance=self.object)
        if revision_formset.is_valid():
            revision_formset.save()

        task_formset = TaskFormSet(self.request.POST, self.request.FILES, instance=self.object)
        if task_formset.is_valid():
            task_formset.save()
        else:
            form_empty_permitted = task_formset.forms[-1].empty_permitted
            form_has_changed = task_formset.forms[-1].changed_data
            total_forms = task_formset.total_form_count()
            raise forms.ValidationError(task_formset.errors)

        return super(DatasetUpdate, self).form_valid(form)
コード例 #3
0
ファイル: views.py プロジェクト: nikolas/open_fmri
    def form_valid(self, form):
        dataset = form.save()

        investigator_formset = InvestigatorFormSet(self.request.POST,
                                                   self.request.FILES,
                                                   instance=dataset)
        if investigator_formset.is_valid():
            investigator_formset.save()

        link_formset = LinkFormSet(self.request.POST, instance=dataset)
        if link_formset.is_valid():
            link_formset.save()

        publication_document_formset = PublicationDocumentFormSet(
            self.request.POST, self.request.FILES, instance=dataset)
        if publication_document_formset.is_valid():
            publication_document_formset.save()

        publication_pubmed_link_formset = PublicationPubMedLinkFormSet(
            self.request.POST, instance=dataset)
        if publication_pubmed_link_formset.is_valid():
            publication_pubmed_link_formset.save()

        revision_formset = RevisionFormSet(self.request.POST, instance=dataset)
        if revision_formset.is_valid():
            revision_formset.save()

        task_formset = TaskFormSet(self.request.POST,
                                   self.request.FILES,
                                   instance=dataset)
        if task_formset.is_valid():
            task_formset.save()

        return super(DatasetCreate, self).form_valid(form)
コード例 #4
0
ファイル: views.py プロジェクト: chrisfilo/open_fmri
    def form_valid(self, form):
        dataset = form.save()
        
        new_contact_form = NewContactForm(self.request.POST)
        contact_form = ContactForm(self.request.POST)
        if new_contact_form.is_valid() and new_contact_form.has_changed():
            new_contact = new_contact_form.save()
            new_contact.save()
            dataset.contact = new_contact
        elif contact_form.is_valid():
            dataset.contact = contact_form.cleaned_data['contact']
        else:
            pass

        investigator_formset = InvestigatorFormSet(self.request.POST,
            self.request.FILES, instance=dataset)
        if investigator_formset.is_valid():
            investigator_formset.save()

        link_formset = LinkFormSet(self.request.POST, instance=dataset)
        if link_formset.is_valid():
            link_formset.save()

        publication_document_formset = PublicationDocumentFormSet(
            self.request.POST, self.request.FILES, instance=dataset)
        if publication_document_formset.is_valid():
            publication_document_formset.save()

        publication_pubmed_link_formset = PublicationPubMedLinkFormSet(
            self.request.POST, instance=dataset)
        if publication_pubmed_link_formset.is_valid():
            publication_pubmed_link_formset.save()

        revision_formset = RevisionFormSet(self.request.POST, 
            instance=dataset)
        if revision_formset.is_valid():
            revision_formset.save()
        
        task_formset = TaskFormSet(self.request.POST, self.request.FILES,
            instance=dataset)
        if task_formset.is_valid():
            task_formset.save()
        
        return super(DatasetCreate, self).form_valid(form)
コード例 #5
0
ファイル: views.py プロジェクト: nikolas/open_fmri
    def form_valid(self, form):
        dataset = form.save()

        investigator_formset = InvestigatorFormSet(self.request.POST,
                                                   self.request.FILES,
                                                   instance=self.object)
        if investigator_formset.is_valid():
            investigator_formset.save()

        link_formset = LinkFormSet(self.request.POST, instance=self.object)
        if link_formset.is_valid():
            link_formset.save()

        publication_document_formset = PublicationDocumentFormSet(
            self.request.POST, self.request.FILES, instance=self.object)
        if publication_document_formset.is_valid():
            publication_document_formset.save()

        publication_pubmed_link_formset = PublicationPubMedLinkFormSet(
            self.request.POST, instance=self.object)
        if publication_pubmed_link_formset.is_valid():
            publication_pubmed_link_formset.save()

        revision_formset = RevisionFormSet(self.request.POST,
                                           instance=self.object)
        if revision_formset.is_valid():
            revision_formset.save()

        task_formset = TaskFormSet(self.request.POST,
                                   self.request.FILES,
                                   instance=self.object)
        if task_formset.is_valid():
            task_formset.save()
        else:
            form_empty_permitted = task_formset.forms[-1].empty_permitted
            form_has_changed = task_formset.forms[-1].changed_data
            total_forms = task_formset.total_form_count()
            raise forms.ValidationError(task_formset.errors)

        return super(DatasetUpdate, self).form_valid(form)
コード例 #6
0
    def form_valid(self, form):
        dataset = form.save()
        self.object = dataset
        invalid_form = False

        investigator_formset = InvestigatorFormSet(self.request.POST,
                                                   self.request.FILES,
                                                   instance=dataset)
        if investigator_formset.is_valid():
            investigator_formset.save()
        else:
            invalid_form = True

        link_formset = LinkFormSet(self.request.POST, instance=dataset)
        if link_formset.is_valid():
            link_formset.save()
        else:
            invalid_form = True

        publication_document_formset = PublicationDocumentFormSet(
            self.request.POST, self.request.FILES, instance=dataset)
        if publication_document_formset.is_valid():
            publication_document_formset.save()
        else:
            invalid_form = True

        publication_pubmed_link_formset = PublicationPubMedLinkFormSet(
            self.request.POST, instance=dataset)
        if publication_pubmed_link_formset.is_valid():
            publication_pubmed_link_formset.save()
        else:
            invalid_form = True

        revision_formset = RevisionFormSet(self.request.POST, instance=dataset)
        if revision_formset.is_valid():
            revision_formset.save()
        else:
            invalid_form = True

        task_formset = TaskFormSet(self.request.POST,
                                   self.request.FILES,
                                   instance=dataset)
        if task_formset.is_valid():
            task_formset.save()
        else:
            invalid_form = True

        contact_formset = ContactFormSet(self.request.POST)
        if contact_formset.is_valid():
            contact_forms = contact_formset.save()
            for contact in contact_forms:
                dataset.contacts.add(contact.pk)
        else:
            invalid_form = True

        print(dataset.contacts.all())
        if invalid_form:
            context = {
                'request':
                self.request,
                'form':
                form,
                'investigator_formset':
                investigator_formset,
                'link_formset':
                link_formset,
                'publication_document_formset':
                publication_document_formset,
                'publication_pubmed_link_formset':
                publication_pubmed_link_formset,
                'revision_formset':
                revision_formset,
                'task_formset':
                task_formset,
                'contact_formset':
                contact_formset,
                'contact_formset_helper':
                ContactFormSetHelper(),
                'investigator_formset_helper':
                InvestigatorFormSetHelper(),
                'link_formset_helper':
                LinkFormSetHelper(),
                'publication_document_formset_helper':
                PublicationDocumentFormSetHelper(),
                'publication_pubmed_link_formset_helper':
                PublicationPubMedLinkFormSetHelper(),
                'task_formset_helper':
                TaskFormSetHelper(),
                'revision_formset_helper':
                RevisionFormSetHelper(),
            }
            return self.render_to_response(context)
        else:
            return HttpResponseRedirect(self.get_success_url())
コード例 #7
0
ファイル: views.py プロジェクト: poldracklab/open_fmri
    def form_valid(self, form):
        dataset = form.save()
        self.object = dataset
        invalid_form = False

        investigator_formset = InvestigatorFormSet(self.request.POST,
            self.request.FILES, instance=dataset)
        if investigator_formset.is_valid():
            investigator_formset.save()
        else:
            invalid_form = True

        link_formset = LinkFormSet(self.request.POST, instance=dataset)
        if link_formset.is_valid():
            link_formset.save()
        else:
            invalid_form = True

        publication_document_formset = PublicationDocumentFormSet(
            self.request.POST, self.request.FILES, instance=dataset)
        if publication_document_formset.is_valid():
            publication_document_formset.save()
        else:
            invalid_form = True

        publication_pubmed_link_formset = PublicationPubMedLinkFormSet(
            self.request.POST, instance=dataset)
        if publication_pubmed_link_formset.is_valid():
            publication_pubmed_link_formset.save()
        else:
            invalid_form = True

        revision_formset = RevisionFormSet(self.request.POST, 
            instance=dataset)
        if revision_formset.is_valid():
            revision_formset.save()
        else:
            invalid_form = True
        
        task_formset = TaskFormSet(self.request.POST, self.request.FILES,
            instance=dataset)
        if task_formset.is_valid():
            task_formset.save()
        else:
            invalid_form = True

        contact_formset = ContactFormSet(self.request.POST)
        if contact_formset.is_valid():
            contact_forms = contact_formset.save()
            for contact in contact_forms:
                dataset.contacts.add(contact.pk)
        else:
            invalid_form = True

        print(dataset.contacts.all())
        if invalid_form:
            context = {
                'request': self.request,
                'form': form,
                'investigator_formset': investigator_formset,
                'link_formset': link_formset,
                'publication_document_formset': publication_document_formset,
                'publication_pubmed_link_formset': publication_pubmed_link_formset,
                'revision_formset': revision_formset,
                'task_formset': task_formset,
                'contact_formset': contact_formset,
                'contact_formset_helper': ContactFormSetHelper(),
                'investigator_formset_helper': InvestigatorFormSetHelper(),
                'link_formset_helper': LinkFormSetHelper(),
                'publication_document_formset_helper': PublicationDocumentFormSetHelper(),
                'publication_pubmed_link_formset_helper': PublicationPubMedLinkFormSetHelper(),
                'task_formset_helper': TaskFormSetHelper(),
                'revision_formset_helper': RevisionFormSetHelper(),
            }
            return self.render_to_response(context)
        else:
            return HttpResponseRedirect(self.get_success_url())