예제 #1
0
파일: views.py 프로젝트: aw1n/needanerd
def jobList(request, student_id):

    u = get_object_or_404(User, pk=student_id)

    if isStudent(u):
        logger.debug('Found student with user id=%d', u.id)
        joblist = u.userprofile.student.job_set.all()
        msg = 'You have applied to the following positions'
    else:
        joblist = Job.objects.filter(released=True).order_by('-updated_at')

    paginator = Paginator(joblist, 5)  # Show 25 contacts per page

    page = request.GET.get('page')
    try:
        j = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        j = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        j = paginator.page(paginator.num_pages)

    return render_to_response('listjobs.html', {
        'msg': msg,
        'student': u,
        'jobs': j
    },
                              context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: aw1n/needanerd
def jobsearch(request):

    if 'str' in request.GET:
        strval = request.GET['str']

    logger.debug('Search for jobs based up on search string=' + strval)

    #userList=User.objects.filter(groups__name=groups.studentgroupname).filter(Q(first_name__contains=strval) |
    #                                                                          Q(last_name__contains=strval )).order_by('last_name')

    search_args = []
    for term in strval.split():
        for query in ('name__icontains', 'employer__company_name__icontains',
                      'skills__icontains', 'description__icontains'):
            search_args.append(Q(**{query: term}))

    jobList = Job.objects.filter(reduce(operator.or_, search_args))

    js = []
    for job in jobList:
        appliedValue = False
        if isStudent(request.user):
            studentpk = str(request.user.pk)
            if job in request.user.userprofile.student.job_set.all():
                appliedValue = True
        'There is a probably a better way to do this but I am getting tired'
        user = User.objects.select_related().filter(
            userprofile__employer__job__pk=job.pk).get()
        datestr = job.updated_at.strftime('%b')
        datestr = datestr.upper()
        datestr += job.updated_at.strftime(' %d %Y')
        if studentpk:
            obj = JobSearch(jobpk=str(job.pk),
                            studentpk=studentpk,
                            name=job.name,
                            employer=job.employer.company_name,
                            employerpk=user.pk,
                            salary=job.salary,
                            applied=appliedValue,
                            updated_at=datestr)
        else:
            obj = JobSearch(jobpk=str(job.pk),
                            name=job.name,
                            employer=job.employer.company_name,
                            employerpk=user.pk,
                            salary=job.salary,
                            applied=appliedValue,
                            updated_at=datestr)
        js.append(obj)

    logger.debug('Found %s jobs', jobList.count())
    json_serializer = serializers.get_serializer("json")()
    response = json_serializer.serialize(js)
    return HttpResponse(response)
예제 #3
0
def student_profile(request):

    logger.debug("student_profile called")

    if isStudent(request.user):
        logger.debug('user pk=%s', request.user.pk)
        return student_detail(request, request.user.pk)
    else:
        logger.debug(
            'userprofile is neither student nor employer, discuss amongst yourselves'
        )
        return HttpResponseRedirect(reverse_lazy('home'))
예제 #4
0
파일: views.py 프로젝트: aw1n/needanerd
def hasResumeCRUDPriv(request, resume_id):
    
    r = get_object_or_404(Resume, pk=resume_id)
    u = get_object_or_404(User, pk=request.user.pk)
    
    logger.debug('Found user: '******'UNAUTHORIZED: This user is not a student')
            if r1.pk != r.pk:
                logger.debug('r1.pk='+r1.pk+",r.pk="+r.pk)
                return HttpResponseForbidden()

    except:
        logger.debug('r.pk='+str(r.pk) +'!='+str(u.userprofile.student.resume.pk))
        return HttpResponseServerError()
    
    logger.debug('authorized update called');
    return True
예제 #5
0
def editStudentForm(request, student_id):

    logger.debug("editstudentform called")

    u = get_object_or_404(User, pk=student_id)
    if u.pk == request.user.pk and isStudent(u):
        if request.method == 'POST':  # If the form has been submitted...
            logger.debug('request.method == POST')
            form = StudentUserEditForm(
                request.POST, instance=u)  # A form bound to the POST data
            if form.is_valid():  # All validation rules pass
                logger.debug('form.is_valid()==true')
                form.save()
                return HttpResponseRedirect('/students/' + str(u.pk) +
                                            '/')  # Redirect after POST
        else:
            try:
                form = StudentUserEditForm(
                    instance=u,
                    initial={
                        'first_name': u.first_name,
                        'last_name': u.last_name,
                        'email': u.email,
                        'currentmajor': u.userprofile.student.currentmajor
                    })
            except:
                logger.debug('u.email ' + u.userprofile)
                form = StudentUserEditForm(instance=u)

        return render_to_response('editstudent.html', {'form': form},
                                  context_instance=RequestContext(request))
    else:
        response = HttpResponse()
        response.write("You are not authorized to edit this profile")
        response.status_code = 401
        logger.info('Returning a 401 unauthorized')
        logger.info('User: ' + str(request.user.pk) +
                    " tried to edit the student with user id: " + str(u.id))
        return response
예제 #6
0
def jobsearch(request):
    
    if 'str' in request.GET:
        strval = request.GET['str']
            
    logger.debug('Search for jobs based up on search string='+strval)
    
    #userList=User.objects.filter(groups__name=groups.studentgroupname).filter(Q(first_name__contains=strval) |
    #                                                                          Q(last_name__contains=strval )).order_by('last_name')
    
    search_args = []
    for term in strval.split():
        for query in ('name__icontains', 'employer__company_name__icontains', 'skills__icontains', 'description__icontains'):
            search_args.append(Q(**{query: term}))

    jobList = Job.objects.filter(reduce(operator.or_, search_args))
    
    js = []
    for job in jobList:
        appliedValue=False
        if isStudent(request.user):
            studentpk=str(request.user.pk)
            if job in request.user.userprofile.student.job_set.all():
                appliedValue=True
        'There is a probably a better way to do this but I am getting tired'
        user=User.objects.select_related().filter(userprofile__employer__job__pk=job.pk).get()
        datestr=job.updated_at.strftime('%b')
        datestr=datestr.upper()
        datestr+=job.updated_at.strftime(' %d %Y')
        if studentpk:
            obj = JobSearch(jobpk=str(job.pk), studentpk=studentpk, name=job.name, employer=job.employer.company_name, employerpk=user.pk, salary=job.salary, applied=appliedValue, updated_at=datestr)
        else:
            obj = JobSearch(jobpk=str(job.pk), name=job.name, employer=job.employer.company_name, employerpk=user.pk, salary=job.salary, applied=appliedValue, updated_at=datestr)
        js.append(obj)
        
    logger.debug('Found %s jobs',jobList.count())
    json_serializer = serializers.get_serializer("json")()
    response = json_serializer.serialize(js)
    return HttpResponse(response)
예제 #7
0
def jobList(request, student_id):
    
    u = get_object_or_404(User, pk=student_id)
    
    if isStudent(u):
        logger.debug('Found student with user id=%d',u.id)
        joblist = u.userprofile.student.job_set.all()
        msg = 'You have applied to the following positions'
    else:
        joblist = Job.objects.filter(released=True).order_by('-updated_at')
    
    paginator = Paginator(joblist, 5) # Show 25 contacts per page

    page = request.GET.get('page')
    try:
        j = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        j = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        j = paginator.page(paginator.num_pages)

    return render_to_response('listjobs.html', {'msg': msg, 'student': u, 'jobs': j}, context_instance=RequestContext(request))
예제 #8
0
def student_detail(request, student_id):

    logger.debug("student_detail called")

    u = get_object_or_404(User, pk=student_id)
    j = u.userprofile.student.job_set.all()

    logger.debug('Found student with user id=%d', u.id)

    if not isStudent(u):
        'Invalid URL just send them home'
        logger.debug('Invalid URL, just send them home')
        return HttpResponseRedirect(reverse_lazy('home'))

    resumes = Resume.objects.filter(student=u.userprofile.student)[:1]

    if resumes:

        resume = resumes[0]

        #resume = Resume(student=u.userprofile.student)
        #logger.debug('resume.pk='+str(resume.pk))
        degrees = Degree.objects.filter(resume__pk=resume.pk)
        skills = Skill.objects.filter(resume__pk=resume.pk)
        certs = Certification.objects.filter(resume__pk=resume.pk)
        empls = Employment.objects.filter(resume__pk=resume.pk)

        resume_json = serializers.serialize("json", [resume])
        degrees_json = serializers.serialize("json", degrees)
        employers_json = serializers.serialize("json", empls)
        skills_json = serializers.serialize("json", skills)
        certs_json = serializers.serialize("json", certs)
        logger.debug(degrees_json)
        logger.debug('resume str: ' + resume_json)

    msg = request.session.get('msg')
    if msg:
        logger.debug('Message: ' + msg)
        del request.session['msg']
    else:
        logger.debug('No message')

    'Check for LinkedIn Variables'
    error = request.GET.get('error')
    accesscode = request.GET.get('code')

    if u.pk != request.user.pk:

        if resumes:
            return render_to_response('student_detail.html', {
                'msg': msg,
                'student': u,
                'resume': resume_json,
                'jobs': j,
                'degrees': degrees_json,
                'skills': skills_json,
                'certs': certs_json,
                'empls': employers_json
            },
                                      context_instance=RequestContext(request))
        else:
            logger.debug('Resume was not found for the student')
            return render_to_response('student_detail.html', {
                'msg': msg,
                'student': u,
                'jobs': j
            },
                                      context_instance=RequestContext(request))

    if error:

        logger.debug('Error code found: ' + error)
        request.session[
            'msg'] = 'Your login attempt with LinkedIn was unsuccessful: ' + error
        '''
        if u.pk == request.user.pk:
            if resumes:
                return render_to_response('student_detail.html', {'msg':msg,'hasCRUDPrivs': True, 'student': u, 'resume': resume_json, 'jobs': j, 'degrees': degrees_json, 'skills': skills_json, 'certs': certs_json, 'empls': employers_json}, context_instance=RequestContext(request))
            else:
                return render_to_response('student_detail.html', {'msg':msg,'hasCRUDPrivs': True, 'student': u}, context_instance=RequestContext(request))
        else:
            return render_to_response('student_detail.html', {'msg':msg,'student': u, 'resume': resume_json, 'jobs': j, 'degrees': degrees_json, 'skills': skills_json, 'certs': certs_json, 'empls': employers_json}, context_instance=RequestContext(request))
        '''
        return HttpResponseRedirect(reverse_lazy('profile'))

    elif accesscode:

        logger.debug('authorization code found ' + accesscode)
        logger.debug(
            'Request Access Token by exchanging the authorization_code for it')

        conn = httplib.HTTPSConnection(settings.LINKED_IN_URL)

        context = "/uas/oauth2/accessToken?grant_type=authorization_code&code=" + accesscode + "&redirect_uri=" + settings.HOST + "" + request.path + "&client_id=" + settings.LINKED_IN_API_KEY + "&client_secret=" + settings.LINKED_IN_SECRET_KEY
        logger.debug('context=' + context)
        #conn.putrequest("POST", context)
        #'Python bug, httplib should be auto calculating the content-length but its not, so we are setting it to 0'
        #header = {'content-length' : '0'}
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        #conn.putheader(header)
        #conn.endheaders()
        #conn.set_debuglevel(1)
        #conn.send("")
        conn.request("POST", context, '', headers)

        'Expecting a JSON response'
        responsestr = conn.getresponse().read()
        logger.debug('response=' + responsestr)

        responseJSON = json.loads(responsestr)
        oauth2_access_token = responseJSON['access_token']
        logger.debug('access token=' + oauth2_access_token)

        logger.debug('Populate LinkedIn Data...')
        conn = httplib.HTTPSConnection(settings.LINKED_IN_API_URL)

        fieldselectors = "id,first-name,last-name,email-address,industry,summary,positions,educations,skills,certifications"

        context = "/v1/people/~:(" + fieldselectors + ")?oauth2_access_token=" + oauth2_access_token
        logger.debug('context=' + context)
        conn.request("GET", context)
        response = conn.getresponse()
        respstr = response.read()
        logger.debug('Status=' + str(response.status) + ", Reason=" +
                     response.reason)
        logger.debug('Response=' + respstr)

        'Delete previous data, we are not syncing with LinkedIn...'
        if resumes:
            logger.debug('Deleting previous employments')
            Employment.objects.filter(resume=resumes[0]).delete()

            logger.debug('Deleting previous certifications')
            Certification.objects.filter(resume=resumes[0]).delete()

            logger.debug('Deleting previous degrees')
            Degree.objects.filter(resume=resumes[0]).delete()

            logger.debug('Deleting previous skills')
            Skill.objects.filter(resume=resumes[0]).delete()

            logger.debug(
                'Deleting previous resumes, we are now syncing with LinkedIn')
            Resume.objects.filter(student=u.userprofile.student).delete()

        tree = ElementTree.fromstring(respstr)
        if tree is None:
            logger.debug("Tree is not valid!!!")
            return HttpResponseRedirect(reverse_lazy('home'))
        '''Create new resume'''
        logger.debug('Creating new resume...')
        r = Resume()

        r.objective = tree.find("summary").text
        logger.debug('Adding new summary: ' + tree.find("summary").text)
        r.student = u.userprofile.student
        r.save()
        logger.debug('r.objective: ' + r.objective)
        '''Create new work history'''
        positions = tree.findall('positions/position')
        empls = []
        for p in positions:

            logger.debug('Adding position...')

            company = p.find("company/name")
            summary = p.find("summary")
            title = p.find("title")
            startyear = p.find("start-date/year")
            startmonth = p.find("start-date/month")
            iscurrent = p.find("is-current")
            endyear = p.find("end-date/year")
            endmonth = p.find("end-date/month")

            e = Employment()
            e.resume = r
            if company is not None and company.text is not None:
                e.company = company.text
            if title is not None and title.text is not None:
                e.title = title.text
            if summary is not None and summary.text is not None:
                e.jobfunctions = summary.text
            startdate = ""
            if startmonth is not None and startmonth.text is not None:
                startdate += startmonth.text
            if startyear is not None and startyear.text is not None:
                startdate += "/"
                startdate += startyear.text
            e.startdate = startdate
            enddate = ""
            if endmonth is not None and endmonth.text is not None:
                enddate += endmonth.text
            if endyear is not None and endyear.text is not None:
                enddate += "/"
                enddate += endyear.text
            e.enddate = enddate

            e.save()
            empls.append(e)
        '''Create new education history'''
        educations = tree.findall('educations/education')
        degrees = []
        for e in educations:

            logger.debug('Adding degree...')

            degree = e.find("degree")
            major = e.find("field-of-study")
            univ = e.find("school-name")
            endyear = e.find("end-date/year")

            d = Degree()
            d.resume = r
            if degree is not None and degree.text is not None:
                d.degreetype = degree.text
            if major is not None and major.text is not None:
                logger.debug('major.text=' + major.text)
                d.major = major.text
            if univ is not None and univ.text is not None:
                d.university = univ.text
            if endyear is not None and endyear.text is not None:
                d.date = endyear.text
            d.save()
            degrees.append(d)
        '''Create new skillset'''
        skills = tree.findall('skills/skill')
        skillsarr = []
        for s in skills:

            skill = s.find("skill/name")
            if skill is not None and skill.text is not None:
                s = Skill()
                s.resume = r
                s.skill = skill.text
                logger.debug('Adding skill...')
                s.save()
                skillsarr.append(s)
        '''Create new certifications'''
        certs = tree.findall('certifications/certification')
        certsarr = []
        for c in certs:

            logger.debug('Adding certificate...')

            cert = c.find("name")
            if cert is not None and cert.text is not None:
                c = Certification()
                c.resume = r
                c.name = cert.text
                logger.debug('Adding cert...')
                c.save()
                certsarr.append(c)

        resume_json = serializers.serialize("json", [r])
        degrees_json = serializers.serialize("json", degrees)
        employers_json = serializers.serialize("json", empls)
        skills_json = serializers.serialize("json", skillsarr)
        certs_json = serializers.serialize("json", certsarr)
        logger.debug('resume str: ' + resume_json)

        #msg = "Successfully synced with LinkedIn!"
        request.session['msg'] = 'Successfully synced with LinkedIn!'
        return HttpResponseRedirect(reverse_lazy('profile'))

        #return render_to_response('student_detail.html', {'msg':msg, 'hasCRUDPrivs': True, 'student': u, 'resume': resume_json, 'jobs': j, 'degrees': degrees_json, 'skills': skills_json, 'certs': certs_json, 'empls': employers_json}, context_instance=RequestContext(None))

    else:
        '''
        #reviewList=StudentReview.objects.select_related().filter(student__pk=u.userprofile.student.pk).order_by('-created_at')
        paginator = Paginator(None, 5) # Show 25 contacts per page
    
        page = request.GET.get('page')
        
        try:
            reviews = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            reviews = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            reviews = paginator.page(paginator.num_pages)
        
        try:
            r=u.userprofile.student.resume    
            logger.debug('Found Resume with pk %s for this student',r.pk)
            return render_to_response('student_detail.html', {'student': u, 'resume': r, 'jobs': j, 'reviews': reviews}, context_instance=RequestContext(request))
        except ObjectDoesNotExist:
            logger.debug('Resume was not found for the student')
            return render_to_response('student_detail.html', {'student': u, 'jobs': j, 'reviews': reviews}, context_instance=RequestContext(request))
        '''

        if resumes:
            return render_to_response('student_detail.html', {
                'msg': msg,
                'hasCRUDPrivs': True,
                'student': u,
                'resume': resume_json,
                'jobs': j,
                'degrees': degrees_json,
                'skills': skills_json,
                'certs': certs_json,
                'empls': employers_json
            },
                                      context_instance=RequestContext(request))
        else:
            logger.debug('Resume was not found for the student')
            return render_to_response('student_detail.html', {
                'msg': msg,
                'hasCRUDPrivs': True,
                'student': u,
                'jobs': j
            },
                                      context_instance=RequestContext(request))
예제 #9
0
def updateStudent(request, student_id):

    logger.debug('updateStudent called')

    u = get_object_or_404(User, pk=student_id)
    logger.debug('Found student with user id=%d', u.id)

    if not isStudent(u) or request.user.pk != u.pk:
        response = HttpResponse()
        response.write("You are not authorized to make this change")
        response.status_code = 401
        logger.debug('Returning a 401 unauthorized')
        return response

    if 'major' in request.POST:
        currentmajor = request.POST['major']
        logger.debug('received new major value of: ' + currentmajor)
        if currentmajor != u.userprofile.student.currentmajor:
            u.userprofile.student.currentmajor = currentmajor
            u.userprofile.student.save()
    else:
        logger.debug('no updates to currentmajor')

    email = request.POST.get('email')
    if 'email' in request.POST:
        logger.debug('received new email value of: ' + email)
        from django.core.exceptions import ValidationError
        from django.core.validators import validate_email
        try:
            validate_email(email)
        except ValidationError:
            logger.debug("This email address did not pass the validator")
            response = HttpResponse()
            response.write("This email address is invalid")
            response.status_code = 500
            logger.info('Returning a 500')
            logger.info('User: '******'Returning a 500')
                logger.info('User: '******'Confirm Email Change'
            message = "Please confirm this new email address within the next 48 hours\n\n"
            message += settings.HOST
            message += "/accounts/confirm/email/"
            message += activation_key
            recipients = [email]

            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                      recipients)

            u.save()
    else:
        logger.debug('no updates to email')

    response = serializers.serialize("json", [u])

    return HttpResponse(response, content_type="application/json")
예제 #10
0
def user_delete(request, user_id):
    
    logger.debug('Attempting to delete user with pk='+user_id)
    user=get_object_or_404(User, pk=user_id)
    
    if int(request.user.pk) != int(user_id):
        logger.debug('request.user.pk='+str(request.user.pk))
        logger.debug('user_id='+str(user_id))
        return render_to_response('userdelete.html', {'wrongpk': True}, context_instance=RequestContext(request))
    if isStudent(user):
        
        resumes=Resume.objects.filter(student=user.userprofile.student)[:1]
            
        if resumes:
        
            resume=resumes[0]
            resume.delete()
                      
        try:
            user.userprofile.student
            user.userprofile.student.delete()
        except ObjectDoesNotExist:        
            logger.debug('No student was object was linked to this user profile')
        
        try:
            user.userprofile
            user.userprofile.delete()
        except ObjectDoesNotExist:        
            logger.debug('No user profile was found')
        
        user.delete()
        
        return render_to_response('userdelete.html', {'student': True}, context_instance=RequestContext(request))
    
    elif isEmployer(user):
        
        try:
            user.userprofile.employer.job_set.all()
            user.userprofile.employer.job_set.all().delete()
        except ObjectDoesNotExist:      
            logger.debug('No jobs were found for this employer')
        
        try:
            user.userprofile.employer
            user.userprofile.employer.delete()        
        except ObjectDoesNotExist:        
            logger.debug('No employer was object was linked to this user profile')
        
        try:
            user.userprofile
            user.userprofile.delete()
        except ObjectDoesNotExist:        
            logger.debug('No user profile was found')
        
        user.delete()
        return render_to_response('userdelete.html', {'employer': True}, context_instance=RequestContext(request))
    elif isAdmin(user):
        user.userprofile.delete()
        user.delete()
        return render_to_response('userdelete.html', {'admin': True}, context_instance=RequestContext(request))
    else:
        return render_to_response('userdelete.html', {'error': True}, context_instance=RequestContext(request))
예제 #11
0
def user_delete(request, user_id):

    logger.debug('Attempting to delete user with pk=' + user_id)
    user = get_object_or_404(User, pk=user_id)

    if int(request.user.pk) != int(user_id):
        logger.debug('request.user.pk=' + str(request.user.pk))
        logger.debug('user_id=' + str(user_id))
        return render_to_response('userdelete.html', {'wrongpk': True},
                                  context_instance=RequestContext(request))
    if isStudent(user):

        resumes = Resume.objects.filter(student=user.userprofile.student)[:1]

        if resumes:

            resume = resumes[0]
            resume.delete()

        try:
            user.userprofile.student
            user.userprofile.student.delete()
        except ObjectDoesNotExist:
            logger.debug(
                'No student was object was linked to this user profile')

        try:
            user.userprofile
            user.userprofile.delete()
        except ObjectDoesNotExist:
            logger.debug('No user profile was found')

        user.delete()

        return render_to_response('userdelete.html', {'student': True},
                                  context_instance=RequestContext(request))

    elif isEmployer(user):

        try:
            user.userprofile.employer.job_set.all()
            user.userprofile.employer.job_set.all().delete()
        except ObjectDoesNotExist:
            logger.debug('No jobs were found for this employer')

        try:
            user.userprofile.employer
            user.userprofile.employer.delete()
        except ObjectDoesNotExist:
            logger.debug(
                'No employer was object was linked to this user profile')

        try:
            user.userprofile
            user.userprofile.delete()
        except ObjectDoesNotExist:
            logger.debug('No user profile was found')

        user.delete()
        return render_to_response('userdelete.html', {'employer': True},
                                  context_instance=RequestContext(request))
    elif isAdmin(user):
        user.userprofile.delete()
        user.delete()
        return render_to_response('userdelete.html', {'admin': True},
                                  context_instance=RequestContext(request))
    else:
        return render_to_response('userdelete.html', {'error': True},
                                  context_instance=RequestContext(request))