Exemplo n.º 1
0
Arquivo: ext.py Projeto: jma/rero-ils
    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)
Exemplo n.º 2
0
def test_clear_and_renew_subscription(patron_type_grown_sion,
                                      patron_sion_no_email):
    """Test the `task patrons.tasks.clear_and_renew_subscription`."""

    patron_sion = patron_sion_no_email

    # To test correctly all the code we need to disconnect the listener
    # `create_subscription_patron_transaction` method. Otherwise, the
    # first part of the task (clean_obsolete_subscriptions) will automatically
    # create new subscriptions because the last instruction is a
    # `patron.update()` call.
    after_record_update.disconnect(create_subscription_patron_transaction)

    # first step : clear all subscription for the patron and crate an new
    # obsolete subscription.
    if 'subscriptions' in patron_sion_no_email.get('patron', {}):
        del patron_sion_no_email['patron']['subscriptions']
    start = datetime.now() - timedelta(days=200)
    end = start + timedelta(days=100)
    patron_sion.add_subscription(patron_type_grown_sion, start, end)
    assert len(patron_sion.get('patron', {}).get('subscriptions', [])) == 1
    assert patron_sion.get('patron', {})['subscriptions'][0]['end_date'] == \
        end.strftime('%Y-%m-%d')

    # clean old subscription - Reload the patron and check they are no more
    # subscriptions
    clean_obsolete_subscriptions()
    patron_sion = Patron.get_record_by_pid(patron_sion.pid)
    assert len(patron_sion.get('patron', {}).get('subscriptions', [])) == 0

    # check for patron needed subscriptions and create new subscription if
    # needed. As our patron has no subscription and is still connected to
    # a patron type requiring subscription, this task should create a
    # new subscription for this patron
    check_patron_types_and_add_subscriptions()
    patron_sion = Patron.get_record_by_pid(patron_sion.pid)
    assert len(patron_sion.get('patron', {}).get('subscriptions', [])) == 1
    assert patron_sion.get('patron', {})['subscriptions'][0]['end_date'] == \
        add_years(datetime.now(), 1).strftime('%Y-%m-%d')

    # run both operation using task_clear_and_renew_subscriptions` and check
    # the result. The patron should still have one subscription but end_date
    # must be today.
    del patron_sion['patron']['subscriptions']
    start = datetime.now() - timedelta(days=200)
    end = start + timedelta(days=100)
    patron_sion.add_subscription(patron_type_grown_sion, start, end)
    task_clear_and_renew_subscriptions()
    patron_sion = Patron.get_record_by_pid(patron_sion.pid)
    assert len(patron_sion.get('patron', {}).get('subscriptions', [])) == 1
    assert patron_sion.get('patron', {})['subscriptions'][0]['end_date'] != \
        end.strftime('%Y-%m-%d')

    # as we disconnect the `create_subscription_patron_transaction` listener
    # at the beginning, we need to connect it now.
    after_record_update.connect(create_subscription_patron_transaction)
Exemplo n.º 3
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)

        # Connect invenio-records signal handlers
        after_record_insert.connect(create_references_record)
        before_record_update.connect(convert_record_refs)
        after_record_update.connect(update_references_record)
        after_record_delete.connect(delete_references_record)

        state = _RecordReferencesState(app)
        app.extensions['oarepo-references'] = state
        return state
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
def signals():
    """Fixtures to connect signals."""
    called = {}

    def _listener(signal_name, sender, *args, **kwargs):
        if signal_name not in called:
            called[signal_name] = 0
        called[signal_name] += 1

    after_record_delete_listener = partial(_listener, 'after_record_delete')
    after_record_insert_listener = partial(_listener, 'after_record_insert')
    after_record_revert_listener = partial(_listener, 'after_record_revert')
    after_record_update_listener = partial(_listener, 'after_record_update')
    before_record_delete_listener = partial(_listener, 'before_record_delete')
    before_record_insert_listener = partial(_listener, 'before_record_insert')
    before_record_revert_listener = partial(_listener, 'before_record_revert')
    before_record_update_listener = partial(_listener, 'before_record_update')
    before_record_insert_listener = partial(_listener, 'before_record_insert')

    after_record_delete.connect(after_record_delete_listener)
    after_record_insert.connect(after_record_insert_listener)
    after_record_revert.connect(after_record_revert_listener)
    after_record_update.connect(after_record_update_listener)
    before_record_delete.connect(before_record_delete_listener)
    before_record_insert.connect(before_record_insert_listener)
    before_record_revert.connect(before_record_revert_listener)
    before_record_update.connect(before_record_update_listener)
    before_record_insert.connect(before_record_insert_listener)

    yield called

    after_record_delete.disconnect(after_record_delete_listener)
    after_record_insert.disconnect(after_record_insert_listener)
    after_record_revert.disconnect(after_record_revert_listener)
    after_record_update.disconnect(after_record_update_listener)
    before_record_delete.disconnect(before_record_delete_listener)
    before_record_insert.disconnect(before_record_insert_listener)
    before_record_revert.disconnect(before_record_revert_listener)
    before_record_update.disconnect(before_record_update_listener)
    before_record_insert.disconnect(before_record_insert_listener)
Exemplo n.º 8
0
 def register_signals(app):
     """Register Literature signals."""
     before_record_insert.connect(preemptively_set_first_isbn_as_cover)
     before_record_update.connect(preemptively_set_first_isbn_as_cover)
     after_record_insert.connect(pick_identifier_with_cover)
     after_record_update.connect(pick_identifier_with_cover)
Exemplo n.º 9
0
def register_location_signals():
    """Register location signals."""
    after_record_update.connect(record_update_listener, weak=False)
Exemplo n.º 10
0
 def register_signals(app):
     """Register signals."""
     if app.config.get("CDS_ILS_LITERATURE_UPDATE_COVERS", True):
         after_record_insert.connect(pick_identifier_with_cover)
         after_record_update.connect(pick_identifier_with_cover)
Exemplo n.º 11
0
def register_triggers(app):
    # TODO(edima): replace this check with explicit permissions
    before_record_update.connect(check_record_immutable_fields)
    before_record_delete.connect(unindex_record_trigger)
    after_record_update.connect(index_record_trigger)
    after_record_insert.connect(index_record_trigger)
Exemplo n.º 12
0
def register_triggers(app):
    # TODO(edima): replace this check with explicit permissions
    before_record_update.connect(check_record_immutable_fields)
    before_record_delete.connect(unindex_record_trigger)
    after_record_update.connect(index_record_trigger)
    after_record_insert.connect(index_record_trigger)