def transform_for_postajob(job): """ Cleans a job coming from My.jobs post-a-job. This should add any required fields, and re-format any fields that are not coming in in the required format. inputs: :job: A dictionary with the following fields: postajob.job.id (id), city, company.id (company), country, country_short, date_new, date_updated, description, guid, link, on_sites, state, state_short, reqid, title, uid, and zipcode. outputs: A solr-ready job as a dictionary """ try: company = Company.objects.get(id=job['company']) except Company.DoesNotExist: return None job['date_new'] = _clean_time(job['date_new']) job['date_updated'] = _clean_time(job['date_updated']) solr_job = {'is_posted': True} on_sites = job.get('on_sites', '0') if not on_sites: solr_job['on_sites'] = '' else: solr_job['on_sites'] = [str(x) for x in on_sites.split(',')] solr_job['id'] = 'postajob.job.%s' % job['guid'] # This has to be seo.joblisting, otherwise the jobs won't be included # in the search results. solr_job['django_ct'] = 'seo.joblisting' solr_job['django_id'] = 0 solr_job['city_slug'] = slugify(job['city']) solr_job['country_short'] = job['country_short'] solr_job['date_updated_exact'] = job['date_updated'] solr_job['job_source_name'] = 'Post-a-Job' solr_job['date_updated'] = job['date_updated'] solr_job['salted_date'] = DEJobFeed.date_salt(job['date_updated']) solr_job['reqid'] = job['reqid'] solr_job['company_digital_strategies_customer'] = company.digital_strategies_customer solr_job['guid'] = job['guid'] solr_job['uid'] = job['id'] solr_job['company_member'] = company.member solr_job['city'] = job['city'] solr_job['date_new'] = job['date_new'] solr_job['country_exact'] = job['country'] solr_job['country_slug'] = slugify(job['country']) solr_job['company_ac'] = company.name solr_job['html_description'] = DEJobFeed.markdown_to_html(job['description']) solr_job['state'] = job['state'] solr_job['country_ac'] = job['country'] solr_job['city_ac'] = job['city'] solr_job['state_short_exact'] = job['state_short'] solr_job['title_ac'] = job['title'] solr_job['company_canonical_microsite'] = company.canonical_microsite solr_job['description'] = job['description'] solr_job['state_ac'] = job['state'] solr_job['company'] = company.name solr_job['state_short'] = job['state_short'] solr_job['title_exact'] = job['title'] solr_job['link'] = job.get('link', '') solr_job['apply_info'] = job.get('apply_info', '') solr_job['company_enhanced'] = company.enhanced solr_job['state_slug'] = slugify(job['state']) solr_job['city_exact'] = job['city'] solr_job['title_slug'] = slugify(job['title']) solr_job['state_exact'] = job['state'] solr_job['zipcode'] = job['zipcode'] solr_job['title'] = job['title'] solr_job['date_new_exact'] = job['date_new'] solr_job['country'] = job['country'] solr_job['company_exact'] = company.name solr_job['company_canonical_microsite_exact'] = company.canonical_microsite solr_job['date_added'] = solr_job['date_added_exact'] = datetime.datetime.now() # Requires city, state_short, state, and country_short to be filled # in on solr_job to work. solr_job['location'] = DEJobFeed.location(solr_job) # Requires city, state, location, and country to be filled in on # solr_jobs. solr_job['full_loc'] = DEJobFeed.full_loc(solr_job) solr_job['full_loc_exact'] = solr_job['full_loc'] solr_job['company_slab'] = DEJobFeed.co_slab(company.name) # Requires solr_job['country_short'], solr_job['state'], and # solr_job['city'] to already be filled in. solr_job['city_slab'] = DEJobFeed.city_slab(solr_job) # Requires solr_job['country_short'] and solr_job['state'] to already be # filled in. solr_job['state_slab'] = DEJobFeed.state_slab(solr_job) # Requires solr_job['country_short'] to already be filled in. solr_job['country_slab'] = DEJobFeed.country_slab(solr_job) # Requires solr_job['title'] to already be filled in. solr_job['title_slab'] = DEJobFeed.title_slab(solr_job) solr_job['location_exact'] = solr_job['location'] solr_job['state_slab_exact'] = solr_job['state_slab'] solr_job['company_slab_exact'] = solr_job['company_slab'] solr_job['country_slab_exact'] = solr_job['country_slab'] solr_job['city_slab_exact'] = solr_job['city_slab'] solr_job['title_slab_exact'] = solr_job['title_slab'] solr_job['text'] = " ".join([force_text((job.get(k)) or "None") for k in text_fields]) return solr_job
on_sites = set(business_unit.site_packages.values_list('pk', flat=True)) on_sites = filter(None, on_sites) job['on_sites'] = on_sites or [0] # This has to be seo.joblisting, otherwise the jobs won't be included # in the search results. job['id'] = 'seo.joblisting.%s' % guid.replace('-', '') job['django_ct'] = 'seo.joblisting' job['django_id'] = 0 job['city_slug'] = slugify(city) job['country_short'] = country_short job['date_updated_exact'] = job['date_updated'] job['job_source_name'] = business_unit.title job['salted_date'] = DEJobFeed.date_salt(job['date_updated']) job['buid'] = business_unit.id job['reqid'] = reqid job['company_digital_strategies_customer'] = company.digital_strategies_customer job['guid'] = guid.replace('-', '') job['uid'] = "" job['company_member'] = company.member job['city'] = city job['country'] = country job['country_exact'] = country job['country_slug'] = slugify(country) job['company_ac'] = company.name job['html_description'] = DEJobFeed.markdown_to_html(description) job['state'] = state job['country_ac'] = country job['city_ac'] = city
def transform_for_postajob(job): """ Cleans a job coming from My.jobs post-a-job. This should add any required fields, and re-format any fields that are not coming in in the required format. inputs: :job: A dictionary with the following fields: postajob.job.id (id), city, company.id (company), country, country_short, date_new, date_updated, description, guid, link, on_sites, state, state_short, reqid, title, uid, and zipcode. outputs: A solr-ready job as a dictionary """ try: company = Company.objects.get(id=job['company']) except Company.DoesNotExist: return None job['date_new'] = _clean_time(job['date_new']) job['date_updated'] = _clean_time(job['date_updated']) solr_job = {'is_posted': True} on_sites = job.get('on_sites', '0') if not on_sites: solr_job['on_sites'] = '' else: solr_job['on_sites'] = [str(x) for x in on_sites.split(',')] solr_job['id'] = 'postajob.job.%s' % job['guid'] # This has to be seo.joblisting, otherwise the jobs won't be included # in the search results. solr_job['django_ct'] = 'seo.joblisting' solr_job['django_id'] = 0 solr_job['city_slug'] = slugify(job['city']) solr_job['country_short'] = job['country_short'].upper() solr_job['country_short_exact'] = job['country_short'].upper() solr_job['date_updated_exact'] = job['date_updated'] solr_job['job_source_name'] = 'Post-a-Job' solr_job['date_updated'] = job['date_updated'] solr_job['salted_date'] = DEJobFeed.date_salt(job['date_new']) solr_job['reqid'] = job['reqid'] solr_job['company_digital_strategies_customer'] = company.digital_strategies_customer solr_job['guid'] = job['guid'] solr_job['uid'] = job['id'] solr_job['company_member'] = company.member solr_job['city'] = job['city'] solr_job['date_new'] = job['date_new'] solr_job['country_exact'] = job['country'] solr_job['country_slug'] = slugify(job['country']) solr_job['company_ac'] = company.name solr_job['html_description'] = DEJobFeed.markdown_to_html(job['description']) solr_job['state'] = job['state'] solr_job['country_ac'] = job['country'] solr_job['city_ac'] = job['city'] solr_job['state_short_exact'] = job['state_short'] solr_job['title_ac'] = job['title'] solr_job['company_canonical_microsite'] = company.canonical_microsite solr_job['description'] = job['description'] solr_job['state_ac'] = job['state'] solr_job['company'] = company.name solr_job['state_short'] = job['state_short'] solr_job['title_exact'] = job['title'] solr_job['link'] = job.get('link', '') solr_job['apply_info'] = job.get('apply_info', '') solr_job['company_enhanced'] = company.enhanced solr_job['state_slug'] = slugify(job['state']) solr_job['city_exact'] = job['city'] solr_job['title_slug'] = slugify(job['title']) solr_job['state_exact'] = job['state'] solr_job['zipcode'] = job['zipcode'] solr_job['title'] = job['title'] solr_job['date_new_exact'] = job['date_new'] solr_job['country'] = job['country'] solr_job['company_exact'] = company.name solr_job['company_canonical_microsite_exact'] = company.canonical_microsite solr_job['date_added'] = solr_job['date_added_exact'] = datetime.datetime.now() # Requires city, state_short, state, and country_short to be filled # in on solr_job to work. solr_job['location'] = DEJobFeed.location(solr_job) # Requires city, state, location, and country to be filled in on # solr_jobs. solr_job['full_loc'] = DEJobFeed.full_loc(solr_job) solr_job['full_loc_exact'] = solr_job['full_loc'] solr_job['company_slab'] = DEJobFeed.co_slab(company.name) # Requires solr_job['country_short'], solr_job['state'], and # solr_job['city'] to already be filled in. solr_job['city_slab'] = DEJobFeed.city_slab(solr_job) # Requires solr_job['country_short'] and solr_job['state'] to already be # filled in. solr_job['state_slab'] = DEJobFeed.state_slab(solr_job) # Requires solr_job['country_short'] to already be filled in. solr_job['country_slab'] = DEJobFeed.country_slab(solr_job) # Requires solr_job['title'] to already be filled in. solr_job['title_slab'] = DEJobFeed.title_slab(solr_job) solr_job['location_exact'] = solr_job['location'] solr_job['state_slab_exact'] = solr_job['state_slab'] solr_job['company_slab_exact'] = solr_job['company_slab'] solr_job['country_slab_exact'] = solr_job['country_slab'] solr_job['city_slab_exact'] = solr_job['city_slab'] solr_job['title_slab_exact'] = solr_job['title_slab'] solr_job['all_locations'] = [job['zipcode'], job['city'], job['state'], job['state_short'], "%s, %s" % (job['city'], job['state']), job['country']] solr_job['text'] = " ".join([force_text((job.get(k)) or "None") for k in text_fields]) return solr_job
on_sites = filter(None, on_sites) job['on_sites'] = on_sites or [0] # This has to be seo.joblisting, otherwise the jobs won't be included # in the search results. job['id'] = 'seo.joblisting.%s' % guid.replace('-', '') job['django_ct'] = 'seo.joblisting' job['django_id'] = 0 job['city_slug'] = slugify(city) job['country_short'] = country_short.upper() job['country_short_exact'] = country_short.upper() job['date_updated_exact'] = job['date_updated'] job['job_source_name'] = business_unit.title job['salted_date'] = DEJobFeed.date_salt(job['date_new']) job['buid'] = business_unit.id job['reqid'] = reqid job['company_digital_strategies_customer'] = company.digital_strategies_customer job['guid'] = guid.replace('-', '') job['uid'] = "" job['company_member'] = company.member job['city'] = city job['country'] = country job['country_exact'] = country job['country_slug'] = slugify(country) job['company_ac'] = company.name job['html_description'] = DEJobFeed.markdown_to_html(description) job['state'] = state job['country_ac'] = country job['city_ac'] = city