コード例 #1
0
ファイル: queries.py プロジェクト: MoMoKorea/MoMo_Web
    def create(data):
        serializer = JobSerializer(data=data)
        pprint(serializer.is_valid())
        if serializer.is_valid():
            job = serializer.save()

            # 근무요일 save
            for dayId in data["selectedDayOfWeeks"]:
                selectedDayOfWeek = JobDayOfWeekORM(dayId)
                JobDayOfWeekMappingORM.objects.create(job_id=job, day_of_week_id=selectedDayOfWeek)

            # 제출문서 save
            for documentId in data["selectedRequiredDocuments"]:
                selectedDocument = JobRequireDocumentORM(documentId)
                JobRequireDocumentMappingORM.objects.create(job_id=job, require_document_id=selectedDocument)

            # 선호 연령 save
            for workerAge in data["selectedWorkerAge"]:
                selectedWorkerAge = JobAgeORM(workerAge)
                JobAgeMappingORM.objects.create(job_id=job, age_id=selectedWorkerAge)


            return serializer
        else:
            pprint("err_message=" + str(serializer.error_messages))
            return None
コード例 #2
0
def get_jobs_in_preferred_cities(request):
    try:
        user = request.user
        if not Candidate.objects.filter(user=user).exists():
            return response_400("No candidate associated with this user",
                                "No candidate associated with this user", None)

        candidate = Candidate.objects.filter(user=user).first()
        preferred_cities = candidate.preferred_city.all()
        preferred_cities_name = [p.name for p in preferred_cities]

        locations = request.query_params.getlist(
            'location') if request.query_params.getlist(
                'location') else preferred_cities_name

        jobs = JobPost.objects.filter(status__in=['Expired', 'Published'])

        if locations:
            locationObjects = City.objects.filter(name__in=locations)
            jobs = jobs.filter(removed=False,
                               locations__in=locationObjects,
                               status__in=['Expired', 'Published'])

        return response_200(
            "Jobs in preferred cities fetched",
            JobSerializer(jobs, context={
                'request': request
            }, many=True).data)

    except Exception as e:
        return response_500("internal error", e)
コード例 #3
0
def get_subscribed_company_jobs(request):
    try:
        user = request.user
        if not Candidate.objects.filter(user=user).exists():
            return response_400("No candidate associated with this user",
                                "No candidate associated with this user", None)

        candidate = Candidate.objects.filter(user=user).first()
        result = []
        if SubscribedCompanies.objects.filter(candidate=candidate).exists():
            sub_companies = SubscribedCompanies.objects.filter(
                candidate=candidate)
            for company in sub_companies:
                obj = {}
                obj['subscribed_company'] = SubscribedCompaniesSerializer(
                    company, context={
                        'request': request
                    }).data
                jobs = JobPost.objects.filter(
                    company=company.company,
                    status__in=['Expired', 'Published'])
                obj['jobs'] = JobSerializer(jobs,
                                            context={
                                                'request': request
                                            },
                                            many=True).data
                result.append(obj)
        return response_200("Subscribed Companies and jobs fetched", result)

    except Exception as e:
        return response_500("internal error", e)
コード例 #4
0
ファイル: serializers.py プロジェクト: michaeljohns2/scale
class RecipeJobsSerializer(serializers.Serializer):
    """Converts recipe model fields to REST output."""
    from job.serializers import JobSerializer

    job = JobSerializer()
    job_name = serializers.CharField()
    recipe = ModelIdSerializer()
コード例 #5
0
    def get_job_detail(jobId):

        querySet = JobORM.objects.get(job_id=jobId)
        jobSerializer = JobSerializer(querySet)

        jobData = jobSerializer.data.copy()
        return jobData
コード例 #6
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)
コード例 #7
0
ファイル: auditSys.py プロジェクト: CQZYQ1994/auditSystem
    def get(self, request):
        id = request.GET.get('id')
        if id:
            try:
                job = Job.objects.get(id=id, is_deleted=False)
                job.department = job.get_department_display()
                job.status = job.get_status_display()
                job.deadline = job.deadline.strftime('%Y-%m-%d %H:%m')
                job.create_time = job.create_time.strftime('%Y-%m-%d %H:%m')
                job.last_update_time = job.last_update_time.strftime(
                    '%Y-%m-%d %H:%m')
                return self.success(JobSerializer(job).data)
            except Job.DoesNotExist:
                return self.error("Job does not exist")
        else:
            if request.user.is_authenticated:
                if request.user.role == 'Office Head':
                    job = Job.objects.filter(created_by=request.user,
                                             is_deleted=False).order_by('-id')

                else:
                    job = Job.objects.filter(is_deleted=False).order_by('-id')
            else:
                job = Job.objects.filter(is_deleted=False).order_by('-id')

            for item in job:
                # item.department = item.get_department_display()
                item.status = item.get_status_display()
                if item.deadline != None:
                    item.deadline = item.deadline.strftime('%Y-%m-%d %H:%M')
                item.create_time = item.create_time.strftime('%Y-%m-%d %H:%M')
                item.last_update_time = item.last_update_time.strftime(
                    '%Y-%m-%d %H:%M')
            return self.success(self.paginate_data(request, job,
                                                   JobSerializer))
