live_share_youtube/player/forms.py

27 lines
729 B
Python
Raw Normal View History

2018-03-25 15:52:52 +00:00
from urllib.parse import urlparse
2018-03-28 15:05:18 +00:00
import django.utils.timezone as timezone
2018-03-25 15:52:52 +00:00
from django import forms
from player.models import Playlist, Link
class PlaylistForm(forms.ModelForm):
class Meta:
model = Playlist
2018-03-28 18:30:37 +00:00
fields = ['name', 'public']
2018-03-25 15:52:52 +00:00
def is_valid(self):
2018-03-28 15:05:18 +00:00
self.instance.date = timezone.now()
self.instance.last_get = timezone.now()
self.instance.last_update = timezone.now()
2018-03-25 15:52:52 +00:00
return super().is_valid()
class LinkForm(forms.Form):
url = forms.URLField(label="URL de la piste à ajouter")
def get_token(self):
p=urlparse(self.cleaned_data['url'])
print(p.query)
return [i for i in p.query.split('&') if i and i[0]=='v'][0].split('=')[-1]