Changeset bddf042 in OpenWorkouts-current
- Timestamp:
- Feb 10, 2019, 7:56:34 AM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- f29d4b4
- Parents:
- 4226ce0
- Location:
- ow
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/models/root.py
r4226ce0 rbddf042 11 11 get_catalog, 12 12 install_catalog, 13 update_indexes, 13 14 reindex_object, 14 15 remove_from_catalog, … … 40 41 indexes = { 41 42 'email': CatalogFieldIndex('email'), 43 'nickname': CatalogFieldIndex('nickname'), 42 44 'sport': CatalogFieldIndex('sport'), 43 45 } 44 46 return indexes 47 48 def _update_indexes(self): 49 return update_indexes(self.catalog, self._get_catalog_indexes()) 45 50 46 51 def reindex(self, obj): … … 77 82 # the catalog will return all users 78 83 res = self.query(Eq('email', email)) 84 if res: 85 return next(res) 86 return None 87 88 def get_user_by_nickname(self, nickname): 89 if nickname is not None: 90 # for some reason, when searching for None 91 # the catalog will return all users 92 res = self.query(Eq('nickname', nickname)) 79 93 if res: 80 94 return next(res) -
ow/templates/profile.pt
r4226ce0 rbddf042 17 17 <div class="user-profile-account"> 18 18 <div> 19 <tal:c tal:condition="getattr( context, 'picture', None)">20 <img tal:attributes="src request.resource_path( context, 'picture')"19 <tal:c tal:condition="getattr(user, 'picture', None)"> 20 <img tal:attributes="src request.resource_path(user, 'picture')" 21 21 width="450" /> 22 22 </tal:c> 23 23 <div> 24 24 <h2> 25 <tal:fullname tal:content=" context.fullname"></tal:fullname>25 <tal:fullname tal:content="user.fullname"></tal:fullname> 26 26 </h2> 27 27 <p> 28 <tal:has-nickname tal:condition="context.nickname"> 29 <tal:nickname tal:content="context.nickname"></tal:nickname> 30 </tal:has-nickname> | 31 <span><tal:email tal:content="context.email"></tal:email></span> 28 <tal:has-nickname tal:condition="user.nickname"> 29 <a href="" 30 tal:attributes="href request.resource_url(request.root, 'profile', user.nickname)" 31 tal:content="request.resource_url(request.root, 'profile', user.nickname)"> 32 </a> | 33 </tal:has-nickname> 34 <span><tal:email tal:content="user.email"></tal:email></span> 32 35 </p> 33 36 <div class="profile-bio"> 34 <p tal:repeat="paragraph getattr( context, 'bio', '').split('\n')"37 <p tal:repeat="paragraph getattr(user, 'bio', '').split('\n')" 35 38 tal:content="paragraph"></p> 36 39 </div> 37 40 <ul class="workout-options"> 38 41 <li><a href="" 39 tal:attributes="href request.resource_url( context, 'edit')"42 tal:attributes="href request.resource_url(user, 'edit')" 40 43 i18n:translate="">edit profile</a></li> 41 44 <li><a href="" 42 tal:attributes="href request.resource_url( context, 'passwd')"45 tal:attributes="href request.resource_url(user, 'passwd')" 43 46 i18n:translate="">change password</a></li> 44 47 </ul> … … 103 106 <ul class="workout-info"> 104 107 <li> 105 <tal:c tal:content="workout.start_in_timezone( context.timezone)"></tal:c>108 <tal:c tal:content="workout.start_in_timezone(user.timezone)"></tal:c> 106 109 </li> 107 110 <li> … … 155 158 <li> 156 159 <span><tal:t i18n:translate="">Gender:</tal:t></span> 157 <tal:c tal:content="getattr( context, 'gender', '-')"></tal:c>158 </li> 159 <li tal:define="birth_date getattr( context, 'birth_date', None)">160 <tal:c tal:content="getattr(user, 'gender', '-')"></tal:c> 161 </li> 162 <li tal:define="birth_date getattr(user, 'birth_date', None)"> 160 163 <span><tal:t i18n:translate="">Birth date:</tal:t></span> 161 164 <tal:c tal:condition="birth_date" … … 165 168 <li> 166 169 <span><tal:t i18n:translate="">Height:</tal:t></span> 167 <tal:c tal:content="getattr( context, 'height', '-')"></tal:c> meters170 <tal:c tal:content="getattr(user, 'height', '-')"></tal:c> meters 168 171 </li> 169 172 <li> 170 173 <span><tal:t i18n:translate="">Weight:</tal:t></span> 171 <tal:c tal:content="getattr( context, 'weight', '-')"></tal:c> kg174 <tal:c tal:content="getattr(user, 'weight', '-')"></tal:c> kg 172 175 </li> 173 176 </ul> … … 195 198 switcher_selector: '.js-month-stats .js-switcher a', 196 199 is_active_class: 'is-active', 197 urls: {"monthly": "${request.resource_url( context, 'monthly')}",198 "weekly": "${request.resource_url( context, 'weekly')}"},200 urls: {"monthly": "${request.resource_url(user, 'monthly')}", 201 "weekly": "${request.resource_url(user, 'weekly')}"}, 199 202 current_month: "${current_month}", 200 203 current_week: "${current_week}", -
ow/tests/models/test_root.py
r4226ce0 rbddf042 35 35 # a new OpenWorkouts instance has a catalog created automatically 36 36 assert isinstance(root.catalog, Catalog) 37 assert len(root.catalog) == 238 assert 'email' in root.catalog39 assert 'sport'in root.catalog37 assert len(root.catalog) == 3 38 for key in ['email', 'nickname', 'sport']: 39 assert key in root.catalog 40 40 41 41 def test_add_user_ok(self, root): -
ow/tests/test_catalog.py
r4226ce0 rbddf042 56 56 changes = update_indexes(catalog, indexes) 57 57 assert changes['added'] == ['newindex'] 58 assert changes['removed'] == ['email', ' sport']58 assert changes['removed'] == ['email', 'nickname', 'sport'] 59 59 60 60 def test_update_indexes_empty(self, root): … … 63 63 changes = update_indexes(catalog, indexes) 64 64 assert changes['added'] == [] 65 assert changes['removed'] == ['email', ' sport']65 assert changes['removed'] == ['email', 'nickname', 'sport'] 66 66 67 67 def test_install_catalog(self): -
ow/tests/views/test_user.py
r4226ce0 rbddf042 270 270 # profile page for the current day (no workouts avalable) 271 271 response = user_views.profile(john, request) 272 assert len(response.keys()) == 4272 assert len(response.keys()) == 5 273 273 current_month = datetime.now(timezone.utc).strftime('%Y-%m') 274 assert response['user'] == john 274 275 assert response['current_month'] == current_month 275 276 assert response['current_week'] is None … … 284 285 request.GET['month'] = 6 285 286 response = user_views.profile(john, request) 286 assert len(response.keys()) == 4 287 assert len(response.keys()) == 5 288 assert response['user'] == john 287 289 assert response['current_month'] == '2015-06' 288 290 assert response['current_week'] is None … … 299 301 request.GET['week'] = 25 300 302 response = user_views.profile(john, request) 301 assert len(response.keys()) == 4 303 assert len(response.keys()) == 5 304 assert response['user'] == john 302 305 assert response['current_month'] == '2015-06' 303 306 assert response['current_week'] == 25 … … 313 316 request.GET['week'] = 26 314 317 response = user_views.profile(john, request) 315 assert len(response.keys()) == 4 318 assert len(response.keys()) == 5 319 assert response['user'] == john 316 320 assert response['current_month'] == '2015-06' 317 321 assert response['current_week'] == 26 -
ow/views/user.py
r4226ce0 rbddf042 4 4 from decimal import Decimal 5 5 6 from pyramid.httpexceptions import HTTPFound 6 from pyramid.httpexceptions import HTTPFound, HTTPNotFound 7 7 from pyramid.view import view_config 8 8 from pyramid.security import remember, forget … … 157 157 158 158 @view_config( 159 context=OpenWorkouts, 160 name='profile', 161 permission='view', 162 renderer='ow:templates/profile.pt') 163 @view_config( 159 164 context=User, 160 165 permission='view', … … 166 171 basic info, stats, etc 167 172 """ 173 if isinstance(context, OpenWorkouts): 174 nickname = request.subpath[0] 175 user = request.root.get_user_by_nickname(nickname) 176 if user is None: 177 return HTTPNotFound() 178 else: 179 user = context 168 180 now = datetime.now(timezone.utc) 169 181 year = int(request.GET.get('year', now.year)) 170 182 month = int(request.GET.get('month', now.month)) 171 183 week = request.GET.get('week', None) 172 workouts = context.workouts(year, month, week)184 workouts = user.workouts(year, month, week) 173 185 totals = { 174 186 'distance': Decimal(0), … … 186 198 187 199 return { 200 'user': user, 188 201 'workouts': workouts, 189 202 'current_month': '{year}-{month}'.format(
Note: See TracChangeset
for help on using the changeset viewer.