Exemple #1
0
 def clean_resume(self):
     if self.cleaned_data['resume']:
         # Read resume to a file
         resume_file_contents = self.cleaned_data['resume']
         resume_test_file_name = get_resume_filename(self.instance, "")
         resume_file = open("%s%s" % (s.MEDIA_ROOT, resume_test_file_name), "wb")
         resume_file.write(resume_file_contents.read())
         resume_file.close()
         
         # File size check
         if os.path.getsize("%s%s" % (s.MEDIA_ROOT, resume_test_file_name)) > s.MAX_RESUME_SIZE:
             max_resume_size = s.MAX_RESUME_SIZE/1024/1024
             raise forms.ValidationError(_(m.resume_file_size % max_resume_size))
         resume_file = open("%s%s" % (s.MEDIA_ROOT, resume_test_file_name), "rb")
         
         # Check that PdfFileReader can read the file
         try:
             PdfFileReader(resume_file)
         except Exception as e:
             raise forms.ValidationError(_(m.resume_file_problem))
         
         # Check that there are less than 3k keywords
         keywords, num = extract_resume_keywords(resume_test_file_name)
         if num > s.MAX_RESUME_KEYWORDS:
             raise forms.ValidationError(_(m.resume_has_too_many_words))
     return self.cleaned_data['resume']
Exemple #2
0
    def clean_resume(self):
        if self.cleaned_data['resume']:
            # Read resume to a file
            resume_file_contents = self.cleaned_data['resume']
            resume_test_file_name = get_resume_filename(self.instance, "")
            resume_file = open("%s%s" % (s.MEDIA_ROOT, resume_test_file_name),
                               "wb")
            resume_file.write(resume_file_contents.read())
            resume_file.close()

            # File size check
            if os.path.getsize(
                    "%s%s" %
                (s.MEDIA_ROOT, resume_test_file_name)) > s.MAX_RESUME_SIZE:
                max_resume_size = s.MAX_RESUME_SIZE / 1024 / 1024
                raise forms.ValidationError(
                    _(m.resume_file_size % max_resume_size))
            resume_file = open("%s%s" % (s.MEDIA_ROOT, resume_test_file_name),
                               "rb")

            # Check that PdfFileReader can read the file
            try:
                PdfFileReader(resume_file)
            except Exception as e:
                raise forms.ValidationError(_(m.resume_file_problem))

            # Check that there are less than 3k keywords
            keywords, num = extract_resume_keywords(resume_test_file_name)
            if num > s.MAX_RESUME_KEYWORDS:
                raise forms.ValidationError(_(m.resume_has_too_many_words))
        return self.cleaned_data['resume']
