Changeset d517001 in OpenWorkouts-current for ow/utilities.py


Ignore:
Timestamp:
Feb 15, 2019, 6:09:04 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
d5429c5
Parents:
d459ee2
Message:

(#58) Set a title automatically when adding manually a workout without
providing one.

The title is generated based on the only required data we have (starting
date and time) + sport (if provided).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/utilities.py

    rd459ee2 rd517001  
    1313from ZODB.blob import Blob
    1414from splinter import Browser
     15
     16from pyramid.i18n import TranslationStringFactory
     17
     18_ = TranslationStringFactory('OpenWorkouts')
    1519
    1620
     
    263267            return weeks.index(week)
    264268    return None
     269
     270
     271def part_of_day(dt):
     272    """
     273    Given a datetime object (dt), return which part of the day was it
     274    (morning, afternoon, evening, night), translated in the proper
     275    """
     276    parts = {
     277        _('Morning'): (5, 11),
     278        _('Afternoon'): (12, 17),
     279        _('Evening'): (18, 22),
     280        _('Night'): (23, 4)
     281    }
     282    for key, value in parts.items():
     283        if value[0] <= dt.hour <= value[1]:
     284            return key
Note: See TracChangeset for help on using the changeset viewer.