diff --git a/embed_video/admin.py b/embed_video/admin.py index aedecdc..88f139d 100644 --- a/embed_video/admin.py +++ b/embed_video/admin.py @@ -24,6 +24,9 @@ class AdminVideoWidget(forms.TextInput): u'
' def __init__(self, attrs=None): + """ + :type attrs: dict + """ default_attrs = {'size': '40'} if attrs: @@ -32,6 +35,10 @@ class AdminVideoWidget(forms.TextInput): super(AdminVideoWidget, self).__init__(default_attrs) def render(self, name, value='', attrs=None, size=(420, 315)): + """ + :type name: str + :type attrs: dict + """ output = super(AdminVideoWidget, self).render(name, value, attrs) if not value: @@ -66,8 +73,11 @@ class AdminVideoMixin(object): """ def formfield_for_dbfield(self, db_field, **kwargs): + """ + :type db_field: str + """ if isinstance(db_field, EmbedVideoField): return db_field.formfield(widget=AdminVideoWidget) - return super(AdminVideoMixin, self) \ + return super(AdminVideoMixin, self)\ .formfield_for_dbfield(db_field, **kwargs) diff --git a/embed_video/backends.py b/embed_video/backends.py index 5fe14df..c982af8 100644 --- a/embed_video/backends.py +++ b/embed_video/backends.py @@ -46,6 +46,12 @@ def detect_backend(url): Goes over backends in ``settings.EMBED_VIDEO_BACKENDS``, calls :py:func:`~VideoBackend.is_valid` and returns backend instance. + + :param url: URL which is passed to `is_valid` methods of VideoBackends. + :type url: str + + :return: Returns recognized VideoBackend + :rtype: VideoBackend """ for backend_name in EMBED_VIDEO_BACKENDS: @@ -102,6 +108,8 @@ class VideoBackend(object): Pattern in which the code is inserted. Example: ``http://myvideo.com?code=%s`` + + :type: str """ pattern_thumbnail_url = None @@ -109,11 +117,15 @@ class VideoBackend(object): Pattern in which the code is inserted to get thumbnail url. Example: ``http://static.myvideo.com/thumbs/%s`` + + :type: str """ allow_https = True """ Sets if HTTPS version allowed for specific backend. + + :type: bool """ template_name = 'embed_video/embed_code.html' @@ -122,22 +134,30 @@ class VideoBackend(object): Passed template variables: ``{{ backend }}`` (instance of VideoBackend), ``{{ width }}``, ``{{ height }}`` + + :type: str """ default_query = '' """ Default query string or `QueryDict` appended to url + + :type: str """ is_secure = False """ Decides if secured protocol (HTTPS) is used. + + :type: bool """ def __init__(self, url): """ First it tries to load data from cache and if it don't succeed, run :py:meth:`init` and then save it to cache. + + :type url: str """ self.backend = self.__class__.__name__ self._url = url @@ -187,6 +207,9 @@ class VideoBackend(object): @query.setter def query(self, value): + """ + :type value: QueryDict | str + """ self._query = value \ if isinstance(value, QueryDict) \ else QueryDict(value, mutable=True) @@ -196,12 +219,16 @@ class VideoBackend(object): """ Class method to control if passed url is valid for current backend. By default it is done by :py:data:`re_detect` regex. + + :type url: str """ return True if cls.re_detect.match(url) else False def get_code(self): """ Returns video code matched from given url by :py:data:`re_code`. + + :rtype: str """ match = self.re_code.search(self._url) if match: @@ -219,6 +246,8 @@ class VideoBackend(object): """ Returns thumbnail URL folded from :py:data:`pattern_thumbnail_url` and parsed code. + + :rtype: str """ return self.pattern_thumbnail_url.format(code=self.code, protocol=self.protocol) @@ -226,6 +255,10 @@ class VideoBackend(object): def get_embed_code(self, width, height): """ Returns embed code rendered from template :py:data:`template_name`. + + :type width: int | str + :type height: int | str + :rtype: str """ return render_to_string(self.template_name, { 'backend': self, @@ -234,9 +267,15 @@ class VideoBackend(object): }) def get_info(self): + """ + :rtype: dict + """ raise NotImplementedError def set_options(self, options): + """ + :type options: dict + """ for key in options: setattr(self, key, options[key]) @@ -321,10 +360,16 @@ class SoundCloudBackend(VideoBackend): @cached_property def width(self): + """ + :rtype: str + """ return self.info.get('width') @cached_property def height(self): + """ + :rtype: str + """ return self.info.get('height') def get_info(self): diff --git a/embed_video/settings.py b/embed_video/settings.py index 0d9a824..b4db923 100644 --- a/embed_video/settings.py +++ b/embed_video/settings.py @@ -6,8 +6,11 @@ EMBED_VIDEO_BACKENDS = getattr(settings, 'EMBED_VIDEO_BACKENDS', ( 'embed_video.backends.VimeoBackend', 'embed_video.backends.SoundCloudBackend', )) +""" :type: tuple[str] """ EMBED_VIDEO_TIMEOUT = getattr(settings, 'EMBED_VIDEO_TIMEOUT', 10) +""" :type: int """ EMBED_VIDEO_YOUTUBE_DEFAULT_QUERY = \ getattr(settings, 'EMBED_VIDEO_YOUTUBE_DEFAULT_QUERY', 'wmode=opaque') +""" :type: django.db.models.QuerySet | str """ diff --git a/embed_video/templatetags/embed_video_tags.py b/embed_video/templatetags/embed_video_tags.py index 6773414..ba3974e 100644 --- a/embed_video/templatetags/embed_video_tags.py +++ b/embed_video/templatetags/embed_video_tags.py @@ -59,6 +59,12 @@ class VideoNode(Node): re_option = re.compile(r'^(?P