# -*- coding: utf-8 -*-
+
from setuptools import setup, find_packages
import os
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')))
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',
{% block extra_javascript %}
{% if item %}
-{% if item.file %}
-{% if public_access or perms.telemeta.can_play_all_items %}
-<script src="{{ STATIC_URL }}timeside/js/libs/soundmanager2-nodebug-jsmin.js" type="text/javascript"></script>
-<script src="{{ STATIC_URL }}timeside/js/timeside.js" type="text/javascript"></script>
-{% endif %}
-{% endif %}
-
<script src="{{ STATIC_URL }}telemeta/js/popupdiv-min.js" type="text/javascript"></script>
<script src="{{ STATIC_URL }}telemeta/js/playlist.js" type="text/javascript"></script>
{% if item.file %}
-{% if public_access or perms.telemeta.can_play_all_items %}
-<script src="{{ STATIC_URL }}telemeta/js/playerLoader.js" type="text/javascript"></script>
-<script src="{{ STATIC_URL }}telemeta/js/divmarker.js" type="text/javascript"></script>
-{% endif %}
+ {% if access == 'full' or perms.telemeta.can_play_all_items %}
+ <script src="{{ STATIC_URL }}timeside/js/libs/soundmanager2-nodebug-jsmin.js" type="text/javascript"></script>
+ <script src="{{ STATIC_URL }}timeside/js/timeside.js" type="text/javascript"></script>
+ <script src="{{ STATIC_URL }}telemeta/js/playerLoader.js" type="text/javascript"></script>
+ <script src="{{ STATIC_URL }}telemeta/js/divmarker.js" type="text/javascript"></script>
+ {% endif %}
{% endif %}
<script type="text/javascript">
{% if item.file %}
- {% if public_access or perms.telemeta.can_play_all_items %}
+ {% if access == 'full' or perms.telemeta.can_play_all_items %}
//initializing soundManager default properties
soundManager.flashVersion = 9;
soundManager.url = "{{ STATIC_URL }}timeside/swf/";
</script>
{% if "video" in mime_type %}
-<script src="{{ STATIC_URL }}video-js/video.js" ></script>
-<link href="{{ STATIC_URL }}video-js/video-js.css" rel="stylesheet">
+ <script src="{{ STATIC_URL }}video-js/video.js" ></script>
+ <link href="{{ STATIC_URL }}video-js/video-js.css" rel="stylesheet">
{% endif %}
{% endif %}
{% endblock %}
{% block content %}
-<div class="{% if item.file %}{% if public_access or perms.telemeta.can_play_all_items %}with-rightcol{% endif %}{% endif %}">
+<div class="{% if item.file %}{% if access == 'full' or perms.telemeta.can_play_all_items %}with-rightcol{% endif %}{% endif %}">
{% if item.file %}
- {% if public_access or perms.telemeta.can_play_all_items %}
+ {% if access == 'full' or perms.telemeta.can_play_all_items %}
<div id="player_maximized" class="ts-skin-lab">
<div id="player_header">
<a href="#" class="toggle">Minimize</a>
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')
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')
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.')
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')
'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,
})