Exemplo n.º 1
0
Arquivo: views.py Projeto: mhaya/weko
def get_schema_form(item_type_id=0):
    """Get schema form.

    :param item_type_id: Item type ID. (Default: 0)
    :return: The json object.
    """
    try:
        cur_lang = current_i18n.language
        result = None
        if item_type_id > 0:
            result = ItemTypes.get_by_id(item_type_id)
        if result is None:
            return '["*"]'
        schema_form = result.form
        filemeta_form = schema_form[0]
        if 'filemeta' == filemeta_form.get('key'):
            group_list = Group.get_group_list()
            filemeta_form_group = filemeta_form.get('items')[-1]
            filemeta_form_group['type'] = 'select'
            filemeta_form_group['titleMap'] = group_list
        if 'default' != cur_lang:
            for elem in schema_form:
                if 'title_i18n' in elem and cur_lang in elem['title_i18n']\
                        and len(elem['title_i18n'][cur_lang]) > 0:
                    elem['title'] = elem['title_i18n'][cur_lang]
                if 'items' in elem:
                    for sub_elem in elem['items']:
                        if 'title_i18n' in sub_elem and cur_lang in \
                            sub_elem['title_i18n'] and len(
                                sub_elem['title_i18n'][cur_lang]) > 0:
                            sub_elem['title'] = sub_elem['title_i18n'][
                                cur_lang]
                        if sub_elem.get('title') == 'Group/Price':
                            for sub_item in sub_elem['items']:
                                if sub_item['title'] == "価格" and \
                                    'validationMessage_i18n' in sub_item and \
                                    cur_lang in sub_item[
                                    'validationMessage_i18n'] and\
                                    len(sub_item['validationMessage_i18n']
                                        [cur_lang]) > 0:
                                    sub_item['validationMessage'] = sub_item[
                                        'validationMessage_i18n'][cur_lang]
                        if 'items' in sub_elem:
                            for sub_item in sub_elem['items']:
                                if 'title_i18n' in sub_item and cur_lang in \
                                        sub_item['title_i18n'] and len(
                                        sub_item['title_i18n'][cur_lang]) > 0:
                                    sub_item['title'] = sub_item['title_i18n'][
                                        cur_lang]

        return jsonify(schema_form)
    except BaseException:
        current_app.logger.error('Unexpected error: ', sys.exc_info()[0])
    return abort(400)
Exemplo n.º 2
0
Arquivo: views.py Projeto: mhaya/weko
def get_json_schema(item_type_id=0):
    """Get json schema.

    :param item_type_id: Item type ID. (Default: 0)
    :return: The json object.
    """
    try:
        result = None
        json_schema = None
        cur_lang = current_i18n.language

        if item_type_id > 0:
            if item_type_id == 20:
                result = ItemTypes.get_by_id(item_type_id)
                if result is None:
                    return '{}'
                json_schema = result.schema
                properties = json_schema.get('properties')
                for key, value in properties.items():
                    if 'validationMessage_i18n' in value:
                        value['validationMessage'] =\
                            value['validationMessage_i18n'][cur_lang]
            else:
                result = ItemTypes.get_record(item_type_id)
                if 'filemeta' in json.dumps(result):
                    group_list = Group.get_group_list()
                    group_enum = list(group_list.keys())
                    filemeta_group = result.get('properties').get(
                        'filemeta').get('items').get('properties').get(
                            'groups')
                    filemeta_group['enum'] = group_enum

                json_schema = result

        if result is None:
            return '{}'
        return jsonify(json_schema)
    except BaseException:
        current_app.logger.error('Unexpected error: ', sys.exc_info()[0])
    return abort(400)
Exemplo n.º 3
0
def get_schema_form(item_type_id=0):
    """Get schema form.

    :param item_type_id: Item type ID. (Default: 0)
    :return: The json object.
    """
    try:
        # cur_lang = 'default'
        # if current_app.config['I18N_SESSION_KEY'] in session:
        #     cur_lang = session[current_app.config['I18N_SESSION_KEY']]
        cur_lang = current_i18n.language
        result = None
        if item_type_id > 0:
            result = ItemTypes.get_by_id(item_type_id)
        if result is None:
            return '["*"]'
        schema_form = result.form
        filemeta_form = schema_form[0]
        if 'filemeta' == filemeta_form.get('key'):
            group_list = Group.get_group_list()
            filemeta_form_group = filemeta_form.get('items')[-1]
            filemeta_form_group['type'] = 'select'
            filemeta_form_group['titleMap'] = group_list
        if 'default' != cur_lang:
            for elem in schema_form:
                if 'title_i18n' in elem:
                    if cur_lang in elem['title_i18n']:
                        if len(elem['title_i18n'][cur_lang]) > 0:
                            elem['title'] = elem['title_i18n'][cur_lang]
                if 'items' in elem:
                    for sub_elem in elem['items']:
                        if 'title_i18n' in sub_elem:
                            if cur_lang in sub_elem['title_i18n']:
                                if len(sub_elem['title_i18n'][cur_lang]) > 0:
                                    sub_elem['title'] = sub_elem['title_i18n'][
                                        cur_lang]
        return jsonify(schema_form)
    except:
        current_app.logger.error('Unexpected error: ', sys.exc_info()[0])
    return abort(400)
