Exemple #1
0
def index():
    """Simplistic front page view."""
    getArgs = request.args
    ctx = {'community': None}
    community_id = ""
    if 'community' in getArgs:
        from weko_workflow.api import GetCommunity
        comm = GetCommunity.get_community_by_id(request.args.get('community'))
        ctx = {'community': comm}
        community_id = comm.id
    # In case user opens the web for the first time,
    # set default language base on Admin language setting
    set_default_language()
    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    if not style:
        IndexStyle.create(
            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'],
            width=3,
            height=None)
        style = IndexStyle.get(
            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width
    height = style.height
    index_link_enabled = style.index_link_enabled

    index_link_list = []
    for index in Index.query.all():
        if index.index_link_enabled and index.public_state:
            if hasattr(current_i18n, 'language'):
                if current_i18n.language == 'ja' and index.index_link_name:
                    index_link_list.append((index.id, index.index_link_name))
                else:
                    index_link_list.append(
                        (index.id, index.index_link_name_english))
            else:
                index_link_list.append(
                    (index.id, index.index_link_name_english))

    detail_condition = get_search_detail_keyword('')
    check_site_license_permission()
    send_info = {}
    send_info['site_license_flag'] = True \
        if hasattr(current_user, 'site_license_flag') else False
    send_info['site_license_name'] = current_user.site_license_name \
        if hasattr(current_user, 'site_license_name') else ''
    top_viewed.send(current_app._get_current_object(), info=send_info)
    return render_template(current_app.config['THEME_FRONTPAGE_TEMPLATE'],
                           render_widgets=True,
                           community_id=community_id,
                           detail_condition=detail_condition,
                           width=width,
                           height=height,
                           index_link_list=index_link_list,
                           index_link_enabled=index_link_enabled,
                           **ctx)
Exemple #2
0
def index():
    """Simplistic front page view."""
    get_args = request.args
    ctx = {'community': None}
    community_id = ""
    if 'community' in get_args:
        from weko_workflow.api import GetCommunity
        comm = GetCommunity.get_community_by_id(request.args.get('community'))
        ctx = {'community': comm}
        community_id = comm.id
    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    if not style:
        IndexStyle.create(
            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'],
            width=3,
            height=None)
        style = IndexStyle.get(
            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width
    height = style.height
    index_link_enabled = style.index_link_enabled

    if hasattr(current_i18n, 'language'):
        index_link_list = get_index_link_list(current_i18n.language)
    else:
        index_link_list = get_index_link_list()

    detail_condition = get_search_detail_keyword('')
    check_site_license_permission()
    send_info = {}
    send_info['site_license_flag'] = True \
        if hasattr(current_user, 'site_license_flag') else False
    send_info['site_license_name'] = current_user.site_license_name \
        if hasattr(current_user, 'site_license_name') else ''
    top_viewed.send(current_app._get_current_object(), info=send_info)

    # For front page, always use main layout
    page, render_widgets = get_design_layout(
        current_app.config['WEKO_THEME_DEFAULT_COMMUNITY'])
    render_header_footer = has_widget_design(
        current_app.config['WEKO_THEME_DEFAULT_COMMUNITY'],
        current_i18n.language)
    page = None

    return render_template(current_app.config['THEME_FRONTPAGE_TEMPLATE'],
                           page=page,
                           render_widgets=render_widgets,
                           render_header_footer=render_header_footer,
                           **get_weko_contents(request.args))
Exemple #3
0
def view(community):
    """Index page with uploader and list of existing depositions.

    :param community_id: ID of the community to view.
    """
    key_val = request.args
    if key_val and 'view' in key_val:
        view_val = request.args.get("view")
    else:
        view_val = None
    if view_val is not None and 'basic' in view_val:
        # return redirect(url_for('.detail', community_id=community.id))
        return generic_item(community,
                            current_app.config['COMMUNITIES_DETAIL_TEMPLATE'])

    ctx = {'community': community}
    community_id = community.id
    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width if style else '3'

    height = style.height if style else None

    sort_options, display_number = SearchSetting.get_results_setting()

    detail_condition = get_search_detail_keyword('')

    return render_template(current_app.config['THEME_FRONTPAGE_TEMPLATE'],
                           sort_option=sort_options,
                           detail_condition=detail_condition,
                           community_id=community_id,
                           width=width,
                           height=height,
                           **ctx)
Exemple #4
0
def search():
    """ Index Search page ui."""
    search_type = request.args.get('search_type', '0')
    getArgs = request.args
    community_id = ""
    ctx = {'community': None}
    cur_index_id = search_type if search_type not in (
        '0',
        '1',
    ) else None
    if 'community' in getArgs:
        from weko_workflow.api import GetCommunity
        comm = GetCommunity.get_community_by_id(request.args.get('community'))
        ctx = {'community': comm}
        community_id = comm.id

    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width if style else '3'

    return render_template(current_app.config['SEARCH_UI_SEARCH_TEMPLATE'],
                           index_id=cur_index_id,
                           community_id=community_id,
                           width=width,
                           **ctx)
Exemple #5
0
def get_weko_contents(getargs):
    """Get all contents needed for rendering WEKO frontpage."""
    community_id, ctx = get_community_id(getargs)

    # Index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    if not style:
        IndexStyle.create(
            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'],
            width=3,
            height=None)
        style = IndexStyle.get(
            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width
    height = style.height
    index_link_enabled = style.index_link_enabled

    index_link_list = []
    for index in Index.query.all():
        if index.index_link_enabled and index.public_state:
            if hasattr(current_i18n, 'language'):
                if current_i18n.language == 'ja' and index.index_link_name:
                    index_link_list.append((index.id, index.index_link_name))
                else:
                    index_link_list.append(
                        (index.id, index.index_link_name_english))
            else:
                index_link_list.append(
                    (index.id, index.index_link_name_english))

    detail_condition = get_search_detail_keyword('')
    check_site_license_permission()

    return dict(community_id=community_id,
                detail_condition=detail_condition,
                width=width,
                height=height,
                index_link_list=index_link_list,
                index_link_enabled=index_link_enabled,
                **ctx)
Exemple #6
0
def curate(community):
    """Index page with uploader and list of existing depositions.

    :param community_id: ID of the community to curate.
    """
    if request.method == 'POST':
        action = request.json.get('action')
        recid = request.json.get('recid')

        # 'recid' is mandatory
        if not recid:
            abort(400)
        if action not in ['accept', 'reject', 'remove']:
            abort(400)

        # Resolve recid to a Record
        resolver = Resolver(pid_type='recid',
                            object_type='rec',
                            getter=Record.get_record)
        pid, record = resolver.resolve(recid)

        # Perform actions
        if action == "accept":
            community.accept_record(record)
        elif action == "reject":
            community.reject_record(record)
        elif action == "remove":
            community.remove_record(record)

        record.commit()
        db.session.commit()
        RecordIndexer().index_by_id(record.id)
        return jsonify({'status': 'success'})

    ctx = {'community': community}
    community_id = community.id
    community_flg = "0"

    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width if style else '3'
    height = style.height if style else None

    sort_options, display_number = SearchSetting.get_results_setting()

    return render_template(current_app.config['COMMUNITIES_CURATE_TEMPLATE'],
                           community_id=community_id,
                           sort_option=sort_options,
                           width=width,
                           height=height,
                           **ctx)
Exemple #7
0
def index():
    """Simplistic front page view."""
    getArgs = request.args
    ctx = {'community': None}
    community_id = ""
    if 'community' in getArgs:
        from weko_workflow.api import GetCommunity
        comm = GetCommunity.get_community_by_id(request.args.get('community'))
        ctx = {'community': comm}
        community_id = comm.id

    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width if style else '3'

    return render_template(current_app.config['THEME_FRONTPAGE_TEMPLATE'],
                           community_id=community_id,
                           width=width,
                           **ctx)
Exemple #8
0
def default_view_method(pid, record, template=None, **kwargs):
    """Display default view.

    Sends record_viewed signal and renders template.

    :param pid: PID object.
    :param record: Record object.
    :param template: Template to render.
    :param \*\*kwargs: Additional view arguments based on URL rule.
    :returns: The rendered template.
    """
    record_viewed.send(
        current_app._get_current_object(),
        pid=pid,
        record=record,
    )

    getargs = request.args
    community_id = ""
    ctx = {'community': None}
    if 'community' in getargs:
        from weko_workflow.api import GetCommunity
        comm = GetCommunity.get_community_by_id(request.args.get('community'))
        ctx = {'community': comm}
        community_id = comm.id

    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width if style else '3'

    return render_template(template,
                           pid=pid,
                           record=record,
                           community_id=community_id,
                           **ctx,
                           **kwargs,
                           width=width)
Exemple #9
0
    def index(self):
        """Index Search page ui."""
        search_type = request.args.get('search_type', '0')
        getArgs = request.args
        community_id = ""
        ctx = {'community': None}
        cur_index_id = search_type if search_type not in (
            '0',
            '1',
        ) else None
        if 'community' in getArgs:
            from weko_workflow.api import GetCommunity
            comm = GetCommunity.get_community_by_id(
                request.args.get('community'))
            ctx = {'community': comm}
            community_id = comm.id

        # Get index style
        style = IndexStyle.get(
            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
        width = style.width if style else '3'

        detail_condition = get_search_detail_keyword('')

        height = style.height if style else None

        if 'item_management' in getArgs:
            management_type = request.args.get('item_management', 'sort')

            has_items = False
            has_child_trees = False
            if management_type == 'delete':
                # Does this tree has items or children?
                q = request.args.get('q')
                if q is not None and q.isdigit():
                    current_tree = Indexes.get_index(q)
                    recursive_tree = Indexes.get_recursive_tree(q)

                    if current_tree is not None:
                        tree_items = get_tree_items(current_tree.id)
                        has_items = len(tree_items) > 0
                        if recursive_tree is not None:
                            has_child_trees = len(recursive_tree) > 1

            return self.render(
                current_app.
                config['WEKO_THEME_ADMIN_ITEM_MANAGEMENT_TEMPLATE'],
                index_id=cur_index_id,
                community_id=community_id,
                width=width,
                height=height,
                management_type=management_type,
                fields=current_app.config['WEKO_RECORDS_UI_BULK_UPDATE_FIELDS']
                ['fields'],
                licences=current_app.
                config['WEKO_RECORDS_UI_BULK_UPDATE_FIELDS']['licences'],
                has_items=has_items,
                has_child_trees=has_child_trees,
                detail_condition=detail_condition,
                **ctx)
        else:
            return abort(500)
Exemple #10
0
    def index(self):
        """Site license setting page."""
        search_setting = get_search_setting()
        # get search author setting
        check_items_settings()
        search_author_flg = 'name'
        if 'ITEM_SEARCH_FLG' in current_app.config:
            search_author_flg = current_app.config['ITEM_SEARCH_FLG']
        search_setting['search_author_flg'] = search_author_flg
        # get index tree style setting
        style = IndexStyle.get(
            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
        width = style.width if style else '3'
        height = style.height if style else None
        search_setting['index_tree_style'] = {
            'width_options':
            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['widths'],
            'width':
            width,
            'height':
            height
        }
        # dump json string
        result = json.dumps(copy.deepcopy(search_setting))
        if 'POST' in request.method:
            jfy = {}
            try:
                # get requset data
                db_data = request.get_json()

                # update search author setting to db
                if 'search_author_flg' in db_data:
                    search_author_flg = db_data.pop('search_author_flg')
                    settings = AdminSettings.get('items_display_settings')
                    settings.items_search_author = search_author_flg
                    AdminSettings.update('items_display_settings',
                                         settings.__dict__)
                # update index tree style setting
                if 'index_tree_style' in db_data:
                    index_tree_style = db_data.pop('index_tree_style')
                    width = index_tree_style.get('width', '3')
                    height = index_tree_style.get('height', None)
                    if style:
                        IndexStyle.update(
                            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']
                            ['id'],
                            width=width,
                            height=height)
                    else:
                        IndexStyle.create(
                            current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']
                            ['id'],
                            width=width,
                            height=height)
                # update other search settings
                res = SearchManagement.get()
                if res:
                    id = res.id
                    SearchManagement.update(id, db_data)
                else:
                    SearchManagement.create(db_data)
                jfy['status'] = 201
                jfy['message'] = 'Search setting was successfully updated.'
            except BaseException as e:
                current_app.logger.error('Could not save search settings', e)
                jfy['status'] = 500
                jfy['message'] = 'Failed to update search setting.'
            return make_response(jsonify(jfy), jfy['status'])

        try:
            return self.render(
                current_app.config['WEKO_ADMIN_SEARCH_MANAGEMENT_TEMPLATE'],
                widths=current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']
                ['widths'],
                setting_data=result,
            )
        except BaseException as e:
            current_app.logger.error('Could not save search settings', e)
            abort(500)
Exemple #11
0
def default_view_method(pid, record, filename=None, template=None, **kwargs):
    r"""Display default view.

    Sends record_viewed signal and renders template.
    :param pid: PID object.
    :param record: Record object.
    :param filename: File name.
    :param template: Template to render.
    :param \*\*kwargs: Additional view arguments based on URL rule.
    :returns: The rendered template.
    """
    check_site_license_permission()
    check_items_settings()
    send_info = {}
    send_info['site_license_flag'] = True \
        if hasattr(current_user, 'site_license_flag') else False
    send_info['site_license_name'] = current_user.site_license_name \
        if hasattr(current_user, 'site_license_name') else ''
    record_viewed.send(current_app._get_current_object(),
                       pid=pid,
                       record=record,
                       info=send_info)
    getargs = request.args
    community_id = ""
    ctx = {'community': None}
    if 'community' in getargs:
        from weko_workflow.api import GetCommunity
        comm = GetCommunity.get_community_by_id(request.args.get('community'))
        ctx = {'community': comm}
        community_id = comm.id

    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width if style else '3'
    height = style.height if style else None

    detail_condition = get_search_detail_keyword('')

    weko_indexer = WekoIndexer()
    res = weko_indexer.get_item_link_info(pid=record.get("control_number"))
    if res is not None:
        record["relation"] = res
    else:
        record["relation"] = {}

    google_scholar_meta = _get_google_scholar_meta(record)

    pdfcoverpage_set_rec = PDFCoverPageSettings.find(1)
    # Check if user has the permission to download original pdf file
    # and the cover page setting is set and its value is enable (not disabled)
    can_download_original = check_original_pdf_download_permission(record) \
        and pdfcoverpage_set_rec is not None \
        and pdfcoverpage_set_rec.avail != 'disable'

    # Get item meta data
    record['permalink_uri'] = None
    pidstore_identifier = get_item_pidstore_identifier(pid.object_uuid)
    if not pidstore_identifier:
        record['permalink_uri'] = request.url
    else:
        record['permalink_uri'] = pidstore_identifier

    from invenio_files_rest.permissions import has_update_version_role
    can_update_version = has_update_version_role(current_user)

    datastore = RedisStore(
        redis.StrictRedis.from_url(current_app.config['CACHE_REDIS_URL']))
    cache_key = current_app.config['WEKO_ADMIN_CACHE_PREFIX'].\
        format(name='display_stats')
    if datastore.redis.exists(cache_key):
        curr_display_setting = datastore.get(cache_key).decode('utf-8')
        display_stats = True if curr_display_setting == 'True' else False
    else:
        display_stats = True

    return render_template(template,
                           pid=pid,
                           record=record,
                           display_stats=display_stats,
                           filename=filename,
                           can_download_original_pdf=can_download_original,
                           is_logged_in=current_user
                           and current_user.is_authenticated,
                           can_update_version=can_update_version,
                           community_id=community_id,
                           width=width,
                           detail_condition=detail_condition,
                           height=height,
                           google_scholar_meta=google_scholar_meta,
                           **ctx,
                           **kwargs)
Exemple #12
0
def default_view_method(pid, record, filename=None, template=None, **kwargs):
    """Display default view.

    Sends record_viewed signal and renders template.
    :param pid: PID object.
    :param record: Record object.
    :param filename: File name.
    :param template: Template to render.
    :param kwargs: Additional view arguments based on URL rule.
    :returns: The rendered template.
    """
    # Get PID version object to retrieve all versions of item
    pid_ver = PIDVersioning(child=pid)
    if not pid_ver.exists or pid_ver.is_last_child:
        abort(404)
    active_versions = list(pid_ver.children or [])
    all_versions = list(
        pid_ver.get_children(ordered=True, pid_status=None) or [])
    try:
        if WekoRecord.get_record(id_=active_versions[-1].object_uuid
                                 )['_deposit']['status'] == 'draft':
            active_versions.pop()
        if WekoRecord.get_record(id_=all_versions[-1].object_uuid
                                 )['_deposit']['status'] == 'draft':
            all_versions.pop()
    except Exception:
        pass
    if active_versions:
        # active_versions.remove(pid_ver.last_child)
        active_versions.pop()

    check_site_license_permission()
    check_items_settings()
    send_info = {}
    send_info['site_license_flag'] = True \
        if hasattr(current_user, 'site_license_flag') else False
    send_info['site_license_name'] = current_user.site_license_name \
        if hasattr(current_user, 'site_license_name') else ''
    record_viewed.send(current_app._get_current_object(),
                       pid=pid,
                       record=record,
                       info=send_info)
    community_arg = request.args.get('community')
    community_id = ""
    ctx = {'community': None}
    if community_arg:
        from weko_workflow.api import GetCommunity
        comm = GetCommunity.get_community_by_id(community_arg)
        ctx = {'community': comm}
        community_id = comm.id

    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width if style else '3'
    height = style.height if style else None

    detail_condition = get_search_detail_keyword('')

    # Add Item Reference data to Record Metadata
    pid_without_ver = record.get("recid").split('.')[0]
    res = ItemLink.get_item_link_info(pid_without_ver)
    if res:
        record["relation"] = res
    else:
        record["relation"] = {}

    google_scholar_meta = _get_google_scholar_meta(record)

    pdfcoverpage_set_rec = PDFCoverPageSettings.find(1)
    # Check if user has the permission to download original pdf file
    # and the cover page setting is set and its value is enable (not disabled)
    can_download_original = check_original_pdf_download_permission(record) \
        and pdfcoverpage_set_rec and pdfcoverpage_set_rec.avail != 'disable'

    # Get item meta data
    record['permalink_uri'] = None
    permalink = get_record_permalink(record)
    if not permalink:
        record['permalink_uri'] = request.url
    else:
        record['permalink_uri'] = permalink

    can_update_version = has_update_version_role(current_user)

    datastore = RedisStore(
        redis.StrictRedis.from_url(current_app.config['CACHE_REDIS_URL']))
    cache_key = current_app.config['WEKO_ADMIN_CACHE_PREFIX'].\
        format(name='display_stats')
    if datastore.redis.exists(cache_key):
        curr_display_setting = datastore.get(cache_key).decode('utf-8')
        display_stats = True if curr_display_setting == 'True' else False
    else:
        display_stats = True

    groups_price = get_groups_price(record)
    billing_files_permission = get_billing_file_download_permission(
        groups_price) if groups_price else None
    billing_files_prices = get_min_price_billing_file_download(
        groups_price, billing_files_permission) if groups_price else None

    from weko_theme.utils import get_design_layout
    # Get the design for widget rendering
    page, render_widgets = get_design_layout(
        request.args.get('community')
        or current_app.config['WEKO_THEME_DEFAULT_COMMUNITY'])

    if hasattr(current_i18n, 'language'):
        index_link_list = get_index_link_list(current_i18n.language)
    else:
        index_link_list = get_index_link_list()

    files_thumbnail = []
    if record.files:
        files_thumbnail = ObjectVersion.get_by_bucket(
            record.get('_buckets').get('deposit')).\
            filter_by(is_thumbnail=True).all()
    files = []
    for f in record.files:
        if check_file_permission(record, f.data) or is_open_restricted(f.data):
            files.append(f)
    # Flag: can edit record
    can_edit = True if pid == get_record_without_version(pid) else False

    open_day_display_flg = current_app.config.get('OPEN_DATE_DISPLAY_FLG')

    return render_template(template,
                           pid=pid,
                           pid_versioning=pid_ver,
                           active_versions=active_versions,
                           all_versions=all_versions,
                           record=record,
                           files=files,
                           display_stats=display_stats,
                           filename=filename,
                           can_download_original_pdf=can_download_original,
                           is_logged_in=current_user
                           and current_user.is_authenticated,
                           can_update_version=can_update_version,
                           page=page,
                           render_widgets=render_widgets,
                           community_id=community_id,
                           width=width,
                           detail_condition=detail_condition,
                           height=height,
                           index_link_enabled=style.index_link_enabled,
                           index_link_list=index_link_list,
                           google_scholar_meta=google_scholar_meta,
                           billing_files_permission=billing_files_permission,
                           billing_files_prices=billing_files_prices,
                           files_thumbnail=files_thumbnail,
                           can_edit=can_edit,
                           open_day_display_flg=open_day_display_flg,
                           **ctx,
                           **kwargs)
Exemple #13
0
def search():
    """Index Search page ui."""
    search_type = request.args.get('search_type', '0')
    getArgs = request.args
    community_id = ""
    ctx = {'community': None}
    cur_index_id = search_type if search_type not in (
        '0',
        '1',
    ) else None
    if 'community' in getArgs:
        from weko_workflow.api import GetCommunity
        comm = GetCommunity.get_community_by_id(request.args.get('community'))
        ctx = {'community': comm}
        community_id = comm.id

    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width if style else '3'

    # add at 1206 for search management
    sort_options, display_number = SearchSetting.get_results_setting()
    disply_setting = dict(size=display_number)

    detail_condition = get_search_detail_keyword('')

    height = style.height if style else None

    index_link_list = []
    for index in Index.query.all():
        if index.index_link_enabled and index.public_state:
            if hasattr(current_i18n, 'language'):
                if current_i18n.language == 'ja' and index.index_link_name:
                    index_link_list.append((index.id, index.index_link_name))
                else:
                    index_link_list.append(
                        (index.id, index.index_link_name_english))
            else:
                index_link_list.append(
                    (index.id, index.index_link_name_english))

    if 'item_link' in getArgs:
        activity_id = request.args.get('item_link')
        from weko_workflow.api import WorkActivity
        workFlowActivity = WorkActivity()
        activity_detail, item, steps, action_id, cur_step, temporary_comment, approval_record, \
            step_item_login_url, histories, res_check, pid, community_id, ctx \
            = workFlowActivity.get_activity_index_search(activity_id=activity_id)
        return render_template('weko_workflow/activity_detail.html',
                               render_widgets=True,
                               activity=activity_detail,
                               item=item,
                               steps=steps,
                               action_id=action_id,
                               cur_step=cur_step,
                               temporary_comment=temporary_comment,
                               record=approval_record,
                               step_item_login_url=step_item_login_url,
                               histories=histories,
                               res_check=res_check,
                               pid=pid,
                               index_id=cur_index_id,
                               community_id=community_id,
                               width=width,
                               height=height,
                               **ctx)
    else:
        journal_info = None
        check_site_license_permission()
        send_info = {}
        send_info['site_license_flag'] = True \
            if hasattr(current_user, 'site_license_flag') else False
        send_info['site_license_name'] = current_user.site_license_name \
            if hasattr(current_user, 'site_license_name') else ''
        if search_type in ('0', '1', '2'):
            searched.send(current_app._get_current_object(),
                          search_args=getArgs,
                          info=send_info)
            if search_type == '2':
                cur_index_id = request.args.get('q', '0')
                journal_info = get_journal_info(cur_index_id)
        return render_template(current_app.config['SEARCH_UI_SEARCH_TEMPLATE'],
                               render_widgets=True,
                               index_id=cur_index_id,
                               community_id=community_id,
                               sort_option=sort_options,
                               disply_setting=disply_setting,
                               detail_condition=detail_condition,
                               width=width,
                               height=height,
                               index_link_enabled=style.index_link_enabled,
                               index_link_list=index_link_list,
                               journal_info=journal_info,
                               **ctx)
Exemple #14
0
def search():
    """Index Search page ui."""
    search_type = request.args.get('search_type',
                                   WEKO_SEARCH_TYPE_DICT['FULL_TEXT'])
    get_args = request.args
    community_id = ""
    ctx = {'community': None}
    cur_index_id = search_type if search_type not in \
        (WEKO_SEARCH_TYPE_DICT['FULL_TEXT'], WEKO_SEARCH_TYPE_DICT[
            'KEYWORD'], ) else None
    if 'community' in get_args:
        from weko_workflow.api import GetCommunity
        comm = GetCommunity.get_community_by_id(request.args.get('community'))
        ctx = {'community': comm}
        community_id = comm.id

    # Get the design for widget rendering
    page, render_widgets = get_design_layout(
        community_id or current_app.config['WEKO_THEME_DEFAULT_COMMUNITY'])

    # Get index style
    style = IndexStyle.get(
        current_app.config['WEKO_INDEX_TREE_STYLE_OPTIONS']['id'])
    width = style.width if style else '3'

    # add at 1206 for search management
    sort_options, display_number = SearchSetting.get_results_setting()
    ts = time.time()
    disply_setting = dict(size=display_number, timestamp=ts)

    detail_condition = get_search_detail_keyword('')

    export_settings = AdminSettings.get('item_export_settings') or \
        AdminSettings.Dict2Obj(
            current_app.config['WEKO_ADMIN_DEFAULT_ITEM_EXPORT_SETTINGS'])

    height = style.height if style else None
    if 'item_link' in get_args:
        from weko_workflow.api import WorkActivity

        activity_id = request.args.get('item_link')
        workflow_activity = WorkActivity()
        activity_detail, item, steps, action_id, cur_step, temporary_comment,\
            approval_record, step_item_login_url, histories, res_check, pid, \
            community_id, ctx = workflow_activity.get_activity_index_search(
                activity_id=activity_id)

        # Get ex-Item Links
        recid = item['pid'].get('value') if item.get('pid') else None
        if recid:
            pid_without_ver = recid.split('.')[0]
            item_link = ItemLink.get_item_link_info(pid_without_ver)
            ctx['item_link'] = item_link

        return render_template(
            'weko_workflow/activity_detail.html',
            page=page,
            render_widgets=render_widgets,
            activity=activity_detail,
            item=item,
            steps=steps,
            action_id=action_id,
            cur_step=cur_step,
            temporary_comment=temporary_comment,
            record=approval_record,
            step_item_login_url=step_item_login_url,
            histories=histories,
            res_check=res_check,
            pid=pid,
            index_id=cur_index_id,
            community_id=community_id,
            width=width,
            height=height,
            allow_item_exporting=export_settings.allow_item_exporting,
            is_permission=check_permission(),
            is_login=bool(current_user.get_id()),
            **ctx)
    else:
        journal_info = None
        index_display_format = '1'
        check_site_license_permission()
        send_info = dict()
        send_info['site_license_flag'] = True \
            if hasattr(current_user, 'site_license_flag') else False
        send_info['site_license_name'] = current_user.site_license_name \
            if hasattr(current_user, 'site_license_name') else ''
        if search_type in WEKO_SEARCH_TYPE_DICT.values():
            searched.send(current_app._get_current_object(),
                          search_args=get_args,
                          info=send_info)
            if search_type == WEKO_SEARCH_TYPE_DICT['INDEX']:
                cur_index_id = request.args.get('q', '0')
                journal_info = get_journal_info(cur_index_id)
                index_info = Indexes.get_index(cur_index_id)
                if index_info:
                    index_display_format = index_info.display_format
                    if index_display_format == '2':
                        disply_setting = dict(size=100, timestamp=ts)

        if hasattr(current_i18n, 'language'):
            index_link_list = get_index_link_list(current_i18n.language)
        else:
            index_link_list = get_index_link_list()
        return render_template(
            current_app.config['SEARCH_UI_SEARCH_TEMPLATE'],
            page=page,
            render_widgets=render_widgets,
            index_id=cur_index_id,
            community_id=community_id,
            sort_option=sort_options,
            disply_setting=disply_setting,
            detail_condition=detail_condition,
            width=width,
            height=height,
            index_link_enabled=style.index_link_enabled,
            index_link_list=index_link_list,
            journal_info=journal_info,
            index_display_format=index_display_format,
            allow_item_exporting=export_settings.allow_item_exporting,
            is_permission=check_permission(),
            is_login=bool(current_user.get_id()),
            **ctx)