From a40bab7536821f7d486115c8878c766835940941 Mon Sep 17 00:00:00 2001 From: yomguy Date: Wed, 9 Jan 2013 14:47:56 +0100 Subject: [PATCH] begin item workflow refactoring --- setup.py | 1 + telemeta/models/media.py | 5 +- .../templates/telemeta/mediaitem_detail.html | 27 ++++----- telemeta/views/core.py | 60 +++++++++++++------ telemeta/views/item.py | 18 +++--- 5 files changed, 68 insertions(+), 43 deletions(-) diff --git a/setup.py b/setup.py index 36b56f66..5198b992 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + from setuptools import setup, find_packages import os diff --git a/telemeta/models/media.py b/telemeta/models/media.py index efaef4e3..67aca019 100644 --- a/telemeta/models/media.py +++ b/telemeta/models/media.py @@ -63,7 +63,7 @@ item_unpublished_code_regex = '[A-Za-z0-9._-]*' item_code_regex = '(?:%s|%s)' % (item_published_code_regex, item_unpublished_code_regex) PUBLIC_ACCESS_CHOICES = (('none', _('none')), ('metadata', _('metadata')), - ('partial', _('partial')), ('full', _('full'))) + ('mixed', _('mixed')), ('full', _('full'))) ITEM_TRANSODING_STATUS = ((0, _('broken')), (1, _('pending')), (2, _('processing')), (3, _('done')), (5, _('ready'))) @@ -383,7 +383,8 @@ class MediaItem(MediaResource): external_references = TextField(_('published references')) copied_from_item = WeakForeignKey('self', related_name="copies", verbose_name=_('copy of')) - mimetype = CharField(_('mime type'), max_length=255, blank=True) + mimetype = CharField(_('mime type'), max_length=255, blank=True) + auto_period_access = BooleanField(_('automatic access after a rolling period'), default=True) # Media file = FileField(_('file'), upload_to='items/%Y/%m/%d', diff --git a/telemeta/templates/telemeta/mediaitem_detail.html b/telemeta/templates/telemeta/mediaitem_detail.html index 4279fbf0..b5143dc4 100644 --- a/telemeta/templates/telemeta/mediaitem_detail.html +++ b/telemeta/templates/telemeta/mediaitem_detail.html @@ -13,26 +13,21 @@ {% block extra_javascript %} {% if item %} -{% if item.file %} -{% if public_access or perms.telemeta.can_play_all_items %} - - -{% endif %} -{% endif %} - {% if item.file %} -{% if public_access or perms.telemeta.can_play_all_items %} - - -{% endif %} + {% if access == 'full' or perms.telemeta.can_play_all_items %} + + + + + {% endif %} {% endif %} {% if "video" in mime_type %} - - + + {% endif %} {% endif %} @@ -109,11 +104,11 @@ Item : {{ item }} {% endblock %} {% block content %} -
+
{% if item.file %} - {% if public_access or perms.telemeta.can_play_all_items %} + {% if access == 'full' or perms.telemeta.can_play_all_items %}
Minimize diff --git a/telemeta/views/core.py b/telemeta/views/core.py index f57f35e0..28594024 100644 --- a/telemeta/views/core.py +++ b/telemeta/views/core.py @@ -136,26 +136,52 @@ def stream_from_file(file): break yield chunk -def get_public_access(access, year_from=None, year_to=None): - # Rolling publishing date : public access is given when time between recorded year - # and current year is over the settings value PUBLIC_ACCESS_PERIOD - if year_from and not year_from == 0: - year = year_from - elif year_to and not year_to == 0: - year = year_to - else: - year = 0 - if access == 'full': - public_access = True - else: - public_access = False +def get_item_access(item, user): + # Item access rules according to this workflow: + # https://docs.google.com/spreadsheet/ccc?key=0ArKCjajoOT-fdDhJSDZoaUhqdDJvVkY5U3BXUWpNT0E#gid=0 + + # Rolling publishing date : public access is automaticcaly given when time between recorded year + # and current year is over the settings value PUBLIC_ACCESS_PERIOD and if item.auto_period_access == True + + if user.is_staff or user.is_superuser or user.has_perm('telemeta.can_play_all_items'): + access = 'full' + + elif user.is_authenticated() and item.collection.public_access != 'mixed': + if item.collection.public_access == 'metadata' and item.auto_period_access: + access = 'full' + else: + access = item.collection.public_access + + elif user.is_authenticated() and item.collection.public_access == 'mixed': + if item.public_access == 'metadata' and item.auto_period_access: + access = 'full' + else: + access = item.public_access + + elif not user.is_authenticated() and item.collection.public_access != 'mixed': + access = item.collection.public_access + + elif not user.is_authenticated() and item.collection.public_access == 'mixed': + access = item.public_access + + # Auto publish after slipping period (settings.TELEMETA_PUBLIC_ACCESS_PERIOD) + if access != 'full' and item.auto_period_access: + year_from = str(item.recorded_from_date).split('-')[0] + year_to = str(item.recorded_to_date).split('-')[0]) + + if year_from and not year_from == 0: + year = year_from + elif year_to and not year_to == 0: + year = year_to + else: + year = 0 + if year and not year == 'None': year_now = datetime.datetime.now().strftime("%Y") if int(year_now) - int(year) >= settings.TELEMETA_PUBLIC_ACCESS_PERIOD: - public_access = True - else: - public_access = False - return public_access + access = 'full' + + return access def get_revisions(nb, user=None): last_revisions = Revision.objects.order_by('-time') diff --git a/telemeta/views/item.py b/telemeta/views/item.py index 0b4aff73..6e22c334 100644 --- a/telemeta/views/item.py +++ b/telemeta/views/item.py @@ -60,7 +60,8 @@ class ItemView(object): return formats def item_previous_next(self, item): - # Get previous and next items + """Get previous and next items inside the collection of the item""" + pks = [] items = MediaItem.objects.filter(collection=item.collection) items = items.order_by('code', 'old_code') @@ -96,15 +97,17 @@ class ItemView(object): template='telemeta/mediaitem_detail.html'): """Show the details of a given item""" + # get item with one of its given marker_id if not public_id and marker_id: marker = MediaItemMarker.objects.get(public_id=marker_id) item_id = marker.item_id item = MediaItem.objects.get(id=item_id) else: - item = MediaItem.objects.get(public_id=public_id) + item = MediaItem.objects.get(public_id=public_id) - item_public_access = item.public_access != 'none' or item.collection.public_access != 'none' - if not item_public_access and not (request.user.is_staff or request.user.is_superuser): + access = get_item_access(item, request.user) + + if access == 'none': mess = ugettext('Access not allowed') title = ugettext('Item') + ' : ' + public_id + ' : ' + mess description = ugettext('Please login or contact the website administator to get a private access.') @@ -123,15 +126,14 @@ class ItemView(object): grapher_id = 'waveform' previous, next = self.item_previous_next(item) + mime_type = self.item_analyze(item) + #FIXME: use mimetypes.guess_type if 'quicktime' in mime_type: mime_type = 'video/mp4' playlists = get_playlists(request) - public_access = get_public_access(item.public_access, str(item.recorded_from_date).split('-')[0], - str(item.recorded_to_date).split('-')[0]) - related_media = MediaItemRelated.objects.filter(item=item) check_related_media(related_media) revisions = Revision.objects.filter(element_type='item', element_id=item.id).order_by('-time') @@ -149,7 +151,7 @@ class ItemView(object): 'visualizers': graphers, 'visualizer_id': grapher_id, 'audio_export_enabled': self.export_enabled, 'previous' : previous, 'next' : next, 'marker': marker_id, 'playlists' : playlists, - 'public_access': public_access, 'width': width, 'height': height, + 'access': access, 'width': width, 'height': height, 'related_media': related_media, 'mime_type': mime_type, 'last_revision': last_revision, 'format': format, }) -- 2.39.5