Commit 4aedbe76307b3f7f1dafbf48259754fe8c568f7e
1 parent
6456e0bc
Exists in
master
and in
2 other branches
correction of bugs 3 and 4 of UC 45 and 3 and 4 of UC 44
Showing
2 changed files
with
6 additions
and
5 deletions
Show diff stats
youtube_video/forms.py
| ... | ... | @@ -67,11 +67,13 @@ class YTVideoForm(forms.ModelForm): |
| 67 | 67 | |
| 68 | 68 | def clean_url(self): |
| 69 | 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 | 73 | self._errors['url'] = [_('Invalid URL. It should be an YouTube link.')] |
| 72 | - | |
| 73 | 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 | 77 | return url |
| 76 | 78 | |
| 77 | 79 | def save(self, commit = True): | ... | ... |
youtube_video/models.py
| ... | ... | @@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse_lazy |
| 5 | 5 | from topics.models import Resource |
| 6 | 6 | |
| 7 | 7 | class YTVideo(Resource): |
| 8 | - url = models.URLField(_('URL'), max_length = 250) | |
| 8 | + url = models.CharField(_('URL'), max_length = 250) | |
| 9 | 9 | |
| 10 | 10 | class Meta: |
| 11 | 11 | verbose_name = _('YTVideo') |
| ... | ... | @@ -37,4 +37,3 @@ class YTVideo(Resource): |
| 37 | 37 | return "https://www.youtube.com/embed/" + parts[1] |
| 38 | 38 | |
| 39 | 39 | return self.url |
| 40 | - | ... | ... |