def add_user(request): c = {} if request.method == 'POST': ucform = UserCreateForm(request.POST) upform = UserProfileForm(request.POST) docform = DoctorForm(request.POST) invoiceform = MiniInvoiceForm(request.POST) if ucform.is_valid() and upform.is_valid() and docform.is_valid() and invoiceform.is_valid(): i = invoiceform.save() u = ucform.save() up = upform.save() doc = docform.save() doc.refer_userprofile = up for st in settings.SLOT_TYPE: doc.get_colorslot(st[0]) doc.invoices.add(i) doc.save() up.user = u up.doctors.add(doc) up.current_doctor = doc up.save() doc.set_slug() doc.save() mail_user_welcome(request, up, False) return HttpResponseRedirect('/') else: c['form'] = [ucform, upform, docform, invoiceform] messages.error(request, "Error") else: c['form'] = [UserCreateForm(), UserProfileForm(), DoctorForm(), MiniInvoiceForm()] c['url'] = "/user/add_user/" c['title'] = _("New doctor") return render(request, 'form.tpl', c)
def create_user(request): c = {} if request.method == 'POST': ucform = UserCreateForm(request.POST) upform = UserProfileForm(request.POST) docform = DoctorForm(request.POST) invoiceform = MiniInvoiceForm(request.POST) if ucform.is_valid() and upform.is_valid() and docform.is_valid( ) and invoiceform.is_valid(): i = invoiceform.save() u = ucform.save() up = upform.save() u.is_active = False u.save() i.active = True i.save() up.confirm = string_random(32) doc = docform.save() doc.refer_userprofile = up for st in settings.SLOT_TYPE: doc.get_colorslot(st[0]) doc.invoices.add(i) doc.save() up.user = u up.doctors.add(doc) # TODO regarder dans collaborator pour voir si il faut en rajouter up.current_doctor = doc up.save() doc.set_slug() doc.save() mail_user_welcome(request, up, True) c['mail'] = True return render(request, 'valid.tpl', c) else: c['form'] = [ucform, upform, docform, invoiceform] messages.error(request, "Error") else: c['form'] = [ UserCreateForm(), UserProfileForm(), DoctorForm(), MiniInvoiceForm() ] c['url'] = "/user/create_user/" c['title'] = _("New doctor") return render(request, 'form.tpl', c)
def create_user(request): c = {} if request.method == 'POST': ucform = UserCreateForm(request.POST) upform = UserProfileForm(request.POST) docform = DoctorForm(request.POST) invoiceform = MiniInvoiceForm(request.POST) if ucform.is_valid() and upform.is_valid() and docform.is_valid() and invoiceform.is_valid(): i = invoiceform.save() u = ucform.save() up = upform.save() u.is_active = False u.save() i.active = True i.save() up.confirm = string_random(32) doc = docform.save() doc.refer_userprofile = up for st in settings.SLOT_TYPE: doc.get_colorslot(st[0]) doc.invoices.add(i) doc.save() up.user = u up.doctors.add(doc) # TODO regarder dans collaborator pour voir si il faut en rajouter up.current_doctor = doc up.save() doc.set_slug() doc.save() mail_user_welcome(request, up, True) c['mail'] = True return render(request, 'valid.tpl', c) else: c['form'] = [ucform, upform, docform, invoiceform] messages.error(request, "Error") else: c['form'] = [UserCreateForm(), UserProfileForm(), DoctorForm(), MiniInvoiceForm()] c['url'] = "/user/create_user/" c['title'] = _("New doctor") return render(request, 'form.tpl', c)
def add_user(request): c = {} if request.method == 'POST': ucform = UserCreateForm(request.POST) upform = UserProfileForm(request.POST) docform = DoctorForm(request.POST) invoiceform = MiniInvoiceForm(request.POST) if ucform.is_valid() and upform.is_valid() and docform.is_valid( ) and invoiceform.is_valid(): i = invoiceform.save() u = ucform.save() up = upform.save() doc = docform.save() doc.refer_userprofile = up for st in settings.SLOT_TYPE: doc.get_colorslot(st[0]) doc.invoices.add(i) doc.save() up.user = u up.doctors.add(doc) up.current_doctor = doc up.save() doc.set_slug() doc.save() mail_user_welcome(request, up, False) return HttpResponseRedirect('/') else: c['form'] = [ucform, upform, docform, invoiceform] messages.error(request, "Error") else: c['form'] = [ UserCreateForm(), UserProfileForm(), DoctorForm(), MiniInvoiceForm() ] c['url'] = "/user/add_user/" c['title'] = _("New doctor") return render(request, 'form.tpl', c)
def user_settings(request): up = request.user.userprofile doc = up.current_doctor c = {'userprofile_id': request.user.userprofile.id, 'user_form': UserForm(instance=doc.refer_userprofile.user), 'personal_data_form': DoctorForm(instance=doc), 'settings_form': SettingsForm(instance=doc), 'avatar': doc.picture, 'text_form': TextForm(instance=doc), 'color_forms': [], 'password_change_form': PasswordChangeForm(user=request.user), 'invoice': doc.get_active_invoice(), 'collaborator_form': CollaboratorForm(), 'collaborators1': UserProfile.objects.filter(doctors=doc), 'collaborators2': Collaborator.objects.filter(doctor=doc), 'new_invoice': MiniInvoiceForm() if not doc.already_use_free_invoice() else NoFreeMiniInvoiceForm(), 'doctor_profile': doc.refer_userprofile} for st in settings.SLOT_TYPE: d = {'id': doc.get_colorslot(st[0]).id, 'name': st[1], 'form': ColorForm(instance=doc.get_colorslot(st[0]))} c['color_forms'].append(d) return render(request, 'config.tpl', c)