Exemplo n.º 1
0
def update():
    form = PatientUpdateForm()
    if form.validate_on_submit():
        # patient_id    = Registration.objects.count()
        # patient_id    += 1
        patient_id = form.patient_id.data
        patient_name = form.patient_name.data
        patient_age = form.patient_age.data
        date_of_join = form.date_of_join.data
        type_of_bed = form.type_of_bed.data
        address = form.address.data
        city = form.city.data
        state = form.state.data

        registration = Registration(patient_id=patient_id,
                                    patient_name=patient_name,
                                    patient_age=patient_age,
                                    date_of_join=date_of_join,
                                    type_of_bed=type_of_bed,
                                    address=address,
                                    city=city,
                                    state=state)
        registration.save()

        #flash("Patient creation initiated successfully")

        flash("Patient details Updated successfully", "success")
        return redirect("/viewdetails")
    return render_template("update.html",
                           update=True,
                           form=form,
                           title="Update Patient")
Exemplo n.º 2
0
def activate(request, activation_key):
    try:
        registration = Registration.objects.get(activation_key=activation_key)
    except Registration.DoesNotExist:
        return render_to_response(
            'application/registration/activation-not-required.html',
            {'step_name': "ไม่จำเป็นต้องมีการยืนยันอีเมล์"})

    applicant = registration.applicant

    if not applicant.activation_required:
        return render_to_response(
            'application/registration/activation-not-required.html',
            {'step_name': "ไม่จำเป็นต้องมีการยืนยันอีเมล์"})

    if not applicant.verify_activation_key(activation_key):
        return render_to_response(
            'application/registration/incorrect-activation-key.html',
            {'applicant': applicant,
             'step_name': "รหัสยืนยันผิดพลาด" })

    if request.method == 'GET':
        # get a click from e-mail
        name_form = ActivationNameForm(initial={
                'title': applicant.title,
                'first_name': applicant.first_name,
                'last_name': applicant.last_name})
    else:
        name_form = ActivationNameForm(request.POST)
        if name_form.is_valid():
            applicant.activation_required = False
            applicant.title = name_form.cleaned_data['title']
            applicant.first_name = name_form.cleaned_data['first_name']
            applicant.last_name = name_form.cleaned_data['last_name']
            passwd = applicant.random_password()
            applicant.save()
            registration = Registration(
                applicant=applicant,
                first_name=applicant.first_name,
                last_name=applicant.last_name)
            registration.random_and_save()
            send_password_by_email(applicant, passwd)           
            return render_to_response(
                'application/registration/activation-successful.html',
                {'applicant': applicant})

    return render_to_response(
        'application/registration/activation-name-confirmation.html',
        {'applicant': applicant,
         'form': name_form,
         'activation_key': activation_key,
         'no_first_page_link': True,
         'step_name': "การยืนยันอีเมล์ - รหัสสำหรับยืนยันถูกต้อง" })
Exemplo n.º 3
0
    def create_applicant(self):
        applicant = Applicant(title=self.regis_data['title'],
                              first_name=self.regis_data['first_name'],
                              last_name=self.regis_data['last_name'],
                              email=self.regis_data['email'])
        password = applicant.random_password()
        applicant.save()
        registration = Registration(applicant=applicant,
                                    first_name=applicant.first_name,
                                    last_name=applicant.last_name)
        registration.random_and_save()

        return applicant, password
Exemplo n.º 4
0
def duplicate_email_error(applicant, email, first_name, last_name):
    # query set is lazy, so we have to force it, using list().
    old_registrations = list(applicant.registrations.all())  

    new_registration = Registration(applicant=applicant,
                                    first_name=first_name,
                                    last_name=last_name)
    new_registration.random_and_save()
    send_activation_by_email(applicant, new_registration.activation_key)
    applicant.activation_required = True
    applicant.save()
    return render_to_response('application/registration/duplicate.html',
                              { 'applicant': applicant,
                                'email': email,
                                'old_registrations': old_registrations,
                                'new_registration': new_registration,
                                'step_name': "อีเมล์นี้มีการลงทะเบียนไว้แล้ว ต้องมีการยืนยันอีเมล์" })
Exemplo n.º 5
0
    def create_applicant(self):
        applicant = Applicant(
            title=self.regis_data['title'],
            first_name=self.regis_data['first_name'],
            last_name=self.regis_data['last_name'],
            email=self.regis_data['email']
            )
        password = applicant.random_password()
        applicant.save()
        registration = Registration(
            applicant=applicant,
            first_name=applicant.first_name,
            last_name=applicant.last_name
            )
        registration.random_and_save()

        return applicant, password
