Changeset 31adfa5 in OpenWorkouts-current
- Timestamp:
- Dec 21, 2018, 11:00:25 AM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- fe6089a
- Parents:
- d507f75
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/models/user.py
rd507f75 r31adfa5 33 33 self.gender = kw.get('gender', 'female') 34 34 self.picture = kw.get('picture', None) # blob 35 self.timezone = kw.get('timezone', 'UTC') 35 36 self.__password = None 36 37 self.last_workout_id = 0 -
ow/models/workout.py
rd507f75 r31adfa5 3 3 from decimal import Decimal 4 4 5 import pytz 5 6 import gpxpy 6 7 from repoze.folder import Folder … … 74 75 return self.start.strftime('%H:%M') 75 76 77 def start_in_timezone(self, timezone): 78 """ 79 Return a string representation of the start date and time, 80 localized into the given timezone 81 """ 82 _start = self.start.astimezone(pytz.timezone(timezone)) 83 return _start.strftime('%d/%m/%Y %H:%M (%Z)') 84 85 def end_in_timezone(self, timezone): 86 """ 87 Return a string representation of the end date and time, 88 localized into the given timezone 89 """ 90 _end = self.end.astimezone(pytz.timezone(timezone)) 91 return _end.strftime('%d/%m/%Y %H:%M (%Z)') 92 76 93 def split_duration(self): 77 94 hours, remainder = divmod(int(self.duration.total_seconds()), 3600) -
ow/schemas/user.py
rd507f75 r31adfa5 1 1 from pyramid.i18n import TranslationStringFactory 2 2 from formencode import Schema, validators 3 from pytz import common_timezones 3 4 4 5 from ow.schemas.blob import FieldStorageBlob … … 74 75 picture = FieldStorageBlob(if_emtpy=None, if_missing=None, 75 76 whitelist=['jpg', 'jpeg', 'png', 'gif']) 77 timezone = validators.OneOf(common_timezones, if_missing='UTC') 76 78 77 79 -
ow/templates/dashboard.pt
rd507f75 r31adfa5 38 38 <ul class="workout-info"> 39 39 <li> 40 <tal:c tal:content="workout.start "></tal:c>40 <tal:c tal:content="workout.start_in_timezone(context.timezone)"></tal:c> 41 41 </li> 42 42 <li> -
ow/templates/delete_workout.pt
rd507f75 r31adfa5 25 25 <input id="delete" name="delete" type="hidden" value="yes" /> 26 26 27 <div id="workout"> 27 <div id="workout" 28 tal:define="timezone request.root[request.authenticated_userid].timezone"> 28 29 <h3 tal:content="context.title"></h3> 29 30 <ul id="" tal:attributes="id 'workout-' + context.workout_id + '-details'"> 30 31 <li> 31 32 <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> 33 34 </li> 34 35 <li> 35 36 <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> 37 38 </li> 38 39 <li> -
ow/templates/edit_profile.pt
rd507f75 r31adfa5 99 99 </fieldset> 100 100 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 101 112 <p> 102 113 ${form.submit("submit", "Save", **{'class':"button button-normal"})} -
ow/templates/workout.pt
rd507f75 r31adfa5 78 78 79 79 <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"> 81 81 <li> 82 82 <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> 84 84 </li> 85 85 <li> 86 86 <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> 88 88 </li> 89 89 <li> -
ow/tests/models/test_workout.py
rd507f75 r31adfa5 77 77 workout = Workout(start=start_date) 78 78 assert workout.start_time == start_date.strftime('%H:%M') 79 80 def test_start_in_timezone(self): 81 start_date = datetime.now(tz=timezone.utc) 82 str_start_date = start_date.strftime('%d/%m/%Y %H:%M (%Z)') 83 workout = Workout(start=start_date) 84 assert workout.start_in_timezone('UTC') == str_start_date 85 assert workout.start_in_timezone('Europe/Madrid') != str_start_date 86 assert workout.start_in_timezone('America/Vancouver') != str_start_date 87 88 def test_end_in_timezone(self): 89 start_date = datetime.now(tz=timezone.utc) 90 end_date = start_date + timedelta(minutes=60) 91 str_end_date = end_date.strftime('%d/%m/%Y %H:%M (%Z)') 92 workout = Workout(start=start_date, duration=timedelta(minutes=60)) 93 assert workout.end_in_timezone('UTC') == str_end_date 94 assert workout.end_in_timezone('Europe/Madrid') != str_end_date 95 assert workout.end_in_timezone('America/Vancouver') != str_end_date 79 96 80 97 def test_split_duration(self): -
ow/tests/views/test_user.py
rd507f75 r31adfa5 259 259 # loaded user profile 260 260 data = ['firstname', 'lastname', 'email', 'nickname', 'bio', 261 'birth_date', 'height', 'weight', 'gender' ]261 'birth_date', 'height', 'weight', 'gender', 'timezone'] 262 262 assert list(response['form'].data.keys()) == data 263 263 # and check the email to see data is properly loaded -
ow/views/user.py
rd507f75 r31adfa5 5 5 from pyramid.i18n import TranslationStringFactory 6 6 from pyramid_simpleform import Form, State 7 from pytz import common_timezones 7 8 8 9 from ..models.user import User … … 167 168 # Saved, send the user to the public view of her profile 168 169 return HTTPFound(location=request.resource_url(context, 'profile')) 170 169 171 # prevent crashes on the form 170 172 if 'picture' in form.data: 171 173 del form.data['picture'] 172 return {'form': OWFormRenderer(form)} 174 175 return {'form': OWFormRenderer(form), 176 'timezones': common_timezones} 173 177 174 178 -
setup.py
rd507f75 r31adfa5 27 27 'unidecode', 28 28 'gpxpy', 29 'lxml' 29 'lxml', 30 'pytz' 30 31 ] 31 32
Note: See TracChangeset
for help on using the changeset viewer.