Commit 4aedbe76307b3f7f1dafbf48259754fe8c568f7e

Authored by Jose Guilherme
1 parent 6456e0bc

correction of bugs 3 and 4 of UC 45 and 3 and 4 of UC 44

youtube_video/forms.py
@@ -67,11 +67,13 @@ class YTVideoForm(forms.ModelForm): @@ -67,11 +67,13 @@ class YTVideoForm(forms.ModelForm):
67 67
68 def clean_url(self): 68 def clean_url(self):
69 url = self.cleaned_data.get('url', '') 69 url = self.cleaned_data.get('url', '')
70 - if not 'youtube' in url or re.compile('[htps:/]*w*\.youtube\.com/?').fullmatch(url) or requests.get(url).status_code == 404: 70 + if url[0].lower() != "h": url = "https://" + url
  71 + if (re.compile("https?://w{3}\.youtube\.com/").match(url) == None
  72 + and re.compile("https?://youtu\.be/").match(url) == None) or requests.get(url).status_code == 404:
71 self._errors['url'] = [_('Invalid URL. It should be an YouTube link.')] 73 self._errors['url'] = [_('Invalid URL. It should be an YouTube link.')]
72 -  
73 return ValueError 74 return ValueError
74 - 75 + if re.compile("https?://youtu\.be/").match(url) != None:
  76 + url = url.replace("youtu.be","www.youtube.com/embed")
75 return url 77 return url
76 78
77 def save(self, commit = True): 79 def save(self, commit = True):
youtube_video/models.py
@@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse_lazy @@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse_lazy
5 from topics.models import Resource 5 from topics.models import Resource
6 6
7 class YTVideo(Resource): 7 class YTVideo(Resource):
8 - url = models.URLField(_('URL'), max_length = 250) 8 + url = models.CharField(_('URL'), max_length = 250)
9 9
10 class Meta: 10 class Meta:
11 verbose_name = _('YTVideo') 11 verbose_name = _('YTVideo')
@@ -37,4 +37,3 @@ class YTVideo(Resource): @@ -37,4 +37,3 @@ class YTVideo(Resource):
37 return "https://www.youtube.com/embed/" + parts[1] 37 return "https://www.youtube.com/embed/" + parts[1]
38 38
39 return self.url 39 return self.url
40 -