def media_player(
    media,
    is_widescreen=False,
    show_like=True,
    show_dislike=True,
    show_download=False,
    show_embed=False,
    show_playerbar=True,
    show_popout=True,
    show_resize=False,
    show_share=True,
    js_init=None,
    **kwargs
):
    """Instantiate and render the preferred player that can play this media.

    We make no effort to pick the "best" player here, we simply return
    the first player that *can* play any of the URIs associated with
    the given media object. It's up to the user to declare their own
    preferences wisely.

    Player preferences are fetched from the database and the
    :attr:`mediadrop.model.players.c.data` dict is passed as kwargs to
    :meth:`AbstractPlayer.__init__`.

    :type media: :class:`mediadrop.model.media.Media`
    :param media: A media instance to play.

    :param js_init: Optional function to call after the javascript player
        controller has been instantiated. Example of a function literal:
        ``function(controller){ controller.setFillScreen(true); }``.
        Any function reference can be used as long as it is defined
        in all pages and accepts the JS player controller as its first
        and only argument.

    :param \*\*kwargs: Extra kwargs for :meth:`AbstractPlayer.__init__`.

    :rtype: `str` or `None`
    :returns: A rendered player.
    """
    player = preferred_player_for_media(media, **kwargs)
    return render(
        "players/html5_or_flash.html",
        {
            "player": player,
            "media": media,
            "uris": media.get_uris(),
            "is_widescreen": is_widescreen,
            "js_init": js_init,
            "show_like": show_like,
            "show_dislike": show_dislike,
            "show_download": show_download,
            "show_embed": show_embed,
            "show_playerbar": show_playerbar,
            "show_popout": show_popout,
            "show_resize": show_resize and (player and player.supports_resizing),
            "show_share": show_share,
        },
    )
Exemple #2
0
def media_player(media,
                 is_widescreen=False,
                 show_like=True,
                 show_dislike=True,
                 show_download=False,
                 show_embed=False,
                 show_playerbar=True,
                 show_popout=True,
                 show_resize=False,
                 show_share=True,
                 js_init=None,
                 **kwargs):
    """Instantiate and render the preferred player that can play this media.

    We make no effort to pick the "best" player here, we simply return
    the first player that *can* play any of the URIs associated with
    the given media object. It's up to the user to declare their own
    preferences wisely.

    Player preferences are fetched from the database and the
    :attr:`mediadrop.model.players.c.data` dict is passed as kwargs to
    :meth:`AbstractPlayer.__init__`.

    :type media: :class:`mediadrop.model.media.Media`
    :param media: A media instance to play.

    :param js_init: Optional function to call after the javascript player
        controller has been instantiated. Example of a function literal:
        ``function(controller){ controller.setFillScreen(true); }``.
        Any function reference can be used as long as it is defined
        in all pages and accepts the JS player controller as its first
        and only argument.

    :param \*\*kwargs: Extra kwargs for :meth:`AbstractPlayer.__init__`.

    :rtype: `str` or `None`
    :returns: A rendered player.
    """
    player = preferred_player_for_media(media, **kwargs)
    return render(
        'players/html5_or_flash.html', {
            'player': player,
            'media': media,
            'uris': media.get_uris(),
            'is_widescreen': is_widescreen,
            'js_init': js_init,
            'show_like': show_like,
            'show_dislike': show_dislike,
            'show_download': show_download,
            'show_embed': show_embed,
            'show_playerbar': show_playerbar,
            'show_popout': show_popout,
            'show_resize': show_resize and
            (player and player.supports_resizing),
            'show_share': show_share,
        })
 def result(success, message=None, comment=None):
     if request.is_xhr:
         result = dict(success=success, message=message)
         if comment:
             result['comment'] = render('comments/_list.html',
                 {'comment_to_render': comment},
                 method='xhtml')
         return result
     elif success:
         return redirect(action='view')
     else:
         return self.view(slug, name=name, email=email, body=body,
                          **kwargs)
