Merge remote-tracking branch 'refs/remotes/tryggvib/532-exif-creation-date'

Conflicts:
	mediagoblin/config_spec.ini
	mediagoblin/templates/mediagoblin/user_pages/media.html
This commit is contained in:
Christopher Allan Webber 2013-05-11 13:48:42 -05:00
commit 058226d0d2
3 changed files with 29 additions and 0 deletions

View File

@ -61,6 +61,7 @@ csrf_cookie_name = string(default='mediagoblin_csrftoken')
push_urls = string_list(default=list())
exif_visible = boolean(default=False)
original_date_visible = boolean(default=False)
# Theming stuff
theme_install_dir = string(default="%(here)s/user_dev/themes/")

View File

@ -44,6 +44,23 @@ class ImageData(Base):
gps_altitude = Column(Float)
gps_direction = Column(Float)
def get_original_date(self):
"""
Get the original date and time from the EXIF information. Returns
either a datetime object or None (if anything goes wrong)
"""
import datetime
try:
# Try wrapped around all since exif_all might be none,
# EXIF DateTimeOriginal or printable might not exist, or
# strptime might not be able to parse date correctly
exif_date = self.exif_all['EXIF DateTimeOriginal']['printable']
original_date = datetime.datetime.strptime(exif_date,
'%Y:%m:%d %H:%M:%S')
return original_date
except:
return None
DATA_MODEL = ImageData
MODELS = [ImageData]

View File

@ -153,6 +153,17 @@
{{ formatted_time }} ago
{%- endtrans -%}
</span></p>
{% if app_config['original_date_visible'] %}
{% set original_date = media.media_data.get_original_date() %}
{% if original_date -%}
{% trans date=original_date.strftime("%Y-%m-%d") -%}
<h3>Created on</h3>
<p>{{ date }}</p>
{%- endtrans %}
{%- endif %}
{% endif %}
{% if media.tags %}
{% include "mediagoblin/utils/tags.html" %}
{% endif %}