Пример #1
0
def add_ambulance_driver(request,pk):
    if request.method == "POST":
        new_ambulance_driver_form = NewAmbulanceDriverForm(request.POST)
        if new_ambulance_driver_form.is_valid():
            firstname = new_ambulance_driver_form.cleaned_data['first_name']
            nationality = new_ambulance_driver_form .cleaned_data['nationality']
            surname = new_ambulance_driver_form .cleaned_data['surname']

            mobile = new_ambulance_driver_form .cleaned_data['mobile']
            email = new_ambulance_driver_form .cleaned_data['email']
            address = new_ambulance_driver_form .cleaned_data['address']
            dob = new_ambulance_driver_form .cleaned_data['date_of_birth']
            sex = new_ambulance_driver_form .cleaned_data['sex']
            driver_license_number = new_ambulance_driver_form .cleaned_data['driver_license_number']
            password = randomPassword()


            now = datetime.datetime.now()

            try:
                user = User.objects.create_user(username=email, password=password,)
                user.groups.add(Group.objects.get_or_create(name="Ambulance Driver")[0])
                user.save()
            except Exception as ab:
                messages.error(request, ab)

            else:

                user_info = AuthUserDemographic(user=user, email=email,
                                                    first_name=firstname,
                                                    surname=surname, sex=sex, date_of_birth=dob,
                                                    nationality=nationality,
                                                    address=address,
                                                    mobile=mobile )

                user_info.save()

                user_info.unique_id = '{}{}{}{}'.format(now.day, now.month,
                                                            now.year, add_zeros(5, str(user_info.id)))

                user_info.save()
                ambulance_service = AmbulanceService.objects.get(id=pk)

                absa = AmbulanceDriver(user=user_info,driver_license_number=driver_license_number,
                                       ambulance_service= ambulance_service)
                absa.save()
                #sendsms(request, mobile, pin)
                send_pin_register(mobile,password)
                _sending_enterprise_acc_creation_password(user_info, password)

                messages.success(request, "Ambulance Driver Added Successfully")

        else:
            context = {'new_ambulance_driver_form': new_ambulance_driver_form }
            return render(request, 'add_ambulance_driver.html', context)

    new_ambulance_driver_form = NewAmbulanceDriverForm()

    context = {'new_ambulance_driver_form': new_ambulance_driver_form }
    return render(request, 'add_ambulance_driver.html', context)
Пример #2
0
def patient_register(request):
    if request.method == 'POST':
        try:
            email = request.POST['email']
            password = request.POST['password']
            countrycode = request.POST['country_code']
            phone_number = request.POST['phone_number']

            try:
                user = User.objects.create_user(
                    username=email,
                    password=password,
                )
                user.groups.add(Group.objects.get_or_create(name="Patient")[0])
                user.save()
            except Exception as ab:
                response = json.dumps({
                    'status': 'error',
                    'message': 'Account already exist'
                })

            else:
                now = datetime.datetime.now()
                user_info = AuthUserDemographic(
                    user=user,
                    email=email,
                    nationality=Country.objects.get(iso=countrycode).name,
                    mobile=phone_number)
                user_info.save()
                user_info.unique_id = 'PA{}{}{}{}'.format(
                    now.day, now.month, now.year,
                    add_zeros(5, str(user_info.id)))

                user_info.save()

                response = json.dumps({
                    'status':
                    'ok',
                    'message':
                    'Account has been created successfully'
                })

        except Exception as exs:
            message = exs.args
            response = json.dumps({'status': 'error', 'message': message})

    else:
        response = json.dumps({
            'status': 'error',
            'message': "something went wrong"
        })

    return HttpResponse(response, content_type='application/json')