Browse Source

Added some Information for audio userview, stringtools integrated

master
Dirk Alders 4 years ago
parent
commit
f88baa3e29
5 changed files with 40 additions and 35 deletions
  1. 15
    5
      templates/pygal/audio.html
  2. 2
    0
      templates/pygal/infoview.html
  3. 2
    0
      views/__init__.py
  4. 4
    5
      views/infoviews.py
  5. 17
    25
      views/userviews.py

+ 15
- 5
templates/pygal/audio.html View File

@@ -13,11 +13,21 @@
13 13
   <div id="openModal" class="image">
14 14
     {% with bar=item.tagbar slim=True %}{% include 'themes/'|add:settings.page_theme|add:'/menubar.html' %}{% endwith %}
15 15
     <div class="image_bg">
16
-        <h1>{{ item.heading }}</h1>
17
-        <audio controls preload{% if item.is_repeatview %} autoplay{% endif %} controlsList="nodownload">
18
-          <source src="{{ item.url_item|safe }}" type="{{ item.mime_type }}">
19
-          Your browser does not support the audio element.
20
-        </audio>
16
+      <h1>{{ item.heading }}</h1>
17
+      <audio controls preload{% if item.is_repeatview %} autoplay{% endif %} controlsList="nodownload">
18
+        <source src="{{ item.url_item|safe }}" type="{{ item.mime_type }}">
19
+        Your browser does not support the audio element.
20
+      </audio>
21
+      <table>
22
+        <tbody>
23
+        {% for line in item.audio_information %}
24
+          <tr>
25
+          <td>{{ line.description }}:</td>
26
+          <td style="text-align:right;">{{ line.data }}</td>
27
+          </tr>
28
+        {% endfor %}
29
+        </tbody>
30
+      </table>
21 31
     </div>
22 32
   </div>
23 33
 

+ 2
- 0
templates/pygal/infoview.html View File

@@ -12,6 +12,7 @@
12 12
         {% endfor %}
13 13
         </tbody>
14 14
       </table>
15
+      {% if item.item_information|length > 0 %}
15 16
       <h1>{{ heading.information }}</h1>
16 17
       <table>
17 18
         <tbody>
@@ -23,6 +24,7 @@
23 24
         {% endfor %}
24 25
         </tbody>
25 26
       </table>
27
+      {% endif %}
26 28
       {% if item.database_information|length > 0 %}
27 29
         <h1>{{ heading.database }}</h1>
28 30
         <table>

+ 2
- 0
views/__init__.py View File

@@ -106,6 +106,8 @@ def pygal_download(request, datatype, rel_path):
106 106
         # Create the Archive from fp_list
107 107
         #
108 108
         flat = pygal.is_flat(request)
109
+        if not os.path.exists(settings.TEMP_ROOT):
110
+            fstools.mkdir(settings.TEMP_ROOT)
109 111
         temp = tempfile.TemporaryFile(dir=settings.TEMP_ROOT)
110 112
         archive = zipfile.ZipFile(temp, 'w', zipfile.ZIP_STORED)
111 113
         for fp in fp_list:

+ 4
- 5
views/infoviews.py View File

@@ -1,7 +1,7 @@
1 1
 from django.utils.translation import gettext as _
2
-import fractions
3 2
 import geo
4 3
 from ..models import get_item_type, TYPE_AUDIO, TYPE_FOLDER, TYPE_IMAGE, TYPE_VIDEO
4
+import stringtools
5 5
 from .userviews import base_view as base_userview
6 6
 
7 7
 
@@ -82,8 +82,7 @@ class image_view(base_view):
82 82
             c = geo.gps.coordinate(**gps_data)
83 83
             rv.append({'description': _('GPS'), 'data': str(c), 'url': geo.osm.landmark_link(c)})
84 84
         rv.append({'description': _('Exposure Program'), 'data': self.item.item_data.exposure_program, 'url': None})
85
-        f = fractions.Fraction(self.item.item_data.exposure_time).limit_denominator()
86
-        rv.append({'description': _('Exposure Time'), 'data': '%d/%d s' % (f.numerator, f.denominator), 'url': None})
85
+        rv.append({'description': _('Exposure Time'), 'data': '%ss' % (stringtools.frac_repr(self.item.item_data.exposure_time)), 'url': None})
87 86
         rv.append({'description': _('ISO'), 'data': self.item.item_data.iso, 'url': None})
