def context(self, request, **kwargs): job_id = kwargs.get('job_id', '') return { 'site_commitments_string': context_tools.get_site_commitments_string(request), 'requested_job': context_tools.get_job(request, job_id), }
def handle_job_detail_redirect(self, request, *args, **kwargs): """ Used on job detail pages, this returns a redirect to the appropriate url if: 1. There is no matching job (404). 2. The matching job isn't actually available on the site because it belongs to a business unit or site package not associated with that site (Redirect to home page). 3. It's missing slugs or the slugs are out of order (Redirect to the page with slugs in the correct order). If there is no redirect, returns None. """ job_id = kwargs.get('job_id', '') job = context_tools.get_job(request, job_id) if not job: raise Http404 if settings.SITE_BUIDS and job.buid not in settings.SITE_BUIDS: on_this_site = set(settings.SITE_PACKAGES) & set(job.on_sites) if job.on_sites and not on_this_site: return redirect('home') title_slug = kwargs.get('title_slug', '').lower() location_slug = kwargs.get('location_slug', '').lower() job_location_slug = slugify(job.location).lower() if (title_slug == job.title_slug.lower() and location_slug == job_location_slug): return None feed = kwargs.get('feed', '') query = "" for k, v in request.GET.items(): query = ("=".join([k, v]) if query == "" else "&".join([query, "=".join([k, v])])) # The url wasn't quite the canonical form, so we redirect them # to the correct version based on the title and location of the # job with the passed in id. new_kwargs = { 'location_slug': slugify(job.location), 'title_slug': job.title_slug, 'job_id': job.guid } redirect_url = reverse('job_detail_by_location_slug_title_slug_job_id', kwargs=new_kwargs) # if the feed type is passed, add source params, otherwise only preserve # the initial query string. if feed: if query != "": query = "&%s" % query redirect_url += "?utm_source=%s&utm_medium=feed%s" % (feed, query) elif query: redirect_url += "?%s" % query return redirect(redirect_url, permanent=True)
def context(self, request, **kwargs): job_id = kwargs.get('job_id', '') return { 'requested_job': context_tools.get_job(request, job_id), }
def handle_job_detail_redirect(self, request, *args, **kwargs): """ Used on job detail pages, this returns a redirect to the appropriate url if: 1. There is no matching job (404). 2. The matching job isn't actually available on the site because it belongs to a business unit or site package not associated with that site (Redirect to home page). 3. It's missing slugs or the slugs are out of order Redirect to the page with slugs in the correct order). If there is no redirect, returns None. """ job_id = kwargs.get('job_id', '') job = context_tools.get_job(request, job_id) if not job: if job_id: search_type = 'guid' if len(job_id) > 31 else 'uid' # The job was not in solr; find and redirect to its apply url # if it's a new job that hasn't been syndicated, otherwise # return a 404. do_redirect = redirect_if_new(**{search_type: job_id}) if do_redirect: return do_redirect raise Http404("myblocks.models.Page.handle_job_detail_redirect: " "job does not exist") if settings.SITE_BUIDS and job.buid not in settings.SITE_BUIDS: on_this_site = set(settings.SITE_PACKAGES) & set(job.on_sites) if job.on_sites and not on_this_site: return redirect('home') title_slug = kwargs.get('title_slug', '').lower() location_slug = kwargs.get('location_slug', '').lower() job_location_slug = slugify(job.location).lower() if (title_slug == job.title_slug.lower() and location_slug == job_location_slug): return None feed = kwargs.get('feed', '') query = "" for k, v in request.GET.items(): query = ("=".join([k, v]) if query == "" else "&".join([query, "=".join([k, v])])) # The url wasn't quite the canonical form, so we redirect them # to the correct version based on the title and location of the # job with the passed in id. new_kwargs = { 'location_slug': slugify(job.location), 'title_slug': job.title_slug, 'job_id': job.guid } redirect_url = reverse('job_detail_by_location_slug_title_slug_job_id', kwargs=new_kwargs) # if the feed type is passed, add source params, otherwise only preserve # the initial query string. if feed: if query != "": query = "&%s" % query redirect_url += "?utm_source=%s&utm_medium=feed%s" % (feed, query) elif query: redirect_url += "?%s" % query return redirect(redirect_url, permanent=True)