Cleaned up EXIF view
authorJoar Wandborg <joar@wandborg.se>
Thu, 23 May 2013 20:21:02 +0000 (22:21 +0200)
committerJoar Wandborg <joar@wandborg.se>
Thu, 23 May 2013 20:21:02 +0000 (22:21 +0200)
The last update made the assumption that EXIF metadata is in some way
consistent between camera models, images, manufacturers. This update
takes into account that nothing is certain whenever EXIF is involved.

mediagoblin/db/mixin.py
mediagoblin/static/css/base.css
mediagoblin/templates/mediagoblin/utils/exif.html

index 027215aa5df3c24d070224a0f03bcd89403b42ae..e7f66fa1e8ce21478c07db171014d220f0efbe07 100644 (file)
@@ -246,7 +246,8 @@ class MediaEntryMixin(GenerateSlugMixin):
 
         exif_all = self.media_data.get("exif_all")
 
-        taken = None
+        exif_short = {}
+
         if 'Image DateTimeOriginal' in exif_all:
             # format date taken
             takendate = datetime.datetime.strptime(
@@ -254,6 +255,8 @@ class MediaEntryMixin(GenerateSlugMixin):
                 '%Y:%m:%d %H:%M:%S').date()
             taken = takendate.strftime('%B %d %Y')
 
+            exif_short.update({'Date Taken': taken})
+
         aperture = None
         if 'EXIF FNumber' in exif_all:
             fnum = str(exif_all['EXIF FNumber']['printable']).split('/')
@@ -264,14 +267,25 @@ class MediaEntryMixin(GenerateSlugMixin):
             elif fnum[0] != 'None':
                 aperture = "f/%s" % (fnum[0])
 
-        return {
-            "Camera" : exif_all['Image Model']['printable'],
-            "Exposure" : '%s sec' % exif_all['EXIF ExposureTime']['printable'],
-            "Aperture" : aperture,
-            "ISO" : exif_all['EXIF ISOSpeedRatings']['printable'],
-            "Focal Length" : '%s mm' % exif_all['EXIF FocalLength']['printable'],
-            "Date Taken" : taken,
-        }
+        if aperture:
+            exif_short.update({'Aperture': aperture})
+
+        short_keys = [
+            ('Camera', 'Image Model', None),
+            ('Exposure', 'EXIF ExposureTime', lambda x: '%s sec' % x),
+            ('ISO Speed', 'EXIF ISOSpeedRatings', None),
+            ('Focal Length', 'EXIF FocalLength', lambda x: '%s mm' % x)]
+
+        for label, key, fmt_func in short_keys:
+            try:
+                val = fmt_func(exif_all[key]['printable']) if fmt_func \
+                        else exif_all[key]['printable']
+                exif_short.update({label: val})
+            except KeyError:
+                pass
+
+        return exif_short
+
 
 class MediaCommentMixin(object):
     @property
index 096e252205c1d5ec3d9f3d51f4837954fe7d03bc..4645b2c588e0b9cd635d0ff400d5fad42ba04b13 100644 (file)
@@ -717,3 +717,29 @@ pre {
     width: 46%;
   }
 }
+
+/* Exif display */
+#exif_content h3 {
+   border-bottom: 1px solid #333;
+}
+#exif_camera_information {
+   margin-bottom: 20px;
+}
+
+#exif_additional_info {
+   display: none;
+}
+#exif_additional_info table {
+   font-size: 11px;
+   margin-top: 10px;
+}
+#exif_additional_info td {
+   vertical-align: top;
+   padding-bottom: 5px;
+}
+#exif_content .col1 {
+   padding-right: 20px;
+}
+#exif_additional_info table tr {
+   margin-bottom: 10px;
+}
index 746dccf5fe32751c97dfb3a706f5cd7283ec458d..b62208e12fa093d62fc4deba22545d80feec3ac5 100644 (file)
 #}
 
 {% block exif_content %}
-<style type="text/css">
-#exif_content h3 {
-   border-bottom: 1px solid #333;
-}
-#exif_camera_information {
-   margin-bottom: 20px;
-}
-
-#exif_additional_info {
-   display: none;
-}
-#exif_additional_info table {
-   font-size: 11px;
-   margin-top: 10px;
-}
-#exif_additional_info td {
-   vertical-align: top;
-   padding-bottom: 5px;
-}
-#exif_content .col1 {
-   padding-right: 20px;
-}
-#exif_additional_info table tr {
-   margin-bottom: 10px;
-}
-</style>
 <noscript>
   <style type="text/css">
     #exif_additional_info {
     <h3>Camera Information</h3>
     <table id="exif_camera_information">
       <tbody>
+      {% for label, value in media.exif_display_data_short().iteritems() %}
       <tr>
-        <td class="col1">Taken on</td>
-        <td>{{ media.exif_display_data_short()['Date Taken'] }}</td>
-      </tr>
-      <tr>
-        <td class="col1">Camera</td>
-        <td>{{ media.exif_display_data_short()['Camera'] }}</td>
-      </tr>
-      <tr>
-        <td class="col1">Exposure</td>
-        <td>{{ media.exif_display_data_short()['Exposure'] }}</td>
-      </tr>
-      <tr>
-        <td class="col1">Aperture</td>
-        <td>{{ media.exif_display_data_short()['Aperture'] }}</td>
-      </tr>
-      <tr>
-        <td class="col1">ISO</td>
-        <td>{{ media.exif_display_data_short()['ISO'] }}</td>
-      </tr>
-      <tr>
-        <td class="col1">Focal Length</td>
-        <td>{{ media.exif_display_data_short()['Focal Length'] }}</td>
+        <td class="col1">{{ label }}</td>
+        <td>{{ value }}</td>
       </tr>
+      {% endfor %}
       </tbody>
     </table>
     <h3 id="exif_additional_info_button" class="button_action">