Esempio n. 1
0
def homepage(request):
    if request.method == 'POST':
        Resume.objects.all().delete()
        file_form = UploadResumeModelForm(request.POST, request.FILES)
        files = request.FILES.getlist('resume')
        resumes_data = []
        competencies = []
        measurable_results = []
        if file_form.is_valid():
            for file in files:
                try:
                    # saving the file
                    resume = Resume(resume=file)
                    resume.save()

                    # extracting resume entities
                    parser = resume_parser.ResumeParser(
                        os.path.join(settings.MEDIA_ROOT, resume.resume.name))
                    data = parser.get_extracted_data()
                    resumes_data.append(data)
                    resume.name = data.get('name')
                    resume.email = data.get('email')
                    resume.mobile_number = data.get('mobile_number')
                    # resume.education     = '\n'.join(data.get('education'))
                    resume.education = get_education(data.get('education'))
                    resume.skills = ', '.join(data.get('skills'))
                    resume.experience = ', '.join(data.get('experience'))
                    competencies.append(data.get('competencies'))
                    measurable_results.append(data.get('measurable_results'))
                    resume.save()
                except IntegrityError:
                    messages.warning(request, 'Duplicate resume found:',
                                     file.name)
                    return redirect('homepage')
            resumes = Resume.objects.all()
            messages.success(request, 'Resumes uploaded!')
            if competencies:
                context = {
                    'resumes': resumes,
                    'competencies': competencies,
                    'measurable_results': measurable_results,
                    'no_of_pages': data.get('no_of_pages'),
                    'total_experience': data.get('total_experience'),
                }
            else:
                context = {
                    'resumes': resumes,
                    'competencies': [],
                    'measurable_results': []
                }
            return render(request, 'base.html', context)
    else:
        form = UploadResumeModelForm()
    return render(request, 'base.html', {'form': form})
Esempio n. 2
0
def homepage(request):
    if request.method == 'POST':
        user = User.objects.get(id=1)
        UserDetails.objects.filter(user=user).delete()
        Competencies.objects.filter(user=user).delete()
        MeasurableResults.objects.filter(user=user).delete()
        Resume.objects.filter(user=user).delete()
        ResumeDetails.objects.filter(resume__user=user).delete()
        file_form = UploadResumeModelForm(request.POST, request.FILES)
        files = request.FILES.getlist('resume')
        if file_form.is_valid():
            for file in files:
                try:
                    user = User.objects.get(id=1)

                    # saving the file
                    resume = Resume(user=user, resume=file)
                    resume.save()
                    
                    # extracting resume entities
                    parser = resume_parser.ResumeParser(os.path.join(settings.MEDIA_ROOT, resume.resume.name))
                    data = parser.get_extracted_data()
                    
                    # User Details
                    # resume.name          = data.get('name')
                    # resume.email         = data.get('email')
                    # resume.education     = get_education(data.get('education'))
                    user_details = UserDetails()
                    user_details.user           = user
                    user_details.name           = data.get('name')
                    user_details.email          = data.get('email')
                    user_details.mobile_number  = data.get('mobile_number')
                    user_details.skills         = ', '.join(data.get('skills'))
                    user_details.years_of_exp   = data.get('total_experience')
                    user_details.save()

                    for comp in data.get('competencies'):
                        competencies = Competencies()
                        competencies.user       = user
                        competencies.competency = comp
                        competencies.save()

                    for mr in data.get('measurable_results'):
                        measurable_results                   = MeasurableResults()
                        measurable_results.user              = user
                        measurable_results.measurable_result = mr
                        measurable_results.save()

                    # Resume Details
                    resume_details          = ResumeDetails()
                    resume_details.resume   = resume
                    resume_details.page_nos = data.get('no_of_pages')
                    resume_details.save()

                    # resume.experience    = ', '.join(data.get('experience'))
                    # measurable_results.append(data.get('measurable_results'))
                    # resume.save()
                except IntegrityError:
                    messages.warning(request, 'Duplicate resume found:', file.name)
                    return redirect('homepage')

            resumes = Resume.objects.filter(user=User.objects.get(id=1))
            user_detail = UserDetails.objects.get(user=user)
            messages.success(request, 'Resumes uploaded!')

            overall_score = 0

            competencies = data.get('competencies')
            measurable_results = data.get('measurable_results')

            if competencies and measurable_results:
                overall_score = competencies.get('score') + measurable_results.get('score')
            
            if competencies:
                context = {
                    'resumes': resumes,
                    'competencies': competencies,
                    'measurable_results': measurable_results,
                    'no_of_pages': data.get('no_of_pages'),
                    'total_experience': data.get('total_experience'),
                    'user_details': user_detail,
                    'overall_score': overall_score
                    }
            else:
                context = {
                    'resumes': resumes,
                    'competencies': [],
                    'measurable_results': [],
                    'no_of_pages': data.get('no_of_pages'),
                    'total_experience': data.get('total_experience'),
                    'user_details': user_detail,
                    'overall_score': overall_score
                    }
            return render(request, 'base.html', context)
    else:
        form = UploadResumeModelForm()
    return render(request, 'base.html', {'form': form})
