예제 #1
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
    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)
예제 #2
0
 def delete(self):
     """ This deletes all sounds in the pack as well. """
     # TODO: remove from solr?
     # delete files
     delete_object_files(self, web_logger)
     # super class delete
     super(SocialModel, self).delete()
예제 #3
0
파일: models.py 프로젝트: willwc/freesound
 def delete(self):
     """ This deletes all sounds in the pack as well. """
     # TODO: remove from solr?
     # delete files
     delete_object_files(self, web_logger)
     # super class delete
     super(SocialModel, self).delete()
예제 #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
파일: models.py 프로젝트: bdejong/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:
        '''
        When deleting the sound is possible that the profile has already been deleted (because of django on cascade
        delete order). See comment below after 'except Pack.DoesNotExist'
        '''
        if hasattr(instance.user, 'profile'):
            instance.user.profile.update_num_sounds()
    except User.DoesNotExist:
        '''
        It might happen that on deleting sound the user does not exist because of the way django deletes objects
        in 'cascade'. See comment below after 'except Pack.DoesNotExist'.
        '''
        pass

    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

    instance.delete_from_indexes()
    instance.unlink_moderation_ticket()
    delete_object_files(instance, web_logger)
    web_logger.debug("Deleted sound with id %i" % instance.id)
예제 #6
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)
예제 #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:
        instance.user.profile.update_num_sounds()
    except User.DoesNotExist:
        '''
        It might happen that on deleting sound the user does not exist because of the way django deletes objects
        in 'cascade'. See comment below after 'except Pack.DoesNotExist'.
        '''
        pass

    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

    instance.delete_from_indexes()
    instance.unlink_moderation_ticket()
    delete_object_files(instance, web_logger)
    web_logger.debug("Deleted sound with id %i" % instance.id)
예제 #8
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)
예제 #9
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
    if instance.pack:
        instance.pack.process()
    
    delete_sound_from_solr(instance)
    delete_object_files(instance, web_logger)
    # N.B. be watchful of errors that might be thrown if the sound is not in the similarity index
    if Similarity.contains(instance.id):
        Similarity.delete(instance.id)
    web_logger.debug("Deleted sound with id %i"%instance.id)
예제 #10
0
파일: models.py 프로젝트: bdejong/freesound
 def delete(self, using=None):
     """ This deletes all sounds in the pack as well. """
     for sound in self.sound_set.all():
         sound.delete()
     delete_object_files(self, web_logger)
     super(SocialModel, self).delete(using=using)  # super class delete
예제 #11
0
 def delete(self, using=None):
     """ This deletes all sounds in the pack as well. """
     for sound in self.sound_set.all():
         sound.delete()
     delete_object_files(self, web_logger)
     super(SocialModel, self).delete(using=using)  # super class delete