Changeset 42baca4 in OpenWorkouts-current for ow/views/workout.py
- Timestamp:
- Apr 22, 2019, 6:14:53 PM (5 years ago)
- Branches:
- current
- Children:
- 0dedfbe
- Parents:
- e52a502
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/views/workout.py
re52a502 r42baca4 89 89 form = Form(request, schema=UploadedWorkoutSchema()) 90 90 91 duplicate = None 92 allow_duplicates = request.POST.get('allow_duplicates') == 'on' 93 91 94 if 'submit' in request.POST and form.validate(): 92 95 # Grab some information from the tracking file … … 98 101 # Add basic info gathered from the file 99 102 workout.load_from_file() 100 # Add the workout 101 context.add_workout(workout) 102 return HTTPFound(location=request.resource_url(workout)) 103 # Ensure this workout is not a duplicate of an existing workout. 104 # 105 # hashed is not "complete" for a workout that has not been added 106 # yet, as it does not have the owner set, so we have to "build it" 107 hashed = str(context.uid) + workout.hashed 108 duplicate = request.root.get_workout_by_hash(hashed) 109 110 if duplicate and not allow_duplicates: 111 form.errors['tracking_file'] = _( 112 'This workout looks like a duplicate of another workout, ' 113 'please enable workout duplicates below to save it' 114 ) 115 else: 116 # Add the workout 117 context.add_workout(workout) 118 return HTTPFound(location=request.resource_url(workout)) 103 119 104 120 return { 105 'form': FormRenderer(form) 121 'form': FormRenderer(form), 122 'duplicate': duplicate 106 123 } 107 124
Note: See TracChangeset
for help on using the changeset viewer.