From ce03870fe6b89cb33db43ec9d8b63aaf4b415ff1 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 6 Jul 2013 11:15:10 +0000 Subject: [PATCH] remove config video.download; use canDownloadVideo capability instead. --- pandora/config.0xdb.jsonc | 1 - pandora/config.indiancinema.jsonc | 1 - pandora/config.padma.jsonc | 1 - pandora/item/models.py | 3 +- pandora/item/views.py | 48 ++++++++++++++----------------- pandora/user/models.py | 8 ++++++ 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/pandora/config.0xdb.jsonc b/pandora/config.0xdb.jsonc index b29713ba2..3c14202fa 100644 --- a/pandora/config.0xdb.jsonc +++ b/pandora/config.0xdb.jsonc @@ -836,7 +836,6 @@ // fixme: this should include colors "userLevels": ["guest", "member", "friend", "staff", "admin"], "video": { - "download": false, "formats": ["webm", "mp4"], "previewRatio": 1.7777777778, "resolutions": [96] diff --git a/pandora/config.indiancinema.jsonc b/pandora/config.indiancinema.jsonc index df795862f..3dd540082 100644 --- a/pandora/config.indiancinema.jsonc +++ b/pandora/config.indiancinema.jsonc @@ -874,7 +874,6 @@ // fixme: this should include colors "userLevels": ["guest", "member", "student", "staff", "admin"], "video": { - "download": false, "formats": ["webm", "mp4"], "previewRatio": 1.375, "resolutions": [240, 480] diff --git a/pandora/config.padma.jsonc b/pandora/config.padma.jsonc index 5072fadbd..5464cc6da 100644 --- a/pandora/config.padma.jsonc +++ b/pandora/config.padma.jsonc @@ -753,7 +753,6 @@ }, "userLevels": ["guest", "member", "staff", "admin"], "video": { - "download": true, "formats": ["webm", "mp4"], "previewRatio": 1.3333333333, //supported resolutions are diff --git a/pandora/item/models.py b/pandora/item/models.py index db66e077e..dc2091475 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1133,8 +1133,7 @@ class Item(models.Model): self.select_frame() self.make_poster(True) self.make_icon() - if settings.CONFIG['video']['download']: - self.make_torrent() + self.make_torrent() self.rendered = streams.count() > 0 self.save() if async: diff --git a/pandora/item/views.py b/pandora/item/views.py index 890c264c3..b1a4b49b1 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -29,6 +29,7 @@ import tasks from archive.models import File, Stream from archive import extract from clip.models import Clip +from user.models import has_capability from ox.django.api import actions @@ -475,18 +476,9 @@ def get(request): if not data['keys'] or 'groups' in data['keys'] \ and request.user.get_profile().capability('canEditMetadata'): info['groups'] = [g.name for g in item.groups.all()] - def check_capability(capability): - if request.user.is_anonymous(): - level = 'guest' - else: - level = request.user.get_profile().get_level() - if request.user == item.user: - return True - return level in settings.CONFIG['capabilities'][capability] \ - and settings.CONFIG['capabilities'][capability][level] for k in settings.CONFIG['itemKeys']: if 'capability' in k \ - and not check_capability(k['capability']) \ + and not (request.user == item.user or can_capability(user, k['capability'])) \ and k['id'] in info \ and k['id'] not in ('parts', 'durations', 'duration'): del info[k['id']] @@ -1018,26 +1010,28 @@ def atom_xml(request): format = ET.SubElement(entry, "format") format.attrib['xmlns'] = 'http://transmission.cc/FileFormat' - stream = item.streams().filter(source=None).order_by('-id')[0] - for key in ('size', 'duration', 'video_codec', - 'framerate', 'width', 'height', - 'audio_codec', 'samplerate', 'channels'): - value = stream.info.get(key) - if not value and stream.info.get('video'): - value = stream.info['video'][0].get({ - 'video_codec': 'codec' - }.get(key, key)) - if not value and stream.info.get('audio'): - value = stream.info['audio'][0].get({ - 'audio_codec': 'codec' - }.get(key, key)) - if value and value != -1: - el = ET.SubElement(format, key) - el.text = unicode(value) + streams = item.streams().filter(source=None).order_by('-id') + if streams.exists(): + stream = streams[0] + for key in ('size', 'duration', 'video_codec', + 'framerate', 'width', 'height', + 'audio_codec', 'samplerate', 'channels'): + value = stream.info.get(key) + if not value and stream.info.get('video'): + value = stream.info['video'][0].get({ + 'video_codec': 'codec' + }.get(key, key)) + if not value and stream.info.get('audio'): + value = stream.info['audio'][0].get({ + 'audio_codec': 'codec' + }.get(key, key)) + if value and value != -1: + el = ET.SubElement(format, key) + el.text = unicode(value) el = ET.SubElement(format, 'pixel_aspect_ratio') el.text = u"1:1" - if settings.CONFIG['video'].get('download'): + if has_capability(request.user, 'canDownloadVideo'): if item.torrent: el = ET.SubElement(entry, "link") el.attrib['rel'] = 'enclosure' diff --git a/pandora/user/models.py b/pandora/user/models.py index 5cf56e17a..de6ac0d8a 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -339,3 +339,11 @@ def user_json(user, keys=None): if key not in keys: del j[key] return j + +def has_capability(user, capability): + if user.is_anonymous(): + level = 'guest' + else: + level = user.get_profile().get_level() + return level in settings.CONFIG['capabilities'][capability] \ + and settings.CONFIG['capabilities'][capability][level]