Esempio n. 3
0
def upload_resume(request):
    request_data            = request.data.dict()
    file_data               = request_data.get('file')
    data                    = eval(request_data.get('signUpDetails'))
    location                = data.get('location')
    desired_job_position    = data.get('desired_job_position')
    designation             = data.get('designation')
    email                   = data.get('email')
    password                = data.get('password1')

    path = default_storage.save(os.path.join(settings.MEDIA_ROOT, file_data.name), ContentFile(file_data.read()))
    parser = resume_parser.ResumeParser(path)
    parsed_data = parser.get_extracted_data()
    try:
        data = {
            'email': email,
            'username': email,
            'password1': password,
            'password2': password,
            }
    except KeyError:
        pass

    response = requests.post("http://localhost:8000/rest-auth/registration/", data=data)
    data = response.json()

    if response.status_code != 400:
        user_id = Token.objects.get(key=data['key']).user_id
        context = {
            'user_id': user_id,
            'token': data['key'],
            'parsed_data': parsed_data
        }
        user = User.objects.get(id=user_id)

        # User Details
        user_details      = UserDetails()
        user_details.user = user
        user_details.name = parsed_data.get('name')
        user_details.email = parsed_data.get('email')
        user_details.skills = parsed_data.get('skills')
        user_details.mobile_number = parsed_data.get('mobile_number')
        user_details.years_of_exp = parsed_data.get('years_of_exp')
        user_details.save()

        # Competencies
        if data.get('competencies'):
            for comp in data.get('competencies'):
                competencies = Competencies()
                competencies.user       = user
                competencies.competency = comp
                competencies.save()

        # Measurable Results
        if data.get('measurable_results'):
            for mr in data.get('measurable_results'):
                measurable_results                   = MeasurableResults()
                measurable_results.user              = user
                measurable_results.measurable_result = mr
                measurable_results.save()

        # Resume
        resume                  = Resume()
        resume.user             = user
        resume.resume           = path
        resume.save()

        # Resume Details
        resume_details          = ResumeDetails()
        resume_details.resume   = resume
        resume_details.page_nos = data.get('no_of_pages')
        resume_details.save()
    else:
        context = data
    return Response(context)