Exemplo n.º 4
0
def get_json_schema(item_type_id=0):
    """Get json schema.

    :param item_type_id: Item type ID. (Default: 0)
    :return: The json object.
    """
    try:
        result = None
        if item_type_id > 0:
            result = ItemTypes.get_record(item_type_id)
            if 'filemeta' in json.dumps(result):
                group_list = Group.get_group_list()
                group_enum = list(group_list.keys())
                filemeta_group = result.get('properties').get('filemeta').get(
                    'items').get('properties').get('groups')
                filemeta_group['enum'] = group_enum
        if result is None:
            return '{}'
        return jsonify(result)
    except:
        current_app.logger.error('Unexpected error: ', sys.exc_info()[0])
    return abort(400)
Exemplo n.º 5
0
def get_json_schema(item_type_id=0, activity_id=""):
    """Get json schema.

    :param item_type_id: Item type ID. (Default: 0)
    :param activity_id: Activity ID.  (Default: Null)
    :return: The json object.
    """
    try:
        result = None
        cur_lang = current_i18n.language

        if item_type_id > 0:
            result = ItemTypes.get_record(item_type_id)
            properties = result.get('properties')
            if 'filemeta' in json.dumps(result):
                group_list = Group.get_group_list()
                group_enum = list(group_list.keys())
                filemeta_group = properties.get('filemeta').get('items').get(
                    'properties').get('groups')
                filemeta_group['enum'] = group_enum
            for _key, value in properties.items():
                translate_validation_message(value, cur_lang)
        if result is None:
            return '{}'
        if activity_id:
            updated_json_schema = update_json_schema_by_activity_id(
                result, activity_id)
            if updated_json_schema:
                result = updated_json_schema
        json_schema = result
        # Remove excluded item in json_schema
        remove_excluded_items_in_json_schema(item_type_id, json_schema)
        return jsonify(json_schema)
    except BaseException:
        current_app.logger.error('Unexpected error: ', sys.exc_info()[0])
    return abort(400)
Exemplo n.º 6
0
def get_schema_form(item_type_id=0):
    """Get schema form.

    :param item_type_id: Item type ID. (Default: 0)
    :return: The json object.
    """
    try:
        cur_lang = current_i18n.language
        result = None
        if item_type_id > 0:
            result = ItemTypes.get_by_id(item_type_id)
        if result is None:
            return '["*"]'
        schema_form = result.form
        filemeta_form = schema_form[0]
        if 'filemeta' == filemeta_form.get('key'):
            group_list = Group.get_group_list()
            filemeta_form_group = filemeta_form.get('items')[-1]
            filemeta_form_group['type'] = 'select'
            filemeta_form_group['titleMap'] = group_list

        from .utils import recursive_form
        recursive_form(schema_form)
        # Check role for input(5 item type)
        update_sub_items_by_user_role(item_type_id, schema_form)

        # hidden option
        hidden_subitem = [
            'subitem_thumbnail', 'subitem_systemidt_identifier',
            'subitem_systemfile_datetime', 'subitem_systemfile_filename',
            'subitem_system_id_rg_doi', 'subitem_system_date_type',
            'subitem_system_date', 'subitem_system_identifier_type',
            'subitem_system_identifier', 'subitem_system_text'
        ]

        for i in hidden_subitem:
            hidden_items = [
                schema_form.index(form) for form in schema_form
                if form.get('items')
                and form['items'][0]['key'].split('.')[1] in i
            ]
            if hidden_items and i in json.dumps(schema_form):
                schema_form = update_schema_remove_hidden_item(
                    schema_form, result.render, hidden_items)

        for elem in schema_form:
            set_multi_language_name(elem, cur_lang)
            if 'items' in elem:
                items = elem['items']
                for item in items:
                    set_multi_language_name(item, cur_lang)

        if 'default' != cur_lang:
            for elem in schema_form:
                if 'title_i18n' in elem and cur_lang in elem['title_i18n']\
                        and len(elem['title_i18n'][cur_lang]) > 0:
                    elem['title'] = elem['title_i18n'][cur_lang]
                if 'items' in elem:
                    for sub_elem in elem['items']:
                        if 'title_i18n' in sub_elem and cur_lang in \
                            sub_elem['title_i18n'] and len(
                                sub_elem['title_i18n'][cur_lang]) > 0:
                            sub_elem['title'] = sub_elem['title_i18n'][
                                cur_lang]
                        if sub_elem.get('title') == 'Group/Price':
                            for sub_item in sub_elem['items']:
                                if sub_item['title'] == "価格" and \
                                    'validationMessage_i18n' in sub_item and \
                                    cur_lang in sub_item[
                                    'validationMessage_i18n'] and\
                                    len(sub_item['validationMessage_i18n']
                                        [cur_lang]) > 0:
                                    sub_item['validationMessage'] = sub_item[
                                        'validationMessage_i18n'][cur_lang]
                        if 'items' in sub_elem:
                            for sub_item in sub_elem['items']:
                                if 'title_i18n' in sub_item and cur_lang in \
                                        sub_item['title_i18n'] and len(
                                        sub_item['title_i18n'][cur_lang]) > 0:
                                    sub_item['title'] = sub_item['title_i18n'][
                                        cur_lang]

        return jsonify(schema_form)
    except BaseException:
        current_app.logger.error('Unexpected error: ', sys.exc_info()[0])
    return abort(400)