Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAVE - Améliorations de la personnalisation du mapping ROME/NAF #370

Merged
merged 16 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions labonneboite/common/models/office.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# coding: utf8


import logging
from functools import lru_cache
from urllib.parse import urlencode
import logging

from babel.dates import format_date
from slugify import slugify
from flask import url_for
from slugify import slugify
from sqlalchemy import Column, Integer, String, Float, Boolean
from sqlalchemy.dialects import mysql
from sqlalchemy import PrimaryKeyConstraint, Index
from sqlalchemy.dialects import mysql

from functools import lru_cache
from werkzeug import cached_property

from labonneboite.common import encoding as encoding_util
from labonneboite.common import scoring as scoring_util
from labonneboite.common import hiring_type_util
from labonneboite.common import mapping as mapping_util
from labonneboite.common import scoring as scoring_util
from labonneboite.common import util
from labonneboite.common.database import Base, db_session, DATABASE
from labonneboite.common.load_data import load_city_codes, load_groupements_employeurs
from labonneboite.common import util
from labonneboite.common.models.base import CRUDMixin
from labonneboite.conf import settings
from labonneboite.importer import settings as importer_settings


logger = logging.getLogger('main')

Expand Down Expand Up @@ -133,7 +133,7 @@ class Office(FinalOfficeMixin, CRUDMixin, Base):
# Improve performance of create_index.py parallel jobs
# by quickly fetching all offices of any given departement.
Index('_departement', 'departement'),

# Improve performance of create_index.py remove_scam_emails()
# by quickly locating offices having a given scam email.
Index('_email', 'email'),
Expand Down Expand Up @@ -318,6 +318,20 @@ def naf_text(self):
def stars(self):
return self.get_stars_for_rome_code(None)

@cached_property
def romes_for_naf_mapping(self):
"""
Returns a list of named tuples for ROME codes matching the company's NAF code.
"""
return mapping_util.romes_for_naf(self.naf)

@cached_property
def romes_codes(self):
"""
Returns the default set of ROME codes for the current company.
"""
return set([rome.code for rome in self.romes_for_naf_mapping])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je suggère de garder seulement cette seconde méthode car la première me semble confusante, vu que partout ailleurs dans le code rome et rome_code sont interchangeables et sont toujours la string de 5 caractères d'un code ROME

ou alors renommer la première, car romes laisse croire que ce sont des codes ROME. peut-être named_romes ou romes_with_names

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui, c'est tout à fait pertinent. Je vais renommer la première en romes_for_naf_mapping car ça décrit exactement ce que c'est : juste un shortcut vers le romes_for_naf de common.mapping.

def get_stars_for_rome_code(self, rome_code, hiring_type=None):
hiring_type = hiring_type or hiring_type_util.DEFAULT
if hiring_type not in hiring_type_util.VALUES:
Expand Down Expand Up @@ -361,8 +375,7 @@ def get_url_for_rome_code(self, rome_code, alternance=False, **query_string):
try:
if rome_code:
return url_for('office.details', siret=self.siret, rome_code=rome_code, _external=True, **query_string)
else:
return url_for('office.details', siret=self.siret, _external=True, **query_string)
return url_for('office.details', siret=self.siret, _external=True, **query_string)
except RuntimeError:
# RuntimeError is raised when we are outside of a Flask's application context.
# Here, we cannot properly generate an URL via url_for.
Expand Down
23 changes: 4 additions & 19 deletions labonneboite/common/models/recruiter_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class RecruiterMessageCommon(object):
def create_from_form(cls, form, is_certified_recruiter=False, uid=''):
instance = cls()
instance.siret = form.siret.data
instance.siret = form.siret.data
instance.requested_by_first_name = form.first_name.data
instance.requested_by_last_name = form.last_name.data
instance.requested_by_email = form.email.data
Expand Down Expand Up @@ -109,21 +108,7 @@ def fill_values(self, form):
except NoResultFound:
raise NoOfficeFoundException('No office found with siret : {}'.format(form.data.siret))

office_romes = set([item.code for item in mapping_util.romes_for_naf(office.naf)])

_, lbb_romes, lba_romes, hide_romes = forms.compute_romes()
lbb_romes = set(lbb_romes)
lba_romes = set(lba_romes)
hide_romes = set(hide_romes)


