def create_blueprint(self, admin): """ Create Flask blueprint. Copy/pasted from from flask.ext.admin.BaseView, with minor edits needed to ensure InvenioBlueprint is being used. """ # Store admin instance self.admin = admin # If endpoint name is not provided, get it from the class name if self.endpoint is None: self.endpoint = self.__class__.__name__.lower() # If the static_url_path is not provided, use the admin's if not self.static_url_path: self.static_url_path = admin.static_url_path # If url is not provided, generate it from endpoint name if self.url is None: if self.admin.url != '/': self.url = '%s/%s' % (self.admin.url, self.endpoint) else: if self == admin.index_view: self.url = '/' else: self.url = '/%s' % self.endpoint else: if not self.url.startswith('/'): self.url = '%s/%s' % (self.admin.url, self.url) # If we're working from the root of the site, set prefix to None if self.url == '/': self.url = None # If name is not povided, use capitalized endpoint name if self.name is None: self.name = self._prettify_name(self.__class__.__name__) import_name = getattr(self, 'import_name', __name__) # Create blueprint and register rules self.blueprint = InvenioBlueprint( self.endpoint, import_name, url_prefix=self.url, subdomain=self.admin.subdomain, template_folder='templates', static_folder=self.static_folder, static_url_path=self.static_url_path, force_https=True, ) for url, name, methods in self._urls: self.blueprint.add_url_rule(url, name, getattr(self, name), methods=methods) return self.blueprint
CFG_SITE_RECORD from invenio.weblinkback_config import CFG_WEBLINKBACK_TYPE, \ CFG_WEBLINKBACK_SUBSCRIPTION_DEFAULT_ARGUMENT_NAME, \ CFG_WEBLINKBACK_STATUS, \ CFG_WEBLINKBACK_ORDER_BY_INSERTION_TIME, \ CFG_WEBLINKBACK_LIST_TYPE, \ CFG_WEBLINKBACK_TRACKBACK_SUBSCRIPTION_ERROR_MESSAGE, \ CFG_WEBLINKBACK_PAGE_TITLE_STATUS, \ CFG_WEBLINKBACK_BROKEN_COUNT blueprint = InvenioBlueprint( 'weblinkback', __name__, url_prefix="/" + CFG_SITE_RECORD, #breadcrumbs=[(_('Comments'), # 'webcomment.subscribtions')], #menubuilder=[('main.personalize.subscriptions', # _('Subscriptions'), # 'webcomment.subscriptions', 20)] ) from invenio.record_blueprint import request_record @blueprint.route('/<int:recid>/linkbacks2', methods=['GET', 'POST']) @request_record def index(recid): uid = current_user.get_id() linkbacks = LnkENTRY.query.filter( db.and_(LnkENTRY.id_bibrec == recid, LnkENTRY.status == CFG_WEBLINKBACK_STATUS['APPROVED'])).all()
from invenio.datastructures import LazyDict from invenio.importutils import autodiscover_modules from invenio.sqlalchemyutils import db from invenio.webaccount_forms import LoginForm, RegisterForm from invenio.webinterface_handler_flask_utils import _, InvenioBlueprint from invenio.websession_model import User from invenio.websession_webinterface import wash_login_method from invenio.webuser_flask import login_user, logout_user, current_user CFG_HAS_HTTPS_SUPPORT = CFG_SITE_SECURE_URL.startswith("https://") CFG_FULL_HTTPS = CFG_SITE_URL.lower().startswith("https://") blueprint = InvenioBlueprint('webaccount', __name__, url_prefix="/youraccount", breadcrumbs=[(_("Your Account"), 'webaccount.index')], menubuilder=[('personalize', _('Personalize'), 'webaccount.index')]) def update_login(nickname, password=None, remember_me=False): where = [db.or_(User.nickname == nickname, User.email == nickname)] if password is not None: where.append(User.password == password) user = User.query.filter(*where).one() login_user(user.get_id(), remember_me=remember_me) return user @blueprint.route('/login/', methods=['GET', 'POST'])
redirect, url_for, jsonify from invenio.webinterface_handler_flask_utils import InvenioBlueprint, _ from invenio.webuser_flask import current_user from invenio.usercollection_forms import CollectionForm, EditCollectionForm, \ DeleteCollectionForm from invenio.usercollection_model import UserCollection from invenio.sqlalchemyutils import db from invenio.search_engine import get_fieldvalues from invenio.cache import cache blueprint = InvenioBlueprint( 'usercollection', __name__, url_prefix="/communities", breadcrumbs=[ (_('Communities'), 'usercollection.index'), ], menubuilder=[ ('main.usercollection', _('Communities'), 'usercollection.index', 2), ], ) def mycollections_ctx(uid): """ Helper method for return ctx used by many views """ return { 'mycollections': UserCollection.query.filter_by(id_user=uid).order_by( db.asc(UserCollection.title)).all()
class InvenioBaseView(BaseView): """ BaseView for administration interfaces """ acc_view_action = None can_view = property(*can_acc_action('view')) def acc_authorize(self, action): """ Check authorization for a given action """ # First check if _can_<action> is set. if not getattr(self, '_can_%s' % action, True): return False # Next check if user is authorized to edit action = getattr(self, 'acc_%s_action' % action, None) if action: return self.blueprint.invenio_authorized(action) else: return current_user.is_super_admin def is_accessible(self): """ Check if admin interface is accessible by the current user """ if not current_user.is_authenticated(): return False return self.can_view def create_blueprint(self, admin): """ Create Flask blueprint. Copy/pasted from from flask.ext.admin.BaseView, with minor edits needed to ensure InvenioBlueprint is being used. """ # Store admin instance self.admin = admin # If endpoint name is not provided, get it from the class name if self.endpoint is None: self.endpoint = self.__class__.__name__.lower() # If the static_url_path is not provided, use the admin's if not self.static_url_path: self.static_url_path = admin.static_url_path # If url is not provided, generate it from endpoint name if self.url is None: if self.admin.url != '/': self.url = '%s/%s' % (self.admin.url, self.endpoint) else: if self == admin.index_view: self.url = '/' else: self.url = '/%s' % self.endpoint else: if not self.url.startswith('/'): self.url = '%s/%s' % (self.admin.url, self.url) # If we're working from the root of the site, set prefix to None if self.url == '/': self.url = None # If name is not povided, use capitalized endpoint name if self.name is None: self.name = self._prettify_name(self.__class__.__name__) import_name = getattr(self, 'import_name', __name__) # Create blueprint and register rules self.blueprint = InvenioBlueprint( self.endpoint, import_name, url_prefix=self.url, subdomain=self.admin.subdomain, template_folder='templates', static_folder=self.static_folder, static_url_path=self.static_url_path, force_https=True, ) for url, name, methods in self._urls: self.blueprint.add_url_rule(url, name, getattr(self, name), methods=methods) return self.blueprint
CFG_WEBCOMMENT_ADMIN_NOTIFICATION_LEVEL,\ CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN,\ CFG_WEBCOMMENT_TIMELIMIT_PROCESSING_COMMENTS_IN_SECONDS,\ CFG_WEBCOMMENT_DEFAULT_MODERATOR, \ CFG_WEBCOMMENT_EMAIL_REPLIES_TO, \ CFG_WEBCOMMENT_ROUND_DATAFIELD, \ CFG_WEBCOMMENT_RESTRICTION_DATAFIELD, \ CFG_WEBCOMMENT_MAX_COMMENT_THREAD_DEPTH from invenio.webcomment_config import CFG_WEBCOMMENT_ACTION_CODE from invenio.access_control_engine import acc_authorize_action blueprint = InvenioBlueprint('webcomment', __name__, url_prefix="/" + CFG_SITE_RECORD, config='invenio.webcomment_config', breadcrumbs=[(_('Comments'), 'webcomment.subscribtions')], menubuilder=[('personalize.comment_subscriptions', _('Your comment subscriptions'), 'webcomment.subscriptions', 20)]) from invenio.record_blueprint import request_record def log_comment_action(action_code, id, recid, uid=None): action = CmtACTIONHISTORY(id_cmtRECORDCOMMENT=id, id_bibrec=recid, id_user=uid or current_user.get_id(), client_host=socket.inet_aton( request.remote_addr), action_time=datetime.now(),
from pprint import pformat from invenio.bibworkflow_model import Workflow, WfeObject from invenio.bibworkflow_api import run import os from invenio.pluginutils import PluginContainer from invenio.config import CFG_PYLIBDIR, CFG_LOGDIR from invenio.webinterface_handler_flask_utils import _, InvenioBlueprint from invenio.bibworkflow_utils import getWorkflowDefinition import traceback blueprint = InvenioBlueprint('bibworkflow', __name__, url_prefix="/admin/bibworkflow", menubuilder=[('main.admin.bibworkflow', _('Configure BibWorkflow'), 'bibworkflow.index')], breadcrumbs=[(_('Administration'), 'help.admin'), (_('Configure BibWorkflow'), 'bibworkflow.index')],) @blueprint.route('/', methods=['GET', 'POST']) @blueprint.route('/index', methods=['GET', 'POST']) @blueprint.invenio_authenticated @blueprint.invenio_templated('bibworkflow_index.html') def index(): """ Dispalys main interface of BibWorkflow. """ w = Workflow.query.all()
blueprint = InvenioBlueprint('invenio_openaire', __name__, url_prefix="", menubuilder=[ ('main.browse', _('Browse'), '', 2), ('main.browse.datasets', _('Datasets'), 'collection.datasets', 1), ('main.browse.images', _('Images'), 'collection.images', 2), ('main.browse.posters', _('Posters'), 'collection.posters', 3), ('main.browse.presentations', _('Presentations'), 'collection.presentations', 4), ('main.browse.publications', _('Publications'), 'collection.publications', 5), ('main.browse.software', _('Software'), 'collection.software', 6), ('main.browse.videos', _('Video/Audio'), 'collection.videos', 6), ('main.getstarted', _('Get started'), '', 4), ('main.getstarted.features', _('Features'), 'invenio_openaire.features', 1), #('main.getstarted.deposit_data', _('Deposit data'), 'invenio_openaire.deposit_data', 2), #('main.getstarted.use_data', _('Use data'), 'invenio_openaire.use_data', 3), ('main.getstarted.faq', _('FAQ'), 'invenio_openaire.faq', 4), ('footermenu_left.about', _('About'), 'invenio_openaire.about', 1), ('footermenu_left.contact', _('Contact'), 'invenio_openaire.contact', 2), ('footermenu_left.policies', _('Policies'), 'invenio_openaire.policies', 3), #('footermenu_left.partners', _('Partners'), 'invenio_openaire.partners', 4), ('footermenu_right.features', _('Features'), 'invenio_openaire.features', 1), #('footermenu_right.deposit_data', _('Deposit data'), 'invenio_openaire.deposit_data', 2), #('footermenu_right.use_data', _('Use data'), 'invenio_openaire.use_data', 3), ('footermenu_right.faq', _('FAQ'), 'invenio_openaire.faq', 4), ('footermenu_right.api', _('API'), 'invenio_openaire.api', 5), ('footermenu_bottom.terms', _('Terms of use'), 'invenio_openaire.terms', 1), ('footermenu_bottom.privacy_policy', _('Privacy policy'), 'invenio_openaire.privacy_policy', 2), ('footermenu_bottom.support', _('Support/Feedback'), 'invenio_openaire.contact', 3), ] )
from invenio.bibworkflow_utils import get_workflow_definition from invenio.bibworkflow_api import continue_oid_delayed from invenio.bibworkflow_hp_load_widgets import widgets from invenio.bibworkflow_config import CFG_OBJECT_VERSION from flask import redirect, url_for, flash from invenio.bibformat_engine import format_record from invenio.bibworkflow_utils import create_hp_containers # from invenio.bibworkflow_containers import bwolist blueprint = InvenioBlueprint('holdingpen', __name__, url_prefix="/admin/holdingpen", menubuilder=[('main.admin.holdingpen', _('Holdingpen'), 'holdingpen.index') ], breadcrumbs=[(_('Administration'), 'help.admin'), (_('Holdingpen'), 'holdingpen.index') ]) @blueprint.route('/index', methods=['GET', 'POST']) @blueprint.invenio_authenticated @blueprint.invenio_templated('bibworkflow_hp_index.html') def index(): """ Displays main interface of BibHoldingpen. """ bwolist = create_hp_containers() return dict(hpcontainers=bwolist)
draft_field_get_all, \ draft_field_error_check, \ draft_field_get, \ set_form_status, \ get_form_status, \ create_user_file_system, \ CFG_DRAFT_STATUS, \ url_upload,\ get_all_drafts from invenio.webuser_flask import current_user from invenio.bibworkflow_config import CFG_WORKFLOW_STATUS blueprint = InvenioBlueprint( 'webdeposit', __name__, url_prefix='/deposit', config='invenio.websubmit_config', menubuilder=[('main.webdeposit', _('Deposit'), 'webdeposit.index_deposition_types', 2)], breadcrumbs=[(_('Deposit'), 'webdeposit.index_deposition_types')]) @blueprint.route('/upload_from_url/<deposition_type>/<uuid>', methods=['POST']) @blueprint.invenio_authenticated def upload_from_url(deposition_type, uuid): if request.method == 'POST': url = request.form['url'] if "name" in request.form: name = request.form['name'] else: name = None
from invenio.webuser_flask import current_user from invenio.config import CFG_SITE_LANG from invenio.websession_model import User, Usergroup, UserUsergroup from invenio.webinterface_handler_flask_utils import _, InvenioBlueprint from invenio.webinterface_handler import wash_urlargd from invenio.dbquery import run_sql from invenio.websession_config import CFG_WEBSESSION_INFO_MESSAGES, \ CFG_WEBSESSION_USERGROUP_STATUS, \ CFG_WEBSESSION_GROUP_JOIN_POLICY, \ InvenioWebSessionError, \ InvenioWebSessionWarning blueprint = InvenioBlueprint('webgroup', __name__, url_prefix="/yourgroups", breadcrumbs=[(_("Your Groups"), 'webgroup.index') ]) def filter_by_user_status(uid, user_status, login_method='INTERNAL'): return db.and_(UserUsergroup.id_user == uid, UserUsergroup.user_status == user_status, Usergroup.login_method == login_method) @blueprint.route('/') @blueprint.route('/index', methods=['GET', 'POST']) @blueprint.invenio_authenticated def index(): uid = current_user.get_id()
from invenio.websearch_model import Collection from invenio.websearch_webinterface import wash_search_urlargd from invenio.webinterface_handler_flask_utils import _, InvenioBlueprint, \ register_template_context_processor from invenio.webuser_flask import current_user from invenio.websearch_facet_builders import \ get_current_user_records_that_can_be_displayed, faceted_results_filter, \ FacetLoader from invenio.search_engine import get_creation_date, perform_request_search,\ print_record, create_nearest_terms_box, browse_pattern_phrases from invenio.paginationutils import Pagination blueprint = InvenioBlueprint('search', __name__, url_prefix="", config='invenio.search_engine_config', breadcrumbs=[], menubuilder=[('main.search', _('Search'), 'search.index', 1)]) FACETS = FacetLoader() def collection_name_from_request(): collection = request.values.get('cc') if collection is None and len(request.values.getlist('c')) == 1: collection = request.values.get('c') return collection def min_length(length, code=406):
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """WebAccess Admin Flask Blueprint""" from flask import redirect, url_for from invenio.webaccess_model import AccACTION, AccROLE from invenio.websession_model import User from invenio.webinterface_handler_flask_utils import _, InvenioBlueprint from invenio.access_control_config import \ WEBACCESSACTION blueprint = InvenioBlueprint('webaccess_admin', __name__, url_prefix="/admin/webaccess", config='invenio.access_control_config', breadcrumbs=[(_('Administration'), 'help.admin'), (_('WebAccess'), 'webaccesss_admin.index')], menubuilder=[('main.admin.webaccess', _('Configure WebAccess'), 'webaccess_admin.index', 90)]) @blueprint.route('/', methods=['GET', 'POST']) @blueprint.invenio_authenticated @blueprint.invenio_authorized(WEBACCESSACTION) @blueprint.invenio_templated('webaccess_admin_index.html') def index(): actions = [ dict( url=url_for('.rolearea'), title=_('Role Area'),
)).scalar() out = '<div data-menu="click" data-menu-source="' + url_for('webmessage.menu') + '">' out += '<i class="icon-envelope icon-white"></i>' if unread: out += ' <span class="badge badge-important">%d</span>' % unread out += "</div>" return out not_guest = lambda: not current_user.is_guest blueprint = InvenioBlueprint('webmessage', __name__, url_prefix="/yourmessages", config='invenio.webmessage_config', menubuilder=[('personalize.messages', _('Your messages'), 'webmessage.index', 10), ('main.messages', MessagesMenu(), 'webmessage.index', -3, [], not_guest)], breadcrumbs=[(_("Your Account"), 'youraccount.edit'), ('Your Messages', 'webmessage.index')]) @blueprint.route('/menu', methods=['GET']) #FIXME if request is_xhr then do not return 401 #@blueprint.invenio_authenticated #@blueprint.invenio_authorized('usemessages') #@blueprint.invenio_templated('webmessage_menu.html') def menu(): uid = current_user.get_id() dbquery.update_user_inbox_for_reminders(uid)
CreateTagForm, \ AttachTagForm, \ DetachTagForm, \ DeleteTagForm, \ validate_tag_exists, \ validate_user_owns_tag, \ validators from invenio.websearch_blueprint import response_formated_records blueprint = InvenioBlueprint('webtag', __name__, url_prefix='/yourtags', config='invenio.webtag_config', menubuilder=[('personalize.tags', _('Your Tags'), 'webtag.display_cloud')], breadcrumbs=[(_('Your Account'), 'youraccount.edit'), (_('Your Tags'), 'webtag.display_cloud')]) @blueprint.route('/', methods=['GET', 'POST']) @blueprint.route('/display', methods=['GET', 'POST']) @blueprint.route('/display/cloud', methods=['GET', 'POST']) @blueprint.invenio_authenticated @blueprint.invenio_templated('webtag_display_cloud.html') def display_cloud(): """ List of user's private/group/public tags """ user = User.query.get(current_user.get_id()) tags = user.tags_query.order_by(WtgTAG.name).all()
from invenio.bibworkflow_config import CFG_WORKFLOW_STATUS from invenio.webdeposit_load_deposition_types import deposition_metadata from invenio.webinterface_handler_flask_utils import InvenioBlueprint from invenio.webdeposit_utils import create_workflow,\ get_workflow, \ set_form_status, \ preingest_form_data, \ get_preingested_form_data, \ validate_preingested_data, \ deposit_files, \ InvenioWebDepositNoDepositionType from invenio.webuser_flask import current_user from invenio.jsonutils import wash_for_json blueprint = InvenioBlueprint('webdeposit_api', __name__, url_prefix='/api/deposit', config='invenio.websubmit_config') class enum(object): def __init__(self, **enums): for enum, code in enums.items(): self.__setattr__(enum, code) ERROR = enum(INVALID_DEPOSITION=1) @blueprint.route('/create/<deposition_type>/', methods=['POST', 'GET']) @blueprint.invenio_api_key_authenticated def deposition_create(deposition_type):
from invenio.webinterface_handler_flask_utils import _, InvenioBlueprint, \ register_template_context_processor from invenio.webuser_flask import current_user from invenio.search_engine import guess_primary_collection_of_a_record, \ check_user_can_view_record from invenio.webcomment import get_mini_reviews from invenio.websearchadminlib import get_detailed_page_tabs,\ get_detailed_page_tabs_counts from invenio.search_engine_utils import get_fieldvalues from invenio.bibrank_downloads_similarity import register_page_view_event blueprint = InvenioBlueprint('record', __name__, url_prefix="/" + CFG_SITE_RECORD, config='invenio.search_engine_config', breadcrumbs=[]) #menubuilder=[('main.search', _('Search'), # 'search.index', 1)]) def request_record(f): @wraps(f) def decorated(recid, *args, **kwargs): # ensure recid to be integer recid = int(recid) g.collection = collection = Collection.query.filter( Collection.name == guess_primary_collection_of_a_record(recid)).\ one()
from invenio.openaire_deposit_engine import get_exisiting_publications_for_uid,\ OpenAIREPublication from werkzeug.datastructures import MultiDict import invenio.template import os from invenio.openaire_forms import DepositionForm, DepositionFormMapper, PublicationMapper import json from invenio.config import CFG_SITE_SUPPORT_EMAIL, CFG_SITE_NAME from invenio.usercollection_model import UserCollection blueprint = InvenioBlueprint( 'deposit', __name__, url_prefix="/deposit", breadcrumbs=[ (_('Upload'), 'deposit.index'), ], menubuilder=[ ('main.deposit', _('Upload'), 'deposit.index', 1), ], ) openaire_deposit_templates = invenio.template.load('openaire_deposit') def is_editable(pub): return pub.status in ['initialized', 'edited'] # - Wash url arg # - check redirect to login on guest