예제 #1
0
def custom_search(data, request):
    form = job_searchForm(data)
    searched_locations = searched_skills = searched_edu = searched_industry = searched_states = ''
    if request.POST.get('refine_search') == 'True':
        jobs_list, searched_skills, searched_locations, searched_industry, searched_edu, searched_states = refined_search(
            request.POST)
    else:
        jobs_list = form.search()
        jobs_list = JobPost.objects.filter(pk__in=[r.pk for r in jobs_list])
        searched_locations = City.objects.filter(name__in=data.get('location'))
        searched_skills = Skill.objects.filter(name__in=data.get('q'))
    jobs_list = jobs_list.filter(status="Live")
    job_type = data.get('job_type') or request.POST.get(
        'job_type') or request.GET.get('job_type')
    if job_type:
        jobs_list = jobs_list.filter(job_type=job_type)
    if data.get('walk-in'):
        jobs_list = jobs_list.filter(job_type="walk-in")

    no_of_jobs = len(jobs_list)
    items_per_page = 20
    no_pages = int(math.ceil(float(jobs_list.count()) / items_per_page))
    page = request.POST.get('page') or data.get('page')
    if page and bool(re.search(r"[0-9]", page)) and int(page) > 0:
        if int(page) > (no_pages + 2):
            page = 1
        else:
            page = int(data.get('page'))
    else:
        page = 1
    jobs_list = jobs_list.select_related('company', 'user').prefetch_related(
        'location', 'skills', 'industry').distinct()

    jobs_list = jobs_list[(page - 1) * items_per_page:page * items_per_page]

    prev_page, previous_page, aft_page, after_page = get_prev_after_pages_count(
        page, no_pages)

    if form.is_valid():
        context = {
            'results': form.search(),
            'query': form.query(),
            'searchform': form,
            'aft_page': aft_page,
            'after_page': after_page,
            'prev_page': prev_page,
            'previous_page': previous_page,
            'current_page': page,
            'last_page': no_pages,
            'no_of_jobs': no_of_jobs,
            'job_list': jobs_list,
            'skill': form.cleaned_data['q'],
            'location': form.cleaned_data['location'],
            'searched_skills': searched_skills,
            'searched_locations': searched_locations,
            'searched_industry': searched_industry,
            'searched_edu': searched_edu,
            'searched_experience': request.POST.get('experience'),
            'searched_job_type': request.POST.get('job_type'),
            'searched_functional_area': request.POST.get('functional_area'),
        }
        return context
    return {'job_list': []}
예제 #2
0
def custom_search(data, request):
    form = job_searchForm(data)
    searched_locations = (
        searched_skills
    ) = searched_edu = searched_industry = searched_states = ""
    if request.POST.get("refine_search") == "True":
        (
            jobs_list,
            searched_skills,
            searched_locations,
            searched_industry,
            searched_edu,
            searched_states,
        ) = refined_search(request.POST)
    else:
        jobs_list = form.search()
        jobs_list = JobPost.objects.filter(pk__in=[r.pk for r in jobs_list])
        searched_locations = City.objects.filter(name__in=data.get("location"))
        searched_skills = Skill.objects.filter(name__in=data.get("q"))
    jobs_list = jobs_list.filter(status="Live")
    job_type = (data.get("job_type") or request.POST.get("job_type")
                or request.GET.get("job_type"))
    if job_type:
        jobs_list = jobs_list.filter(job_type=job_type)
    if data.get("walk-in"):
        jobs_list = jobs_list.filter(job_type="walk-in")

    no_of_jobs = len(jobs_list)
    items_per_page = 20
    no_pages = int(math.ceil(float(jobs_list.count()) / items_per_page))
    page = request.POST.get("page") or data.get("page")
    if page and bool(re.search(r"[0-9]", page)) and int(page) > 0:
        if int(page) > (no_pages + 2):
            page = 1
        else:
            page = int(data.get("page"))
    else:
        page = 1
    jobs_list = (jobs_list.select_related("company", "user").prefetch_related(
        "location", "skills", "industry").distinct())

    jobs_list = jobs_list[(page - 1) * items_per_page:page * items_per_page]

    prev_page, previous_page, aft_page, after_page = get_prev_after_pages_count(
        page, no_pages)

    if form.is_valid():
        context = {
            "results": form.search(),
            "query": form.query(),
            "searchform": form,
            "aft_page": aft_page,
            "after_page": after_page,
            "prev_page": prev_page,
            "previous_page": previous_page,
            "current_page": page,
            "last_page": no_pages,
            "no_of_jobs": no_of_jobs,
            "job_list": jobs_list,
            "skill": form.cleaned_data["q"],
            "location": form.cleaned_data["location"],
            "searched_skills": searched_skills,
            "searched_locations": searched_locations,
            "searched_industry": searched_industry,
            "searched_edu": searched_edu,
            "searched_experience": request.POST.get("experience"),
            "searched_job_type": request.POST.get("job_type"),
            "searched_functional_area": request.POST.get("functional_area"),
        }
        return context
    return {"job_list": []}
