From 6ad4a228dc2af4fe6edb1583ad1ea82603616073 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 23 May 2013 10:11:04 +0200 Subject: [PATCH] better filter items in collection player --- telemeta/templates/telemeta/collection_detail.html | 2 -- telemeta/templates/telemeta/collection_xspf.xml | 6 +++++- telemeta/templatetags/telemeta_utils.py | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/telemeta/templates/telemeta/collection_detail.html b/telemeta/templates/telemeta/collection_detail.html index d84e5f37..bdba2f19 100644 --- a/telemeta/templates/telemeta/collection_detail.html +++ b/telemeta/templates/telemeta/collection_detail.html @@ -54,7 +54,6 @@ {% block content %}
{% if collection.has_mediafile %} - {% if public_access == 'full' or perms.telemeta.can_play_all_items %}
@@ -78,7 +77,6 @@
{% endif %} - {% endif %} {% block infos %}
{% if collection.items.count %}{{ collection.items.count }} {% ifequal collection.items.count 1 %}item{% else %}items{% endifequal %}{% else %}No item{% endif %} diff --git a/telemeta/templates/telemeta/collection_xspf.xml b/telemeta/templates/telemeta/collection_xspf.xml index 317284b7..3d1aca51 100644 --- a/telemeta/templates/telemeta/collection_xspf.xml +++ b/telemeta/templates/telemeta/collection_xspf.xml @@ -1,7 +1,7 @@ {% extends "telemeta/base_xspf.xml" %} {% load telemeta_utils %} -{% block listinfo %} +{% block listinfo %} {% with collection.to_dublincore.flatten as dc %} {{ dc.creator }} {{ dc.title }} @@ -11,6 +11,8 @@ {% block tracklist %} {% for item in collection.items.all %} + {% if item.file %} + {% if user|has_access:item == 'full' or perms.telemeta.can_play_all_items %} {{ item }} mp3 @@ -18,6 +20,8 @@ {{ item.computed_duration.as_seconds|mul:1000 }} http://{{ host }}{% url telemeta-item-detail item.public_id %} + {% endif %} + {% endif %} {% endfor %} {% endblock %} diff --git a/telemeta/templatetags/telemeta_utils.py b/telemeta/templatetags/telemeta_utils.py index cbf2ec54..6cca0ecc 100644 --- a/telemeta/templatetags/telemeta_utils.py +++ b/telemeta/templatetags/telemeta_utils.py @@ -17,6 +17,7 @@ import datetime from django.conf import settings from django.template.defaultfilters import stringfilter from django.template import NodeList +from telemeta.views.core import get_item_access register = template.Library() @@ -446,3 +447,9 @@ class IfLoadedNode(template.Node): if str(app) == str(self.var): return self.nodelist_true.render(context) return self.nodelist_false.render(context) + + +@register.filter +def has_access(user, item): + return get_item_access(item, user) + -- 2.39.5