def respect_purge_setting(*args): """Raise or delete related objects based on settings. This is a when_missing handler for ObjectSimilarityQueryset.get_instances_for. """ if conf.settings.RECOMMEND_PURGE_MISSING_DATA: django_recommend.forget_object(*args) else: raise
def __iter__(self): ctype = ct_models.ContentType.objects.get_for_model(self.obj) # Get all users who rated this object relevant_users = models.UserScore.objects.filter( object_content_type=ctype, object_id=self.obj.pk ).values_list('user', flat=True).distinct() # Get all objects that those users have rated relevant_objects = models.UserScore.objects.filter( user__in=relevant_users ).values_list( 'object_content_type', 'object_id' ).distinct() for args in relevant_objects: try: yield get_object(*args) except django.core.exceptions.ObjectDoesNotExist: if conf.settings.RECOMMEND_PURGE_MISSING_DATA: django_recommend.forget_object(*args) else: raise