Esempio n. 4
0
def homepage(request):
    if request.method == 'POST':
        user = User.objects.get(id=1)
        UserDetails.objects.filter(user=user).delete()
        Competencies.objects.filter(user=user).delete()
        MeasurableResults.objects.filter(user=user).delete()
        Resume.objects.filter(user=user).delete()
        ResumeDetails.objects.filter(resume__user=user).delete()
        file_form = UploadResumeModelForm(request.POST, request.FILES)
        files = request.FILES.getlist('resume')
        if file_form.is_valid():
            for file in files:
                try:
                    user = User.objects.get(id=1)

                    # saving the file
                    resume = Resume(user=user, resume=file)
                    resume.save()

                    # extracting resume entities
                    parser = resume_parser.ResumeParser(
                        os.path.join(settings.MEDIA_ROOT, resume.resume.name))
                    data = parser.get_extracted_data()

                    # User Details
                    # resume.name          = data.get('name')
                    # resume.email         = data.get('email')
                    #resume.education     = get_education(data.get('education'))
                    user_details = UserDetails()
                    user_details.user = user
                    user_details.name = data.get('name')
                    user_details.email = data.get('email')
                    user_details.mobile_number = data.get('mobile_number')
                    user_details.skills = ', '.join(data.get('skills'))
                    user_details.years_of_exp = data.get('total_experience')
                    user_details.education = data.get('education')
                    user_details.save()

                    for comp in data.get('competencies'):
                        competencies = Competencies()
                        competencies.user = user
                        competencies.competency = comp
                        competencies.save()

                    for mr in data.get('measurable_results'):
                        measurable_results = MeasurableResults()
                        measurable_results.user = user
                        measurable_results.measurable_result = mr
                        measurable_results.save()

                    # Resume Details
                    resume_details = ResumeDetails()
                    resume_details.resume = resume
                    resume_details.page_nos = data.get('no_of_pages')
                    resume_details.save()

                    # resume.experience    = ', '.join(data.get('experience'))
                    # measurable_results.append(data.get('measurable_results'))
                    # resume.save()
                except IntegrityError:
                    messages.warning(request, 'Duplicate resume found:',
                                     file.name)
                    return redirect('homepage')

            resumes = Resume.objects.filter(user=User.objects.get(id=1))
            user_detail = UserDetails.objects.get(user=user)
            messages.success(request, 'Resumes uploaded!')

            overall_score = 0

            competencies = data.get('competencies')
            measurable_results = data.get('measurable_results')

            if competencies and measurable_results:
                overall_score = competencies.get(
                    'score') + measurable_results.get('score')

            if competencies:
                context = {
                    'resumes': resumes,
                    'competencies': competencies,
                    'measurable_results': measurable_results,
                    'no_of_pages': data.get('no_of_pages'),
                    'total_experience': data.get('total_experience'),
                    'user_details': user_detail,
                    'overall_score': overall_score,
                    'education': data.get('education'),
                    'designation': data.get('designation')
                }
            else:
                context = {
                    'resumes': resumes,
                    'competencies': [],
                    'measurable_results': [],
                    'no_of_pages': data.get('no_of_pages'),
                    'total_experience': data.get('total_experience'),
                    'user_details': user_detail,
                    'overall_score': overall_score,
                    'education': data.get('education'),
                    'designation': data.get('designation')
                }

            db = MySQLdb.connect("localhost", "root", "1234", "parser")
            cursor = db.cursor()
            sql = """INSERT INTO resume(File, Name, Email, Mobile, Designation, Education, Skills, Experience) VALUES ('{file}','{name}','{email}','{mobile}','{designation}','{education}','{skills}','{experience}')"""
            name = data.get("name")
            email = data.get('email')
            mobile = data.get('mobile_number') if (
                data.get('mobile_number')) else 0
            designation = data.get('designation')
            education = data.get('education')
            skills = ""
            experience = data.get('total_experience')

            for i in data.get('skills'):
                skills += i
            sql = sql.format(file=file,
                             name=name,
                             email=email,
                             mobile=mobile,
                             designation=designation,
                             education=education,
                             skills=skills,
                             experience=experience)
            cursor.execute(sql)
            db.commit()
            return render(request, 'base.html', context)
    else:
        form = UploadResumeModelForm()
    return render(request, 'base.html', {'form': form})