コード例 #1
0
    def handle(self, *args, **options):

        # Index all those which are processed and moderated ok that has is_index_dirty
        sounds_to_index = Sound.objects.filter(processing_state="OK", moderation_state="OK", is_index_dirty=True)
        num_sounds = sounds_to_index.count()
        logger.info("Starting posting dirty sounds to solr. %i sounds to be added/updated to the solr index"
                    % num_sounds)

        num_correctly_indexed_sounds = add_all_sounds_to_solr(sounds_to_index, mark_index_clean=True)

        logger.info("Finished posting dirty sounds to solr. %i sounds have been added/updated"
                    % num_correctly_indexed_sounds)

        # Remove all those which are not processed or moderated ok and that are still in solr (should not happen)
        sounds_dirty_to_remove = \
            Sound.objects.filter(is_index_dirty=True).exclude(moderation_state='OK', processing_state='OK')
        n_deleted_sounds = 0
        for sound in sounds_dirty_to_remove:
            if check_if_sound_exists_in_solr(sound):
                # We need to know if the sound exists in solr so that besides deleting it (which could be accomplished
                # by simply using delete_sound_from_solr), we know whether we have to change is_index_dirty state. If
                # we do not change it, then we would try to delete the sound at every attempt.
                delete_sound_from_solr(sound.id)
                n_deleted_sounds += 1
                sound.is_index_dirty = False
                sound.save()
        logger.info("Deleted %i sounds from solr index." % n_deleted_sounds)
コード例 #2
0
ファイル: models.py プロジェクト: yanomamo/freesound
def on_delete_sound(sender,instance, **kwargs):
    if instance.moderation_state == "OK" and instance.processing_state == "OK":
        try:
            DeletedSound.objects.get_or_create(sound_id=instance.id, user=instance.user)
        except User.DoesNotExist:
            deleted_user = User.objects.get(id=settings.DELETED_USER_ID)
            DeletedSound.objects.get_or_create(sound_id=instance.id, user=deleted_user)

    try:
        if instance.geotag:
            instance.geotag.delete()
    except:
        pass
    if instance.pack:
        instance.pack.process()

    delete_sound_from_solr(instance)
    delete_object_files(instance, web_logger)
    if instance.similarity_state=='OK':
	try:
    		if Similarity.contains(instance.id):
        		Similarity.delete(instance.id)
	except:
		web_logger.warn("ommitting similarity deletion for deleted sound %d"%instance.id)

    web_logger.debug("Deleted sound with id %i"%instance.id)
コード例 #3
0
    def handle(self, *args, **options):

        # Index all those which are processed and moderated ok that has is_index_dirty
        sounds_to_index = Sound.objects.filter(processing_state="OK",
                                               moderation_state="OK",
                                               is_index_dirty=True)
        num_sounds = sounds_to_index.count()
        logger.info(
            "Starting posting dirty sounds to solr. %i sounds to be added/updated to the solr index"
            % num_sounds)

        num_correctly_indexed_sounds = add_all_sounds_to_solr(
            sounds_to_index,
            mark_index_clean=True,
            delete_if_existing=options['delete-if-existing'])

        logger.info(
            "Finished posting dirty sounds to solr. %i sounds have been added/updated"
            % num_correctly_indexed_sounds)

        # Remove all those which are not processed or moderated ok and that are still in solr (should not happen)
        sounds_dirty_to_remove = \
            Sound.objects.filter(is_index_dirty=True).exclude(moderation_state='OK', processing_state='OK')
        n_deleted_sounds = 0
        for sound in sounds_dirty_to_remove:
            if check_if_sound_exists_in_solr(sound):
                # We need to know if the sound exists in solr so that besides deleting it (which could be accomplished
                # by simply using delete_sound_from_solr), we know whether we have to change is_index_dirty state. If
                # we do not change it, then we would try to delete the sound at every attempt.
                delete_sound_from_solr(sound.id)
                n_deleted_sounds += 1
                sound.is_index_dirty = False
                sound.save()
        logger.info("Deleted %i sounds from solr index." % n_deleted_sounds)
コード例 #4
0
ファイル: models.py プロジェクト: willwc/freesound
def on_delete_sound(sender, instance, **kwargs):
    if instance.moderation_state == "OK" and instance.processing_state == "OK":
        try:
            DeletedSound.objects.get_or_create(sound_id=instance.id,
                                               user=instance.user)
        except User.DoesNotExist:
            deleted_user = User.objects.get(id=settings.DELETED_USER_ID)
            DeletedSound.objects.get_or_create(sound_id=instance.id,
                                               user=deleted_user)

    try:
        if instance.geotag:
            instance.geotag.delete()
    except:
        pass
    if instance.pack:
        instance.pack.process()

    delete_sound_from_solr(instance)
    delete_object_files(instance, web_logger)
    if instance.similarity_state == 'OK':
        try:
            if Similarity.contains(instance.id):
                Similarity.delete(instance.id)
        except:
            web_logger.warn(
                "ommitting similarity deletion for deleted sound %d" %
                instance.id)

    web_logger.debug("Deleted sound with id %i" % instance.id)
