Changeset bddf042 in OpenWorkouts-current for ow/views/user.py


Ignore:
Timestamp:
Feb 10, 2019, 7:56:34 AM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
f29d4b4
Parents:
4226ce0
Message:

(#7) Allow users profiles to be accessed using a more friendly url:

https://openworkouts.org/profile/NICKNAME

IMPORTANT: This change adds a new index to the catalog, so ensure you
update any existing databases after pulling.

Enter pshell and run this code:

root._update_indexes()
for user in root.users:

root.reindex(user)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/views/user.py

    r4226ce0 rbddf042  
    44from decimal import Decimal
    55
    6 from pyramid.httpexceptions import HTTPFound
     6from pyramid.httpexceptions import HTTPFound, HTTPNotFound
    77from pyramid.view import view_config
    88from pyramid.security import remember, forget
     
    157157
    158158@view_config(
     159    context=OpenWorkouts,
     160    name='profile',
     161    permission='view',
     162    renderer='ow:templates/profile.pt')
     163@view_config(
    159164    context=User,
    160165    permission='view',
     
    166171    basic info, stats, etc
    167172    """
     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
    168180    now = datetime.now(timezone.utc)
    169181    year = int(request.GET.get('year', now.year))
    170182    month = int(request.GET.get('month', now.month))
    171183    week = request.GET.get('week', None)
    172     workouts = context.workouts(year, month, week)
     184    workouts = user.workouts(year, month, week)
    173185    totals = {
    174186        'distance': Decimal(0),
     
    186198
    187199    return {
     200        'user': user,
    188201        'workouts': workouts,
    189202        'current_month': '{year}-{month}'.format(
Note: See TracChangeset for help on using the changeset viewer.