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)
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 get_community_id(getargs): # TODO: Use this to refactor """Get the community data for specific args.""" ctx = {'community': None} community_id = "" if 'community' in getargs: from weko_workflow.api import GetCommunity comm = GetCommunity.get_community_by_id(getargs.get('community')) ctx = {'community': comm} community_id = comm.id return community_id, 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 export(): """Item export view.""" export_settings = AdminSettings.get('item_export_settings') or \ AdminSettings.Dict2Obj( current_app.config['WEKO_ADMIN_DEFAULT_ITEM_EXPORT_SETTINGS']) if not export_settings.allow_item_exporting: return abort(403) if request.method == 'POST': return export_items(request.form.to_dict()) from weko_search_ui.api import SearchSetting search_type = request.args.get('search_type', '0') # TODO: Refactor community_id = "" ctx = {'community': None} cur_index_id = search_type if search_type not in ( '0', '1', ) else None if 'community' in request.args: from weko_workflow.api import GetCommunity comm = GetCommunity.get_community_by_id(request.args.get('community')) ctx = {'community': comm} community_id = comm.id from weko_theme.utils import get_design_layout # Get the design for widget rendering page, render_widgets = get_design_layout( community_id or current_app.config['WEKO_THEME_DEFAULT_COMMUNITY']) sort_options, display_number = SearchSetting.get_results_setting() disply_setting = dict(size=display_number) return render_template( current_app.config['WEKO_ITEMS_UI_EXPORT_TEMPLATE'], page=page, render_widgets=render_widgets, index_id=cur_index_id, community_id=community_id, sort_option=sort_options, disply_setting=disply_setting, enable_contents_exporting=export_settings.enable_contents_exporting, max_export_num=_get_max_export_items(), **ctx)
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)
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)
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)
def prepare_edit_item(): """Prepare_edit_item. Host the api which provide 2 service: Create new activity for editing flow Check permission: check if user is owner/admin/shared user request: header: Content type must be json data: pid_value: pid_value return: The result json: code: status code, msg: meassage result, data: url redirect """ def _get_workflow_by_item_type_id(item_type_name_id, item_type_id): """Get workflow settings by item type id.""" workflow = WorkFlow.query.filter_by(itemtype_id=item_type_id).first() if not workflow: item_type_list = ItemTypes.get_by_name_id(item_type_name_id) id_list = [x.id for x in item_type_list] workflow = (WorkFlow.query.filter( WorkFlow.itemtype_id.in_(id_list)).order_by( WorkFlow.itemtype_id.desc()).order_by( WorkFlow.flow_id.asc()).first()) return workflow if request.headers['Content-Type'] != 'application/json': """Check header of request""" return jsonify(code=-1, msg=_('Header Error')) post_activity = request.get_json() pid_value = post_activity.get('pid_value') if pid_value: try: record = WekoRecord.get_record_by_pid(pid_value) owner = str(record.get('owner')) shared_id = str(record.get('weko_shared_id')) user_id = str(get_current_user()) is_admin = get_user_roles() activity = WorkActivity() pid_object = PersistentIdentifier.get('recid', pid_value) latest_pid = PIDVersioning(child=pid_object).last_child # check user's permission if user_id != owner and not is_admin[0] and user_id != shared_id: return jsonify( code=-1, msg=_(r"You are not allowed to edit this item.")) lists = ItemTypes.get_latest() if not lists: return jsonify(code=-1, msg=_(r"You do not even have an Itemtype.")) item_type_id = record.get('item_type_id') item_type = ItemTypes.get_by_id(item_type_id) if not item_type: return jsonify(code=-1, msg=_(r"This itemtype isn't found.")) # check item is being editied item_id = latest_pid.object_uuid workflow_activity = activity.get_workflow_activity_by_item_id( item_id) if not workflow_activity: # get workflow of first record attached version ID: x.1 workflow_activity = activity.get_workflow_activity_by_item_id( pid_object.object_uuid) # if workflow of the item is not found # use default settings of item type to which the item belongs else: # show error when has stt is Begin or Doing if workflow_activity.action_status == \ ActionStatusPolicy.ACTION_BEGIN \ or workflow_activity.action_status == \ ActionStatusPolicy.ACTION_DOING: return jsonify(code=-1, msg=_(r"The workflow is being edited.")) # prepare params for new workflow activity if workflow_activity: post_activity['workflow_id'] = workflow_activity.workflow_id post_activity['flow_id'] = workflow_activity.flow_id else: workflow = _get_workflow_by_item_type_id( item_type.name_id, item_type_id) if not workflow: return jsonify(code=-1, msg=_('Workflow setting does not exist.')) post_activity['workflow_id'] = workflow.id post_activity['flow_id'] = workflow.flow_id post_activity['itemtype_id'] = item_type_id getargs = request.args community = getargs.get('community', None) # Create a new version of a record. record = WekoDeposit.get_record(item_id) if not record: return jsonify(code=-1, msg=_('Record does not exist.')) deposit = WekoDeposit(record, record.model) draft_record = deposit.newversion(pid_object) if not draft_record: return jsonify(code=-1, msg=_('An error has occurred.')) # Create snapshot bucket for draft record from invenio_records_files.models import RecordsBuckets try: with db.session.begin_nested(): from weko_workflow.utils import delete_bucket draft_deposit = WekoDeposit(draft_record, draft_record.model) snapshot = record.files.bucket.snapshot(lock=False) snapshot.locked = False draft_deposit['_buckets'] = {'deposit': str(snapshot.id)} draft_record_bucket = RecordsBuckets.create( record=draft_record.model, bucket=snapshot) # Remove duplicated buckets draft_record_buckets = RecordsBuckets.query.filter_by( record_id=draft_record.model.id).all() for record_bucket in draft_record_buckets: if record_bucket != draft_record_bucket: delete_bucket_id = record_bucket.bucket_id RecordsBuckets.query.filter_by( bucket_id=delete_bucket_id).delete() delete_bucket(delete_bucket_id) draft_deposit.commit() except Exception as ex: db.session.rollback() current_app.logger.exception(str(ex)) return jsonify(code=-1, msg=_('An error has occurred.')) # Create a new workflow activity. rtn = activity.init_activity(post_activity, community, draft_record.model.id) if rtn: # GOTO: TEMPORARY EDIT MODE FOR IDENTIFIER identifier_actionid = get_actionid('identifier_grant') if workflow_activity: identifier = activity.get_action_identifier_grant( workflow_activity.activity_id, identifier_actionid) else: identifier = activity.get_action_identifier_grant( '', identifier_actionid) if identifier: if identifier.get('action_identifier_select') > \ IDENTIFIER_GRANT_DOI: identifier['action_identifier_select'] = \ IDENTIFIER_GRANT_CAN_WITHDRAW elif identifier.get('action_identifier_select') == \ IDENTIFIER_GRANT_IS_WITHDRAWING: identifier['action_identifier_select'] = \ IDENTIFIER_GRANT_WITHDRAWN activity.create_or_update_action_identifier( rtn.activity_id, identifier_actionid, identifier) mail_list = FeedbackMailList.get_mail_list_by_item_id( item_id=pid_object.object_uuid) if mail_list: activity.create_or_update_action_feedbackmail( activity_id=rtn.activity_id, action_id=ITEM_REGISTRATION_ACTION_ID, feedback_maillist=mail_list) if community: comm = GetCommunity.get_community_by_id(community) url_redirect = url_for('weko_workflow.display_activity', activity_id=rtn.activity_id, community=comm.id) else: url_redirect = url_for('weko_workflow.display_activity', activity_id=rtn.activity_id) return jsonify(code=0, msg='success', data={'redirect': url_redirect}) except Exception as e: current_app.logger.error('Unexpected error: ', str(e)) return jsonify(code=-1, msg=_('An error has occurred.'))
def iframe_items_index(pid_value='0'): """Iframe items index.""" try: if pid_value == '0' or pid_value == 0: return redirect(url_for('.iframe_index')) record = WekoRecord.get_record_by_pid(pid_value) action = 'private' if record.get('publish_status', '1') == '1' \ else 'publish' community_id = session.get('itemlogin_community_id') ctx = {'community': None} if community_id: comm = GetCommunity.get_community_by_id(community_id) ctx = {'community': comm} if request.method == 'GET': cur_activity = session['itemlogin_activity'] # If enable auto set index feature # and activity is usage application item type steps = session['itemlogin_steps'] contain_application_endpoint = False for step in steps: if step.get('ActionEndpoint') == 'item_login_application': contain_application_endpoint = True enable_auto_set_index = current_app.config.get( 'WEKO_WORKFLOW_ENABLE_AUTO_SET_INDEX_FOR_ITEM_TYPE') if enable_auto_set_index and contain_application_endpoint: index_id = get_index_id(cur_activity.activity_id) update_index_tree_for_record(pid_value, index_id) return redirect(url_for('weko_workflow.iframe_success')) # Get the design for widget rendering from weko_theme.utils import get_design_layout page, render_widgets = get_design_layout( community_id or current_app.config['WEKO_THEME_DEFAULT_COMMUNITY']) return render_template('weko_items_ui/iframe/item_index.html', page=page, render_widgets=render_widgets, pid_value=pid_value, action=action, activity=session['itemlogin_activity'], item=session['itemlogin_item'], steps=session['itemlogin_steps'], action_id=session['itemlogin_action_id'], cur_step=session['itemlogin_cur_step'], record=session['itemlogin_record'], histories=session['itemlogin_histories'], res_check=session['itemlogin_res_check'], pid=session['itemlogin_pid'], community_id=community_id, **ctx) if request.headers['Content-Type'] != 'application/json': flash(_('Invalid Request'), 'error') from weko_theme.utils import get_design_layout page, render_widgets = get_design_layout( current_app.config['WEKO_THEME_DEFAULT_COMMUNITY']) return render_template('weko_items_ui/iframe/item_index.html', page=page, render_widgets=render_widgets, community_id=community_id, **ctx) data = request.get_json() 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')))) if request.method == 'PUT': """update index of item info.""" item_str = sessionstore.get('item_index_{}'.format(pid_value)) sessionstore.delete('item_index_{}'.format(pid_value)) item = json.loads(item_str) item['index'] = data elif request.method == 'POST': """update item data info.""" sessionstore.put('item_index_{}'.format(pid_value), json.dumps(data), ttl_secs=300) return jsonify(data) except BaseException: current_app.logger.error('Unexpected error: ', sys.exc_info()[0]) return abort(400)
def prepare_edit_item(): """Prepare_edit_item. Host the api which provide 2 service: Create new activity for editing flow Check permission: check if user is owner/admin/shared user request: header: Content type must be json data: pid_value: pid_value return: The result json: code: status code, msg: meassage result, data: url redirect """ if request.headers['Content-Type'] != 'application/json': """Check header of request""" return jsonify(code=-1, msg=_('Header Error')) post_activity = request.get_json() pid_value = post_activity.get('pid_value') if pid_value: try: record = WekoRecord.get_record_by_pid(pid_value) owner = str(record.get('owner')) shared_id = str(record.get('weko_shared_id')) user_id = str(get_current_user()) is_admin = get_user_roles() activity = WorkActivity() pid_object = PersistentIdentifier.get('recid', pid_value) # check item is being editied item_id = pid_object.object_uuid workflow_action_stt = \ activity.get_workflow_activity_status_by_item_id( item_id=item_id) # show error when has stt is Begin or Doing if workflow_action_stt is not None and \ (workflow_action_stt == ActionStatusPolicy.ACTION_BEGIN or workflow_action_stt == ActionStatusPolicy.ACTION_DOING): return jsonify(code=-13, msg=_('The workflow is being edited. ')) if user_id != owner and not is_admin[0] and user_id != shared_id: return jsonify(code=-1, msg=_('You are not allowed to edit this item.')) lists = ItemTypes.get_latest() if not lists: return jsonify(code=-1, msg=_('You do not even have an itemtype.')) item_type_id = record.get('item_type_id') item_type = ItemTypes.get_by_id(item_type_id) if item_type is None: return jsonify(code=-1, msg=_('This itemtype not found.')) upt_current_activity = activity.upt_activity_detail( item_id=pid_object.object_uuid) if upt_current_activity is not None: post_activity['workflow_id'] = upt_current_activity.workflow_id post_activity['flow_id'] = upt_current_activity.flow_id post_activity['itemtype_id'] = item_type_id getargs = request.args community = getargs.get('community', None) # Create a new version of a record. record = WekoDeposit.get_record(item_id) if record is None: return jsonify(code=-1, msg=_('Record does not exist.')) deposit = WekoDeposit(record, record.model) new_record = deposit.newversion(pid_object) if new_record is None: return jsonify(code=-1, msg=_('An error has occurred.')) rtn = activity.init_activity(post_activity, community, new_record.model.id) if rtn: # GOTO: TEMPORARY EDIT MODE FOR IDENTIFIER identifier_actionid = get_actionid('identifier_grant') identifier = activity.get_action_identifier_grant( upt_current_activity.activity_id, identifier_actionid) if identifier: if identifier.get('action_identifier_select') > \ IDENTIFIER_GRANT_DOI: identifier['action_identifier_select'] = \ IDENTIFIER_GRANT_CAN_WITHDRAW elif identifier.get('action_identifier_select') == \ IDENTIFIER_GRANT_IS_WITHDRAWING: identifier['action_identifier_select'] = \ IDENTIFIER_GRANT_WITHDRAWN activity.create_or_update_action_identifier( rtn.activity_id, identifier_actionid, identifier) if community: comm = GetCommunity.get_community_by_id(community) url_redirect = url_for( 'weko_workflow.display_activity', activity_id=rtn.activity_id, community=comm.id) else: url_redirect = url_for( 'weko_workflow.display_activity', activity_id=rtn.activity_id) return jsonify(code=0, msg='success', data={'redirect': url_redirect}) except Exception as e: current_app.logger.error('Unexpected error: ', str(e)) return jsonify(code=-1, msg=_('An error has occurred.'))
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)
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)
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)