def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.extensions['b2share-records'] = self self._register_signals(app) app.cli.add_command(b2records) register_triggers(app) register_error_handlers(app) app.logger.info("Creating enpoints...") # Register records API blueprints endpoints = app.config['B2SHARE_RECORDS_REST_ENDPOINTS'] #for i in endpoints: # app.logger.info("- Creating enpoint: {}".format(i)) app.register_blueprint(create_blueprint(endpoints)) @app.before_first_request def extend_default_endpoint_prefixes(): """Fix the endpoint prefixes as .""" endpoint_prefixes = utils.build_default_endpoint_prefixes( endpoints) #app.logger.info("- Fixing endpoint: {}".format(endpoint_prefixes)) current_records_rest = app.extensions['invenio-records-rest'] current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes) before_record_index.connect(indexer_receiver, sender=app) app.url_map.converters['pid'] = PIDConverter
def register_signals(self): """Register signals.""" file_uploaded.connect(file_uploaded_listener) file_processed.connect(file_processed_listener) file_deleted.connect(file_deleted_listener) after_record_delete.connect(record_deleted_listener) before_record_index.connect(index_file_content)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) self.create_resources() self.init_views(app) app.extensions['sonar'] = self if app.config['SONAR_APP_ENABLE_CORS']: from flask_cors import CORS CORS(app) Bootstrap(app) Wiki(app) app.context_processor(utility_processor) # Connect to signal sent when a user is created in Flask-Security. user_registered.connect(user_registered_handler, weak=False) # Connect to signal sent when a file is uploaded or deleted file_uploaded.connect(file_uploaded_listener, weak=False) file_deleted.connect(file_deleted_listener, weak=False) # Add user's full name before record index before_record_index.connect(add_full_name, weak=False)
def register_signals(app): """Register Zenodo Deposit signals.""" before_record_index.connect(indexer_receiver, sender=app, weak=False) post_action.connect(datacite_register_after_publish, sender=app, weak=False) post_action.connect(index_versioned_record_siblings, sender=app, weak=False)
def register_signals(self, app): """Register the signals.""" before_record_index.connect(inject_provisional_community) if app.config['COMMUNITIES_OAI_ENABLED']: listen(Community, 'after_insert', create_oaipmh_set) listen(Community, 'after_delete', destroy_oaipmh_set) inclusion_request_created.connect(new_request)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.extensions['invenio-pidrelations'] = _InvenioPIDRelationsState(app) # Register indexers the default indexer if necessary if app.config.get('PIDRELATIONS_REGISTER_DEFAULT_INDEXER'): before_record_index.connect(index_relations, sender=app)
def update_authors_recid(record_id, uuid, profile_recid): """Update author profile for a given signature. The method receives UUIDs representing record and signature respectively together with an author profile recid. The new recid will be placed in the signature with the given UUID. :param record_id: A string representing UUID of a given record. Example: record_id = "a5afb151-8f75-4e91-8dc1-05e7e8e8c0b8" :param uuid: A string representing UUID of a given signature. Example: uuid = "c2f432bd-2f52-4c16-ac66-096f168c762f" :param profile_recid: A string representing author profile recid, that updated signature should point to. Example: profile_recid = "1" """ try: record = Record.get_record(record_id) update_flag = False for author in record['authors']: if author['uuid'] == uuid: author['recid'] = str(profile_recid) update_flag = True if update_flag: # Disconnect the signal on insert of a new record. before_record_index.disconnect(append_updated_record_to_queue) # Update the record in the database. record.commit() db.session.commit() # Update the record in Elasticsearch. indexer = RecordIndexer() indexer.index_by_id(record.id) except StaleDataError as exc: raise update_authors_recid.retry(exc=exc) finally: # Reconnect the disconnected signal. before_record_index.connect(append_updated_record_to_queue) # Report. logger.info("Updated signature %s with profile %s", uuid, profile_recid)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.extensions['sonar_documents'] = self # Connect to oaiharvester signal oaiharvest_finished.connect(transform_harvested_records, weak=False) # Connect to record index signal, to modify record before indexing. before_record_index.connect(populate_fulltext_field, weak=False)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.extensions['invenio-explicit-acls'] = AclAPI(app) # register signals from invenio_explicit_acls.signals import add_acls from invenio_indexer.signals import before_record_index before_record_index.connect(add_acls)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) # Register context processors app.context_processor(record_communities) # Register blueprint app.register_blueprint(blueprint) before_record_index.connect(indexer_receiver, sender=app) app.extensions['zenodo-records'] = self
def init_app(self, app): """Flask application initialization.""" self.init_config(app) # app.register_blueprint(blueprint) app.extensions['invenio-pidrelations'] = _InvenioPIDRelationsState(app) # Register indexers if they are required if app.config.get('PIDRELATIONS_INDEX_RELATIONS'): from invenio_indexer.signals import before_record_index before_record_index.connect(index_relations, sender=app)
def register_signals(app): """Register CDS Deposit signals.""" # index records after published # note: if publish a project -> index also videos post_action.connect(index_deposit_after_action, sender=app, weak=False) # if it's a project/video, expands informations before index before_record_index.connect( cdsdeposit_indexer_receiver, sender=app, weak=False) # register Datacite after publish record post_action.connect( datacite_register_after_publish, sender=app, weak=False)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) # Register context processors app.context_processor(record_communities) # Register blueprint app.register_blueprint(blueprint) # Add global record serializer template filter app.add_template_filter(serialize_record, 'serialize_record') before_record_index.connect(indexer_receiver, sender=app) app.extensions['zenodo-records'] = self
def register_signals(app): """Register Zenodo Deposit signals.""" before_record_index.connect(indexer_receiver, sender=app, weak=False) post_action.connect(datacite_register_after_publish, sender=app, weak=False) post_action.connect(index_versioned_record_siblings, sender=app, weak=False) post_action.connect(openaire_direct_index_after_publish, sender=app, weak=False)
def update_authors_recid(record_id, uuid, profile_recid): """Update author profile for a given signature. The method receives UUIDs representing record and signature respectively together with an author profile recid. The new recid will be placed in the signature with the given UUID. :param record_id: A string representing UUID of a given record. Example: record_id = "a5afb151-8f75-4e91-8dc1-05e7e8e8c0b8" :param uuid: A string representing UUID of a given signature. Example: uuid = "c2f432bd-2f52-4c16-ac66-096f168c762f" :param profile_recid: A string representing author profile recid, that updated signature should point to. Example: profile_recid = "1" """ try: record = InspireRecord.get_record(record_id) update_flag = False for author in record['authors']: if author['uuid'] == uuid: author['recid'] = str(profile_recid) update_flag = True if update_flag: # Disconnect the signal on insert of a new record. before_record_index.disconnect(append_updated_record_to_queue) # Update the record in the database. record.commit() db.session.commit() except StaleDataError as exc: raise update_authors_recid.retry(exc=exc) finally: # Reconnect the disconnected signal. before_record_index.connect(append_updated_record_to_queue) # Report. logger.info("Updated signature %s with profile %s", uuid, profile_recid)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.extensions['sonar_documents'] = self # Connect to oaiharvester signal oaiharvest_finished.connect(transform_harvested_records, weak=False) oaiharvest_finished.connect(export_json, weak=False) # Connect to record index signal, to modify record before indexing. before_record_index.connect(enrich_document_data, weak=False) # Adds `_oai` property before_record_insert.connect(update_oai_property) before_record_update.connect(update_oai_property)
def register_signals(self): """Register signals.""" before_record_index.connect(enrich_loan_data) before_record_index.connect(enrich_document_data) item_at_desk.connect(listener_item_at_desk) oaiharvest_finished.connect(publish_harvested_records, weak=False) apiharvest_part.connect(publish_api_harvested_records, weak=False) after_record_insert.connect(mef_person_insert) after_record_update.connect(mef_person_update) after_record_delete.connect(mef_person_delete) after_record_revert.connect(mef_person_revert)
def init_config(self, app): """Initialize configuration. :param app: The Flask application. """ # Use theme's base template if theme is installed if 'BASE_TEMPLATE' in app.config: app.config.setdefault( 'WEKO_DEPOSIT_BASE_TEMPLATE', app.config['BASE_TEMPLATE'], ) for k in dir(config): if k.startswith('WEKO_DEPOSIT_'): app.config.setdefault(k, getattr(config, k)) before_record_index.connect(append_file_content)
def register_signals(self): """Register signals.""" from invenio_indexer.signals import before_record_index from .loans.listener import enrich_loan_data before_record_index.connect(enrich_loan_data) from .documents.listener import enrich_document_data before_record_index.connect(enrich_document_data) from .patrons.listener import listener_item_at_desk from .items.signals import item_at_desk item_at_desk.connect(listener_item_at_desk) from invenio_oaiharvester.signals import oaiharvest_finished from .ebooks.receivers import publish_harvested_records oaiharvest_finished.connect(publish_harvested_records, weak=False) from .apiharvester.signals import apiharvest_part from .mef_persons.receivers import publish_api_harvested_records apiharvest_part.connect(publish_api_harvested_records, weak=False)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) # Register context processors app.context_processor(record_communities) # Register blueprint app.register_blueprint(blueprint) # Add global record serializer template filter app.add_template_filter(serialize_record, 'serialize_record') # Register versioning blueprint app.register_blueprint(versioning_blueprint) self.custom_metadata = CustomMetadataAPI( term_types=app.config.get('ZENODO_CUSTOM_METADATA_TERM_TYPES'), vocabularies=app.config.get('ZENODO_CUSTOM_METADATA_VOCABULARIES'), ) before_record_index.connect(indexer_receiver, sender=app) app.extensions['zenodo-records'] = self
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.extensions['b2share-records'] = self register_triggers(app) register_error_handlers(app) # Register records API blueprints endpoints = app.config['B2SHARE_RECORDS_REST_ENDPOINTS'] app.register_blueprint(create_blueprint(endpoints)) @app.before_first_request def extend_default_endpoint_prefixes(): """Fix the endpoint prefixes as .""" endpoint_prefixes = utils.build_default_endpoint_prefixes( endpoints) current_records_rest = app.extensions['invenio-records-rest'] current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes) before_record_index.connect(indexer_receiver, sender=app) app.url_map.converters['pid'] = PIDConverter
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.cli.add_command(b2records) app.extensions['b2share-records'] = self register_triggers(app) register_error_handlers(app) # Register records API blueprints endpoints = app.config['B2SHARE_RECORDS_REST_ENDPOINTS'] app.register_blueprint(create_blueprint(endpoints)) @app.before_first_request def extend_default_endpoint_prefixes(): """Fix the endpoint prefixes as .""" endpoint_prefixes = utils.build_default_endpoint_prefixes(endpoints) current_records_rest = app.extensions['invenio-records-rest'] current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes ) before_record_index.connect(indexer_receiver, sender=app) app.url_map.converters['pid'] = PIDConverter
def indexer(app, es): """Create a record indexer.""" InvenioIndexer(app) before_record_index.connect(record_indexer_receiver, sender=app) yield RecordIndexer()
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.extensions['my-site'] = self before_record_index.connect(indexer_receiver, sender=app, weak=False)
def register_signals(self): """Register signals.""" before_record_index.connect(enrich_loan_data) before_record_index.connect(enrich_document_data) before_record_index.connect(enrich_item_data) before_record_index.connect(enrich_patron_data) before_record_index.connect(enrich_location_data) before_record_index.connect(enrich_holding_data) before_record_index.connect(enrich_notification_data) loan_state_changed.connect(listener_loan_state_changed, weak=False) oaiharvest_finished.connect(publish_harvested_records, weak=False) apiharvest_part.connect(publish_api_harvested_records, weak=False) after_record_insert.connect(mef_person_insert) after_record_update.connect(mef_person_update) after_record_delete.connect(mef_person_delete) after_record_revert.connect(mef_person_revert)
def init_app(self, app): """Flask application initialization.""" app.extensions['cd2h-records'] = self before_record_index.connect(before_deposit_index_hook, sender=app, weak=False)
def register_signals(self, app): """Register signals.""" # TODO: use before_record_index.dynamic_connect() if it works # example: # before_record_index.dynamic_connect( # enrich_patron_data, sender=app, index='patrons-patron-v0.0.1') before_record_index.connect(enrich_acq_account_data, sender=app) before_record_index.connect(enrich_acq_order_data, sender=app) before_record_index.connect(enrich_acq_receipt_data, sender=app) before_record_index.connect(enrich_acq_receipt_line_data, sender=app) before_record_index.connect(enrich_acq_order_line_data, sender=app) before_record_index.connect(enrich_collection_data, sender=app) before_record_index.connect(enrich_loan_data, sender=app) before_record_index.connect(enrich_document_data, sender=app) before_record_index.connect(enrich_contributions_data, sender=app) before_record_index.connect(enrich_item_data, sender=app) before_record_index.connect(enrich_patron_data, sender=app) before_record_index.connect(enrich_location_data, sender=app) before_record_index.connect(enrich_holding_data, sender=app) before_record_index.connect(enrich_notification_data, sender=app) before_record_index.connect(enrich_patron_transaction_event_data, sender=app) before_record_index.connect(enrich_patron_transaction_data, sender=app) before_record_index.connect(enrich_ill_request_data, sender=app) before_record_index.connect(prepare_template_data, sender=app) after_record_insert.connect(create_subscription_patron_transaction) after_record_update.connect(create_subscription_patron_transaction) after_record_update.connect(update_items_locations_and_types) before_record_update.connect(budget_is_active_changed) before_record_update.connect(negative_availability_changes) loan_state_changed.connect(listener_loan_state_changed, weak=False) oaiharvest_finished.connect(publish_harvested_records, weak=False) apiharvest_part.connect(publish_api_harvested_records, weak=False) # invenio-userprofiles signal after_profile_update.connect(update_from_profile) # store the username in the session user_logged_in.connect(set_user_name) user_logged_out.connect(remove_user_name) user_loaded_from_cookie.connect(set_user_name)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.register_blueprint(blueprint) before_record_index.connect(indexer_receiver, sender=app) app.extensions['zenodo-records'] = self
# Create Flask application app = Flask(__name__, template_folder='.') app.config.update(dict( TEMPLATES_AUTO_RELOAD=True, CELERY_ALWAYS_EAGER=True, CELERY_RESULT_BACKEND='cache', CELERY_CACHE_BACKEND='memory')) InvenioDB(app) InvenioPIDStore(app) InvenioPIDRelations(app) app.register_blueprint(versioning_blueprint) InvenioIndexer(app) InvenioRecords(app) InvenioRecordsUI(app) before_record_index.connect(index_relations, sender=app) record_resolver = Resolver( pid_type='recid', object_type='rec', getter=Record.get_record ) class SimpleRecordSchema(Schema): """Tiny schema for our simple record.""" recid = fields.Str() title = fields.Str() body = fields.Str() @app.route('/')
def register_signals(self, app): """Register signals.""" before_record_index.connect(enrich_mef_data, sender=app)
def init_app(self, app): """Flask application initialization.""" app.register_blueprint(blueprint) before_record_index.connect(indexer_receiver, sender=app) app.config.setdefault('JSONSCHEMAS_HOST', JSONSCHEMAS_HOST) app.extensions['records'] = self
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.cli.add_command(openaire) before_record_index.connect(indexer_receiver, sender=app) app.extensions['invenio-openaire'] = self
def register_signals(app): """Register Zenodo Deposit signals.""" oaiharvest_finished.connect(publish_harvested_records, weak=False) before_record_index.connect(indexer_receiver, weak=False)
def register_signals(self, app): """Register signals.""" # TODO: use before_record_index.dynamic_connect() if it works # example: # before_record_index.dynamic_connect( # enrich_patron_data, sender=app, index='patrons-patron-v0.0.1') before_record_index.connect(enrich_collection_data, sender=app) before_record_index.connect(enrich_loan_data, sender=app) before_record_index.connect(enrich_document_data, sender=app) before_record_index.connect(enrich_contributions_data, sender=app) before_record_index.connect(enrich_item_data, sender=app) before_record_index.connect(enrich_patron_data, sender=app) before_record_index.connect(enrich_location_data, sender=app) before_record_index.connect(enrich_holding_data, sender=app) before_record_index.connect(enrich_notification_data, sender=app) before_record_index.connect(enrich_patron_transaction_event_data, sender=app) before_record_index.connect(enrich_patron_transaction_data, sender=app) before_record_index.connect(enrich_ill_request_data, sender=app) after_record_insert.connect(create_subscription_patron_transaction) after_record_update.connect(create_subscription_patron_transaction) loan_state_changed.connect(listener_loan_state_changed, weak=False) oaiharvest_finished.connect(publish_harvested_records, weak=False) apiharvest_part.connect(publish_api_harvested_records, weak=False) # invenio-userprofiles signal after_profile_update.connect(update_from_profile)