Exemplo n.º 1
0
def watch_changes(old_attr=None, new_attr=None, instance=None, sender=None,
                  **kwargs):
    if old_attr is None:
        old_attr = {}
    if new_attr is None:
        new_attr = {}
    changes = {
        x for x in new_attr
        if not x.startswith('_') and new_attr[x] != old_attr.get(x)
    }

    if 'recommendation_approved' in changes:
        from olympia.addons.models import update_search_index
        # Update ES because Addon.is_recommended depends on it.
        update_search_index(
            sender=sender, instance=instance.addon, **kwargs)

    if (instance.channel == amo.RELEASE_CHANNEL_UNLISTED and
            'deleted' in changes) or 'recommendation_approved' in changes:
        # Sync the related add-on to basket when recommendation_approved is
        # changed or when an unlisted version is deleted. (When a listed
        # version is deleted, watch_changes() in olympia.addon.models should
        # take care of it (since _current_version will change).
        from olympia.amo.tasks import sync_object_to_basket
        sync_object_to_basket.delay('addon', instance.addon.pk)
Exemplo n.º 2
0
def watch_changes(old_attr=None,
                  new_attr=None,
                  instance=None,
                  sender=None,
                  **kw):
    if old_attr is None:
        old_attr = {}
    if new_attr is None:
        new_attr = {}
    changes = {
        x
        for x in new_attr
        if not x.startswith('_') and new_attr[x] != old_attr.get(x)
    }

    # Log email changes.
    if 'email' in changes and new_attr['email'] is not None:
        log.debug('Creating user history for user: %s' % instance.pk)
        UserHistory.objects.create(email=old_attr.get('email'),
                                   user_id=instance.pk)
    # If username or display_name changes, reindex the user add-ons, if there
    # are any.
    if 'username' in changes or 'display_name' in changes:
        from olympia.addons.tasks import index_addons
        ids = [addon.pk for addon in instance.get_addons_listed()]
        if ids:
            index_addons.delay(ids)

    basket_relevant_changes = ('deleted', 'display_name', 'email', 'homepage',
                               'last_login', 'location')
    if any(field in changes for field in basket_relevant_changes):
        from olympia.amo.tasks import sync_object_to_basket
        log.info('Triggering a sync of %s %s with basket because of %s change',
                 'userprofile', instance.pk, 'attribute')
        sync_object_to_basket.delay('userprofile', instance.pk)
Exemplo n.º 3
0
def watch_new_unlisted_version(sender=None, instance=None, **kwargs):
    # Sync the related add-on to basket when an unlisted version is uploaded.
    # Unlisted version deletion is handled by watch_changes() above, and new
    # version approval changes are handled by watch_changes()
    # in olympia.addon.models (since _current_version will change).
    # What's left here is unlisted version upload.
    if instance and instance.channel == amo.RELEASE_CHANNEL_UNLISTED:
        from olympia.amo.tasks import sync_object_to_basket
        sync_object_to_basket.delay('addon', instance.addon.pk)
Exemplo n.º 4
0
def update_es_for_promoted(sender, instance, **kw):
    from olympia.addons.models import update_search_index
    from olympia.amo.tasks import sync_object_to_basket

    # Update ES because Addon.promoted depends on it.
    update_search_index(sender=sender, instance=instance.addon, **kw)

    # Sync the related add-on to basket when promoted groups is changed
    sync_object_to_basket.delay('addon', instance.addon.pk)
Exemplo n.º 5
0
def watch_changes(old_attr=None,
                  new_attr=None,
                  instance=None,
                  sender=None,
                  **kwargs):
    if old_attr is None:
        old_attr = {}
    if new_attr is None:
        new_attr = {}
    changes = {
        x
        for x in new_attr
        if not x.startswith('_') and new_attr[x] != old_attr.get(x)
    }

    if (instance.channel == amo.RELEASE_CHANNEL_UNLISTED
            and 'deleted' in changes):
        # Sync the related add-on to basket when an unlisted version is
        # deleted. (When a listed version is deleted, watch_changes() in
        # olympia.addon.models should take care of it (since _current_version
        # will change).
        from olympia.amo.tasks import sync_object_to_basket
        sync_object_to_basket.delay('addon', instance.addon.pk)