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)
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)
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)
def get_context_data(self, **kwargs): context = super(DatasetCreateUpdate, self).get_context_data(**kwargs) contact_pk = 0 # initial = {'contact': contact_pk}) context['investigator_formset'] = InvestigatorFormSet( instance=self.object) context['investigator_formset_helper'] = InvestigatorFormSetHelper() context['link_formset'] = LinkFormSet(instance=self.object) context['link_formset_helper'] = LinkFormSetHelper() context['publication_document_formset'] = \ PublicationDocumentFormSet(instance=self.object) context['publication_document_formset_helper'] = \ PublicationDocumentFormSetHelper() context['publication_pubmed_link_formset'] = \ PublicationPubMedLinkFormSet(instance=self.object) context['publication_pubmed_link_formset_helper'] = \ PublicationPubMedLinkFormSetHelper() context['task_formset'] = TaskFormSet(instance=self.object) context['task_formset_helper'] = TaskFormSetHelper() context['revision_formset'] = RevisionFormSet(instance=self.object) context['revision_formset_helper'] = RevisionFormSetHelper() print(self.object) if self.object: context['contact_formset'] = ContactFormSet( queryset=self.object.contacts.all(), ) else: context['contact_formset'] = ContactFormSet( queryset=Contact.objects.none(), ) context['contact_formset_helper'] = ContactFormSetHelper() return context
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)
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)
def get_context_data(self, **kwargs): context = super(DatasetCreate, self).get_context_data(**kwargs) context['investigator_formset'] = InvestigatorFormSet() context['investigator_formset_helper'] = InvestigatorFormSetHelper() context['link_formset'] = LinkFormSet() context['link_formset_helper'] = LinkFormSetHelper() context['publication_document_formset'] = PublicationDocumentFormSet() context['publication_document_formset_helper'] = \ PublicationDocumentFormSetHelper() context['publication_pubmed_link_formset'] = \ PublicationPubMedLinkFormSet() context['publication_pubmed_link_formset_helper'] = \ PublicationPubMedLinkFormSetHelper() context['task_formset'] = TaskFormSet() context['task_formset_helper'] = TaskFormSetHelper() context['revision_formset'] = RevisionFormSet(instance=self.object) context['revision_formset_helper'] = RevisionFormSetHelper() return context
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())