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)
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))
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)
def default_view_method(pid, record, template=None): """Default view method. Sends ``record_viewed`` signal and renders template. """ 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 '' record_viewed.send(current_app._get_current_object(), pid=pid, record=record, info=send_info) item_type_id = record.get('item_type_id') lists = ItemTypes.get_latest() if lists is None or len(lists) == 0: return render_template( current_app.config['WEKO_ITEMS_UI_ERROR_TEMPLATE']) item_type = ItemTypes.get_by_id(item_type_id) if item_type is None: return redirect( url_for('.index', item_type_id=lists[0].item_type[0].id)) json_schema = '/items/jsonschema/{}'.format(item_type_id) schema_form = '/items/schemaform/{}'.format(item_type_id) sessionstore = RedisStore( redis.StrictRedis.from_url('redis://{host}:{port}/1'.format( host=os.getenv('INVENIO_REDIS_HOST', 'localhost'), port=os.getenv('INVENIO_REDIS_PORT', '6379')))) files = to_files_js(record) record = record.item_metadata endpoints = {} activity_session = session['activity_info'] activity_id = activity_session.get('activity_id', None) if activity_id and sessionstore.redis.exists('activity_item_' + activity_id): item_str = sessionstore.get('activity_item_' + activity_id) item_json = json.loads(item_str) if 'metainfo' in item_json: record = item_json.get('metainfo') if 'files' in item_json: files = item_json.get('files') if 'endpoints' in item_json: endpoints = item_json.get('endpoints') need_file, need_billing_file = is_schema_include_key(item_type.schema) return render_template( template, need_file=need_file, need_billing_file=need_billing_file, record=record, jsonschema=json_schema, schemaform=schema_form, lists=lists, links=to_links_js(pid), id=item_type_id, files=files, pid=pid, item_save_uri=url_for('weko_items_ui.iframe_save_model'), endpoints=endpoints)
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)
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)