Exemple #4
0
 def result(success, message=None, comment=None):
     if request.is_xhr:
         result = dict(success=success, message=message)
         if comment:
             result['comment'] = render('comments/_list.html',
                 {'comment_to_render': comment},
                 method='xhtml')
         return result
     elif success:
         return redirect(action='view')
     else:
         return self.view(slug, name=name, email=email, body=body,
                          **kwargs)
    def wrapped_f(*args, **kwargs):
        if request_method and request_method != request.method:
            raise HTTPMethodNotAllowed().exception

        result = f(*args, **kwargs)
        tmpl = template

        if hasattr(request, 'override_template'):
            tmpl = request.override_template

        if tmpl == 'string':
            return result

        if tmpl == 'json':
            if isinstance(result, (list, tuple)):
                msg = ("JSON responses with Array envelopes are susceptible "
                       "to cross-site data leak attacks, see "
                       "http://wiki.pylonshq.com/display/pylonsfaq/Warnings")
                if config['debug']:
                    raise TypeError(msg)
                warnings.warn(msg, Warning, 2)
                log.warning(msg)
            response.headers['Content-Type'] = 'application/json'
            return simplejson.dumps(result)

        if request.environ.get('paste.testing', False):
            # Make the vars passed from action to template accessible to tests
            request.environ['paste.testing_variables']['tmpl_vars'] = result

            # Serve application/xhtml+xml instead of text/html during testing.
            # This allows us to query the response xhtml as ElementTree XML
            # instead of BeautifulSoup HTML.
            # NOTE: We do not serve true xhtml to all clients that support it
            #       because of a bug in Mootools Swiff as of v1.2.4:
            #       https://mootools.lighthouseapp.com/projects/2706/tickets/758
            if response.content_type == 'text/html':
                response.content_type = 'application/xhtml+xml'

        return render(tmpl, tmpl_vars=result, method='auto')
Exemple #6
0
    def wrapped_f(*args, **kwargs):
        if request_method and request_method != request.method:
            raise HTTPMethodNotAllowed().exception

        result = f(*args, **kwargs)
        tmpl = template

        if hasattr(request, 'override_template'):
            tmpl = request.override_template

        if tmpl == 'string':
            return result

        if tmpl == 'json':
            if isinstance(result, (list, tuple)):
                msg = ("JSON responses with Array envelopes are susceptible "
                       "to cross-site data leak attacks, see "
                       "http://wiki.pylonshq.com/display/pylonsfaq/Warnings")
                if config['debug']:
                    raise TypeError(msg)
                warnings.warn(msg, Warning, 2)
                log.warning(msg)
            response.headers['Content-Type'] = 'application/json'
            return simplejson.dumps(result)

        if request.environ.get('paste.testing', False):
            # Make the vars passed from action to template accessible to tests
            request.environ['paste.testing_variables']['tmpl_vars'] = result

            # Serve application/xhtml+xml instead of text/html during testing.
            # This allows us to query the response xhtml as ElementTree XML
            # instead of BeautifulSoup HTML.
            # NOTE: We do not serve true xhtml to all clients that support it
            #       because of a bug in Mootools Swiff as of v1.2.4:
            #       https://mootools.lighthouseapp.com/projects/2706/tickets/758
            if response.content_type == 'text/html':
                response.content_type = 'application/xhtml+xml'

        return render(tmpl, tmpl_vars=result, method='auto')
Exemple #7
0
 def render_rows(media):
     rows = {}
     for m in media:
         stream = render('admin/media/index-table.html', {'media': [m]})
         rows[m.id] = unicode(stream.select('table/tbody/tr'))
     return rows
Exemple #8
0
 def render_rows(media):
     rows = {}
     for m in media:
         stream = render('admin/media/index-table.html', {'media': [m]})
         rows[m.id] = unicode(stream.select('table/tbody/tr'))
     return rows
Exemple #9
0
 def render_rows(media):
     rows = {}
     for m in media:
         stream = render("admin/media/index-table.html", {"media": [m]})
         rows[m.id] = unicode(stream.select("table/tbody/tr"))
     return rows