def save_exercise(request, post_data=None): post_data = post_data or {} # save_exercise_to_amazon(post_data) ExerciseCacher.update_cache_with_exercise(post_data) Tokenizer.bust_cache() Exercise.rebuild() updated_exercises = ExerciseCacher().exercises DynamoClient().save_exercises(updated_exercises) return render_to_json({}, status=204)
def save_exercise_to_amazon(exercise_json): if _no_save_necessary(exercise_json): return with CloudSearchIndexer.for_domain_index( settings.AWS_CLOUDSEARCH_INDEX) as indexer: exercise_doc = ExerciseDocument(exercise_json) indexer.add_document(exercise_doc) print "Finished adding document to AWS" ExerciseCacher.update_cache_with_exercise(exercise_json) print "Finished updating Exercise cache" Tokenizer.bust_cache() print "Finished busting Tokenizer cache" Exercise.rebuild() print "Finished rebuilding Exercise Filter"
def _no_save_necessary(exercise_json): exercise_id = exercise_json["id"] exercise = Exercise.get_by_id(exercise_id) needs_save = False for attr in exercise_json.keys(): if getattr(exercise, attr) != exercise_json[attr]: needs_save = True return not needs_save
def muscle(request, muscle_name): muscle_id = MuscleGroup.get_id_from_canonical(muscle_name) muscle_name = MuscleGroup.get_name_for_id(muscle_id) exercises = sorted(list(Exercise().for_muscle_group(muscle_id).query), key=lambda e: e.name) render_data = { "muscle_name": muscle_name, "exercises": exercises, } return global_render_to_response("basic_navigation/muscle_group.html", render_data)
def _get_grouped_exercises(): muscle_name_to_exercises = {} list_of_sets = MuscleGroup.get_rings() for muscle_group_id_set in list_of_sets: for muscle_group_id in muscle_group_id_set: muscle_name = MuscleGroup.get_name_for_id(muscle_group_id) exercises = sorted(list( Exercise().for_muscle_group(muscle_group_id).query), key=lambda e: e.name) if exercises: muscle_name_to_exercises[muscle_name] = exercises return muscle_name_to_exercises
def exercise(request, exercise_name): exercise = Exercise.get_by_canonical_name(exercise_name) render_data = { 'exercise': exercise, 'equipment_names': [ Equipment.get_name_for_id(equipment_id) for equipment_id in exercise.equipment_ids ], 'exercise_types': [ ExerciseType.get_name_for_id(exercise_type_id) for exercise_type_id in exercise.exercise_type_ids ], "primary_muscle_group": MuscleGroup.get_name_for_id(exercise.muscle_group_id) } return global_render_to_response("basic_navigation/exercise.html", render_data)
def home(request): exercise_json = Exercise().as_json() JSContext = { 'exercises': exercise_json, 'equipment': sorted(Equipment.as_json(), key=lambda d: d['title']), 'muscle_groups': sorted(MuscleGroup.as_json(), key=lambda d: d['title']), 'phases': sorted(Phase.as_json(), key=lambda p: p['title']), 'workout_components': sorted(WorkoutComponent.as_json(), key=lambda w: w['title']), 'exercise_types': sorted(ExerciseType.as_json(), key=lambda d: d['title']) } render_data = { "grouped_exercises": _get_grouped_exercises(), "admin": request.GET.get("god_mode", "") == "yesplease", "JSContext": json.dumps(JSContext) } return global_render_to_response( "basic_navigation/search_engine_content.html", render_data)