def get_acquisition_framework(info_role, id_acquisition_framework): """ Get one AF with nomenclatures .. :quickref: Metadata; :param id_acquisition_framework: the id_acquisition_framework :param type: int :returns: dict<TAcquisitionFramework> """ acquisitionFrameworkSchema = AcquisitionFrameworkSchema() user_cruved = cruved_scope_for_user_in_module( id_role=info_role.id_role, module_code="METADATA", )[0] acquisitionFrameworkSchema.context = { 'info_role': info_role, 'user_cruved': user_cruved } acquisition_framework = DB.session.query(TAcquisitionFramework).get( id_acquisition_framework) if not acquisition_framework: raise NotFound('Acquisition framework "{}" does not exist'.format( id_acquisition_framework)) return acquisitionFrameworkSchema.jsonify(acquisition_framework)
def get_acquisition_frameworks(info_role): """ Get a simple list of AF without any nested relationships Use for AF select in form Get the GeoNature CRUVED """ only = [] af_list = ( TAcquisitionFramework.query.filter_by_readable().filter_by_params( request.args.to_dict()).options( Load(TAcquisitionFramework).raiseload('*'), # for permission checks: joinedload('creator'), joinedload('cor_af_actor').options( joinedload('role'), joinedload('organism'), ), joinedload('t_datasets').options( joinedload('digitizer'), joinedload('cor_dataset_actor').options( joinedload('role'), joinedload('organism'), ), ), )) if request.args.get('datasets', default=False, type=int): only.extend([ 't_datasets', ]) if request.args.get('creator', default=False, type=int): only.append('creator') af_list = af_list.options(joinedload('creator')) if request.args.get('actors', default=False, type=int): only.extend([ 'cor_af_actor', 'cor_af_actor.nomenclature_actor_role', 'cor_af_actor.organism', 'cor_af_actor.role', ]) af_list = af_list.options( joinedload('cor_af_actor').options( joinedload('nomenclature_actor_role'), ), ) if request.args.get('datasets', default=False, type=int): only.extend([ 't_datasets.cor_dataset_actor', 't_datasets.cor_dataset_actor.nomenclature_actor_role', 't_datasets.cor_dataset_actor.organism', 't_datasets.cor_dataset_actor.role', ]) af_list = af_list.options( joinedload('t_datasets').options( joinedload('cor_dataset_actor').options( joinedload('nomenclature_actor_role'), ), ), ) af_schema = AcquisitionFrameworkSchema(only=only) user_cruved = cruved_scope_for_user_in_module( id_role=info_role.id_role, module_code="METADATA", )[0] af_schema.context = {'user_cruved': user_cruved} return af_schema.jsonify(af_list.all(), many=True)
def get_acquisition_frameworks_list(info_role): """ Get all AF with their datasets Use in metadata module for list of AF and DS Add the CRUVED permission for each row (Dataset and AD) .. :quickref: Metadata; :param info_role: add with kwargs :type info_role: TRole :qparam list excluded_fields: fields excluded from serialization :qparam boolean nested: Default False - serialized relationships. If false: remove add all relationships in excluded_fields """ if current_app.config["CAS_PUBLIC"]["CAS_AUTHENTIFICATION"]: # synchronise the CA and JDD from the MTD WS try: mtd_utils.post_jdd_from_user(id_user=info_role.id_role, id_organism=info_role.id_organisme) except Exception as e: log.error(e) params = request.args.to_dict() params["orderby"] = "acquisition_framework_name" if "selector" not in params: params["selector"] = None user_cruved = cruved_scope_for_user_in_module( id_role=info_role.id_role, module_code="METADATA", )[0] nested_serialization = params.get("nested", False) nested_serialization = True if nested_serialization == "true" else False exclude_fields = [] if "excluded_fields" in params: exclude_fields = params.get("excluded_fields") try: exclude_fields = exclude_fields.split(',') except: raise BadRequest("Malformated parameter 'excluded_fields'") if not nested_serialization: # exclude all relationships from serialization if nested = false exclude_fields = [ db_rel.key for db_rel in inspect(TAcquisitionFramework).relationships ] acquisitionFrameworkSchema = AcquisitionFrameworkSchema( exclude=exclude_fields) acquisitionFrameworkSchema.context = { 'info_role': info_role, 'user_cruved': user_cruved } return acquisitionFrameworkSchema.jsonify(get_metadata_list( info_role, params, exclude_fields).all(), many=True)
def get_acquisition_framework(info_role, id_acquisition_framework): """ Get one AF with nomenclatures .. :quickref: Metadata; :param id_acquisition_framework: the id_acquisition_framework :param type: int :returns: dict<TAcquisitionFramework> """ af = TAcquisitionFramework.query.get_or_404(id_acquisition_framework) if not af.has_instance_permission(scope=int(info_role.value_filter)): raise Forbidden(f"User {g.current_user} cannot read acquisition " "framework {af.id_acquisition_framework}") exclude = request.args.getlist("exclude") try: af_schema = AcquisitionFrameworkSchema(only=[ 'creator', 'nomenclature_territorial_level', 'nomenclature_financing_type', 'cor_af_actor', 'cor_af_actor.nomenclature_actor_role', 'cor_af_actor.organism', 'cor_af_actor.role', 'cor_volets_sinp', 'cor_objectifs', 'cor_territories', 't_datasets', 't_datasets.creator', 't_datasets.nomenclature_data_type', 't_datasets.cor_dataset_actor', 't_datasets.cor_dataset_actor.nomenclature_actor_role', 't_datasets.cor_dataset_actor.organism', 't_datasets.cor_dataset_actor.role', ], exclude=exclude) except ValueError as e: raise BadRequest(str(e)) user_cruved = cruved_scope_for_user_in_module( id_role=info_role.id_role, module_code="METADATA", )[0] af_schema.context = {'user_cruved': user_cruved} return af_schema.jsonify(af)