Skip to content

Commit

Permalink
Add more media.dateobj values and correct documentation
Browse files Browse the repository at this point in the history
As discussed in Issue saimn#271

In the documentation media.dateobj was mistakenly called
media.datetime while media.datetime itself is a string.

Added some more media date related values.  To avoid breaking things,
dateobj and datetime remain unchanged.  datetimelocal, datelocal and
timelocal were added.  As their names imply, they contain values
appropriate for the system's LOCALE.
  • Loading branch information
nelsonov committed Nov 25, 2017
1 parent 7e35d1f commit c583b5c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ alphabetical order):
- Julien Voisin
- Kai Fricke
- Keith Johnson
- Lee Nelson
- Lukas Vacek
- Luke Cyca (@lukecyca)
- Mate Lakat
Expand Down
50 changes: 46 additions & 4 deletions docs/themes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,62 @@ templates. If available, you can use:
``media.exif.fstop``
The aperture value given as an F-number and formatted as a decimal.

``media.exif.datetime``
``media.exif.dateobj``
The time the image was *taken*. It is a datetime object, that can be
formatted with ``strftime``:

.. code-block:: jinja
{% if media.exif.datetime %}
{{ media.exif.datetime.strftime('%A, %d. %B %Y') }}
{% if media.exif.dateobj %}
{{ media.exif.dateobj.strftime('%A, %d. %B %Y') }}
{% endif %}
This will output something like "Monday, 25. June 2013", depending on your
locale.

``media.exif.datetime``
The time the image was *taken*. It is formatted as:

.. code-block:: python
media.exif.dateobj.strftime('%A, %d. %B %Y')
This will output something like "Monday, 25. June 2013", depending on your
locale.

``media.exif.datetimelocal``
The date and time the image was *taken*. It is formatted in the system's
configured LOCALE using:

.. code-block:: python
media.exif.dateobj.strftime('%c')
This will output something like "Sat 25 Nov 2017 03:08:17 PM PST",
depending on your locale.

``media.exif.datelocal``
The date the image was *taken*. It is formatted in the system's
configured LOCALE using:

.. code-block:: python
media.exif.dateobj.strftime('%x')
This will output something like "11/25/2017", depending on your
locale.

``media.exif.timelocal``
The time the image was *taken*. It is formatted in the system's
configured LOCALE using:

.. code-block:: python
media.exif.dateobj.strftime('%X')
This will output something like "03:09:39 PM", depending on your
locale.

``media.exif.gps``
If not None, the dict contains two keys ``lat`` and ``lon`` denoting the
GPS coordinates of the location where the image was taken. ``lat`` will
Expand All @@ -135,4 +178,3 @@ templates. If available, you can use:
<a href="http://openstreetmap.org/index.html?lat={{
media.exif.gps.lat }}&lon={{ media.exif.long}}">Go to location</a>
{% endif %}
6 changes: 6 additions & 0 deletions sigal/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ def get_exif_tags(data):
simple['dateobj'] = datetime.strptime(date, '%Y:%m:%d %H:%M:%S')
dt = simple['dateobj'].strftime('%A, %d. %B %Y')
simple['datetime'] = dt.decode('utf8') if compat.PY2 else dt
dt = simple['dateobj'].strftime('%c')
simple['datetimelocal'] = dt.decode('utf8') if compat.PY2 else dt
dt = simple['dateobj'].strftime('%x')
simple['datelocal'] = dt.decode('utf8') if compat.PY2 else dt
dt = simple['dateobj'].strftime('%X')
simple['timelocal'] = dt.decode('utf8') if compat.PY2 else dt
except (ValueError, TypeError) as e:
logger.info(u'Could not parse DateTimeOriginal: %s', e)

Expand Down

0 comments on commit c583b5c

Please sign in to comment.