コード例 #5
0
    def handle(self, *args, **options):
        # Get all sounds moderated and processed ok
        sound_qs = Sound.objects.select_related("pack", "user", "license") \
                                .filter(processing_state="OK", moderation_state="OK")
        add_all_sounds_to_solr(sound_qs, mark_index_clean=True)

        # Get all sounds that should not be in solr and remove them if they are
        sound_qs = Sound.objects.exclude(processing_state="OK", moderation_state="OK")
        for sound in sound_qs:
            delete_sound_from_solr(sound)  # Will only do something if sound in fact exists in solr
コード例 #6
0
    def handle(self, *args, **options):
        mark_index_clean = not options['no_index_clean']

        # Get all sounds moderated and processed ok
        sounds_to_index = Sound.objects.filter(processing_state="OK", moderation_state="OK")
        console_logger.info("Reindexing %d sounds to solr", sounds_to_index.count())

        add_all_sounds_to_solr(sounds_to_index, mark_index_clean=mark_index_clean)

        # Get all sounds that should not be in solr and remove them if they are
        sound_qs = Sound.objects.exclude(processing_state="OK", moderation_state="OK")
        for sound in sound_qs:
            delete_sound_from_solr(sound.id)  # Will only do something if sound in fact exists in solr
コード例 #7
0
def on_delete_sound(sender, instance, **kwargs):
    if instance.moderation_state == "OK" and instance.processing_state == "OK":
        try:
            DeletedSound.objects.get_or_create(sound_id=instance.id,
                                               user=instance.user)
        except User.DoesNotExist:
            deleted_user = User.objects.get(id=settings.DELETED_USER_ID)
            DeletedSound.objects.get_or_create(sound_id=instance.id,
                                               user=deleted_user)

    try:
        if instance.geotag:
            instance.geotag.delete()
    except:
        pass

    try:
        if instance.pack:
            instance.pack.process()
    except Pack.DoesNotExist:
        '''
        It might happen when we do user.delete() to a user that has several sounds in packs that when post_delete
        signals for sounds are called, the packs have already been deleted. This is because the way in which django
        deletes all the related objects with foreign keys. When a user is deleted, its packs and sounds must be deleted
        too. Django first runs pre_delete on all objects to be deleted, then delete and then post_delete. Therefore
        it can happen that when the post_delete signal for a sound is called, the pack has already been deleted but the
        instance passed to the post_delete function still points to that pack. We can therefore safely use try/except
        here and we'll still be doing the job correctly.
        '''
        pass

    delete_sound_from_solr(instance)
    delete_object_files(instance, web_logger)

    if instance.similarity_state == 'OK':
        try:
            if Similarity.contains(instance.id):
                Similarity.delete(instance.id)
        except:
            web_logger.warn(
                "ommitting similarity deletion for deleted sound %d" %
                instance.id)

    web_logger.debug("Deleted sound with id %i" % instance.id)
コード例 #8
0
ファイル: models.py プロジェクト: harish211/freesound
def on_delete_sound(sender, instance, **kwargs):
    if instance.moderation_state == "OK" and instance.processing_state == "OK":
        try:
            DeletedSound.objects.get_or_create(sound_id=instance.id, user=instance.user)
        except User.DoesNotExist:
            deleted_user = User.objects.get(id=settings.DELETED_USER_ID)
            DeletedSound.objects.get_or_create(sound_id=instance.id, user=deleted_user)

    try:
        if instance.geotag:
            instance.geotag.delete()
    except:
        pass

    try:
        if instance.pack:
            instance.pack.process()
    except Pack.DoesNotExist:
        '''
        It might happen when we do user.delete() to a user that has several sounds in packs that when post_delete
        signals for sounds are called, the packs have already been deleted. This is because the way in which django
        deletes all the related objects with foreign keys. When a user is deleted, its packs and sounds must be deleted
        too. Django first runs pre_delete on all objects to be deleted, then delete and then post_delete. Therefore
        it can happen that when the post_delete signal for a sound is called, the pack has already been deleted but the
        instance passed to the post_delete function still points to that pack. We can therefore safely use try/except
        here and we'll still be doing the job correctly.
        '''
        pass

    delete_sound_from_solr(instance)
    delete_object_files(instance, web_logger)

    if instance.similarity_state == 'OK':
        try:
            if Similarity.contains(instance.id):
                Similarity.delete(instance.id)
        except:
            web_logger.warn("ommitting similarity deletion for deleted sound %d" % instance.id)

    web_logger.debug("Deleted sound with id %i" % instance.id)
コード例 #9
0
 def delete_from_indexes(self):
     delete_sound_from_solr(self)
     delete_sound_from_gaia(self)
コード例 #10
0
 def delete_from_indexes(self):
     delete_sound_from_solr(self)
     delete_sound_from_gaia(self)