예제 #3
0
def custom_walkins(request, skill_name, city_name, **kwargs):
    current_url = reverse('custom_walkins',
                          kwargs={
                              'skill_name': skill_name,
                              'city_name': city_name
                          })
    if kwargs.get('page_num') == '1' or request.GET.get('page') == '1':
        return redirect(current_url, permanent=True)
    if 'page' in request.GET:
        url = current_url + request.GET.get('page') + '/'
        return redirect(url, permanent=True)
    final_skill = get_valid_skills_list(skill_name)
    final_location = get_valid_locations_list(city_name)
    if not final_location or not final_skill:
        if request.POST:
            save_search_results.delay(request.META['REMOTE_ADDR'],
                                      request.POST, 0, request.user.id)
        location = final_location or [city_name]
        skills = final_skill or [skill_name]
        template = 'mobile/404.html' if request.is_mobile else '404.html'
        meta_title = meta_description = ''
        return render(
            request,
            template, {
                'message':
                'Unfortunately, we are unable to locate the jobs you are looking for',
                'searched_job_type': 'walk-in',
                'reason':
                "Only Valid Skills/Cities names are accepted in search",
                'searched_skills': skills,
                'searched_locations': location,
                'meta_title': meta_title,
                'meta_description': meta_description,
                'data_empty': True,
                'job_search': True
            },
            status=404)
    if request.POST.get('refine_search') == 'True':
        job_list, searched_skills, searched_locations, searched_industry, searched_edu, searched_states = refined_search(
            request.POST)
    else:
        search_dict = QueryDict('', mutable=True)
        search_dict.setlist('refine_skill', final_skill)
        search_dict.setlist('refine_location', final_location)
        search_dict.update({'job_type': 'walk-in'})
        if request.POST.get('experience'):
            search_dict.update(
                {'refine_experience_min': request.POST.get('experience')})
        job_list, searched_skills, searched_locations, searched_industry, searched_edu, searched_states = refined_search(
            search_dict)
    if job_list:
        no_of_jobs = job_list.count()
        items_per_page = 20
        no_pages = int(math.ceil(float(no_of_jobs) / items_per_page))
        page = get_page_number(request, kwargs, no_pages)
        if not page:
            return HttpResponseRedirect(current_url)
        prev_page, previous_page, aft_page, after_page = get_prev_after_pages_count(
            page, no_pages)
        job_list = job_list[(page - 1) * items_per_page:page * items_per_page]
        meta_title, meta_description, h1_tag = get_meta_data(
            'skill_location_walkin_jobs', {
                'skills': searched_skills,
                'final_skill': final_skill,
                'page': page,
                'locations': searched_locations,
                'final_location': final_location
            })
        data = {
            'job_list': job_list,
            'aft_page': aft_page,
            'after_page': after_page,
            'prev_page': prev_page,
            'previous_page': previous_page,
            'current_page': page,
            'last_page': no_pages,
            'no_of_jobs': no_of_jobs,
            "is_job_list": False,
            'current_url': current_url,
            'searched_skills': searched_skills,
            'searched_states': searched_states,
            'searched_locations': searched_locations,
            'searched_industry': searched_industry,
            'searched_edu': searched_edu,
            'searched_experience': request.POST.get('experience'),
            'searched_job_type': 'walk-in',
            'meta_title': meta_title,
            'meta_description': meta_description,
            'h1_tag': h1_tag,
            'walkin': True
        }
        template = 'jobs/jobs_list.html'
        if request.is_mobile:
            data.update({
                'searched_industry':
                request.POST.get('industry'),
                'searched_functional_area':
                request.POST.get('functional_area')
            })
            template = 'mobile/jobs/list.html'
        return render(request, template, data)
    else:
        template = 'mobile/404.html' if request.is_mobile else '404.html'
        meta_title, meta_description = get_404_meta('skill_location_404', {
            'skill': final_skill,
            'city': final_location
        })
        return render(
            request, template, {
                'message':
                'Unfortunately, we are unable to locate the jobs you are looking for',
                'reason':
                "Only Valid Skills/Cities names are accepted in search",
                'job_search': True,
                'searched_skills': searched_skills,
                'searched_locations': searched_locations,
                'meta_title': meta_title,
                'meta_description': meta_description
            })
