def _set_version_moderation_status(version, team, user, status, updates_meta=True): if not user_can_moderate(version.language.video, user): raise SuspiciousOperation("User cannot approve this version") version.moderation_status = status version.save() if updates_meta: video_cache.invalidate_cache(version.video.video_id) _update_search_index(version.video) return version
def delete(self, *args, **kwargs): video_id = self.video_id super(SubtitleLanguage, self).delete(*args, **kwargs) #asynchronous call update_team_video.delay(video_id) if not self.video.subtitlelanguage_set.exclude(is_complete=False).exists(): self.video.complete_date = None self.video.save() video_cache.invalidate_cache(self.video.video_id) self.video.update_languages_count()
def add_moderation( video, team, user): """ Adds moderation and approves all """ if video.moderated_by : raise AlreadyModeratedException("Video is already moderated") if not team.can_add_moderation(user) : raise SuspiciousOperation("User cannot set this video as moderated") video.moderated_by = team video.save() SubtitleVersion.objects.filter(language__video__id = video.pk, moderation_status=UNMODERATED).update(moderation_status=APPROVED) video_cache.invalidate_cache(video.video_id) _update_search_index(video) return True
def test_cache_delete_valid_chars(self): # this tests depends on memcache being available try: from memcache.Client import MemcachedKeyCharacterError except ImportError: return request = RequestMockup(self.user_0) session = create_two_sub_session(request) video = session.video # make sure we have video on cache video_id = video_cache.get_video_id(video.get_absolute_url(video.get_video_url())) self.assertEquals(video_id, video.video_id) self.assertTrue(bool(video_id)) try: video_cache.invalidate_cache(video_id) except MemcachedKeyCharacterError: self.fail("Cache invalidation should not fail")
def remove_moderation( video, team, user): """ Removes the moderation lock for that video, sets all the sub versions to approved , invalidates the cache and updates the search index. """ if not video.moderated_by: return None if not team.can_remove_moderation( user) : raise SuspiciousOperation("User cannot unset this video as moderated") for lang in video.subtitlelanguage_set.all(): latest = lang.latest_version(public_only=False) if latest and latest.moderation_status == REJECTED: # rollback to the last moderated status latest_approved = lang.latest_version(public_only=Tue) v = latest_approved.rollback(user) v.save() num = SubtitleVersion.objects.filter(language__video=video).update(moderation_status=UNMODERATED) video.moderated_by = None; video.save() video_cache.invalidate_cache(video.video_id) _update_search_index(video) return num
def video_delete_handler(sender, instance, **kwargs): video_cache.invalidate_cache(instance.video_id)
def _invalidate_cache(video): from widget import video_cache video_cache.invalidate_cache(video.video_id)
def subtile_language_delete_handler(sender, instance, **kwargs): video_cache.invalidate_cache(instance.video.video_id)
def subtile_language_delete_handler(sender, instance, **kwargs): video_cache.invalidate_cache(instance.video.video_id) instance.video.update_languages_count()