def term_get_tree(uuid): """Get a term given the uuid, in deep, meaning the children Receive <level> as an argument, defining the level of the tree considering the children as level=1 and parent as level=-1 If argument <level> is not provided or equal 0, returns the first level, meaning only the term. Whith negative values it gets to the parents. TermNode { term:Term, children: TermNode[], parent:TermNode } """ try: level = int( request.args.get('level')) if request.args.get('level') else 0 msg, term = Terms.get_term(uuid) if not term: raise Exception(msg) return iroko_json_response( IrokoResponseStatus.SUCCESS, msg, 'term_node', term_node_schema.dump_term_node(term, level, 0)) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def source_new(): try: if not request.is_json: raise Exception("No JSON data provided") input_data = request.json msg, source = SourcesDeprecated.insert_new_source(input_data) if not source: raise Exception(msg) notification = NotificationSchema() notification.classification = NotificationType.INFO notification.description = _( 'Nueva fuente ingresada, requiere revisión de un gestor {0}'. format(source.name)) notification.emiter = _('Sistema') msg, users = SourcesDeprecated.get_user_ids_source_managers( source.uuid) if users: for user_id in users: notification.receiver_id = user_id Notifications.new_notification(notification) return iroko_json_response( IrokoResponseStatus.SUCCESS, \ 'ok', 'source', \ {'data': source_schema.dump(source), 'count': 1} ) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def get_users_organization(uuid): """ get the list of user with permission of organization manager :param uuid: organization uuid :return: """ try: org = CuorHelper.query_cuor_by_uuid(uuid) if not org: raise Exception('Organization not found') if is_user_sources_admin(current_user) or \ user_is_organization_manager(org['id'], current_user): ids = get_user_ids_for_source_from_action( 'source_organization_manager_actions', uuid) users = User.query.filter(User.id.in_(ids)).all() return iroko_json_response( IrokoResponseStatus.SUCCESS, 'ok', 'permission', { 'action': 'manager', 'organization': uuid, 'users': user_schema_many.dump(users) }) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def get_users_source_editor(uuid): """ get the lists of user with permission of editor and manager :param uuid: source uuid :return: """ try: source = SourceRecord.get_record(uuid) if not source: raise Exception('Not source found') if source.user_has_manager_permission(current_user): ids = get_user_ids_for_source_from_action('source_editor_actions', uuid) users = User.query.filter(User.id.in_(ids)).all() return iroko_json_response( IrokoResponseStatus.SUCCESS, 'ok', 'permission', { 'action': 'editor', 'source': uuid, 'users': user_schema_many.dump(users) }) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def get_editor_source_versions(uuid): try: # listar las versiones de este editor que no se han revisado para que pueda cambiarlas source = SourceRecord.get_record(uuid) # print('source> ', source) if not source: raise Exception('Not source found') if source.user_has_edit_permission(current_user): versions = source.get_editor_versions_not_reviewed() return iroko_json_response( IrokoResponseStatus.SUCCESS, \ 'ok', 'source', \ { 'data': source, 'versions': source_version_schema_many.dump(versions), 'count': 1 } ) except PermissionDenied as err: msg = 'Permission denied for changing source' return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def source_unpublish(uuid): # pone source_status = SourceStatus.TO_REVIEW try: source = SourceRecord.get_record(uuid) if not source: raise Exception('Not source found') if source.user_has_manager_permission(current_user): source['source_status'] = SourceStatus.TO_REVIEW.value source.update() # TODO: aqui hay un error con los get managers # notification = NotificationSchema() # notification.classification = NotificationType.INFO # notification.description = _('Se ha despublicado la fuente: {0}.'.format(source[ # 'name'])) # notification.emiter = _('Sistema') # # for user in source.get_managers: # notification.receiver_id = user # Notifications.new_notification(notification) # print('************************** to response') return iroko_json_response(IrokoResponseStatus.SUCCESS, 'ok', 'source', source) except PermissionDenied as err: msg = 'Permission denied for changing source' return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None) except Exception as e: raise e return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def get_users_term(uuid): """ get the lists of user with permission of term manager :param uuid: term uuid :return: """ try: term = Term.query.filter_by(uuid=uuid).first() if not term: raise Exception('Term not found') if is_user_sources_admin(current_user) or \ user_is_term_manager(term.uuid, current_user): ids = get_user_ids_for_source_from_action( 'source_term_manager_actions', uuid) users = User.query.filter(User.id.in_(ids)).all() return iroko_json_response( IrokoResponseStatus.SUCCESS, 'ok', 'permission', { 'action': 'manager', 'term': uuid, 'users': user_schema_many.dump(users) }) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def get_editor_source_versions(uuid): try: # listar las versiones de este editor que no se han revisado para que pueda cambiarlas source = SourcesDeprecated.get_source_by_id(uuid=uuid) # print('source> ', source) if not source: raise Exception('Not source found') with source_editor_permission_factory({'uuid': source.uuid}).require(): versions = SourcesDeprecated.get_editor_versions_not_reviewed( source) return iroko_json_response( IrokoResponseStatus.SUCCESS, \ 'ok', 'source', \ { 'data': source_schema.dump(source), 'versions': source_version_schema_many.dump(versions), 'count': 1 } ) except PermissionDenied as err: msg = 'Permission denied for changing source' return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def term_edit(uuid): msg = '' try: msg, term = Terms.get_term(uuid) # # print(term) if not term: raise Exception(msg) with vocabulary_editor_permission_factory({ 'name': term.vocabulary_id }).require(): # # print(term.vocabulary_id) # user = current_user if not request.is_json: raise Exception("No JSON data provided") input_data = request.json # # print(input_data) msg, term = Terms.edit_term(uuid, input_data) if not term: raise Exception(msg) return iroko_json_response( IrokoResponseStatus.SUCCESS, \ msg, 'term', \ term_schema.dump(term) ) except PermissionDenied as err: msg = 'Permission denied for editing term' except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def get_journal_by_issn(issn): """Get a journal by UUID""" # print('def get_journal_by_issn(issn):') try: issn_db = SourceRawData.query.filter_by(identifier=issn).first() if not issn_db: return iroko_json_response( IrokoResponseStatus.NOT_FOUND, "ISSN {0} not found on Cuban ISSNs list".format(issn), None, None) # raise Exception("ISSN {0} not found on Cuban ISSNs list".format(issn)) issns_with_info = issn_db.data if not "@graph" in issns_with_info.keys(): raise Exception("Wrong json format for ISSN: {0}".format(issn)) for item in issns_with_info["@graph"]: if item['@id'] == 'resource/ISSN/' + issn + '#KeyTitle': return iroko_json_response(IrokoResponseStatus.SUCCESS, "ok", "issn_org", { "issn": issn, "title": item["value"] }) # if "issn" in item.keys() and "name" in item.keys(): # return iroko_json_response(IrokoResponseStatus.SUCCESS, # "ok", "ISSN validation", # {"issn":issn, "name":item["name"]}) raise Exception("Internal Error: Name not found on the ISSN info") except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def term_new(): msg = '' try: # print(request) if not request.is_json: raise Exception("No JSON data provided") input_data = request.json with vocabulary_editor_permission_factory({ 'name': input_data['vocabulary_id'] }).require(): msg, term = Terms.new_term(input_data) if not term: raise Exception(msg) return iroko_json_response( IrokoResponseStatus.SUCCESS, \ msg, 'term', \ term_schema.dump(term) ) except PermissionDenied as err: msg = 'Permission denied for adding term' except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def get_notifications(): try: """ List all notifications """ count = int( request.args.get('size')) if request.args.get('size') else 10 page = int(request.args.get('page')) if request.args.get('page') else 1 if page < 1: page = 1 offset = count * (page - 1) limit = offset + count result = Notification.query.filter_by( receiver_id=current_user.id).order_by('viewed').all() result1 = Notification.query.filter_by(receiver_id=current_user.id, viewed=False).all() count_not_viewed = len(result1) count_total = len(result) return iroko_json_response( IrokoResponseStatus.SUCCESS, \ 'ok', 'notifications', \ { 'data': notification_schema_many.dump(result[offset:limit]), 'total': count_total, 'total_not_view': count_not_viewed } ) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def get_sources_from_manager(status): """ param status: 'all', 'approved', 'to_review', 'unofficial' """ try: count = int( request.args.get('size')) if request.args.get('size') else 10 page = int(request.args.get('page')) if request.args.get('page') else 1 if page < 1: page = 1 offset = count * (page - 1) limit = offset + count msg, sources = SourcesDeprecated.get_sources_from_manager_current_user( status) return iroko_json_response( IrokoResponseStatus.SUCCESS, msg, 'sources', source_schema_many.dump(sources[offset:limit])) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def repo_schedule_harvest(uuid): """ schedule a harvest of a source params: uuid: Source uuid """ try: source = SourceRecord.get_record(uuid) if not source: raise Exception('Not source found') repository = Repository.query.filter_by(source_uuid=source.id).first() if not repository: raise Exception('Not repository found') if not request.is_json: raise Exception("No JSON data provided") input_data = request.json schedule_datetime = datetime.datetime.now() if 'datetime' in input_data: schedule_datetime = input_data['datetime'] harvester_class = 'iroko.harvester.oai.harvester.OaiHarvester' if 'harvester_class' in input_data: harvester_class = input_data['harvester_class'] # TODO: how instantiate an object from a class name. oai_harvester = OaiHarvester(repository) HarvestersTaskManager.schedule_harvest(oai_harvester, schedule_datetime) return iroko_json_response(IrokoResponseStatus.SUCCESS, 'ok', 'repositories', None) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def get_terms_tree(vocabulary_id): """List all the terms in a vocabulary, in a tree Receive <level> as an argument, defining the level of the tree you want. If argument <level> is not provided returns the first level level=0 is the first level. """ try: level = int(request.args.get('level')) if request.args.get( 'level') and int(request.args.get('level')) >= 0 else 0 vocab = Vocabulary.query.filter_by(identifier=vocabulary_id).first() if not vocab: raise Exception( 'Invalid Vocabulary identifier {0}'.format(vocabulary_id)) terms = vocab.terms.filter_by(parent_id=None).all() return iroko_json_response( IrokoResponseStatus.SUCCESS, \ 'ok', 'tree', \ { 'vocab': vocabulary_schema.dump(vocab), \ 'term_node': term_node_schema.dump_term_node_list(terms, level, 0) } ) except Exception as e: # print(e) return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def sources_count_by_vocabulary(vocabulary_id): """List all the terms name from vocabulary_id and count of filtered by some relations with terms, also by type and status, Receive <agg_level> do the job from this specific level of the terms tree until all its sons <status> params: 'all', 'approved', 'to_review', 'unofficial' <type> params: 'all', 'journal', 'student', 'popularization', 'repository', 'website' <count> params: '0' for False, '1' for True <temrs> params: terms_uuid that each source should has """ try: count_list = SourcesDeprecated.get_sources_count_by_vocabulary( vocabulary_id) return iroko_json_response(IrokoResponseStatus.SUCCESS, 'ok', 'sources count', { 'counts': count_list, 'total': len(count_list) }) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def source_set_approved(uuid): try: source = SourcesDeprecated.get_source_by_id(uuid=uuid) if not source: raise Exception('Source not found.') with source_manager_permission_factory({'uuid': uuid}).require(): SourcesDeprecated.set_source_approved(source) notification = NotificationSchema() notification.classification = NotificationType.INFO notification.description = _( 'El gestor ha aprobado para incluir en Sceiba la fuente: {0}.'. format(source.name)) notification.emiter = _('Sistema') msg, users = SourcesDeprecated.get_user_ids_source_editor( source.uuid) if users: for user_id in users: notification.receiver_id = user_id Notifications.new_notification(notification) return iroko_json_response( IrokoResponseStatus.SUCCESS, 'Source {0} approved.'.format(source.name), 'source', source_schema.dump(source)) except PermissionDenied as err: msg = 'Permission denied for changing source' return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def set_organization_manager(user, uuid, allow=False): """ Set user as manager of a organization :param uuid: organization or term uuid :param user: user id :param allow: if allow or deny :return: """ try: userObj = User.query.filter_by(id=user).first() if not userObj: raise Exception('User not found') org = CuorHelper.query_cuor_by_uuid(uuid) if not org: raise Exception('Organization not found') parents = CuorHelper.get_relationships_parent(org) print(parents) allow_parent = False for p in parents: try: allow_parent = user_is_organization_manager( p['id'], current_user) except PermissionDenied: pass if is_user_sources_admin(current_user) or \ allow_parent or \ user_is_organization_manager(org['id'], current_user): with db.session.begin_nested(): ActionUsers.query.filter_by( user_id=user, action='source_organization_manager_actions', argument=uuid).delete() if allow: db.session.add( ActionUsers.allow( ObjectSourceOrganizationManager(uuid), user=userObj)) else: db.session.add( ActionUsers.deny(ObjectSourceOrganizationManager(uuid), user=userObj)) db.session.commit() return iroko_json_response(IrokoResponseStatus.SUCCESS, 'ok', 'permission', { 'org': uuid, 'user': user, 'permission': 'manager', 'allow': allow }) raise PermissionDenied() except PermissionDenied as err: msg = 'Permission denied' return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def source_publish(uuid): # inserta un nuevo sourceVersion de un source que ya existe # input_data = request.json # updata el input_data en el SourceRecord try: if not request.is_json: raise Exception("No JSON data provided") input_data = request.json user_id = current_user.id comment = 'no comment' if 'comment' in input_data: comment = input_data['comment'] source = SourceRecord.get_record(uuid) if not source: raise Exception('Not source found') if source.user_has_manager_permission(current_user): data = dict(input_data['data']) data['source_status'] = SourceStatus.APPROVED.value source_version = IrokoSourceVersions.new_version(source.id, data, user_id=user_id, comment=comment, is_current=True) if not source_version: raise Exception('Not source for changing found') source.update(data) # TODO: aqui hay un error con los get managers # notification = NotificationSchema() # notification.classification = NotificationType.INFO # notification.description = _('Se ha publicado una nueva version de la fuente: {0}:{ # 1}.'.format(source['name'], source.id)) # notification.emiter = _('Sistema') # # for user in source.get_managers: # notification.receiver_id = user # Notifications.new_notification(notification) # print('************************** to response') return iroko_json_response(IrokoResponseStatus.SUCCESS, 'ok', 'source', source) except PermissionDenied as err: msg = 'Permission denied for changing source' except PIDObjectAlreadyAssigned as err: msg = 'El Identificador persistente ya existe: ' + str(err) # print('*******', msg) except Exception as e: msg = str(e) # print('*******', msg) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def get_terms(vocabulary_id): """Get all terms of a vocabulary in a list """ try: msg, terms = Terms.get_terms_by_vocab(vocabulary_id) return iroko_json_response(IrokoResponseStatus.SUCCESS, 'ok', 'terms', term_schema_many.dump(terms)) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def source_new_version(uuid): # inserta un nuevo sourceVersion de un source que ya existe # input_data = request.json # source = Sources.get_source_by_id(uuid=uuid) # Sources.insert_new_source_version(input_data, source, False) try: if not request.is_json: raise Exception("No JSON data provided") input_data = request.json user_id = current_user.id comment = 'no comment' if 'comment' in input_data: comment = input_data['comment'] source = SourceRecord.get_record(uuid) if not source: raise Exception('Not source found') if source.user_has_edit_permission(current_user): # si no esta aprobada significa que siempre es la current. # si esta aprobada el proceso es otro # print(input_data) data = dict(input_data['data']) # data['source_status'] = SourceStatus.TO_REVIEW.value # # source.update(data) source_version = IrokoSourceVersions.new_version(source.id, data, user_id=user_id, comment=comment, is_current=False) if not source_version: raise Exception('Not source for changing found') # notification = NotificationSchema() # notification.classification = NotificationType.INFO # notification.description = _('Editor has change this source: {0}.'.format(source[ # 'name'])) # notification.emiter = _('Sistema') # # for user in source.get_managers: # notification.receiver_id = user # Notifications.new_notification(notification) return iroko_json_response( IrokoResponseStatus.SUCCESS, 'ok', 'source_version', source_version_schema.dump(source_version)) except PermissionDenied as err: msg = 'Permission denied for changing source' return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None) except Exception as e: raise e
def get_source_manager(uuid): try: msg, user_ids = SourcesDeprecated.get_user_ids_source_managers(uuid) return iroko_json_response(IrokoResponseStatus.SUCCESS, msg, 'users', user_ids) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def sources_current_user_permissions(): msg = '' try: actions, vocabs = get_current_user_source_permissions() return iroko_json_response(IrokoResponseStatus.SUCCESS, msg, 'permissions', {actions: vocabs}) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def set_term_manager(user, uuid, allow=False): """ Set user as manager of a organization :param uuid: organization or term uuid :param user: user id :param allow: if allow or deny :return: """ try: userObj = User.query.filter_by(id=user).first() if not userObj: raise Exception('User not found') term = Term.query.filter_by(uuid=uuid).first() if not term: raise Exception('Term not found') parent = None if term.parent_id: parent = Term.query.filter_by(id=term.parent_id).first() if is_user_sources_admin(current_user) or \ user_is_term_manager(term.uuid, current_user) or \ (parent and user_is_term_manager(parent.uuid, current_user)): with db.session.begin_nested(): ActionUsers.query.filter_by( user_id=user, action='source_term_manager_actions', argument=uuid).delete() if allow: db.session.add( ActionUsers.allow(ObjectSourceTermManager(uuid), user=userObj)) else: db.session.add( ActionUsers.deny(ObjectSourceTermManager(uuid), user=userObj)) db.session.commit() return iroko_json_response( IrokoResponseStatus.SUCCESS, 'ok', 'permission', { 'term': uuid, 'user': user, 'permission': 'manager', 'allow': allow }) raise PermissionDenied() except PermissionDenied as err: msg = 'Permission denied' return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def get_sources_from_user(status): """ param status: 'all', 'approved', 'to_review', 'unofficial' """ # print("## start get sources {0}".format(datetime.datetime.now().strftime("%H:%M:%S"))) try: count = int( request.args.get('size')) if request.args.get('size') else 10 page = int(request.args.get('page')) if request.args.get('page') else 1 if page < 1: page = 1 offset = count * (page - 1) limit = offset + count # print(offset) # print(limit) # print(status) msg, sources_manager = SourcesDeprecated.get_sources_from_manager_current_user( status) # print("## get_sources_from_manager_current_user {0}".format(datetime.datetime.now( # ).strftime("%H:%M:%S"))) msg, sources_editor = SourcesDeprecated.get_sources_from_editor_current_user( status) # print("## get_sources_from_editor_current_user {0}".format(datetime.datetime.now( # ).strftime("%H:%M:%S"))) in_first = set(sources_manager) # print("## in_first = set(sources_manager) {0}".format(datetime.datetime.now().strftime( # "%H:%M:%S"))) in_second = set(sources_editor) # print("## in_second = set(sources_editor) {0}".format(datetime.datetime.now().strftime( # "%H:%M:%S"))) in_second_but_not_in_first = in_second - in_first # print("## in_second_but_not_in_first = in_second - in_first {0}".format( # datetime.datetime.now().strftime("%H:%M:%S"))) result = sources_manager + list(in_second_but_not_in_first) # print("## result = sources_manager + list {0}".format(datetime.datetime.now().strftime( # "%H:%M:%S"))) # result.sort(key=lambda k: int(k['name']), reverse=True) # TODO: optimizar esta operacion porque puede ser lenta response = iroko_json_response( IrokoResponseStatus.SUCCESS, msg, 'sources', { 'count': len(result), 'sources': source_schema_many.dump(result[offset:limit]) }) # print("## iroko_json_response {0}".format(datetime.datetime.now().strftime("%H:%M:%S"))) return response except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def source_edit_version(id): try: if not request.is_json: raise Exception("No JSON data provided") input_data = request.json version = SourcesDeprecated.get_source_version_by_id(id) if not version: raise Exception('Not version found') source = SourcesDeprecated.get_source_by_id(uuid=version.source.uuid) if not source: raise Exception('Not source found') with source_editor_permission_factory({'uuid': source.uuid}).require(): msg, source, source_version = SourcesDeprecated.edit_source_version( input_data, version) if not source or not source_version: raise Exception('Not source for changing found') notification = NotificationSchema() notification.classification = NotificationType.INFO notification.description = _( 'The edit has change data in version of source: {0}.'.format( source.name)) notification.emiter = _('System') msg, users = SourcesDeprecated.get_user_ids_source_managers( source.uuid) if users: for user_id in users: notification.receiver_id = user_id Notifications.new_notification(notification) return iroko_json_response( IrokoResponseStatus.SUCCESS, \ 'ok', 'source', \ { 'data': source_schema_no_versions.dump(source), 'version': source_version_schema.dump(source_version), 'count': 1 } ) except PermissionDenied as err: msg = 'Permission denied for changing source' return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def term_delete(uuid): try: msg, term = Terms.get_term(uuid) with vocabulary_editor_permission_factory({ 'name': term.vocabulary_id }).require(): msg, deleted = Terms.delete_term(uuid) if deleted: return iroko_json_response(IrokoResponseStatus.SUCCESS, msg, 'term', {}) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def get_sources_count(): """return sources count""" try: result = SourcesDeprecated.count_sources() if not result: raise Exception('SourcesDeprecated not found') return iroko_json_response(IrokoResponseStatus.SUCCESS, 'ok', 'count', result) except Exception as e: return iroko_json_response(IrokoResponseStatus.ERROR, str(e), None, None)
def list_repositories(status): """ list repositories status: ALL, ERROR, FETCHING, HARVESTED, RECORDED """ try: if status == '' or status == 'ALL': status = None # TODO: repositories return iroko_json_response(IrokoResponseStatus.SUCCESS, 'ok', 'repositories', None) except Exception as e: msg = str(e) return iroko_json_response(IrokoResponseStatus.ERROR, msg, None, None)
def get_sources_clasification(uuid): """ Return the counts of sources using <uuid> argument as the base relations. receive the argument level, meaning, how deep will go in the tree of related terms level=0 means, only the received term, level=1 means the terms and its children. result in the form relations : { <termuuid>: { doc_count: number, <termname>: string, children: { <termuuid>: { doc_count: number, <termname>: string, children: } ... } } } """ # try: level = int(request.args.get('level')) if request.args.get('level') else 0 result = SourcesDeprecated.count_sources_clasified_by_term(uuid, level) if not result: raise Exception('Source not found') return iroko_json_response( IrokoResponseStatus.SUCCESS, \ 'ok', 'relations', result.data )