Example #1
0
class EmployerSerializer(serializers.ModelSerializer):
    user = UserSerializer(required=True)
    jobs = JobSerializer(many=True)

    class Meta:
        model = Employer
        fields = ['user', 'company', 'jobs']
Example #2
0
def my_created_jobs(request):
    user = get_user(request)
    if user == False:
        return JsonResponse({'error': 'User not found'})

    jobs = user.employer.all()
    serializer = JobSerializer(jobs, many=True)
    return JsonResponse(serializer.data, safe=False)
Example #3
0
def job_detail(request, uid):
    """
    Retrieve, update or delete a job.
    """
    try:
        job = Job.objects.get(uid=uid)
    except Job.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        try:
            pickup_json = json.loads(job.pickup_location.json)
        except:
            pickup_json = 'null'
        try:
            drop_json = json.loads(job.drop_location.json)
        except:
            drop_json = 'null'
        data_dict = {"uid":job.uid, 
                'status': job.status, 
                'pickup_location': pickup_json, 
                'drop_location': drop_json,
                'shipper': job.shipper.id,
                'porters': job.porters.values_list('pk', flat=True),
                'time_to_reach': job.time_to_reach,
                'amount_offered': job.amount_offered,
                'created_at': job.created_at
                }
        print data_dict
        return JSONResponse(data_dict)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = JobSerializer(snippet, data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data)
        return JSONResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        snippet.delete()
        return HttpResponse(status=204)
Example #4
0
def job_list(request):
    """
    List all jobs, or create a job.
    """
    if request.method == 'GET':
        queryset = Job.objects.all().order_by('-created_at')
        data = list()
        for job in queryset:
            try:
                pickup_json = json.loads(job.pickup_location.json)
            except:
                pickup_json = 'null'
            try:
                drop_json = json.loads(job.drop_location.json)
            except:
                drop_json = 'null'
            if job.status in [6]:
                job_status = 'Fulfilled'
            else:
                job_status = 'Pending'
            data_dict = {"uid":job.uid, 
                    'status': job_status, 
                    'pickup_location': pickup_json, 
                    'drop_location': drop_json,
                    'shipper': job.shipper.id,
                    'porters': job.porters.values_list('pk', flat=True),
                    'time_to_reach': job.time_to_reach,
                    'amount_offered': job.amount_offered,
                    'created_at': job.created_at
                    }
            data.append(data_dict)
        #serializer = JobSerializer(queryset, many=True)
        return JSONResponse(data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = JobSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)
Example #5
0
class ReviewSerializer(serializers.ModelSerializer):
    company = CompanySerializer(
        read_only=True
    )

    job = JobSerializer(
        read_only=True
    )

    class Meta:
        model = Review
        fields = '__all__'
Example #6
0
def addJobs(data):
#this function takes the POST request data and creates jobs from there
   backup_server = data["backupID"]
   #update the backupserver with the last communication time
   bksvr = BackupServer.objects.get(id=backup_server)
   bksvr.last_communication = str(localTime())
   bksvr.save()
   jobs = data["jobs"]
   result = False
   for job in jobs:
      #don't save repeats
      st = job["start_time"]
      st = datetime.datetime.strptime(st, "%m/%d/%Y %H:%M:%S")
      jobfilter = BackupJob.objects.filter(name=job["name"].strip(), start_time=str(st.strftime("%Y-%m-%d %H:%M:%S")).strip())
      if jobfilter:
         print (job)
         continue
      serializer = JobSerializer(data=jobFormat(job, backup_server))
      if serializer.is_valid():
         serializer.save()
         result = True
      else:
         result = False
   return result
Example #7
0
class CandidateTestScoreSerializer(serializers.ModelSerializer):
    candidate = CandidateSerializer()
    job = JobSerializer()

    class Meta:
        model = CandidateTestScore
        fields = ('candidate', 'logic_test_score', 'job')

    def create(self, validated_data):
        candidate_data = validated_data.pop('candidate')
        candidate, _ = Candidate.objects.get_or_create(**candidate_data)

        job_data = validated_data.pop('job')
        job, _ = Job.objects.get_or_create(**job_data)

        return CandidateTestScore.objects.create(**validated_data, job=job, candidate=candidate)
