예제 #1
0
 def authenticate(self, request):
     result = super(ProfessionalAuthentication, self).authenticate(request)
     if result is not None:
         user = result[0]
         if is_professional(user):
             return result
     return None
예제 #2
0
파일: api_misc.py 프로젝트: apanik/JobXprss
    def post(self, request, *args, **kwargs):
        if request.user.is_authenticated and is_professional(request.user):
            current_user_id = request.user.id
            pro_id = Professional.objects.get(user_id=current_user_id).id
        else:
            resp = profile_create_with_user_create(request._request)
            if resp.data["code"] == 500:
                return resp
            current_user_id = resp.data["result"]['user']['user_id']
            user = User.objects.get(id=current_user_id)
            user.is_active = True
            user.save()
            pro_id = resp.data["result"]['user']['professional_id']
            request.user.id = current_user_id
        req_data = request.data.copy()
        req_data['pro'] = pro_id
        populate_user_info_querydict(request, req_data, False, False)
        job_application_serializer = JobApplySerializer(data=req_data)
        if job_application_serializer.is_valid():
            job_application_serializer.save()
            # TODO
            # save_recent_activity(request.user.id, 'apply', 'Job applied')
            job = Job.objects.select_related('company__user').get(job_id=request.data["job"])
            applied_job_counter(job)

            save_recent_activity(request.user.id, 'apply_pro', )
            if job.company.user_id:
                save_recent_activity(job.company.user_id, 'apply_com')

            return Response(job_application_serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(job_application_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #3
0
파일: api_auth.py 프로젝트: apanik/JobXprss
def professional_signin(request):
    email = request.data['email']
    password = request.data['password']

    try:
        user = User.objects.get(email=email)
        if not user.is_active:
            raise AuthenticationFailed(INACTIVE_USER)
        elif not check_password(password, user.password):
            raise AuthenticationFailed(INCORRECT_PASSWORD)
        elif not is_professional(user):
            raise AuthenticationFailed()
    except User.DoesNotExist:
        raise AuthenticationFailed(NO_SUCH_USER)

    if 'device_id' in request.data and request.data['device_id']:
        RefreshToken.lifetime = DEVICE_REFRESH_TOKEN_LIFETIME
        AccessToken.lifetime = DEVICE_ACCESS_TOKEN_LIFETIME
    else:
        RefreshToken.lifetime = WEB_REFRESH_TOKEN_LIFETIME
        AccessToken.lifetime = WEB_ACCESS_TOKEN_LIFETIME

    token = RefreshToken.for_user(user)
    data = {}
    data['username'] = user.username
    data['access'] = str(token.access_token)
    data['refresh'] = str(token)

    pro = Professional.objects.get(user_id=user.id)
    data['user'] = {'id': user.id, 'email': email, 'type': 'professional'}
    data['pro'] = ProfessionalSerializer(pro, many=False).data
    data['token_lifetime'] = SIMPLE_JWT
    return Response(data)
예제 #4
0
def recent_jobs(request, limit:int = 6):
    if request.user.is_authenticated and is_professional(request.user):
        current_user_id = request.user.id
    else:
        current_user_id = 0

    queryset = Job.objects.annotate(
        applied = FilteredRelation(
            'applied_jobs', condition=Q(applied_jobs__created_by=current_user_id)
        )
    ).annotate(
        favourite = FilteredRelation(
            'fav_jobs', condition=Q(fav_jobs__created_by=current_user_id)
        )
    ).filter(
        is_archived=False,
        status='Published',
    ).select_related('company'
                     ).annotate(is_favourite=Count('favourite')
                                ).annotate(is_applied=Count('applied')
                                           ).annotate(applied_at=Max('applied__created_at')
                                                      ).annotate(favourite_at=Max('favourite__created_at')
                                                                 ).order_by('-post_date')[:limit]

    data = JobSerializer(queryset, many=True).data
    return Response(data)
예제 #5
0
    def post(self, request):
        payload = {
            'access_token': request.data.get("token")
        }  # validate the token
        r = requests.get('https://www.googleapis.com/oauth2/v2/userinfo',
                         params=payload)
        data = json.loads(r.text)

        if 'error' in data:
            content = {
                'message':
                'wrong google token / this google token is already expired.'
            }
            return Response(content)
        pro = Professional.objects.filter(email=data['email']).first()
        # create user if not exist
        try:
            user = User.objects.get(email=data['email'])
            if not is_professional(user):
                raise AuthenticationFailed()
        except User.DoesNotExist:
            user = User()
            user.username = data['email']
            # provider random default password
            user.password = make_password(
                BaseUserManager().make_random_password())
            user.email = data['email']
            user.is_active = 1
            user.save()
            pro_group = Group.objects.get(name='Professional')
            user.groups.add(pro_group)

            if not pro:
                pro = Professional(full_name=data['name'],
                                   email=data['email'],
                                   password=user.password,
                                   terms_and_condition_status=1)
                pro.user_id = user.id
                pro.created_by = user.id
                pro.created_from = get_user_address(request)
                pro.job_alert_status = True
                pro.save()

        token = RefreshToken.for_user(
            user)  # generate token without username & password

        data = {}
        data['username'] = user.username
        data['access'] = str(token.access_token)
        data['refresh'] = str(token)

        data['user'] = {
            'id': user.id,
            'email': user.email,
            'type': 'professional'
        }
        data['pro'] = ProfessionalSerializer(pro, many=False).data
        data['token_lifetime'] = SIMPLE_JWT
        return Response(data)
예제 #6
0
파일: api_auth.py 프로젝트: apanik/JobXprss
def verify_user(request):
    if request.user.is_anonymous:
        raise AuthenticationFailed()
    data = {
        'id': request.user.id,
        'email': request.user.email,
        'type': 'professional' if is_professional(request.user) else 'company'
    }
    response = Response(data)
    return response
예제 #7
0
def similar_jobs(request, identifier, limit = 5):
    try:
        selected_job = Job.objects.get(job_id=identifier)
    except Job.DoesNotExist:
        return JsonResponse(Job.DoesNotExist)

    if request.user.is_authenticated and is_professional(request.user):
        current_user_id = request.user.id
    else:
        current_user_id = 0

    queryset = Job.objects.annotate(
        applied = FilteredRelation(
            'applied_jobs', condition=Q(applied_jobs__created_by=current_user_id)
        )
    ).annotate(
        favourite = FilteredRelation(
            'fav_jobs', condition=Q(fav_jobs__created_by=current_user_id)
        )
    ).filter(
        is_archived=False,
        status='Published',
    ).exclude(
        job_id=identifier
    ).select_related('company'
                     ).annotate(is_favourite=Count('favourite')
                                ).annotate(is_applied=Count('applied')
                                           ).annotate(applied_at=Max('applied__created_at')
                                                      ).annotate(favourite_at=Max('favourite__created_at')
                                                                 ).order_by('-post_date')

    data = []
    for job in queryset:
        if(similar(selected_job.title, job.title) > 0.8 ): # TODO: Read from settings)
            data.append(job)
        if len(data) >= limit:
            break

    data = JobSerializer(data, many=True).data
    return Response(data)
예제 #8
0
    def get(self, request, slug):
        if request.user.is_authenticated and is_professional(request.user):
            current_user_id = request.user.id
        else:
            current_user_id = 0

        queryset = Job.objects.annotate(applied=FilteredRelation(
            'applied_jobs',
            condition=Q(applied_jobs__created_by=current_user_id)
        )).annotate(favourite=FilteredRelation(
            'fav_jobs', condition=Q(fav_jobs__created_by=current_user_id)
        )).filter(
            is_archived=False,
            status='Published',
            slug=slug,
        ).select_related('company').prefetch_related('job_skills').annotate(
            is_favourite=Count('favourite')).annotate(
                is_applied=Count('applied')).annotate(
                    applied_at=Max('applied__created_at')).annotate(
                        favourite_at=Max('favourite__created_at')).first()
        data = JobSerializerAllField(queryset, many=False).data
        return Response(data)
예제 #9
0
def applied_jobs(request):
    if request.user.is_authenticated and is_professional(request.user):
        current_user_id = request.user.id
    else:
        current_user_id = 0

    queryset = Job.objects.annotate(
        favourite = FilteredRelation(
            'fav_jobs', condition=Q(fav_jobs__created_by=current_user_id)
        )
    ).filter(
        is_archived=False,
        status='Published',
        applied_jobs__created_by = current_user_id
    ).select_related('company'
                     ).annotate(is_favourite=Count('favourite')
                                ).annotate(is_applied=Count('applied_jobs')
                                           ).annotate(applied_at=Max('applied_jobs__created_at')
                                                      ).annotate(favourite_at=Max('favourite__created_at')
                                                                 ).order_by('-applied_jobs__created_at')
    paginator = P7Pagination()
    result_page = paginator.paginate_queryset(queryset, request)
    serializer = JobSerializer(result_page, many=True)
    return paginator.get_paginated_response(serializer.data)
예제 #10
0
파일: api_misc.py 프로젝트: apanik/JobXprss
    def post(self, request, *args, **kwargs):
        if request.user.is_authenticated and is_professional(request.user):
            current_user_id = request.user.id
        else:
            current_user_id = None

        pro_obj = Professional.objects.get(user_id=current_user_id)
        resp = profile_completeness(request._request)
        user_profile_completeness = resp.data['percent_of_profile_completeness']
        settings_minimum_profile_completeness = Settings.objects.values('minimum_profile_completeness')[0][
            'minimum_profile_completeness']

        if user_profile_completeness < settings_minimum_profile_completeness:
            return Response({'details': 'Please complete your profile with necessary and authentic information.'},status=status.HTTP_400_BAD_REQUEST)

        if JobApplication.objects.filter(job=request.data['job'], pro=pro_obj):
            return Response({'details': 'Already applied for this job'}, status=status.HTTP_400_BAD_REQUEST)

        queryset = Professional.objects.filter(user_id=current_user_id).prefetch_related(
            Prefetch('educations',
                     queryset=ProfessionalEducation.objects.filter(is_archived=False).order_by('-enrolled_date')),
            Prefetch('skills',
                     queryset=ProfessionalSkill.objects.filter(is_archived=False).order_by('skill_name')),
            Prefetch('work_experiences',
                     queryset=WorkExperience.objects.filter(is_archived=False).order_by('-start_date')),
            Prefetch('portfolios',
                     queryset=Portfolio.objects.filter(is_archived=False).order_by('created_at')),
            Prefetch('memberships',
                     queryset=Membership.objects.filter(is_archived=False).order_by('created_at')),
            Prefetch('certifications',
                     queryset=Certification.objects.filter(is_archived=False).order_by('-issue_date')),
            Prefetch('references',
                     queryset=Reference.objects.filter(is_archived=False).order_by('created_at'))
        )
        html = self.template.render({'data': queryset, 'SITE_URL': SITE_URL})
        options = {
            'page-size': "A4",
            'encoding': "UTF-8",
            "enable-local-file-access": None,
            "viewport-size": "1024x768",
        }

        resume = pdfkit.from_string(html, False, options=options)
        filename = 'resume-' + str(uuid.uuid4()) + '.pdf'
        req_data = request.data.copy()
        company = Job.objects.get(job_id=req_data['job']).company
        req_data['pro'] = pro_obj.id
        req_data['resume'] = ContentFile(resume, name=filename)
        populate_user_info_querydict(request, req_data, False, False)
        job_application_serializer = JobApplySerializer(data=req_data)

        if job_application_serializer.is_valid():
            job_application_obj = job_application_serializer.save()
            # TODO
            # save_recent_activity(request.user.id, 'apply', 'Job applied')
            job = Job.objects.select_related('company__user').get(job_id=request.data["job"])
            # applied_job_counter(job)

            ##Create notification
            # if (company.user):
            #     notification = Notification()
            #     notification.title = 'job notification'
            #     notification.message = job_application_obj.id
            #     notification.recipient = company.user.id
            #     notification.is_read = False
            #     populate_user_info(request, notification, False, False)
            #     notification.save()

            save_recent_activity(request.user.id, 'apply_pro', )
            if job.company.user_id:
                save_recent_activity(job.company.user_id, 'apply_com')

            return Response(job_application_serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(job_application_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #11
0
    def get_queryset(self):
        request = self.request
        if not request.user.is_authenticated:
            if request.GET.get('page') and request.GET.get('page') != "1":
                raise AuthenticationFailed()
        query = request.GET.get('q')
        featured = request.GET.get('featured')
        unspecified_salary = request.GET.get('unspecified_salary', 1)
        sorting = request.GET.get('sort')
        category = request.GET.get('category')
        company = request.GET.get('company')
        skill = request.GET.get('skill')
        job_city = request.GET.get('job_city')
        salaryMin = request.GET.get('salaryMin')
        salaryMax = request.GET.get('salaryMax')
        experienceMin = request.GET.get('experienceMin')
        experienceMax = request.GET.get('experienceMax')
        datePosted = request.GET.get('datePosted')
        gender = request.GET.get('gender')
        job_type = request.GET.get('job_type')
        qualification = request.GET.get('qualification')

        if request.user.is_authenticated and is_professional(request.user):
            current_user_id = request.user.id
        else:
            current_user_id = 0

        queryset = Job.objects.annotate(
            applied = FilteredRelation(
                'applied_jobs', condition=Q(applied_jobs__created_by=current_user_id)
            )
        ).annotate(
            favourite = FilteredRelation(
                'fav_jobs', condition=Q(fav_jobs__created_by=current_user_id)
            )
        ).filter(
            is_archived=False,
            status='Published',
        ).select_related(
            'company'
        ).annotate(
            is_favourite=Count('favourite')
        ).annotate(
            is_applied=Count('applied')
        ).annotate(
            applied_at=Max('applied__created_at')
        ).annotate(favourite_at=Max('favourite__created_at'))

        if sorting == 'most-applied':
            queryset = queryset.order_by('-applied_count')
        elif sorting == 'top-rated':
            queryset = queryset.order_by('-favorite_count')
        else:
            queryset = queryset.order_by('-post_date')

        if query:
            queryset = queryset.filter(
                Q(title__icontains=query) | Q(description__icontains=query) |
                Q(company_id__name__icontains=query) |
                Q(additional_requirements__icontains=query)
            )

        if featured:
            queryset = queryset.filter(featured=featured)

        if salaryMin and salaryMax:
            if unspecified_salary=='1':
                queryset = queryset.filter(
                    Q(salary_min__isnull=True, salary_max__isnull=True) |
                    Q(salary_min__range=(salaryMin, salaryMax)) |
                    Q(salary_max__range=(salaryMin, salaryMax))
                )
            else:
                queryset = queryset.filter(salary_min__gte=salaryMin, salary_min__lte=salaryMax)


        if category:
            queryset = queryset.filter(job_category=category)

        if datePosted:
            if datePosted == 'Last hour':
                queryset = queryset.filter(post_date__gt=datetime.now() - timedelta(hours=1))
            elif datePosted == 'Last 24 hour':
                queryset = queryset.filter(post_date__gt=datetime.now() - timedelta(hours=24))
            elif datePosted == 'Last 7 days':
                queryset = queryset.filter(post_date__gt=datetime.now() - timedelta(days=7))
            elif datePosted == 'Last 14 days':
                queryset = queryset.filter(post_date__gt=datetime.now() - timedelta(days=14))
            elif datePosted == 'Last 30 days':
                queryset = queryset.filter(post_date__gt=datetime.now() - timedelta(days=30))

        if gender and gender != 'Any':
            queryset = queryset.filter(job_gender=gender)

        if job_type:
            queryset = queryset.filter(job_type=job_type)

        if company:
            queryset = queryset.filter(company=company)

        if qualification:
            queryset = queryset.filter(qualification_id=qualification)

        if skill:
            queryset = queryset.filter(job_skills__name__in = [skill])

        if experienceMin and  experienceMax:
            queryset = queryset.filter(
                Q(experience__isnull=True) |
                Q(experience__gte=experienceMin, experience__lte = experienceMax)
            )

        if job_city:
            queryset = queryset.filter(job_city__icontains=job_city)

        return queryset
예제 #12
0
 def has_permission(self, request, view):
     return bool(request.user and request.user.is_authenticated
                 and is_professional(request.user))