コード例 #1
0
ファイル: forms.py プロジェクト: GestorPsi-MES/gestorpsi
    def save(self, request, *args, **kwargs):
        organization = super(RegistrationForm, self).save(False, *args, **kwargs) # send_email = False 

        # add phone number to 'first' professional registered
        if self.cleaned_data['phone']:
            p = Phone()
            p.area = self.cleaned_data['phone'][1:3]
            p.phoneNumber = self.cleaned_data['phone'][5:15]
            p.phoneType_id = 2
            person = organization.care_professionals()[0]
            person.phones.add(p)
            
        # add cpf number to 'first' professional registered
        if self.cleaned_data['cpf']:
            d = Document()
            t = TypeDocument.objects.get(description='CPF')
            d.typeDocument_id = t.id
            d.document = self.cleaned_data['cpf']
            person.document.add(d)

        # add address to 'first' professional registered
        if self.cleaned_data['address']:
            a = Address()
            at = AddressType.objects.get(description='Comercial')
            a.addressType_id = at.id
            a.addressLine1 = self.cleaned_data['address']
            a.addressNumber = self.cleaned_data['address_number']
            a.zipCode = self.cleaned_data['zipcode']
            a.city_id = request.POST.get('city')
            person.address.add(a)