<commit_before># encoding: utf-8
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models

class Migration(DataMigration):
    
    def forwards(self, orm):
        if not db.dry_run:
            for video in orm.Video.objects.all():
                url = self.get_video_url(video)
                if url:
                    print 'Update video: %s' % video.id
                    if video.videourl_set.filter(original=True).exists():
                        obj = video.videourl_set.get(original=True)
                    else:
                        obj = orm.VideoUrl()
                    obj.type = video.video_type
                    obj.url = url
                    obj.primary = True
                    obj.original = True
                    obj.video = video
                    obj.videoid = self.get_video_id(video)
                    obj.save()                
    
    def backwards(self, orm):
        "Write your backwards methods here."
    
    def get_video_id(self, video):
        from videos.models import VIDEO_TYPE_HTML5, VIDEO_TYPE_YOUTUBE, VIDEO_TYPE_BLIPTV, VIDEO_TYPE_VIMEO, VIDEO_TYPE_DAILYMOTION
        if video.video_type == VIDEO_TYPE_YOUTUBE:
            return video.youtube_videoid
        elif video.video_type == VIDEO_TYPE_BLIPTV:
            return video.bliptv_fileid
        elif video.video_type == VIDEO_TYPE_VIMEO:
            return video.vimeo_videoid
        elif video.video_type == VIDEO_TYPE_DAILYMOTION:
            return video.dailymotion_videoid
        else:<commit_msg>Further fix to update videourl migration.<commit_after># encoding: utf-8
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models

class Migration(DataMigration):
    
    def forwards(self, orm):
        if not db.dry_run:
            for video in orm.Video.objects.all():
                url = self.get_video_url(video)
                if url:
                    print 'Update video: %s' % video.id
                    if video.videourl_set.filter(url=url).exists():
                        video.videourl_set.get(url=url).delete()
                        video = orm.Video.objects.get(id=video.id)
                    if video.videourl_set.filter(original=True).exists():
                        obj = video.videourl_set.get(original=True)
                    else:
                        obj = orm.VideoUrl()
                    obj.type = video.video_type
                    obj.url = url
                    obj.primary = True
                    obj.original = True
                    obj.video = video
                    obj.videoid = self.get_video_id(video)
                    obj.save()                
    
    def backwards(self, orm):
        "Write your backwards methods here."
    
    def get_video_id(self, video):
        from videos.models import VIDEO_TYPE_HTML5, VIDEO_TYPE_YOUTUBE, VIDEO_TYPE_BLIPTV, VIDEO_TYPE_VIMEO, VIDEO_TYPE_DAILYMOTION
        if video.video_type == VIDEO_TYPE_YOUTUBE:
            return video.youtube_videoid
        elif video.video_type == VIDEO_TYPE_BLIPTV:
            return video.bliptv_fileid
        elif video.video_type == VIDEO_TYPE_VIMEO:
            return video.vimeo_videoid
        elif video.video_type == VIDEO_TYPE_DAILYMOTION:
            return video.dailymotion_videoid
        else:
{'fraction_non_alphanumeric': 0.07324276432368576, 'fraction_numerical': 0.0017720023626698169, 'mean_word_length': 1.6481626270523846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4818856', 'n_tokens_mistral': 1025, 'n_tokens_neox': 967, 'n_words': 205}