]> git.parisson.com Git - telemeta.git/commitdiff
fix public access rights, make timeside processors private, fix messages
authoryomguy <yomguy@parisson.com>
Fri, 25 Mar 2011 14:31:36 +0000 (15:31 +0100)
committeryomguy <yomguy@parisson.com>
Fri, 25 Mar 2011 14:31:36 +0000 (15:31 +0100)
telemeta/cache.py
telemeta/templates/telemeta_default/messages.html
telemeta/urls.py
telemeta/web/base.py

index a0b548eac6721af9a54e5f19d1dafd1769eb585b..66b82aeb89ec07ca5b178c6e0bb12170dc68e018 100644 (file)
@@ -79,7 +79,7 @@ class TelemetaCache(object):
         
     def read_stream_bin(self, file):
         path = self.dir + os.sep + file
-        chunk_size = 0xFFFFF
+        chunk_size = 0x80000
         f = open(path,  'r')
         while True:
             chunk = f.read(chunk_size)
index 300986dc699c82adc1e90bb8ddcfbc6261846b67..15ced94940d440e4010ebc8958d19fa7932163de 100644 (file)
@@ -6,6 +6,8 @@
 {% if messages %}
  {% for message in messages %}
   <h3>{{ message }}</h3>
+  <p>{{ description }}
+  
  {% endfor %}
 {% endif %}
 
index b4721389b001060ab9d6df1c6e6038af155d638d..c554ed88896af0b4f6c0101fc1aa8e35c84648c9 100644 (file)
@@ -209,5 +209,5 @@ urlpatterns = patterns('',
     url(r'^rss/$', web_view.rss, name="telemeta-rss"),
     
     # Not allowed
-    url(r'^not_allowed/$', web_view.not_allowed, name="telemeta-not-allowed"),
+    url(r'/*/(?P<public_id>[A-Za-z0-9._-]+)/not_allowed/$', web_view.not_allowed, name="telemeta-not-allowed"),
 )
index 2b53590b4b927ae3daf2d9867cf8986f084b55bf..fbe392cc96d8957ad6da7543da7358e5ef72a1a3 100644 (file)
@@ -86,7 +86,7 @@ def stream_from_processor(decoder, processor):
         yield _chunk
 
 def stream_from_file(file):
-    chunk_size = 0xFFFFF
+    chunk_size = 0x80000
     f = open(file, 'r')
     while True:
         _chunk = f.read(chunk_size)
@@ -148,6 +148,8 @@ class WebView(object):
         
     def collection_detail(self, request, public_id, template='telemeta/collection_detail.html'):
         collection = MediaCollection.objects.get(public_id=public_id)
+        if collection.public_access == 'none' and not request.user.is_staff:
+            return HttpResponseRedirect('not_allowed/')
         playlists = self.get_playlists(request)
         return render(request, template, {'collection': collection, 'playlists' : playlists, })
 
@@ -232,6 +234,7 @@ class WebView(object):
         
     def item_detail(self, request, public_id=None, marker_id=None, template='telemeta/mediaitem_detail.html'):
         """Show the details of a given item"""
+        
         if not public_id and marker_id:
             marker = MediaItemMarker.objects.get(public_id=marker_id)
             item_id = marker.item_id
@@ -239,6 +242,9 @@ class WebView(object):
         else:
             item = MediaItem.objects.get(public_id=public_id)
         
+        if item.public_access == 'none' and not request.user.is_staff:
+            return HttpResponseRedirect('not_allowed/')
+            
         # Get TimeSide processors
         formats = []
         for encoder in self.encoders:
@@ -255,32 +261,36 @@ class WebView(object):
         previous, next = self.item_previous_next(item)
         analyzers = self.item_analyze(item)
         playlists = self.get_playlists(request)
+        public_access = self.get_public_access(item.public_access, item.recorded_from_date, item.recorded_to_date)
         
+        return render(request, template,
+                    {'item': item, 'export_formats': formats,
+                    'visualizers': graphers, 'visualizer_id': grapher_id,'analysers': analyzers,
+                    'audio_export_enabled': getattr(settings, 'TELEMETA_DOWNLOAD_ENABLED', True),
+                    'previous' : previous, 'next' : next, 'marker': marker_id, 'playlists' : playlists, 
+                    'public_access': public_access, 
+                    })
+
+    def get_public_access(self, access, date_from, date_to):
         # Rolling publishing date : Public access when time between recorded year 
         # and currant year is over settings value PUBLIC_ACCESS_PERIOD