Exemplo n.º 6
0
    def test_activation_key_verification(self):
        applicant = Applicant(first_name='สมชาย',
                              last_name='ใจดี',
                              email='*****@*****.**')
        applicant.save()
        keys = []
        # try with 3 registrations
        for i in range(3):
            registration = Registration(applicant=applicant,
                                        first_name='s',
                                        last_name='c')
            registration.random_and_save()
            keys.append(registration.activation_key)

        for k in keys:
            self.assertTrue(applicant.verify_activation_key(k))
        self.assertFalse(applicant.verify_activation_key('1234567'))
        for k in keys:
            self.assertFalse(applicant.verify_activation_key('1'+k))
Exemplo n.º 7
0
def duplicate_email_error(applicant, email, first_name, last_name,
                          national_id):
    # query set is lazy, so we have to force it, using list().
    old_registrations = list(applicant.registrations.all())

    new_registration = Registration(applicant=applicant,
                                    first_name=first_name,
                                    last_name=last_name,
                                    national_id=national_id)
    new_registration.random_and_save()
    send_activation_by_email(applicant, new_registration.activation_key)
    applicant.activation_required = True
    applicant.save()
    return render_to_response(
        'application/registration/duplicate.html', {
            'applicant': applicant,
            'email': email,
            'old_registrations': old_registrations,
            'new_registration': new_registration,
            'step_name': "อีเมล์นี้มีการลงทะเบียนไว้แล้ว ต้องมีการยืนยันอีเมล์"
        })
Exemplo n.º 8
0
def register(request):
    if request.method == 'POST':
        if 'cancel' in request.POST:
            return redirect_to_index(request)
        form = RegistrationForm(request.POST)

        if not settings.NAT_ID_VERIFICATION:
            form.disable_national_id_verification()

        if form.is_valid():
            email = form.cleaned_data['email']
            first_name=form.cleaned_data['first_name']
            last_name=form.cleaned_data['last_name']
            national_id=form.cleaned_data['national_id']

            result, error_field, applicant = (
                validate_email_and_national_id(email,
                                               national_id))

            if result:
                try:
                    applicant = form.get_applicant()
                    passwd = applicant.random_password()
                    applicant.save()
                except IntegrityError:
                    # somehow, it gets error

                    result, error_field, applicant = (
                        validate_email_and_national_id(email,
                                                       national_id))
                    return registration_error(error_field,
                                              applicant,
                                              email,
                                              national_id,
                                              first_name,
                                              last_name)
                
                registration = Registration(
                    applicant=applicant,
                    first_name=first_name,
                    last_name=last_name)
                registration.random_and_save()
                send_password_by_email(applicant, passwd)
                return render_to_response(
                    'application/registration/success.html',
                    {'email': form.cleaned_data['email'],
                     'step_name': "การลงทะเบียนเรียบร้อย" })
            else:
                if not applicant.has_logged_in:
                    return registration_error(error_field,
                                              applicant,
                                              email,
                                              national_id,
                                              first_name,
                                              last_name)

                # e-mail or national id has been registered and logged in
                from django.forms.util import ErrorList
                from commons.utils import admin_email

                if error_field == 'email':
                    dup_obj = u'อีเมล์'
                else:
                    dup_obj = u'รหัสประจำตัวประชาชน'

                form._errors['__all__'] = ErrorList([
u"""%(dup_obj)sนี้ถูกลงทะเบียนและถูกใช้แล้ว ถ้าอีเมล์นี้เป็นของคุณจริงและยังไม่เคยลงทะเบียน
กรุณาติดต่อผู้ดูแลระบบทางอีเมล์ <a href="mailto:%(email)s">%(email)s</a> หรือทางเว็บบอร์ด
อาจมีผู้ไม่ประสงค์ดีนำอีเมล์คุณไปใช้""" % {'dup_obj': dup_obj,
                                 'email': admin_email()}])
                
    else:
        form = RegistrationForm()
    return render_to_response('application/registration/register.html',
                              { 'form': form },
                              context_instance=RequestContext(request))
