Changeset 31adfa5 in OpenWorkouts-current for ow/templates


Ignore:
Timestamp:
Dec 21, 2018, 11:00:25 AM (5 years ago)
Author:
borja <borja@…>
Branches:
current, feature/docs, master
Children:
fe6089a
Parents:
d507f75
Message:

(#14) Timezones support:

  • Added pytz as a new dependency, please install it in your existing envs:

pip install pytz

  • Added a timezone attribute to users, to store in which timezone they are, defaults to 'UTC'. Ensure any users you could have in your database have such attribute. You can add it in pshell:

for user in root.users:

user.timezone = 'UTC'

request.tm.commit()

  • Modified schemas/templates/views to let users choose their timezone based on a list of "common" timezones provided by pytz
  • Added two methods to the Workout model so we can get the start and end dates formatted in the appropiate timezone (all datetime objects are stored in UTC)
  • Modified the templates where we show workout dates and times so the new timezone-formatting methods are used.
Location:
ow/templates
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ow/templates/dashboard.pt

    rd507f75 r31adfa5  
    3838            <ul class="workout-info">
    3939              <li>
    40                 <tal:c tal:content="workout.start"></tal:c>
     40                <tal:c tal:content="workout.start_in_timezone(context.timezone)"></tal:c>
    4141              </li>
    4242              <li>
  • ow/templates/delete_workout.pt

    rd507f75 r31adfa5  
    2525        <input id="delete" name="delete" type="hidden" value="yes" />
    2626
    27       <div id="workout">
     27        <div id="workout"
     28             tal:define="timezone request.root[request.authenticated_userid].timezone">
    2829        <h3 tal:content="context.title"></h3>
    2930        <ul id="" tal:attributes="id 'workout-' + context.workout_id + '-details'">
    3031          <li>
    3132            <tal:t i18n:translate="">Start:</tal:t>
    32             <tal:c tal:content="context.start"></tal:c>
     33            <tal:c tal:content="context.start_in_timezone(timezone)"></tal:c>
    3334          </li>
    3435          <li>
    3536            <tal:t i18n:translate="">End:</tal:t>
    36             <tal:c tal:content="context.end"></tal:c>
     37            <tal:c tal:content="context.end_in_timezone(timezone)"></tal:c>
    3738          </li>
    3839          <li>
  • ow/templates/edit_profile.pt

    rd507f75 r31adfa5  
    9999        </fieldset>
    100100
     101        <fieldset>
     102            <p>
     103                <label for="timezone" i18n:translate="">Timezone:</label>
     104                <small i18n:translate="">
     105                    All dates and times will be formatted for this timezone
     106                </small>
     107                ${form.errorlist('timezone')}
     108                ${form.select('timezone', timezones)}
     109            </p>
     110        </fieldset>
     111
    101112        <p>
    102113            ${form.submit("submit", "Save",  **{'class':"button button-normal"})}
  • ow/templates/workout.pt

    rd507f75 r31adfa5  
    7878
    7979      <ul id="" tal:attributes="id 'workout-' + context.workout_id + '-details'"
    80           tal:define="hr context.hr; cad context.cad">
     80          tal:define="hr context.hr; cad context.cad; timezone context.owner.timezone">
    8181        <li>
    8282          <tal:t i18n:translate="">Start:</tal:t>
    83           <tal:c tal:content="context.start"></tal:c>
     83          <tal:c tal:content="context.start_in_timezone(timezone)"></tal:c>
    8484        </li>
    8585        <li>
    8686          <tal:t i18n:translate="">End:</tal:t>
    87           <tal:c tal:content="context.end"></tal:c>
     87          <tal:c tal:content="context.end_in_timezone(timezone)"></tal:c>
    8888        </li>
    8989        <li>
Note: See TracChangeset for help on using the changeset viewer.