def _get_advice_data(project, advice_id): try: return next(advice for advice in project.advices if advice.advice_id == advice_id) except StopIteration: flask.abort(404, 'Conseil "%s" inconnu.' % advice_id) _ACTION_STOPPED_STATUSES = frozenset([ action_pb2.ACTION_SNOOZED, action_pb2.ACTION_DONE, action_pb2.ACTION_STICKY_DONE, action_pb2.ACTION_DECLINED ]) # Cache (from MongoDB) of known chantiers. _CHANTIERS = proto.MongoCachedCollection(chantier_pb2.Chantier, 'chantiers') def _chantiers(): """Returns a list of known chantiers as protos.""" return _CHANTIERS.get_collection(_DB) # TODO: Split this into separate endpoints for registration and login. # Having both in the same endpoint makes refactoring the frontend more difficult. @app.route('/api/user/authenticate', methods=['POST']) @proto.flask_api(in_type=user_pb2.AuthRequest, out_type=user_pb2.AuthResponse) def authenticate(auth_request): """Authenticate a user.""" authenticator = auth.Authenticator( _DB, lambda u: _save_user(u, is_new_user=True))
def setUp(self): """Set up mock environment.""" super(CacheMongoTestCase, self).setUp() self._db = mongomock.MongoClient().get_database('test') self._collection = proto.MongoCachedCollection(job_pb2.JobGroup, 'basic')
def __init__(self): super(_AdviceEventScoringModel, self).__init__() self._db = proto.MongoCachedCollection(event_pb2.Event, 'events')
from bob_emploi.frontend import auth from bob_emploi.frontend import french from bob_emploi.frontend import mail from bob_emploi.frontend import proto from bob_emploi.frontend.api import job_pb2 from bob_emploi.frontend.api import project_pb2 from bob_emploi.frontend.api import user_pb2 from bob_emploi.frontend.asynchronous import report _DB = pymongo.MongoClient(os.getenv('MONGO_URL', 'mongodb://localhost/test'))\ .get_default_database() # Cache (from MongoDB) of job group info. _JOB_GROUPS_INFO = proto.MongoCachedCollection(job_pb2.JobGroup, 'job_group_info') # The base URL to use as the prefix of all links to the website. E.g. in dev, # you should use http://localhost:3000. _BASE_URL = os.getenv('BASE_URL', 'https://www.bob-emploi.fr') # There is 2 spaces between the rank (2e, 3e) and the Arrondissement, # except for the first one where there is only 1 space (i.e 1er Arrondissement). _DISTRICT_MATCHER = re.compile(r'(\w+)\s(\d+e)r?(\s{1,2}Arrondissement)') class RomePrefixInfo(object): """Info per job group organized by ROME prefix.""" def __init__(self, records=None): self._data = collections.defaultdict(dict) if records:
if not scoring_project: scoring_project = scoring.ScoringProject(project, user.profile, user.features_enabled, database, now=now.get()) cache['scoring_project'] = scoring_project filtered_tips = scoring.filter_using_score(tip_templates, lambda t: t.filters, scoring_project) return filtered_tips # Cache (from MongoDB) of known advice module. _ADVICE_MODULES = proto.MongoCachedCollection(advisor_pb2.AdviceModule, 'advice_modules') _EASY_ADVICE_MODULES = set() def _advice_modules(database): return _ADVICE_MODULES.get_collection(database) def get_advice_module(advice_id, database): """Get a module by its ID.""" try: return next(a for a in _advice_modules(database) if a.advice_id == advice_id) except StopIteration: return None
def __init__(self): super(_AdviceJobBoards, self).__init__(user_pb2.NO_OFFERS) self._db = proto.MongoCachedCollection(jobboard_pb2.JobBoard, 'jobboards')
def __init__(self): super(_AdviceAssociationHelp, self).__init__() self._db = proto.MongoCachedCollection(association_pb2.Association, 'associations')
def __init__(self, network_level): super(_ImproveYourNetworkScoringModel, self).__init__() self._db = proto.MongoCachedCollection(network_pb2.ContactLeadTemplate, 'contact_lead') self._network_level = network_level