Exemplo n.º 9
0
def activate(request, activation_key):
    try:
        registration = Registration.objects.get(activation_key=activation_key)
    except Registration.DoesNotExist:
        return render_to_response(
            'application/registration/activation-not-required.html',
            {'step_name': "ไม่จำเป็นต้องมีการยืนยันอีเมล์"})

    applicant = registration.applicant

    if not applicant.activation_required:
        return render_to_response(
            'application/registration/activation-not-required.html',
            {'step_name': "ไม่จำเป็นต้องมีการยืนยันอีเมล์"})

    if not applicant.verify_activation_key(activation_key):
        return render_to_response(
            'application/registration/incorrect-activation-key.html', {
                'applicant': applicant,
                'step_name': "รหัสยืนยันผิดพลาด"
            })

    if request.method == 'GET':
        # get a click from e-mail
        name_form = ActivationNameForm(
            initial={
                'title': applicant.title,
                'first_name': applicant.first_name,
                'last_name': applicant.last_name
            })
    else:
        name_form = ActivationNameForm(request.POST)
        if name_form.is_valid():
            applicant.activation_required = False
            applicant.national_id = registration.national_id
            applicant.title = name_form.cleaned_data['title']
            applicant.first_name = name_form.cleaned_data['first_name']
            applicant.last_name = name_form.cleaned_data['last_name']
            passwd = applicant.random_password()
            try:
                applicant.save()
            except IntegrityError:
                return registration_error('national_id', applicant,
                                          applicant.email,
                                          registration.national_id,
                                          applicant.first_name,
                                          applicant.last_name)
            registration = Registration(applicant=applicant,
                                        first_name=applicant.first_name,
                                        last_name=applicant.last_name,
                                        national_id=registration.national_id)
            registration.random_and_save()
            send_password_by_email(applicant, passwd)
            return render_to_response(
                'application/registration/activation-successful.html',
                {'applicant': applicant})

    return render_to_response(
        'application/registration/activation-name-confirmation.html', {
            'applicant': applicant,
            'national_id': registration.national_id,
            'form': name_form,
            'activation_key': activation_key,
            'no_first_page_link': True,
            'step_name': "การยืนยันอีเมล์ - รหัสสำหรับยืนยันถูกต้อง"
        })
Exemplo n.º 10
0
def register(request):
    if request.method == 'POST':
        if 'cancel' in request.POST:
            return redirect_to_index(request)
        form = RegistrationForm(request.POST)

        if not settings.NAT_ID_VERIFICATION:
            form.disable_national_id_verification()

        if form.is_valid():
            email = form.cleaned_data['email']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            national_id = form.cleaned_data['national_id']

            result, error_field, applicant = (validate_email_and_national_id(
                email, national_id))

            if result:
                try:
                    applicant = form.get_applicant()
                    passwd = applicant.random_password()
                    applicant.save()
                except IntegrityError:
                    # somehow, it gets error

                    result, error_field, applicant = (
                        validate_email_and_national_id(email, national_id))
                    return registration_error(error_field, applicant, email,
                                              national_id, first_name,
                                              last_name)

                registration = Registration(applicant=applicant,
                                            first_name=first_name,
                                            last_name=last_name)
                registration.random_and_save()
                send_password_by_email(applicant, passwd)
                return render_to_response(
                    'application/registration/success.html', {
                        'email': form.cleaned_data['email'],
                        'step_name': "การลงทะเบียนเรียบร้อย"
                    })
            else:
                if not applicant.has_logged_in:
                    return registration_error(error_field, applicant, email,
                                              national_id, first_name,
                                              last_name)

                # e-mail or national id has been registered and logged in
                from django.forms.util import ErrorList
                from commons.utils import admin_email

                if error_field == 'email':
                    dup_obj = u'อีเมล์'
                else:
                    dup_obj = u'รหัสประจำตัวประชาชน'

                form._errors['__all__'] = ErrorList([
                    u"""%(dup_obj)sนี้ถูกลงทะเบียนและถูกใช้แล้ว ถ้าอีเมล์นี้เป็นของคุณจริงและยังไม่เคยลงทะเบียน
กรุณาติดต่อผู้ดูแลระบบทางอีเมล์ <a href="mailto:%(email)s">%(email)s</a> หรือทางเว็บบอร์ด
อาจมีผู้ไม่ประสงค์ดีนำอีเมล์คุณไปใช้""" % {
                        'dup_obj': dup_obj,
                        'email': admin_email()
                    }
                ])

    else:
        form = RegistrationForm()
    return render_to_response('application/registration/register.html',
                              {'form': form},
                              context_instance=RequestContext(request))