예제 #4
0
def custom_walkins(request, skill_name, city_name, **kwargs):
    current_url = reverse("custom_walkins",
                          kwargs={
                              "skill_name": skill_name,
                              "city_name": city_name
                          })
    if kwargs.get("page_num") == "1" or request.GET.get("page") == "1":
        return redirect(current_url, permanent=True)
    if "page" in request.GET:
        url = current_url + request.GET.get("page") + "/"
        return redirect(url, permanent=True)
    final_skill = get_valid_skills_list(skill_name)
    final_location = get_valid_locations_list(city_name)
    if not final_location or not final_skill:
        if request.POST:
            save_search_results.delay(request.META["REMOTE_ADDR"],
                                      request.POST, 0, request.user.id)
        location = final_location or [city_name]
        skills = final_skill or [skill_name]
        template = "mobile/404.html" if request.is_mobile else "404.html"
        meta_title = meta_description = ""
        return render(
            request,
            template,
            {
                "message":
                "Unfortunately, we are unable to locate the jobs you are looking for",
                "searched_job_type": "walk-in",
                "reason":
                "Only Valid Skills/Cities names are accepted in search",
                "searched_skills": skills,
                "searched_locations": location,
                "meta_title": meta_title,
                "meta_description": meta_description,
                "data_empty": True,
                "job_search": True,
            },
            status=404,
        )
    if request.POST.get("refine_search") == "True":
        (
            job_list,
            searched_skills,
            searched_locations,
            searched_industry,
            searched_edu,
            searched_states,
        ) = refined_search(request.POST)
    else:
        search_dict = QueryDict("", mutable=True)
        search_dict.setlist("refine_skill", final_skill)
        search_dict.setlist("refine_location", final_location)
        search_dict.update({"job_type": "walk-in"})
        if request.POST.get("experience"):
            search_dict.update(
                {"refine_experience_min": request.POST.get("experience")})
        (
            job_list,
            searched_skills,
            searched_locations,
            searched_industry,
            searched_edu,
            searched_states,
        ) = refined_search(search_dict)
    if job_list:
        no_of_jobs = job_list.count()
        items_per_page = 20
        no_pages = int(math.ceil(float(no_of_jobs) / items_per_page))
        page = get_page_number(request, kwargs, no_pages)
        if not page:
            return HttpResponseRedirect(current_url)
        prev_page, previous_page, aft_page, after_page = get_prev_after_pages_count(
            page, no_pages)
        job_list = job_list[(page - 1) * items_per_page:page * items_per_page]
        meta_title, meta_description, h1_tag = get_meta_data(
            "skill_location_walkin_jobs",
            {
                "skills": searched_skills,
                "final_skill": final_skill,
                "page": page,
                "locations": searched_locations,
                "final_location": final_location,
            },
        )
        data = {
            "job_list": job_list,
            "aft_page": aft_page,
            "after_page": after_page,
            "prev_page": prev_page,
            "previous_page": previous_page,
            "current_page": page,
            "last_page": no_pages,
            "no_of_jobs": no_of_jobs,
            "is_job_list": False,
            "current_url": current_url,
            "searched_skills": searched_skills,
            "searched_states": searched_states,
            "searched_locations": searched_locations,
            "searched_industry": searched_industry,
            "searched_edu": searched_edu,
            "searched_experience": request.POST.get("experience"),
            "searched_job_type": "walk-in",
            "meta_title": meta_title,
            "meta_description": meta_description,
            "h1_tag": h1_tag,
            "walkin": True,
        }
        template = "jobs/jobs_list.html"
        if request.is_mobile:
            data.update({
                "searched_industry":
                request.POST.get("industry"),
                "searched_functional_area":
                request.POST.get("functional_area"),
            })
            template = "mobile/jobs/list.html"
        return render(request, template, data)
    else:
        template = "mobile/404.html" if request.is_mobile else "404.html"
        meta_title, meta_description = get_404_meta("skill_location_404", {
            "skill": final_skill,
            "city": final_location
        })
        return render(
            request,
            template,
            {
                "message":
                "Unfortunately, we are unable to locate the jobs you are looking for",
                "reason":
                "Only Valid Skills/Cities names are accepted in search",
                "job_search": True,
                "searched_skills": searched_skills,
                "searched_locations": searched_locations,
                "meta_title": meta_title,
                "meta_description": meta_description,
            },
        )