コード例 #1
0
ファイル: views.py プロジェクト: Foxugly/medagenda
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)
コード例 #2
0
def personal_data(request):
    results = {}
    if request.is_ajax():
        form = DoctorForm(request.POST, instance=request.user.userprofile.current_doctor)
        user_form = UserForm(request.POST, instance=request.user.userprofile.current_doctor.refer_userprofile.user)
        if form.is_valid() and user_form.is_valid():
            form.save()
            user_form.save()
            results['return'] = True
        else:
            print
            results['errors'] = form.errors + user_form.errors
            results['return'] = False
    else:
        results['return'] = False
    return HttpResponse(json.dumps(results))
コード例 #3
0
ファイル: views.py プロジェクト: Foxugly/medagenda
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)
コード例 #4
0
def add_doctor(request):
    if request.method == 'POST':
        form = DoctorForm(request.POST)
        if form.is_valid():
            # data = form.cleaned_data
            # username = data['username']
            # name = data['name']
            # phone = data['phone']
            # email = data['email']
            # gender = data['gender']
            # department = data['department']
            # attendance = data['attendance']
            # salary = data['salary']
            # status = data['status']
            # d = Doctor(username=username,name=name,phone=phone,email=email,gender=gender,department=department,attendance=attendance,salary=salary,status=status)
            form.save()
            return render(request, 'HR/view_doctors.html',
                          {'doctorsDB': Doctor.objects.all()})
        else:
            return render(request, 'HR/add_dr.html', {
                'doctorForm': DoctorForm(),
                'message': "Please try again"
            })

    return render(request, 'HR/add_dr.html', {'doctorForm': DoctorForm()})
コード例 #5
0
def edit_profile(request, dr_id):
    doctor = Doctor.objects.get(pk=dr_id)
    dr_form = DoctorForm(instance=doctor)

    if request.method == 'POST':
        form = DoctorForm(request.POST, instance=doctor)
        if form.is_valid():
            # data = form.cleaned_data
            # doctor.username = data['username']
            # doctor.name = data['name']
            # doctor.phone = data['phone']
            # doctor.email = data['email']
            # doctor.gender = data['gender']
            # doctor.department = data['department']
            # doctor.attendance = data['attendance']
            # doctor.salary = data['salary']
            # doctor.status = data['status']
            form.save()
            return render(request, 'HR/view_doctors.html',
                          {'doctorsDB': Doctor.objects.all()})
        else:
            return render(request, 'HR/edit_dr.html', {
                'dr': doctor,
                'dr_form': dr_form,
                'error': 'Please edit again'
            })

    return render(request, 'HR/edit_dr.html', {
        'dr': doctor,
        'dr_form': dr_form
    })
コード例 #6
0
ファイル: views.py プロジェクト: Foxugly/medagenda
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)
コード例 #7
0
ファイル: views.py プロジェクト: Foxugly/medagenda
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)
コード例 #8
0
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)