# Remove checkboxes and romes not open to applications
romes_to_remove = hide_romes.union(office_romes) - lbb_romes

# Remove checkboxes and romes not open to alternance
romes_alternance_to_remove = hide_romes.union(office_romes) - lba_romes

self.romes_to_add = ','.join(lbb_romes - office_romes)
self.romes_to_remove = ','.join(romes_to_remove)
self.romes_alternance_to_add = ','.join(lba_romes - office_romes)
self.romes_alternance_to_remove = ','.join(romes_alternance_to_remove)
self.romes_alternance_to_add = ','.join(form.romes_alternance_to_add)
self.romes_alternance_to_remove = ','.join(form.romes_alternance_to_remove)
self.romes_to_add = ','.join(form.romes_to_add)
self.romes_to_remove = ','.join(form.romes_to_remove)
6 changes: 4 additions & 2 deletions labonneboite/conf/common/settings_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf8
"""
Main app default settings.

Expand Down Expand Up @@ -42,6 +41,8 @@
SENTRY_ENVIRONMENT = ""

ADMIN_EMAIL = 'no-reply@labonneboite.pole-emploi.fr'
LBB_EMAIL = 'labonneboite@pole-emploi.fr'
LBA_EMAIL = 'labonnealternance@pole-emploi.fr'

SERVER_NAME = 'labonneboite.pole-emploi.fr'
PREFERRED_URL_SCHEME = 'http'
Expand Down Expand Up @@ -208,4 +209,5 @@
from .overrides.development import *
elif get_current_env() == ENV_TEST:
# pylint: disable=wildcard-import,unused-wildcard-import
from .overrides.test import *
from .overrides.test import *

4 changes: 2 additions & 2 deletions labonneboite/tests/app/maps/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUp(self):
self.cache = cache.RedisCache()

def test_access_cache_with_disconnected_redis(self):
with self.test_request_context:
with self.test_request_context():
self.assertIsNone(self.cache.get("new key"))
self.assertIsNone(self.cache.set("new key", 1))
self.assertIsNone(self.cache.get("new key"))
Expand All @@ -48,5 +48,5 @@ def test_master_not_found(self):
)
)

with self.test_request_context:
with self.test_request_context():
self.assertIsNone(self.cache.get('somekey'))
6 changes: 3 additions & 3 deletions labonneboite/tests/app/maps/test_ign.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_ign_500_error(self):
)
requests_get = mock.Mock(return_value=response)

with self.test_request_context:
with self.test_request_context():
with mock.patch.object(ign.requests, 'get', requests_get):
self.assertRaises(exceptions.BackendUnreachable,
ign.isochrone, places.vallouise, constants.ISOCHRONE_DURATIONS_MINUTES[0])
Expand All @@ -50,15 +50,15 @@ def test_ign_authentication_error(self):
)
requests_get = mock.Mock(return_value=response)

with self.test_request_context:
with self.test_request_context():
with mock.patch.object(ign.requests, 'get', requests_get):
self.assertRaises(exceptions.BackendUnreachable,
ign.isochrone, places.metz, constants.ISOCHRONE_DURATIONS_MINUTES[0])

def test_ign_timeout(self):
requests_get = mock.Mock(side_effect=ign.requests.exceptions.Timeout())

with self.test_request_context:
with self.test_request_context():
with mock.patch.object(ign.requests, 'get', requests_get):
self.assertRaises(exceptions.BackendUnreachable,
ign.isochrone, places.metz, constants.ISOCHRONE_DURATIONS_MINUTES[0])
Expand Down
4 changes: 2 additions & 2 deletions labonneboite/tests/app/test_api_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_update_office_boost_flag_specific_romes_alternance(self):
'contract': 'alternance'
})

with self.test_request_context:
with self.test_request_context():
rv = self.app.get(self.url_for("api.company_list", **params))
self.assertEqual(rv.status_code, 200)
data_list = json.loads(rv.data.decode())
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_update_office_boost_flag_all_romes_alternance(self):
'contract': 'alternance'
})

with self.test_request_context:
with self.test_request_context():
rv = self.app.get(self.url_for("api.company_list", **params))
self.assertEqual(rv.status_code, 200, msg=rv.data)
data_list = json.loads(rv.data.decode())
Expand Down
Loading