Esempio n. 1
0
def add_doctor(request, form_class=AddDoctorForm, template="add_doctor.html"):

    context = {"title": "Parceiro"}
    if request.method == "POST":
        form = form_class(request.POST)

        if form.is_valid():
            company_admin = request.user.companyadmin_set.all()[0]
            user, password = form.save(company_admin)
            form = form_class()

            vars_dict = {"first_name": user.first_name, "username": user.username, "password": password}
            html_email(
                "Cadastro no Sisquiropraxia", "add_doctor_email.html", vars_dict, "*****@*****.**", user.email
            )

            messages.success(request, __("Médico criado com sucesso!"))
            context["css_message"] = "message success"
        else:
            messages.error(request, __(u"Ocorreu um erro ao tentar salvar o perfil. Verifique os campos!"))
            context["css_message"] = "message error"
    else:
        form = form_class
    context["form"] = form
    return render_to_response(template, context, context_instance=RequestContext(request))
Esempio n. 2
0
    def save(self, *args, **kwargs):
        user = User.objects.create(
            username=self.cleaned_data['username'],
            email=self.cleaned_data['email'],
            is_active=True,
        )
        name = self.cleaned_data['first_name']
        user.first_name = name
        user.last_name = self.cleaned_data['last_name']
        
        if settings.DEBUG:
            password = '******'
        else:
            password = User.objects.make_random_password(length=8, \
                allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')
        user.set_password(password)
        user.save()
        
        # UserProfile
        user_profile = UserProfile()
        user_profile.user = user
        user_profile.user_type = '5'
        user_profile.save()

        self.instance.user = user
        # self.instance.activation_key = self._make_activation_key()
        
        # Clinic Address
        address = Address()
        if self.cleaned_data:
            address.street = self.cleaned_data.get('street','')
            address.complement = self.cleaned_data.get('complement', '')
            address.neighborhood = self.cleaned_data.get('neighborhood', '')
            address.zip = self.cleaned_data.get('zip', '')
            address.state = self.cleaned_data.get('state', '')
            address.city = self.cleaned_data.get('city', '')
            address.save()
        
        # BillingAccount
        billing_account = BillingAccount()
        if self.cleaned_data['agency']:
            billing_account.agency = self.cleaned_data['agency']
            billing_account.account_number = self.cleaned_data['account_number']
            billing_account.bank = self.cleaned_data['bank']
            billing_account.account_type = self.cleaned_data['account_type']
            billing_account.save()
        else:
            billing_account = None
        
        # Employee
        self.instance.address = address
        if billing_account:
            self.instance.billing_account = billing_account
        self.instance.birthday = self.cleaned_data['birthday']
        self.instance.user = user
        self.instance.cnpf = self.cleaned_data['cnpf']
        self.instance.clinic = self.cleaned_data['clinic']
        self.instance.save()
        
        # Sending email
        vars_dict = {'first_name': user.first_name, 'username': user.username, 'password': password}
        html_email('Cadastro no Sisquiropraxia', "add_doctor_email.html", vars_dict, '*****@*****.**', user.email)
            
        return super(AddEmployeeForm, self).save(*args, **kwargs)
Esempio n. 3
0
    def save(self, *args, **kwargs):
        user = User.objects.create(
            username=self.cleaned_data['admin_username'],
            email=self.cleaned_data['email'],
            is_active=True,
        )
        name = self.cleaned_data['admin_name'].split(' ')
        user.first_name = name[0]
        if name.__len__() > 1:
            user.last_name = name[1]
        
        if settings.DEBUG:
            password = '******'
        else:
            password = User.objects.make_random_password(length=8, \
                allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')
        user.set_password(password)
        user.save()
        
        # UserProfile
        user_profile = UserProfile()
        user_profile.user = user
        user_profile.user_type = '4'
        user_profile.save()

        self.instance.user = user
        # self.instance.activation_key = self._make_activation_key()
        
        # Clinic Address
        clinic_address = Address()
        if self.cleaned_data:
            clinic_address.street = self.cleaned_data.get('clinic_street','')
            clinic_address.complement = self.cleaned_data.get('clinic_complement', '')
            clinic_address.neighborhood = self.cleaned_data.get('clinic_neighborhood', '')
            clinic_address.zip = self.cleaned_data.get('clinic_zip', '')
            clinic_address.state = self.cleaned_data.get('clinic_state', '')
            clinic_address.city = self.cleaned_data.get('clinic_city', '')
            clinic_address.save()
        
        # Admin Address
        admin_address = Address()
        if self.cleaned_data:
            admin_address.street = self.cleaned_data.get('admin_street','')
            admin_address.complement = self.cleaned_data.get('admin_complement', '')
            admin_address.neighborhood = self.cleaned_data.get('admin_neighborhood', '')
            admin_address.zip = self.cleaned_data.get('admin_zip', '')
            admin_address.state = self.cleaned_data.get('admin_state', '')
            admin_address.city = self.cleaned_data.get('admin_city', '')
            admin_address.save()
        
        # BillingAccount
        billing_account = BillingAccount()
        if self.cleaned_data:
            billing_account.agency = self.cleaned_data['agency']
            billing_account.account_number = self.cleaned_data['account_number']
            billing_account.bank = self.cleaned_data['bank']
            billing_account.account_type = self.cleaned_data['account_type']
            billing_account.save()
        
        # Clinic
        self.instance.name = self.cleaned_data['name']
        self.instance.cnpj = format_cnpf(self.cleaned_data['cnpj'])
        self.instance.address = clinic_address
        self.instance.save()
        
        # CompanyAdmin
        company_admin = CompanyAdmin()
        company_admin.address = admin_address
        company_admin.billing_account = billing_account
        company_admin.birthday = self.cleaned_data['birthday']
        company_admin.user = user
        company_admin.cnpf = self.cleaned_data['cnpf']
        company_admin.save()
        company_admin.clinics.add(self.instance)
        company_admin.save()
        
        # Sending email
        vars_dict = {'first_name': user.first_name, 'username': user.username, 'password': password}
        html_email('Cadastro no Sisquiropraxia', "add_doctor_email.html", vars_dict, '*****@*****.**', user.email)
            
        return super(AddClinicForm, self).save(*args, **kwargs)