Example #1
0
 def render(self, context):
     host = template.resolve_variable(self.host, context)
     url = template.resolve_variable(self.url, context)
     cache_key = u':'.join(['oembed', urlquote(url)])
     value = cache.get(cache_key)
     if value is None:
         ctx = utils.get_embed_code(host, url)
         if ctx is None:
             # retry once
             time.sleep(.125)
             ctx = utils.get_embed_code(host, url)
         if ctx:
             ctx['host'] = ctx['service_provider'].host.replace('.', '-')
             ctx['url'] = url
             tpl = [
                 u'oembed/tags/type_%s.html' %
                 ctx['service_provider'].service_type
             ]
             value = template.loader.select_template(tpl).render(
                 template.Context(ctx))
             cache.set(cache_key, value, 24 * 3600)
         else:
             value = ''
             cache.set(cache_key, value,
                       180)  # Stop retrying for a few minutes
     return value
Example #2
0
 def clean_embed_url(self):
     url = self.cleaned_data.get("embed_url", None)
     host = self.cleaned_data.get("embed_service", None)
     if url:
         if not url.startswith("http"):
             raise forms.ValidationError(_(u"Only <em>http</em> and <em>https</em> URLs are allowed here."))
         if host:
             resp_dict = oembed_utils.get_embed_code(host, url)
             if not resp_dict:
                 raise forms.ValidationError(
                     _(
                         u"This embeddable  audio or video URL is not valid. Its embed code could not be generated."
                     )
                 )
         else:
             raise forms.ValidationError(
                 _(u"Please select your embeddable audio or video service from the above list.")
             )
     else:
         if host:
             raise forms.ValidationError(
                 _(
                     u"An embeddable audio or video URL is required when you select an audio or video service above."
                 )
             )
     return url
Example #3
0
 def clean_mp3_url(self):
     url = self.cleaned_data.get("mp3_url", None)
     if url:
         url = oembed_utils.get_soundcloud_param_value(url)
         if not url:
             raise forms.ValidationError(_(u"Only SoundCloud.com URLs and embed codes are allowed here."))
         url = url[:200]
         soundcloud_host = OEmbedProvider.objects.get(host__iexact="soundcloud.com", service_type="rich")
         if not oembed_utils.get_embed_code(soundcloud_host, url):
             raise forms.ValidationError(_(u"That SoundCloud.com URL does not work."))
     return url or None
Example #4
0
 def render(self, context):
     host = template.resolve_variable(self.host, context)
     url = template.resolve_variable(self.url, context)
     cache_key = u':'.join(['oembed', urlquote(url)])
     value = cache.get(cache_key)
     if value is None:
         ctx = utils.get_embed_code(host, url)
         if ctx is None:
             # retry once
             time.sleep(.125)
             ctx = utils.get_embed_code(host, url)                
         if ctx:
             ctx['host'] = ctx['service_provider'].host.replace('.', '-')
             ctx['url'] = url
             tpl = [u'oembed/tags/type_%s.html' % ctx['service_provider'].service_type]
             value = template.loader.select_template(tpl).render(template.Context(ctx))
             cache.set(cache_key, value, 24*3600)
         else:
             value = ''
             cache.set(cache_key, value, 180) # Stop retrying for a few minutes
     return value
Example #5
0
 def clean_mp3_url(self):
     url = self.cleaned_data.get('mp3_url', None)
     if url:
         url = oembed_utils.get_soundcloud_param_value(url)
         if not url:
             raise forms.ValidationError(
                 _(u'Only SoundCloud.com URLs and embed codes are allowed here.'
                   ))
         url = url[:200]
         soundcloud_host = OEmbedProvider.objects.get(
             host__iexact='soundcloud.com', service_type='rich')
         if not oembed_utils.get_embed_code(soundcloud_host, url):
             raise forms.ValidationError(
                 _(u'That SoundCloud.com URL does not work.'))
     return url or None
Example #6
0
 def clean_embed_url(self):
     url = self.cleaned_data.get('embed_url', None)
     host = self.cleaned_data.get('embed_service', None)
     if url:
         if not url.startswith('http'):
             raise forms.ValidationError(_(u'Only <em>http</em> and <em>https</em> URLs are currently supported.'))
         if host:
             resp_dict = oembed_utils.get_embed_code(host, url)
             if not resp_dict:
                 raise forms.ValidationError(_(u'This embeddable video URL is not valid. Its embed code could not be generated.'))
         else:
             raise forms.ValidationError(_(u'Please select your embeddable video service from the above list.'))
     else:
         if host:
             raise forms.ValidationError(_(u'An embeddable video URL is required when you select a video service above.'))
     return url
Example #7
0
 def clean_embed_url(self):
     url = self.cleaned_data.get('embed_url', None)
     host = self.cleaned_data.get('embed_service', None)
     if url:
         if not url.startswith('http'):
             raise forms.ValidationError(
                 _(u'Only <em>http</em> and <em>https</em> URLs are currently supported.'
                   ))
         if host:
             resp_dict = oembed_utils.get_embed_code(host, url)
             if not resp_dict:
                 raise forms.ValidationError(
                     _(u'This embeddable video URL is not valid. Its embed code could not be generated.'
                       ))
         else:
             raise forms.ValidationError(
                 _(u'Please select your embeddable video service from the above list.'
                   ))
     else:
         if host:
             raise forms.ValidationError(
                 _(u'An embeddable video URL is required when you select a video service above.'
                   ))
     return url