]> git.parisson.com Git - telemeta.git/commitdiff
do not compute all graphers at item import
authorGuillaume Pellerin <yomguy@parisson.com>
Tue, 11 Feb 2014 10:09:40 +0000 (11:09 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Tue, 11 Feb 2014 10:09:40 +0000 (11:09 +0100)
telemeta/urls.py
telemeta/views/item.py

index 8c664f1ca1814e47da79d96700b72e20b3f1819c..a8774bfda0a82cd58252f2651cf9258cfadf3802 100644 (file)
@@ -95,7 +95,7 @@ urlpatterns = patterns('',
             + export_extensions + ')$',
         item_view.item_export,
         name="telemeta-item-export"),
-    url(r'^archives/items/(?P<public_id>[A-Za-z0-9._-]+)/visualize/(?P<visualizer_id>[0-9a-z_]+)/(?P<width>[0-9A-Z]+)x(?P<height>[0-9A-Z]+)/$',
+    url(r'^archives/items/(?P<public_id>[A-Za-z0-9._-]+)/visualize/(?P<grapher_id>[0-9a-z_]+)/(?P<width>[0-9A-Z]+)x(?P<height>[0-9A-Z]+)/$',
         item_view.item_visualize,
         name="telemeta-item-visualize"),
     url(r'^archives/items/(?P<public_id>[A-Za-z0-9._-]+)/analyze/xml/$',
index 23e3eec9a39b0ef72a32c4373a65ed5fa2045f0b..c78344e933ca0b16b107bb14be2cae3e28622282 100644 (file)
@@ -51,7 +51,8 @@ class ItemView(object):
 
     export_enabled = getattr(settings, 'TELEMETA_DOWNLOAD_ENABLED', True)
     export_formats = getattr(settings, 'TELEMETA_DOWNLOAD_FORMATS', ('mp3', 'wav'))
-    default_grapher = getattr(settings, 'TIMESIDE_DEFAULT_GRAPHER_ID', ('waveform_simple'))
+    default_grapher_id = getattr(settings, 'TIMESIDE_DEFAULT_GRAPHER_ID', ('waveform_simple'))
+    default_grapher_sizes = getattr(settings, 'TELEMETA_DEFAULT_GRAPHER_SIZES', ['360x130', ])
     auto_zoom = getattr(settings, 'TIMESIDE_AUTO_ZOOM', False)
 
     def get_export_formats(self):
@@ -99,12 +100,18 @@ class ItemView(object):
     def get_graphers(self):
         graphers = []
         for grapher in self.graphers:
-            if grapher.id() == self.default_grapher:
+            if grapher.id() == self.default_grapher_id:
                 graphers.insert(0, {'name':grapher.name(), 'id': grapher.id()})
             else:
                 graphers.append({'name':grapher.name(), 'id': grapher.id()})
         return graphers
         
+    def get_grapher(self, id):
+        for grapher in self.graphers:
+            if grapher.id() == id:
+                break        
+        return grapher
+
     def item_detail(self, request, public_id=None, marker_id=None, width=None, height=None,
                         template='telemeta/mediaitem_detail.html'):
         """Show the details of a given item"""
@@ -367,21 +374,16 @@ class ItemView(object):
                     subpipe = analyzer()
                     analyzers_sub.append(subpipe)
                     pipe = pipe | subpipe
-
-                try:
-                    sizes = settings.TELEMETA_DEFAULT_GRAPHER_SIZES
-                except:
-                    sizes = ['360x130', ]
-
-                for grapher in self.graphers:
-                    for size in sizes:
-                        width = size.split('x')[0]
-                        height = size.split('x')[1]
-                        image_file = '.'.join([item.public_id, grapher.id(), size.replace('x', '_'), 'png'])
-                        path = self.cache_data.dir + os.sep + image_file
-                        graph = grapher(width = int(width), height = int(height))
-                        graphers_sub.append({'graph' : graph, 'path': path})
-                        pipe = pipe | graph
+                
+                default_grapher = self.get_grapher(self.default_grapher_id)                
+                for size in self.default_grapher_sizes:
+                    width = size.split('x')[0]
+                    height = size.split('x')[1]
+                    image_file = '.'.join([item.public_id, self.default_grapher_id, size.replace('x', '_'), 'png'])
+                    path = self.cache_data.dir + os.sep + image_file
+                    graph = default_grapher(width = int(width), height = int(height))
+                    graphers_sub.append({'graph' : graph, 'path': path})
+                    pipe = pipe | graph
 
                 pipe.run()
 
@@ -438,15 +440,11 @@ class ItemView(object):
         response['Content-Disposition'] = 'attachment; filename='+public_id+'.xml'
         return response
 
-    def item_visualize(self, request, public_id, visualizer_id, width, height):
+    def item_visualize(self, request, public_id, grapher_id, width, height):
         item = MediaItem.objects.get(public_id=public_id)
         mime_type = 'image/png'
-        grapher_id = visualizer_id
-
-        for grapher in self.graphers:
-            if grapher.id() == grapher_id:
-                break
-
+        grapher = self.get_grapher(grapher_id)                
+        
         if grapher.id() != grapher_id:
             raise Http404