Created
September 1, 2017 15:17
-
-
Save FlowFX/73646d4b2affad4ef82f076110696645 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ServicesAgreementWizardGeneralInformation(ServicesAgreementWizard): | |
"""Step 1 of the ServicesAgreement wizard.""" | |
form_class = GeneralInformationForm | |
def form_valid(self, form): | |
"""...""" | |
obj = self.object | |
if not obj.contractor: | |
obj.contractor = Party.objects.create() | |
if not obj.lender: | |
obj.lender = Party.objects.create() | |
obj.contractor.type = form.cleaned_data['contractor_type'] | |
obj.contractor.name = form.cleaned_data['contractor_name'] | |
obj.contractor.save() | |
obj.lender.type = form.cleaned_data['lender_type'] | |
obj.lender.name = form.cleaned_data['lender_name'] | |
obj.lender.save() | |
obj.save() | |
# this redirects to success url (FormMixin) | |
return super(ServicesAgreementWizardGeneralInformation, self).form_valid(form) | |
def get_form_class(self): | |
"""Returns the form class to use in this view""" | |
# Revert to default behavior instead of custom method in parent class | |
return self.form_class | |
def get_initial(self): | |
"""Returns the initial data to use for forms on this view.""" | |
initial = {} | |
if self.object.contractor: | |
initial.update({ | |
'contractor_type': self.object.contractor.type, | |
'contractor_name': self.object.contractor.name, | |
}) | |
if self.object.lender: | |
initial.update({ | |
'lender_type': self.object.lender.type, | |
'lender_name': self.object.lender.name, | |
}) | |
return initial |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment