Пример #1
0
def save_employee(request):
    files = request.FILES.getlist('photo', [])
    if len(files) > 0:
        file = files[0]
        path = os.path.join(MEDIA_ROOT, 'images', file.name)
        with open(path, 'wb+') as f:
            f.write(file.file.read())

    params = request.POST

    if params.get('id', None) is None:
        employee = Employee()
    else:
        employee = Employee.objects.get(id=params.get('id'))

    if len(files) > 0:
        employee.photo = f"/media/images/{file.name}"
    elif params['photo'] != 'null':
        employee.photo = f"{params['photo']}"
    else:
        employee.photo = f'/media/images/default.png'
    employee.name = params['name']
    employee.lastname = params['lastname']
    employee.position = params['position']
    employee.birthday = params['birthday'] if params[
        'birthday'] != '' and params['birthday'] != 'null' else None
    employee.remote = True if params['remote'] == 'true' else False
    employee.city = params['city']
    employee.street = params['street']
    employee.house = params['house']
    employee.flat = params['flat']

    employee.save()
    return JsonResponse({}, status=201)
Пример #2
0
def register(request):
    if request.method == 'POST':
        user_type = request.POST['user_type']
        first_name = request.POST['first_name']
        last_name = request.POST['last_name']
        username = request.POST['username']
        password = request.POST['password']
        password2 = request.POST['password2']
        email = request.POST['email']
        apartment_no = request.POST['apartment_no']
        street = request.POST['street']
        city = request.POST['city']
        zip_code = request.POST['zip_code']
        age = request.POST['age']
        if (password != password2):
            messages.error(request, 'Password did not match')
            return redirect('register')
        if user_type == 'JobSeeker':
            resume = request.POST['resume']
            jobseekers = Jobseeker.objects.all()
            for jobseeker1 in jobseekers:
                if jobseeker1.username == username:
                    messages.error(
                        request,
                        'This jobseeker exist in the in the system. Choose another username'
                    )
                    return redirect('register')
            jobseeker = Jobseeker()
            jobseeker.username = username
            jobseeker.password = password
            jobseeker.e_mail = email
            jobseeker.name = first_name + ' ' + last_name
            jobseeker.user_type = user_type
            jobseeker.password = password
            jobseeker.password2 = password2
            jobseeker.e_mail = email
            jobseeker.apartment_no = apartment_no
            jobseeker.city = city
            jobseeker.street = street
            jobseeker.zip_code = zip_code
            jobseeker.age = age
            jobseeker.resume = resume
            jobseeker.save()
        if user_type == 'HR':
            company_name = request.POST['company_name']
            hr = HR()
            hr.username = username
            hr.password = password
            hr.e_mail = email
            hr.name = first_name + ' ' + last_name
            hr.user_type = user_type
            hr.apartment_no = apartment_no
            hr.city = city
            hr.street = street
            hr.zip_code = zip_code
            hr.age = age
            hr.company_name = company_name
            hr.save()
        if user_type == 'Employee':
            position = request.POST['position']
            salary = request.POST['salary']
            resume = request.POST['resume']
            employee = Employee()
            employee.username = username
            employee.password = password
            employee.e_mail = email
            employee.name = first_name + ' ' + last_name
            employee.user_type = user_type
            employee.apartment_no = apartment_no
            employee.city = city
            employee.street = street
            employee.zip_code = zip_code
            employee.age = age
            employee.position = position
            employee.salary = salary
            employee.resume = resume
            employee.save()
        messages.success(request, 'Registration Successfull!!')
        return redirect('login')
    else:
        return render(request, 'accounts/register.html')