def response_formated_records(records, collection, of, **kwargs): """Return formatter records. Response contains correct Cache and TTL information in HTTP headers. """ response = make_response(format_records(records, collection=collection, of=of, **kwargs)) response.mimetype = get_output_format_content_type(of) current_time = datetime.datetime.now() response.headers['Last-Modified'] = http_date( time.mktime(current_time.timetuple()) ) expires = current_app.config.get( 'CFG_WEBSEARCH_SEARCH_CACHE_TIMEOUT', None) if expires is None: response.headers['Cache-Control'] = ( 'no-store, no-cache, must-revalidate, ' 'post-check=0, pre-check=0, max-age=0' ) response.headers['Expires'] = '-1' else: expires_time = current_time + datetime.timedelta(seconds=expires) response.headers['Vary'] = 'Accept' response.headers['Cache-Control'] = ( 'public' if current_user.is_guest else 'private' ) response.headers['Expires'] = http_date(time.mktime( expires_time.timetuple() )) return response
def metadata(recid, of='hd', ot=None): """Display formated record metadata.""" from invenio.legacy.bibrank.downloads_similarity import \ register_page_view_event from invenio.modules.formatter import get_output_format_content_type from invenio.modules.formatter.engine import get_output_format, \ InvenioBibFormatError register_page_view_event(recid, current_user.get_id(), str(request.remote_addr)) try: get_output_format(of or request.args.get('of')) except InvenioBibFormatError: # Needed to prevent propagation to legacy pages. return render_template('404.html'), 404 if get_output_format_content_type(of) != 'text/html': from invenio.modules.search.views.search import \ response_formated_records return response_formated_records([recid], g.collection, of, qid=None) # Send the signal 'document viewed' record_viewed.send(current_app._get_current_object(), recid=recid, id_user=current_user.get_id(), request=request) return render_template('records/metadata.html', of=of, ot=ot)
def response_formated_records(recids, collection, of, **kwargs): """Return formatter records. Response contains correct Cache and TTL information in HTTP headers. """ from invenio.modules.formatter import (get_output_format_content_type, print_records) response = make_response( print_records(recids, collection=collection, of=of, **kwargs)) response.mimetype = get_output_format_content_type(of) current_time = datetime.datetime.now() response.headers['Last-Modified'] = http_date( time.mktime(current_time.timetuple())) expires = current_app.config.get('CFG_WEBSEARCH_SEARCH_CACHE_TIMEOUT', None) if expires is None: response.headers['Cache-Control'] = ( 'no-store, no-cache, must-revalidate, ' 'post-check=0, pre-check=0, max-age=0') response.headers['Expires'] = '-1' else: expires_time = current_time + datetime.timedelta(seconds=expires) response.headers['Vary'] = 'Accept' response.headers['Cache-Control'] = ('public' if current_user.is_guest else 'private') response.headers['Expires'] = http_date( time.mktime(expires_time.timetuple())) return response
def response_formated_records(recids, collection, of, **kwargs): """TODO.""" from invenio.modules.formatter import (get_output_format_content_type, print_records) response = make_response( print_records(recids, collection=collection, of=of, **kwargs)) response.mimetype = get_output_format_content_type(of) return response
def response_formated_records(recids, collection, of, **kwargs): """TODO.""" from invenio.modules.formatter import (get_output_format_content_type, print_records) response = make_response(print_records(recids, collection=collection, of=of, **kwargs)) response.mimetype = get_output_format_content_type(of) return response
def metadata(recid, of='hd'): from invenio.legacy.bibrank.downloads_similarity import register_page_view_event from invenio.modules.formatter import get_output_format_content_type register_page_view_event(recid, current_user.get_id(), str(request.remote_addr)) if get_output_format_content_type(of) != 'text/html': from invenio.modules.search.views.search import response_formated_records return response_formated_records([recid], g.collection, of, qid=None) # Send the signal 'document viewed' record_viewed.send( current_app._get_current_object(), recid=recid, id_user=current_user.get_id(), request=request) def splitting(value, delimiter='/', maxsplit=0): return value.split(delimiter, maxsplit) def get_record_name(recid): tmp_rec = get_record(recid) if tmp_rec is None: return 'Can\'t link to record ( WRONG recid )' if 'title_additional' in tmp_rec : return tmp_rec.get('title_additional', '').get('title', '') elif tmp_rec.get('title',{}).get('title',''): return tmp_rec.get('title',{}).get('title','') def get_record_author_list(recid): tmp_rec = get_record(recid) if tmp_rec is None: return None return tmp_rec.get('authors','') current_app.jinja_env.filters['splitthem'] = splitting current_app.jinja_env.filters['get_record_name'] = get_record_name current_app.jinja_env.filters['get_record_author_list'] = get_record_author_list current_app.jinja_env.filters['get_download_time'] = calculate_download_time record_collection = get_record(recid)['collections'][0]['primary'] rec_col = Collection.query.filter(Collection.name == record_collection).first_or_404() parent_collection = rec_col.most_specific_dad if ( rec_col.most_specific_dad.id != 1 ) else None breadcrumbs = [{}] if parent_collection: breadcrumbs.append({ "url":".collection", "text": parent_collection.name_ln, "param":"name", "value": parent_collection.name }) breadcrumbs.append({"url":".collection", "text": rec_col.name_ln, "param":"name", "value":rec_col.name }) try: return render_template('records/base_base.html', breadcrumbs = breadcrumbs ) except TemplateNotFound: return abort(404) # FIX
def metadata(recid, of='hd'): from invenio.legacy.bibrank.downloads_similarity import register_page_view_event from invenio.modules.formatter import get_output_format_content_type register_page_view_event(recid, current_user.get_id(), str(request.remote_addr)) if get_output_format_content_type(of) != 'text/html': from invenio.modules.search.views.search import response_formated_records return response_formated_records([recid], g.collection, of, qid=None) # Send the signal 'document viewed' record_viewed.send( current_app._get_current_object(), recid=recid, id_user=current_user.get_id(), request=request) def get_record_name(recid): tmp_rec = get_record(recid) if tmp_rec is None: return 'Can\'t link to record ( WRONG recid )' if 'title_additional' in tmp_rec : return tmp_rec.get('title_additional', '').get('title', '') elif tmp_rec.get('title',{}).get('title',''): return tmp_rec.get('title',{}).get('title','') def get_record_author_list(recid): tmp_rec = get_record(recid) if tmp_rec is None: return None return tmp_rec.get('authors','') current_app.jinja_env.filters['splitthem'] = splitting current_app.jinja_env.filters['get_record_name'] = get_record_name current_app.jinja_env.filters['get_record_author_list'] = get_record_author_list current_app.jinja_env.filters['get_download_time'] = calculate_download_time record_collection = get_record(recid)['collections'][0]['primary'] rec_col = Collection.query.filter(Collection.name == record_collection).first_or_404() parent_collection = rec_col.most_specific_dad \ if (rec_col.most_specific_dad and \ rec_col.most_specific_dad.id != 1) else None breadcrumbs = [{}] if parent_collection: breadcrumbs.append({ "url":".collection", "text": parent_collection.name_ln, "param":"name", "value": parent_collection.name }) breadcrumbs.append({"url":".collection", "text": rec_col.name_ln, "param":"name", "value":rec_col.name }) try: return render_template(['records/'+record_collection+'_base.html','records/base_base.html'], breadcrumbs = breadcrumbs ) except TemplateNotFound: return abort(404) # FIX
def metadata(recid, of="hd", ot=None): """Display formated record metadata.""" from invenio.legacy.bibrank.downloads_similarity import register_page_view_event from invenio.modules.formatter import get_output_format_content_type register_page_view_event(recid, current_user.get_id(), str(request.remote_addr)) if get_output_format_content_type(of) != "text/html": from invenio.modules.search.views.search import response_formated_records return response_formated_records([recid], g.collection, of, qid=None) # Send the signal 'document viewed' record_viewed.send(current_app._get_current_object(), recid=recid, id_user=current_user.get_id(), request=request) return render_template("records/metadata.html", of=of, ot=ot)
def metadata(recid, of='hd', ot=None): """Display formated record metadata.""" from invenio.legacy.bibrank.downloads_similarity import \ register_page_view_event from invenio.modules.formatter import get_output_format_content_type register_page_view_event(recid, current_user.get_id(), str(request.remote_addr)) if get_output_format_content_type(of) != 'text/html': from invenio.modules.search.views.search import \ response_formated_records return response_formated_records([recid], g.collection, of, qid=None) # Send the signal 'document viewed' record_viewed.send(current_app._get_current_object(), recid=recid, id_user=current_user.get_id(), request=request) return render_template('records/metadata.html', of=of, ot=ot)