88 87
         rv.append({'description': _('Focal Length'), 'data': self.item.item_data.focal_length, 'url': None})
89 88
         rv.append({'description': _('Apeture'), 'data': self.item.item_data.f_number, 'url': None})
@@ -117,7 +116,7 @@ class audio_view(base_view):
117 116
         rv.append({'description': _('Year'), 'data': self.item.item_data.year, 'url': None})
118 117
         rv.append({'description': _('Title'), 'data': self.item.item_data.title, 'url': None})
119 118
         rv.append({'description': _('Track'), 'data': self.item.item_data.track, 'url': None})
120
-        rv.append({'description': _('Duration'), 'data': self.__duration_txt__(self.item.item_data.duration), 'url': None})
119
+        rv.append({'description': _('Duration'), 'data': stringtools.time_repr(self.item.item_data.duration), 'url': None})
121 120
         rv.append({'description': _('Genre'), 'data': self.item.item_data.genre, 'url': None})
122
-        rv.append({'description': _('Bitrate'), 'data': self.__size_txt__(self.item.item_data.bitrate), 'url': None})
121
+        rv.append({'description': _('Bitrate'), 'data': stringtools.physical_value_repr(self.item.item_data.bitrate), 'url': None})
123 122
         return rv

+ 17
- 25
views/userviews.py View File

@@ -7,8 +7,8 @@ import os
7 7
 import pygal
8 8
 from ..queries import search_result_query
9 9
 import random
10
+import stringtools
10 11
 import themes
11
-import time
12 12
 
13 13
 ADDTAG_ENTRY = 'addtag-main'
14 14
 INFOVIEW_ENTRY = 'infoview-main'
@@ -85,7 +85,7 @@ class base_view(object):
85 85
         rv.append({'description': _('Name'), 'data': os.path.basename(full_path), 'url': None})
86 86
         rv.append({'description': _('Creation Time'), 'data': self.item.item_data.formatted_datetime, 'url': None})
87 87
         rv.append({'description': _('Path'), 'data': os.path.dirname(full_path), 'url': None})
88
-        rv.append({'description': _('Size'), 'data': self.__size_txt__(self.item.item_data.size) + 'B', 'url': None})
88
+        rv.append({'description': _('Size'), 'data': stringtools.physical_value_repr(self.item.item_data.size, 'B'), 'url': None})
89 89
         rv.append({'description': _('UID'), 'data': self.item.current_uid(), 'url': None})
90 90
         return rv
91 91
 
@@ -241,29 +241,6 @@ class base_view(object):
241 241
     def date_txt(self):
242 242
         return self.item.item_data.formatted_datetime
243 243
 
244
-    def __size_txt__(self, size):
245
-        unit = {
246
-            0: '',
247
-            1: 'k',
248
-            2: 'M',
249
-            3: 'G',
250
-            4: 'T',
251
-        }
252
-        u = 0
253
-        while u < 4 and size > 1000.:
254
-            u += 1
255
-            size /= 1000.
256
-        if size < 100.:
257
-            return '%.2f %s' % (size, unit.get(u, '?'))
258
-        else:
259
-            return '%.1f %s' % (size, unit.get(u, '?'))
260
-
261
-    def __duration_txt__(self, duration):
262
-        if duration >= 3600:
263
-            return time.strftime('%H:%M:%S', time.gmtime(duration))
264
-        else:
265
-            return time.strftime('%M:%S', time.gmtime(duration))
266
-
267 244
     def __parent__(self):
268 245
         if pygal.is_searchview(self.request):
269 246
             return query_view(self.request, search_result_query(self.request))
@@ -528,6 +505,21 @@ class audio_view(base_view):
528 505
     def heading(self):
529 506
         return '%02d - %s' % (self.item.item_data.track, self.item.item_data.title)
530 507
 
508
+    @property
509
+    def audio_information(self):
510
+        rv = []
511
+        entries = (
512
+            (_('Artist'), self.item.artist_c),
513
+            (_('Album'), self.item.album_c),
514
+            (_('Year'), self.item.year_c),
515
+            (_('Title'), self.item.title_c),
516
+            (_('Duration'), stringtools.time_repr(self.item.duration_c)),
517
+        )
518
+        for description, data in entries:
519
+            if data is not None:
520
+                rv.append({'description': description, 'data': data, 'url': None})
521
+        return rv
522
+
531 523
 
532 524
 class other_view(base_view):
533 525
     def __init__(self, *args, **kwargs):

Loading…
Cancel
Save