]> git.parisson.com Git - telemeta.git/commitdiff
begin item workflow refactoring
authoryomguy <yomguy@parisson.com>
Wed, 9 Jan 2013 13:47:56 +0000 (14:47 +0100)
committeryomguy <yomguy@parisson.com>
Wed, 9 Jan 2013 13:47:56 +0000 (14:47 +0100)
setup.py
telemeta/models/media.py
telemeta/templates/telemeta/mediaitem_detail.html
telemeta/views/core.py
telemeta/views/item.py

index 36b56f66fa34736f95407a7d3d4597556a38ec3b..5198b992336f381be9b9de8cde068e4e199bb574 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+
 from setuptools import setup, find_packages
 import os
 
index efaef4e3b97166a42fff74adf9770a0b7b593f55..67aca019b11697b4d1d1b380421154fdfb4545a2 100644 (file)
@@ -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',
index 4279fbf02809c1337eb278f89fd3cbd7329ef8aa..b5143dc4d71dab4eb63d678258e76a136912c4f6 100644 (file)
 {% 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/";
@@ -80,8 +75,8 @@
 </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 %}
@@ -109,11 +104,11 @@ Item : <a href="{% url telemeta-item-detail item.public_id %}">{{ item }}</a>
 {% 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>
index f57f35e09e3ac27506ef826a7dc1ab1c2c44a9d9..2859402472d622fd6e20d82f7fd652d42b8d7863 100644 (file)
@@ -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')
index 0b4aff73045a88f076ba9aa47563a5438e4e6d70..6e22c334f5e8296a7d0d1966b53729b04a991820 100644 (file)
@@ -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,
                     })