-        date_from = item.recorded_from_date
-        date_to = item.recorded_to_date
         if date_to:
             date = date_to
         elif date_from:
             date = date_from
         else:
             date = None
-        public_access = True
+        if access == 'full':
+            public_access = True
+        else:
+            public_access = False
         if date:
             year = str(date).split('-')
             year_now = datetime.datetime.now().strftime("%Y")
-            if int(year_now) - int(year[0]) < settings.TELEMETA_PUBLIC_ACCESS_PERIOD:
-                public_access = False
-            
-        return render(request, template,
-                    {'item': item, 'export_formats': formats,
-                    'visualizers': graphers, 'visualizer_id': grapher_id,'analysers': analyzers,
-                    'audio_export_enabled': getattr(settings, 'TELEMETA_DOWNLOAD_ENABLED', True),
-                    'previous' : previous, 'next' : next, 'marker': marker_id, 'playlists' : playlists, 
-                    'public_access': public_access, 
-                    })
-
+            if int(year_now) - int(year[0]) >= settings.TELEMETA_PUBLIC_ACCESS_PERIOD:
+                public_access = True
+        return public_access
+        
     @method_decorator(permission_required('telemeta.change_mediaitem'))
     def item_edit(self, request, public_id, template='telemeta/mediaitem_edit.html'):
         """Show the details of a given item"""
@@ -423,15 +433,16 @@ class WebView(object):
         if not self.cache.exists(image_file):
             if item.file:
                 path = self.cache.dir + os.sep + image_file
-                decoder  = timeside.decoder.FileDecoder(item.file.path)
+                __decoder  = timeside.decoder.FileDecoder(item.file.path)
                 graph = grapher(width = int(width), height = int(height))
-                pipe = decoder | graph
+                pipe = __decoder | graph
                 pipe.run()
                 f = open(path, 'w')
                 graph.render(path)
                 f.close()
                 
         response = HttpResponse(self.cache.read_stream_bin(image_file), mimetype=mime_type)
+        response['Content-Disposition'] = 'attachment'
         return response
 
     def list_export_extensions(self):
@@ -446,7 +457,7 @@ class WebView(object):
         
         item = MediaItem.objects.get(public_id=public_id)
         
-        if extension != 'mp3' and not getattr(settings, 'TELEMETA_DOWNLOAD_ENABLED', False) or item.public_access != 'full':
+        if settings.TELEMETA_DOWNLOAD_ENABLED == False or not item.public_access == 'full':
             return HttpResponseRedirect('/not_allowed/')
 
         for encoder in self.encoders:
@@ -459,22 +470,23 @@ class WebView(object):
         mime_type = encoder.mime_type()
         file = public_id + '.' + encoder.file_extension()
         audio = item.file.path
-        decoder = timeside.decoder.FileDecoder(audio)
-
-        if decoder.format() == mime_type:
+        __decoder = timeside.decoder.FileDecoder(audio)
+        format = __decoder.format()
+        if format == mime_type:
             # source > stream
+            __decoder.release()
             response = HttpResponse(stream_from_file(audio), mimetype = mime_type)
             
         else:        
             if not self.cache_export.exists(file):
                 # source > encoder > stream
-                decoder.setup()
+                __decoder.setup()
                 media = self.cache_export.dir + os.sep + file
-                proc = encoder(media, streaming=True)
-                proc.setup(channels=decoder.channels(), samplerate=decoder.samplerate(), nframes=decoder.nframes())
+                __proc = encoder(media, streaming=True)
+                __proc.setup(channels=__decoder.channels(), samplerate=__decoder.samplerate(), nframes=__decoder.nframes())
 #                metadata = dublincore.express_item(item).to_list()
 #                enc.set_metadata(metadata)
-                response = HttpResponse(stream_from_processor(decoder, proc), mimetype = mime_type)
+                response = HttpResponse(stream_from___processor(__decoder, __proc), mimetype = mime_type)
             else:
                 # cache > stream
                 response = HttpResponse(self.cache_export.read_stream_bin(file), mimetype = mime_type)
@@ -982,6 +994,9 @@ class WebView(object):
         response = HttpResponse(feed, mimetype='application/rss+xml')
         return response
         
-    def not_allowed(self, request):
-        messages.error(request, ugettext('Access not allowed'))
-        return render(request, 'telemeta/messages.html')
+    def not_allowed(self, request,  public_id = None):
+        mess = ugettext('Access not allowed') 
+        title = public_id + ' : ' + mess
+        description = 'Please login or contact the website administator to get private access.'
+        messages.error(request, title)
+        return render(request, 'telemeta/messages.html', {'description' : description})