def test_long_form(self): self.assertEqual( parse_youtube_video_id( 'http://www.youtube.com/watch?v=dbh4re56u4&feature=feedu'), 'dbh4re56u4') self.assertEqual( parse_youtube_video_id( 'https://www.youtube.com/watch?v=br56urn6u'), 'br56urn6u')
def forwards(apps, schema_editor): OtherVideo = apps.get_model("arkisto", "OtherVideo") for video in OtherVideo.objects.all(): video_id = parse_youtube_video_id(video.youtube_url) if video_id: video.youtube_url = 'https://www.youtube.com/v/{}'.format(video_id) video.save()
def forwards(apps, schema_editor): Entry = apps.get_model("kompomaatti", "Entry") for entry in Entry.objects.all(): video_id = parse_youtube_video_id(entry.youtube_url) if video_id: entry.youtube_url = 'https://www.youtube.com/v/{}'.format(video_id) entry.save()
def clean_youtube_url(self): # Make sure field has content if not self.cleaned_data['youtube_url']: return self.cleaned_data['youtube_url'] # Parse video id video_id = parse_youtube_video_id(self.cleaned_data['youtube_url']) # Warn if something is wrong if not video_id: raise ValidationError('Osoitteesta ei löytynyt videotunnusta.') # Return a new video url return 'https://www.youtube.com/v/{}'.format(video_id)
def test_long_form(self): self.assertEqual(parse_youtube_video_id('http://www.youtube.com/watch?v=dbh4re56u4&feature=feedu'), 'dbh4re56u4') self.assertEqual(parse_youtube_video_id('https://www.youtube.com/watch?v=br56urn6u'), 'br56urn6u')
def test_youtu_be(self): self.assertEqual(parse_youtube_video_id('http://youtu.be/w34tvwoier8'), 'w34tvwoier8')
def test_short_embed_form(self): self.assertEqual(parse_youtube_video_id('http://www.youtube.com/v/egv5yber5yre5?version=3&hl=en_US'), 'egv5yber5yre5')
def test_embed_form(self): self.assertEqual(parse_youtube_video_id('http://www.youtube.com/embed/w4v6be547'), 'w4v6be547')
def test_short_embed_form(self): self.assertEqual( parse_youtube_video_id( 'http://www.youtube.com/v/egv5yber5yre5?version=3&hl=en_US' ), 'egv5yber5yre5')
def test_embed_form(self): self.assertEqual( parse_youtube_video_id('http://www.youtube.com/embed/w4v6be547'), 'w4v6be547')