Пример #1
0
 def form_valid(self, form):
     link = form.cleaned_data.get('video_url')
     consumer = oembed.OEmbedConsumer(link)
     result = consumer.result()
     obj = Video()
     obj.embedcode = result['html']
     obj.thumbnail = image_from_url(result['thumbnail_url'])
     if 'duration' in result:
         obj.duration = result['duration']
     obj.user = self.request.user
     obj.project_name = form.cleaned_data.get('project_name')
     obj.project_url = form.cleaned_data.get('project_url')
     obj.video_provider = get_video_provider_from_link(form.cleaned_data.get('video_url'))
     obj.publish = True
     obj.description = form.cleaned_data.get('description')
     obj.video_url = link
     obj.save()
     obj.slug = gen_shortcut(obj.id)
     tags = form.cleaned_data.get('tags')
     alltags = Tag.objects.all().filter(name__in=tags)
     for tag in tags:
         obj.tags.add(alltags.get(name=tag))
         obj.save()
     self.success_url = obj.get_absolute_url()
     action.send(self.request.user, verb=_('added the video'), action_type=ACTION_ADDED, target=obj,
                 request=self.request)
     return super(VideoAdd, self).form_valid(form)
Пример #2
0
 def form_valid(self, form):
     link = form.cleaned_data.get('video_url')
     consumer = oembed.OEmbedConsumer(link)
     result = consumer.result()
     obj = Video()
     obj.embedcode = result['html']
     obj.thumbnail = image_from_url(result['thumbnail_url'])
     if 'duration' in result:
         obj.duration = result['duration']
     obj.user = self.request.user
     obj.project_name = form.cleaned_data.get('project_name')
     obj.project_url = form.cleaned_data.get('project_url')
     obj.video_provider = get_video_provider_from_link(form.cleaned_data.get('video_url'))
     obj.publish = True
     obj.description = form.cleaned_data.get('description')
     obj.video_url = link
     obj.save()
     obj.slug = gen_shortcut(obj.id)
     tags = form.cleaned_data.get('tags')
     alltags = Tag.objects.all().filter(name__in=tags)
     for tag in tags:
         obj.tags.add(alltags.get(name=tag))
         obj.save()
     self.success_url = obj.get_absolute_url()
     action.send(self.request.user, verb=_('added the video'), action_type=ACTION_ADDED, target=obj,
                 request=self.request)
     return super(VideoAdd, self).form_valid(form)
Пример #3
0
 def form_valid(self, form):
     link = form.cleaned_data.get('video_url')
     if not link[:7] == 'http://':
         link = 'http://%s' % link
     if link.find('youtu.be') != -1:
         link = link.replace('youtu.be/','www.youtube.com/watch?v=')
     consumer = oembed.OEmbedConsumer()
     # TODO: more code security here - big chance to get fatal error
     endpoint = get_oembed_end_point(link)
     #
     consumer.addEndpoint(endpoint)
     response = consumer.embed(link)
     result = response.getData()
     obj = Video()
     obj.embedcode = result['html']
     obj.thumbnail = image_from_url(result['thumbnail_url'])
     if result.has_key('duration'):
         obj.duration = result['duration']
     obj.user = self.request.user
     obj.project_name = form.cleaned_data.get('project_name')
     obj.project_url = form.cleaned_data.get('project_url')
     obj.video_provider = get_video_provider_from_link(form.cleaned_data.get('video_url'))
     obj.publish = True
     obj.description = form.cleaned_data.get('description')
     obj.video_url = link
     obj.save()
     obj.slug = gen_shortcut(obj.id)
     tags = form.cleaned_data.get('tags')
     alltags = Tag.objects.all().filter(name__in=tags)
     for tag in tags:
         obj.tags.add(alltags.get(name=tag))
         obj.save()
     self.success_url = obj.get_absolute_url()
     action.send(self.request.user, verb=_('added the video'), action_type=ACTION_ADDED, target=obj,
         request=self.request)
     return super(VideoAdd, self).form_valid(form)
Пример #4
0
 def form_valid(self, form):
     link = form.cleaned_data.get('video_url')
     if not link[:7] == 'http://':
         link = 'http://%s' % link
     if link.find('youtu.be') != -1:
         link = link.replace('youtu.be/', 'www.youtube.com/watch?v=')
     consumer = oembed.OEmbedConsumer()
     # TODO: more code security here - big chance to get fatal error
     endpoint = get_oembed_end_point(link)
     #
     consumer.addEndpoint(endpoint)
     response = consumer.embed(link)
     result = response.getData()
     obj = Video()
     obj.embedcode = result['html']
     obj.thumbnail = image_from_url(result['thumbnail_url'])
     if result.has_key('duration'):
         obj.duration = result['duration']
     obj.user = self.request.user
     obj.project_name = form.cleaned_data.get('project_name')
     obj.project_url = form.cleaned_data.get('project_url')
     obj.video_provider = get_video_provider_from_link(form.cleaned_data.get('video_url'))
     obj.publish = True
     obj.description = form.cleaned_data.get('description')
     obj.video_url = link
     obj.save()
     obj.slug = gen_shortcut(obj.id)
     tags = form.cleaned_data.get('tags')
     alltags = Tag.objects.all().filter(name__in=tags)
     for tag in tags:
         obj.tags.add(alltags.get(name=tag))
         obj.save()
     self.success_url = obj.get_absolute_url()
     action.send(self.request.user, verb=_('added the video'), action_type=ACTION_ADDED, target=obj,
                 request=self.request)
     return super(VideoAdd, self).form_valid(form)