コード例 #8
0
ファイル: serializers.py プロジェクト: GRSEB9S/scale
class BatchDetailsSerializer(BatchSerializer):
    """Converts batch model fields to REST output."""
    from job.serializers import JobSerializer
    from recipe.serializers import RecipeTypeSerializer
    from trigger.serializers import TriggerEventDetailsSerializer

    recipe_type = RecipeTypeSerializer()
    event = TriggerEventDetailsSerializer()
    creator_job = JobSerializer()

    definition = serializers.JSONField(default=dict)
コード例 #9
0
    def post(self, request):
        """Increase max_tries, place it on the queue, and returns the new job information in JSON form

        :param request: the HTTP GET request
        :type request: :class:`rest_framework.request.Request`
        :returns: the HTTP response to send back to the user
        """

        started = rest_util.parse_timestamp(request, 'started', required=False)
        ended = rest_util.parse_timestamp(request, 'ended', required=False)
        rest_util.check_time_range(started, ended)

        job_status = rest_util.parse_string(request, 'status', required=False)
        job_ids = rest_util.parse_int_list(request, 'job_ids', required=False)
        job_type_ids = rest_util.parse_int_list(request,
                                                'job_type_ids',
                                                required=False)
        job_type_names = rest_util.parse_string_list(request,
                                                     'job_type_names',
                                                     required=False)
        job_type_categories = rest_util.parse_string_list(
            request, 'job_type_categories', required=False)
        error_categories = rest_util.parse_string_list(request,
                                                       'error_categories',
                                                       required=False)

        priority = rest_util.parse_int(request, 'priority', required=False)

        # Fetch all the jobs matching the filters
        job_status = [job_status] if job_status else job_status
        jobs = Job.objects.get_jobs(started=started,
                                    ended=ended,
                                    statuses=job_status,
                                    job_ids=job_ids,
                                    job_type_ids=job_type_ids,
                                    job_type_names=job_type_names,
                                    job_type_categories=job_type_categories,
                                    error_categories=error_categories)

        # Attempt to queue all jobs matching the filters
        requested_job_ids = {job.id for job in jobs}
        if requested_job_ids:
            Queue.objects.requeue_jobs(requested_job_ids, priority)

            # Refresh models to get the new status information for all originally requested jobs
            jobs = Job.objects.get_jobs(job_ids=requested_job_ids)

        page = self.paginate_queryset(jobs)
        serializer = JobSerializer(page, many=True)
        return self.get_paginated_response(serializer.data)
コード例 #10
0
ファイル: auditSys.py プロジェクト: CQZYQ1994/auditSystem
    def post(self, request):
        try:
            data = request.data
            """ BlockingScheduler 阻塞式调度器
                BackgroundScheduler 后台调度器
            """

            create_time = datetime.now()
            "deadline为''时,不执行定时任务"
            if data['deadline'] != '':
                deadline = datetime.strptime(
                    data['deadline'].replace('T', ' '), '%Y-%m-%d %H:%M')
                if str(create_time) > data['deadline']:
                    raise ValidationError("任务截至时间不能早于当前时间")
                else:
                    job = Job.objects.create(department_id=data['department'],
                                             position=data['position'],
                                             deadline=data['deadline'],
                                             salary=data['salary'],
                                             describe=data['describe'],
                                             requirement=data['requirement'],
                                             other=data['other'],
                                             table_id=data['table_id'],
                                             created_by=request.user)
                    sched = BackgroundScheduler()
                    task = sched.add_job(self.change_job_status,
                                         'date',
                                         run_date=deadline,
                                         args=[job.id])
                    sched.start()
                    job.task_id = task.id
                    job.save()
                    print(task.id)
            else:
                job = Job.objects.create(department_id=data['department'],
                                         position=data['position'],
                                         deadline=None,
                                         salary=data['salary'],
                                         describe=data['describe'],
                                         requirement=data['requirement'],
                                         other=data['other'],
                                         table_id=data['table_id'],
                                         created_by=request.user)
            return self.success(JobSerializer(job).data)

        except ValidationError as e:
            print(e)
            return self.error(msg=str(e))
コード例 #11
0
ファイル: auditSys.py プロジェクト: CQZYQ1994/auditSystem
 def put(self, request):
     try:
         data = request.data
         job_id = request.GET.get('id')
         if job_id:
             try:
                 job = Job.objects.get(id=job_id)
             except Job.DoesNotExist:
                 return self.error("Job does not exist")
         for k, v in data.items():
             setattr(job, k, v)
         job.save()
         if job.task_id != '':
             pass
         return self.success(JobSerializer(job).data)
     except Exception as e:
         return self.error("error")
コード例 #12
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)
コード例 #13
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)
コード例 #14
0
ファイル: serializers.py プロジェクト: ihabShhadat17/hrSystem
class CandidateSerializer(Apply_Serializer):
    job_id = JobSerializer(many=False, read_only=True)
コード例 #15
0
 def get(self, request, pk):
     job = self.get_object(pk)
     job_serializer = JobSerializer(job)
     return Response(job_serializer.data)
コード例 #16
0
    def get(self, request):
        jobs = Job.objects.all()
        job_serializer = JobSerializer(jobs, many=True)

        return Response(job_serializer.data, status=status.HTTP_200_OK)