Example #8
0
def job_list(request):
    """
    List all code snippets, or create a new snippet.
    """
    if request.method == 'GET':
        jobs = Job.objects.all()
        serializer = JobSerializer(jobs, many=True)
        return JsonResponse(serializer.data, safe=False)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = JobSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse(serializer.errors, status=400)
Example #9
0
 def get_job_requests(self, obj):
     return JobSerializer(obj.user.job_set.all(), many=True).data
Example #10
0
class ClientSerializer(serializers.ModelSerializer):
    jobs = JobSerializer(many=True, read_only=True)

    class Meta:
        model = Client
        fields = '__all__'
Example #11
0
 def jobs(self, request, slug=None):
     company = self.get_object()
     jobs = Job.objects.filter(company=company)
     page = self.paginate_queryset(jobs)
     job_serializer = JobSerializer(page, many=True)
     return self.get_paginated_response(job_serializer.data)
Example #12
0
    def post(self, request):
        company = CompanyModel.objects.get(user=request.user)
        data = {
            "company":
            company.id,
            "title":
            request.POST.get("title"),
            "role_responsibility":
            request.POST.get("role_responsibility"),
            "requirements":
            request.POST.get("requirements"),
            "experience":
            request.POST.get("minexp") + "to" + request.POST.get("maxexp"),
            "shift_timing":
            request.POST.get("startoffice") + " to " +
            request.POST.get("endoffice"),
            "package":
            request.POST.get("package"),
            "apply_last_date":
            request.POST.get("applybefore"),
            "part_time":
            True if request.POST.get("parttime") else False,
            "no_of_opening":
            request.POST.get("no_of_opening"),
            "status":
            "DRAFT" if request.POST.get("draft") else "PUBLISHED",
            "gender":
            request.POST.get("gender")
        }
        # job data
        job_serializer = JobSerializer(data=data)
        if job_serializer.is_valid():
            job_serializer.save()

            # location data
            location_data = []
            for location in request.POST.getlist("locations"):
                location_data.append({
                    "job": job_serializer.data["id"],
                    "location": location
                })
            location_serializer = JobLocationSerializer(data=location_data,
                                                        many=True)
            if location_serializer.is_valid():
                location_serializer.save()

                # language data
                language_data = []
                for language in request.POST.getlist("linguistic"):
                    language_data.append({
                        "job": job_serializer.data["id"],
                        "laguage": language
                    })
                language_serializer = JobLinguisticLanguageSerializer(
                    data=language_data, many=True)
                if language_serializer.is_valid():
                    language_serializer.save()

                    # skills data
                    skill_data = []
                    for skill in request.POST.getlist("skills"):
                        skill_data.append({
                            "job": job_serializer.data["id"],
                            "skill": skill
                        })
                    skill_serializer = JobSkillSerializer(data=skill_data,
                                                          many=True)
                    if skill_serializer.is_valid():
                        skill_serializer.save()

                        # week data
                        week_data = []
                        for week in request.POST.getlist("weekoff"):
                            week_data.append({
                                "job": job_serializer.data["id"],
                                "day": week
                            })
                        week_serializer = JobWeeklyOffSerializer(
                            data=week_data, many=True)
                        if week_serializer.is_valid():
                            week_serializer.save()
                            self.context[
                                "success"] = "You have  successfully created new Job Post.."
                        else:
                            self.context["error"] = week_serializer.errors
                    else:
                        self.context["error"] = skill_serializer.errors
                else:
                    self.context["error"] = language_serializer.errors
            else:
                self.context["error"] = location_serializer.errors
        else:
            self.context["error"] = job_serializer.errors
        self.context["company"] = company
        self.context["locations"] = LocationModel.objects.all()
        self.context["skills"] = SkillsModel.objects.all()
        self.context["linguistics"] = LinguisticLanguageModel.objects.all()
        return render(request,
                      "company/createnewjob.html",
                      context=self.context)
