Permalink
Browse files

Merge pull request #4 from TigorC/master

Player config, pep8 rules, template parameter fixes. Thanks TigorC
  • Loading branch information...
2 parents 9a33147 + 0a98e91 commit f6e6ce584a0b7ff2096ad7a9005dfdb437736783 @mfitzp committed Jan 14, 2013
Showing with 28 additions and 28 deletions.
  1. +2 −2 flowplayer/templates/flowplayer/flowplayer.html
  2. +26 −26 flowplayer/templatetags/flowplayer_tags.py
View
4 flowplayer/templates/flowplayer/flowplayer.html
@@ -33,12 +33,12 @@
{% if player_config.plugins.controls %}
controls: {
{% for keyc, valuec in player_config.plugins.controls.items %}
- {{ keyc }}: {{ valuec }}
+ {{ keyc }}: {{ valuec }},
{% endfor %}
{% if player_config.plugins.controls.tooltips %}
tooltips: {
{% for keyct, valuect in player_config.plugins.controls.tooltips.items %}
- {{ keyct }}: {{ valuect }}
+ {{ keyct }}: {{ valuect }},
{% endfor %}
}
{% endif %}
View
52 flowplayer/templatetags/flowplayer_tags.py
@@ -1,16 +1,17 @@
from django.conf import settings
from django.db.models.query import QuerySet
-from django.template import TemplateSyntaxError, VariableDoesNotExist, Node
+from django.template import Node, TemplateSyntaxError
from django.template import Library, Variable, loader, Context
# ID of current flowplayer being rendered (global to ensure unique)
FLOWPLAYER_ITERATOR = 0
register = Library()
+
class FlowPlayerNode(Node):
"Renderer class for the flowplayer template tag."
-
+
def __init__(self, media, player_class, player_id=None):
"""
Constructor.
@@ -32,30 +33,29 @@ def __init__(self, media, player_class, player_id=None):
else:
self.player_url = "%sflowplayer/FlowPlayerLight.swf" % (settings.MEDIA_URL)
+ def render(self, context):
# Import the configuration settings to set on the player output
# Configuration is defined in the settings (multiple types of player)
if 'default' in settings.FLOWPLAYER_CONFIG:
self.player_config = settings.FLOWPLAYER_CONFIG['default']
else:
self.player_config = dict()
- if player_class in settings.FLOWPLAYER_CONFIG:
- self.player_config.update(settings.FLOWPLAYER_CONFIG[player_class])
-
- def render(self, context):
+ if self.player_class in settings.FLOWPLAYER_CONFIG:
+ self.player_config.update(settings.FLOWPLAYER_CONFIG[self.player_class])
if 'flowplayer_iterator' in context:
context['flowplayer_iterator'] += 1
else:
context['flowplayer_iterator'] = 0
- try:
+ try:
# Try resolve this variable in the template context
- self.media_element = self.media.resolve(context)
+ self.media_element = self.media.resolve(context)
except:
# Cannot resolve, therefore treat as url string
self.media_element = self.media
-
+
try:
self.extra_id = self.player_id.resolve(context)
except:
@@ -73,18 +73,19 @@ def render(self, context):
else:
self.media_url = self.media_element
self.media_playlist = False
-
+
t = loader.get_template('flowplayer/flowplayer.html')
code_context = Context(
{"player_url": self.player_url,
- "player_id": '%s%s' % (context['flowplayer_iterator'],self.extra_id),
+ "player_id": '%s%s' % (context['flowplayer_iterator'], self.extra_id),
"player_class": self.player_class,
"player_config": self.player_config,
"media_url": self.media_url,
- "media_playlist":self.media_playlist
+ "media_playlist": self.media_playlist
}, autoescape=context.autoescape)
return t.render(code_context)
+
def do_flowplayer(parser, token):
"""
This will insert an flash-based flv videoplayer (flowplayer) in form of an <object>
@@ -95,28 +96,28 @@ def do_flowplayer(parser, token):
{% flowplayer media_url %}
Example::
-
- {% flowplayer video.flv %}
-
- By default, 'flowplayer' tag will use FlowPlayerLight.swf found at
+
+ {% flowplayer video.flv %}
+
+ By default, 'flowplayer' tag will use FlowPlayerLight.swf found at
``{{ MEDIA_URL }}flowplayer/FlowPlayerLight.swf``.
-
+
To change this add FLOWPLAYER_URL to your settings.py file
Pass a dict of urls to the player to get a playlisted player instance
-
- """
-
+
+ """
+
args = token.split_contents()
-
+
if len(args) < 2:
- raise TemplateSyntaxError, "'flowplayer' tag requires at least one argument."
-
+ raise TemplateSyntaxError("'flowplayer' tag requires at least one argument.")
+
if len(args) == 3:
player_class = args[2]
else:
player_class = None
-
+
if len(args) == 4:
player_id = args[3]
else:
@@ -127,6 +128,5 @@ def do_flowplayer(parser, token):
return FlowPlayerNode(media, player_class, player_id)
-# register the tag
+# register the tag
register.tag('flowplayer', do_flowplayer)
-

0 comments on commit f6e6ce5

Please sign in to comment.