Exemple #3
0
def student_quick_registration(request, form_class=StudentQuickRegistrationForm, extra_context=None):
    context = {}
    if request.method == "POST":
        data = {}
        form = form_class(data=request.POST, files=request.FILES)
        if form.is_valid():
            pdf_file_path = "student/student/quick_reg_resume_%s.pdf" %(datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S'))
            handle_uploaded_file(request.FILES['resume'], "%s%s" % (s.MEDIA_ROOT, pdf_file_path))
            
            # process_resume_data returns either an error or the keywords
            keywords, num =  extract_resume_keywords(pdf_file_path)
            
            # If the resume is not unparsable, then resume_parsing_results
            # contains the keywords
            if num == 0:
                data['unparsable_resume'] = True

            user_info =  {'username': request.POST['email'],
                          'first_name': request.POST['first_name'],
                          'last_name': request.POST['last_name'],
                          'email': request.POST['email'],
                          'password': request.POST['password']}
            student = register_student(request, **user_info)
            student.degree_program = DegreeProgram.objects.get(id=request.POST['degree_program'])
            student.graduation_month = request.POST['graduation_month']
            student.graduation_year = GraduationYear.objects.get(id=request.POST['graduation_year'])
            student.first_major = Course.objects.get(id=request.POST['first_major'])
            student.gpa = request.POST['gpa']
            file_content = file("%s%s" % (s.MEDIA_ROOT, pdf_file_path), "rb")
            student.resume.save(request.FILES['resume'].name, File(file_content))
            
            if keywords:
                student.keywords = keywords
            student.profile_created = True
            student.save()
            for attendee in Attendee.objects.filter(email=student.user.email):
                attendee.student = student
                attendee.save()
            event = Event.objects.get(id=request.POST['event_id'])
            action = request.POST['action']
            DroppedResume.objects.create(student=student, event=event)
            if action == "rsvp":
                RSVP.objects.create(student=student, event=event)
        else:
            data['errors'] = form.errors
        return HttpResponse(simplejson.dumps(data), mimetype="text/html")
    if not request.GET.has_key('event_id'):
        raise Http400("Request GET is missing the event_id.")
    if not request.GET.has_key('action'):
        raise Http400("Request GET is missing the action.")
    context['form'] = form_class(initial={'event_id':request.GET['event_id'], 'action':request.GET['action']})
    action = request.GET['action']
    if action=="rsvp":
        context['action'] = "RSVP"
    elif action=="drop":
        context['action'] = "drop resume"
    context.update(extra_context or {})
    return context
Exemple #4
0
def student_update_resume(request, form_class=StudentUpdateResumeForm):
    form = form_class(data=request.POST, files=request.FILES, instance=request.user.student)
    if form.is_valid():
        form.save()
        data = {}
        student = request.user.student 
        keywords, num = extract_resume_keywords(student.resume.name)
        if num == 0:
            data['unparsable_resume'] = True
        data['num_of_extracted_keywords'] = num
        student.keywords = keywords
        student.last_updated = datetime.datetime.now()
        student.save()
        return HttpResponse(simplejson.dumps(data), mimetype="application/json")
    else:
        data = {'errors': form.errors }
        return HttpResponse(simplejson.dumps(data), mimetype="application/json")
Exemple #5
0
def student_profile(request, form_class=StudentProfileForm, extra_context=None):
    if request.method == 'POST':
        form = form_class(data=request.POST, files=request.FILES, instance=request.user.student)
        if form.is_valid():
            student = form.save()
            if form.cleaned_data['sat_w'] != None and form.cleaned_data['sat_m'] != None and form.cleaned_data['sat_v'] != None:
                student.sat_t = int(form.cleaned_data['sat_w']) + int(form.cleaned_data['sat_v']) + int(form.cleaned_data['sat_m'])
            else:
                student.sat_t = None
            data = {'valid':True, 'unparsable_resume':False}
            if request.FILES.has_key('resume'):
                keywords, num = extract_resume_keywords(request.user.student.resume.name)
                student.keywords = keywords
                student.last_update = datetime.datetime.now()
                student.profile_created = True
                if num==0 and request.POST['ignore_unparsable_resume'] == "false":
                    data['unparsable_resume'] = True
                student.save()
                for a in Attendee.objects.filter(email=student.user.email):
                    a.student = student
                    a.save()
        else:
            data = {'errors':form.errors}
        return HttpResponse(simplejson.dumps(data), mimetype="text/html")
    else:
        form = form_class(instance=request.user.student)
        context = { 'form' : form,
                    'max_resume_size' : s.MAX_RESUME_SIZE,
                    'edit' : request.user.student.profile_created,
                    'industries_of_interest_max' : s.SP_MAX_INDUSTRIES_OF_INTEREST,
                    'campus_involvement_max': s.SP_MAX_CAMPUS_INVOLVEMENT,
                    'languages_max':s.SP_MAX_LANGUAGES,
                    'countries_of_citizenship_max':s.SP_MAX_COUNTRIES_OF_CITIZENSHIP,
                    'previous_employers_max':s.SP_MAX_PREVIOUS_EMPLOYERS,
                    'max_industries':s.EP_MAX_INDUSTRIES}
        context.update(extra_context or {})
        return context
Exemple #6
0
 def handle(self, *args, **options):
     try:
         unparsable_resumes = []
         
         students = Student.objects.filter(profile_created=True, user__is_active=True)
         if not options["all"]:
             if args:
                 students = students.filter(user__email__in = args)
             else:
                 students = students.filter(Q(keywords=None) | Q(keywords=""))
         for student in students:
             name = "%s %s" % (student.first_name, student.last_name)
             if options['dry']:
                 print name
             else:
                 keywords, num = extract_resume_keywords(student.resume.name)
                 student.keywords = keywords
                 student.save()
                 if not keywords:
                     unparsable_resumes.append(name)
         if unparsable_resumes:
             print "Unparsable resumes: %s" % (", ".join(unparsable_resumes))
     except Exception as e:
         print e