Example #13
0
def result(request):
    """
    return top 3 jobs after game
    """
    # if !request.is_ajax():
    #     return JsonResponse(serializer.errors, status=404)

    # if request.method != 'POST':
    #     return JsonResponse('serializer.errors', status=404)

    data = json.loads(request.body)

    #récupère le profil 1 et tous les jobs en base de données avec le profil 1 sinon les met à none
    try:
        p1 = Profile.objects.get(type=data['profile_1'])
        jobs_p1 = Job.objects.filter(profile=p1.id)
    except ObjectDoesNotExist:
        p1 = None
        jobs_p1 = None
    #récupère le profil 2 et tous les jobs avec le profil 2 sinon les met à none
    try:
        p2 = Profile.objects.get(type=data['profile_2'])
        jobs_p2 = Job.objects.filter(profile=p2.id)
    except ObjectDoesNotExist:
        p2 = None
        jobs_p2 = None
    #récupère le profil 3 et tous les jobs avec le profil 3 sinon les met à none
    try:
        p3 = Profile.objects.get(type=data['profile_3'])
        jobs_p3 = Job.objects.filter(profile=p3.id)
    except ObjectDoesNotExist:
        p3 = None
        jobs_p3 = None

    #je crée une liste vide de jobs
    jobs = list()

    #jobs with all profile
    if p2 is not None and p3 is not None:
        jobs_allr = jobs_p1.filter(profile=p2.id).filter(
            profile=p3.id).distinct()

        jobs = jobs + randomize(jobs_allr)

    #jobs with profile 1 & 2
    if p2 is not None:
        jobs_1_2 = jobs_p1.filter(profile=p2.id).distinct()

        jobs = jobs + randomize(jobs_1_2)

    #jobs with profile 1 & 3
    if p3 is not None:
        jobs_1_3 = jobs_p1.filter(profile=p3.id).distinct()
        jobs = jobs + randomize(jobs_1_3)

    #jobs with profile 2 & 3
    if p2 is not None and p3 is not None:
        jobs_2_3 = Job.objects.filter(profile=p1.id).filter(
            profile=p3.id).distinct()
        jobs = jobs + randomize(jobs_2_3)

    #jobs with one of the 3 profile
    jobs_1r = jobs_p1
    if p2 is not None:
        jobs_1r = list(jobs_1r) + list(jobs_p2)
    if p3 is not None:
        jobs_1r = list(jobs_1r) + list(jobs_p3)
    OrderedDict.fromkeys(jobs_1r)
    jobs = jobs + randomize(jobs_1r)

    jobs = OrderedDict.fromkeys(jobs)
    jobs = list(jobs)[:3]

    serializer = JobSerializer(jobs, many=True)
    return JsonResponse(serializer.data, safe=False)
Example #14
0
 def get_taken_jobs(self, obj):
     return JobSerializer(obj.user.jobs.all(), many=True).data
Example #15
0
def job_detail(request, pk):
    """
    Retrieve, update or delete a code blog count.
    """
    try:
        job = Job.objects.get(bid=pk)

        if request.method == 'GET':
            serializer = JobSerializer(job)
            return JsonResponse(serializer.data)

        elif request.method == 'PUT':
            # data = JSONParser().parse(request)
            data = {}
            data['bid'] = pk
            data['bcount'] = job.bcount + 1
            serializer = JobSerializer(job, data=data)
            if serializer.is_valid():
                serializer.save()
                return JsonResponse(serializer.data)
            return JsonResponse(serializer.errors, status=400)

        elif request.method == 'DELETE':
            job.delete()
            return HttpResponse(status=204)

    except Job.DoesNotExist:
        if request.method == 'GET':
            job = Job(bid=pk, bcount=0)
            serializer = JobSerializer(job)
            return JsonResponse(serializer.data)
        elif request.method == 'PUT':  # 保存
            data = {}
            data['bid'] = pk  #JSONParser().parse(request)
            data['bcount'] = 1
            serializer = JobSerializer(data=data)
            if serializer.is_valid():
                serializer.save()
                return JsonResponse(serializer.data, status=201)

        return HttpResponse(status=404)
Example #16
0
class PositionSerializer(serializers.ModelSerializer):
    jobs = JobSerializer(many=True, read_only=True)

    class Meta:
        model = Position
        fields = '__all__'
Example #17
0
 def mydonejobs(self, request):
     qs = Job.objects.all().filter(author=self.request.user).filter(
         status=-1)
     serializer = JobSerializer(qs, many=True)
     return Response(serializer.data)