def test_validate_departments(self): with self.app_context(): form = CompanySearchForm( MultiDict({ 'j': 'test j', 'l': 'test l', 'occupation': 'test occupation', 'departments': '1,2' })) self.assertEqual(form.validate(), True) form = CompanySearchForm( MultiDict({ 'j': 'test j', 'l': 'test l', 'occupation': 'test occupation', 'departments': '1, 2, 3' })) self.assertEqual(form.validate(), True) form = CompanySearchForm( MultiDict({ 'j': 'test j', 'l': 'test l', 'occupation': 'test occupation', 'departments': 'a,b' })) self.assertEqual(form.validate(), False)
def home(): fix_csrf_session() activity.log(event_name='home', ) refresh_token_result = attempt_to_refresh_peam_token() if refresh_token_result["token_has_expired"]: return redirect(refresh_token_result["redirect_url"]) return render_template('home.html', form=CompanySearchForm())
def home(): fix_csrf_session() activity.log( event_name='home', # GA tracking is used in PSE 2019-2020 experiment utm_medium=request.args.get('utm_medium', ''), utm_source=request.args.get('utm_source', ''), utm_campaign=request.args.get('utm_campaign', ''), ) return render_template('home.html', form=CompanySearchForm())
def logout_from_peam_callback(): """ The route where a user is redirected after a log out through the PEAM website. """ # Quick ugly but useful fix referer = request.referrer if referer and len(referer) > 1700: # If the referer is too long, the redirect will return a 502 status code. # I did not find how to change the referrer. See https://github.com/pallets/flask/issues/3310 fix_csrf_session() return render_template('home.html', form=CompanySearchForm()) return redirect(url_for('root.home'))
def home(): fix_csrf_session() return render_template('home.html', form=CompanySearchForm())
def search(): form = CompanySearchForm(request.args) if request.args and form.validate(): return form.redirect('search.results') return render_template('search/results.html', form=form)
def results(city, zipcode, occupation): kwargs = get_parameters(request.args) kwargs['city'] = city kwargs['zipcode'] = zipcode kwargs['occupation'] = occupation canonical = '/entreprises/%s-%s/%s' % (city, zipcode, occupation) # Remove keys with empty values. form_kwargs = {key: val for key, val in dict(**kwargs).items() if val} city = city.replace('-', ' ').capitalize() full_location = '%s (%s)' % (city, zipcode) form_kwargs['location'] = full_location # Get ROME code (Répertoire Opérationnel des Métiers et des Emplois). rome = mapping_util.SLUGIFIED_ROME_LABELS.get(occupation) # Stop here if the ROME code does not exists. if not rome: form_kwargs['job'] = occupation form = CompanySearchForm(**form_kwargs) context = {'job_doesnt_exist': True, 'form': form} return render_template('search/results.html', **context) session['search_args'] = request.args # Fetch companies and alternatives. fetcher = search_util.Fetcher(**kwargs) alternative_rome_descriptions = [] alternative_distances = {} location_error = False try: current_app.logger.debug("fetching companies and company_count") companies = fetcher.get_companies() for alternative, count in fetcher.alternative_rome_codes.iteritems(): if settings.ROME_DESCRIPTIONS.get(alternative) and count: desc = settings.ROME_DESCRIPTIONS.get(alternative) slug = slugify(desc) alternative_rome_descriptions.append( [alternative, desc, slug, count]) company_count = fetcher.company_count alternative_distances = fetcher.alternative_distances except search_util.JobException: companies = [] company_count = 0 except search_util.LocationError: companies = [] company_count = 0 location_error = True # Pagination. from_number_param = int(kwargs.get('from') or 1) to_number_param = int(kwargs.get('to') or 10) pagination_manager = PaginationManager(company_count, from_number_param, to_number_param, request.full_path) current_page = pagination_manager.get_current_page() # Get contact mode and position. for position, company in enumerate(companies, start=1): company.contact_mode = util.get_contact_mode_for_rome_and_naf( fetcher.rome, company.naf) # position is later used in labonneboite/web/static/js/results.js company.position = position # Get NAF code and their descriptions. rome_2_naf_mapper = mapping_util.Rome2NafMapper() naf_codes = rome_2_naf_mapper.map([ rome, ]) naf_codes_with_descriptions = [] for naf_code in naf_codes: naf_description = settings.NAF_CODES.get(naf_code) naf_codes_with_descriptions.append((naf_code, naf_description)) if kwargs.get('naf') in [item[0] for item in naf_codes_with_descriptions]: naf_text = settings.NAF_CODES.get(kwargs['naf']) naf_codes_with_descriptions.append((kwargs['naf'], naf_text)) form_kwargs['job'] = settings.ROME_DESCRIPTIONS[rome] form = CompanySearchForm(**form_kwargs) form.naf.choices = [('', u'Tous les secteurs')] + sorted( naf_codes_with_descriptions, key=lambda t: t[1]) form.validate() context = { 'alternative_distances': alternative_distances, 'alternative_rome_descriptions': alternative_rome_descriptions, 'canonical': canonical, 'city': city, 'companies': list(companies), 'company_count': company_count, 'distance': kwargs['distance'], 'doorbell_tags': util.get_doorbell_tags('results'), 'form': form, 'headcount': kwargs['headcount'], 'job_doesnt_exist': False, 'location': full_location, 'location_error': location_error, 'naf': kwargs['naf'], 'naf_codes': naf_codes_with_descriptions, 'page': current_page, 'pagination': pagination_manager, 'rome_code': rome, 'rome_description': settings.ROME_DESCRIPTIONS.get(fetcher.rome, ''), 'show_favorites': True, 'sort': kwargs['sort'], 'tile_server_url': settings.TILE_SERVER_URL, 'user_favs_as_sirets': UserFavoriteOffice.user_favs_as_sirets(current_user), } return render_template('search/results.html', **context)
def home(): return render_template('home.html', form=CompanySearchForm())