def test_empty(self): data = [] sum = 0 for i in chunkediter(data): sum += i self.assertEqual(sum, 0) sum = 0 for i in chunkediter(data, 1): sum += i self.assertEqual(sum, 0)
def forwards(self, orm): "Write your forwards methods here." for missing_set_version in chunkediter(orm['subtitles.SubtitleVersion'].objects.filter(serialized_subtitles='')): subtitles = SubtitleSet(missing_set_version.language_code) missing_set_version.serialized_subtitles = compress(subtitles.to_xml()) missing_set_version.subtitle_count = 0 missing_set_version.save()
def forwards(self, orm): if not db.dry_run: for t in chunkediter(orm.BillingRecord.objects.all()): if t.subtitle_version: t.new_subtitle_version = t.subtitle_version.new_subtitle_version if t.subtitle_language: t.new_subtitle_language = t.subtitle_language.new_subtitle_language t.save()
def test_iterate(self): data = [1, 10, 100, 1000, 10000] sum = 0 for i in chunkediter(data): sum += i self.assertEqual(sum, 11111) sum = 0 for i in chunkediter(data, 2): sum += i self.assertEqual(sum, 11111) sum = 0 for i in chunkediter(data, 1): sum += i self.assertEqual(sum, 11111)
def backwards(self, orm): "Write your backwards methods here." if not db.dry_run: for video in chunkediter(orm.Video.objects.all()): try: sl = orm.SubtitleLanguage.objects.get( video=video, language=video.primary_audio_language) sl.is_original = True sl.save() except models.ObjectDoesNotExist: pass
def forwards(self, orm): "Write your forwards methods here." if not db.dry_run: total = orm.Video.objects.count() i = 0 for video in chunkediter(orm.Video.objects.all()): if i % 100 == 0: print '%d/%d' % (i, total) video.primary_audio_language = language(video) video.save() i += 1