コード例 #1
0
ファイル: log.py プロジェクト: seraphyn/wger
    def get_context_data(self, **kwargs):

        # Call the base implementation first to get a context
        context = super(WorkoutLogDetailView, self).get_context_data(**kwargs)

        # Prepare the entries for rendering and the D3 chart
        workout_log = {}
        entry = WorkoutLog()

        for day in self.object.day_set.select_related():
            workout_log[day] = {}

            for set in day.set_set.select_related():
                exercise_log = {}

                for exercise in set.exercises.select_related():
                    exercise_log[exercise] = []
                    logs = exercise.workoutlog_set.filter(user=self.request.user)
                    entry_log, chart_data = entry.process_log_entries(logs)
                    if entry_log:
                        exercise_log[exercise].append(entry_log)

                    if exercise_log:
                        workout_log[day][exercise] = {}
                        workout_log[day][exercise]['log_by_date'] = entry_log
                        workout_log[day][exercise]['div_uuid'] = str(uuid.uuid4())
                        workout_log[day][exercise]['chart_data'] = chart_data

        context['workout_log'] = workout_log
        context['reps'] = _("Reps")

        return context
コード例 #2
0
def view(request, id, slug=None):
    '''
    Detail view for an exercise
    '''

    template_data = {}
    template_data['comment_edit'] = False

    # Load the exercise itself
    exercise = get_object_or_404(Exercise, pk=id)
    template_data['exercise'] = exercise

    # Create the backgrounds that show what muscles the exercise works on
    backgrounds_back = []
    backgrounds_front = []

    for muscle in exercise.muscles.all():
        if muscle.is_front:
            backgrounds_front.append('images/muscles/main/muscle-%s.svg' %
                                     muscle.id)
        else:
            backgrounds_back.append('images/muscles/main/muscle-%s.svg' %
                                    muscle.id)

    for muscle in exercise.muscles_secondary.all():
        if muscle.is_front:
            backgrounds_front.append('images/muscles/secondary/muscle-%s.svg' %
                                     muscle.id)
        else:
            backgrounds_back.append('images/muscles/secondary/muscle-%s.svg' %
                                    muscle.id)

    # Append the "main" background, with the silhouette of the human body
    # This has to happen as the last step, so it is rendered behind the muscles.
    backgrounds_front.append('images/muscles/muscular_system_front.svg')
    backgrounds_back.append('images/muscles/muscular_system_back.svg')

    template_data['muscle_backgrounds_front'] = backgrounds_front
    template_data['muscle_backgrounds_back'] = backgrounds_back

    # If the user is logged in, load the log and prepare the entries for
    # rendering in the D3 chart
    entry_log = []
    chart_data = []
    if request.user.is_authenticated():
        entry = WorkoutLog()
        logs = WorkoutLog.objects.filter(user=request.user, exercise=exercise)
        entry_log, chart_data = entry.process_log_entries(logs)

    template_data['logs'] = entry_log
    template_data['json'] = chart_data
    template_data['svg_uuid'] = str(uuid.uuid4())
    template_data['reps'] = _("Reps")

    # Render
    return render_to_response('view.html',
                              template_data,
                              context_instance=RequestContext(request))
コード例 #3
0
ファイル: exercises.py プロジェクト: seraphyn/wger
def view(request, id, slug=None):
    '''
    Detail view for an exercise
    '''

    template_data = {}
    template_data['comment_edit'] = False

    # Load the exercise itself
    exercise = get_object_or_404(Exercise, pk=id)
    template_data['exercise'] = exercise

    # Create the backgrounds that show what muscles the exercise works on
    backgrounds_back = []
    backgrounds_front = []

    for muscle in exercise.muscles.all():
        if muscle.is_front:
            backgrounds_front.append('images/muscles/main/muscle-%s.svg' % muscle.id)
        else:
            backgrounds_back.append('images/muscles/main/muscle-%s.svg' % muscle.id)

    for muscle in exercise.muscles_secondary.all():
        if muscle.is_front:
            backgrounds_front.append('images/muscles/secondary/muscle-%s.svg' % muscle.id)
        else:
            backgrounds_back.append('images/muscles/secondary/muscle-%s.svg' % muscle.id)

    # Append the "main" background, with the silhouette of the human body
    # This has to happen as the last step, so it is rendered behind the muscles.
    backgrounds_front.append('images/muscles/muscular_system_front.svg')
    backgrounds_back.append('images/muscles/muscular_system_back.svg')

    template_data['muscle_backgrounds_front'] = backgrounds_front
    template_data['muscle_backgrounds_back'] = backgrounds_back

    # If the user is logged in, load the log and prepare the entries for
    # rendering in the D3 chart
    entry_log = []
    chart_data = []
    if request.user.is_authenticated():
        entry = WorkoutLog()
        logs = WorkoutLog.objects.filter(user=request.user, exercise=exercise)
        entry_log, chart_data = entry.process_log_entries(logs)

    template_data['logs'] = entry_log
    template_data['json'] = chart_data
    template_data['svg_uuid'] = str(uuid.uuid4())
    template_data['reps'] = _("Reps")

    # Render
    return render_to_response('view.html',
                              template_data,
                              context_instance=RequestContext(request))