Beispiel #1
0
    def test_equipmet_cache_update(self):
        '''
        Test that the template cache for the overview is correctly reseted when
        performing certain operations
        '''

        self.assertFalse(
            cache.get(get_template_cache_name('equipment-overview', 2)))

        self.client.get(reverse('exercise:equipment:overview'))
        self.client.get(reverse('exercise:exercise:view', kwargs={'id': 2}))

        old_exercise = cache.get(cache_mapper.get_exercise_key(2))
        old_overview = cache.get(
            get_template_cache_name('equipment-overview', 2))

        exercise = Exercise.objects.get(pk=2)
        exercise.name = 'Very cool exercise 2'
        exercise.description = 'New description'
        exercise.equipment.add(Equipment.objects.get(pk=2))
        exercise.save()

        self.assertFalse(
            cache.get(get_template_cache_name('equipment-overview', 2)))

        self.client.get(reverse('exercise:equipment:overview'))
        self.client.get(reverse('exercise:exercise:view', kwargs={'id': 2}))

        new_exercise = cache.get(cache_mapper.get_exercise_key(2))
        new_overview = cache.get(
            get_template_cache_name('equipment-overview', 2))

        self.assertNotEqual(old_exercise.name, new_exercise.name)
        self.assertNotEqual(old_overview, new_overview)
Beispiel #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 = cache.get(cache_mapper.get_exercise_key(int(id)))
    if not exercise:
        exercise = get_object_or_404(Exercise, pk=id)
        cache.set(cache_mapper.get_exercise_key(exercise), exercise)

    template_data['exercise'] = exercise

    # Create the backgrounds that show what muscles the exercise works on
    backgrounds = cache.get(cache_mapper.get_exercise_muscle_bg_key(int(id)))
    if not backgrounds:
        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')
        backgrounds = (backgrounds_front, backgrounds_back)

        cache.set(cache_mapper.get_exercise_muscle_bg_key(int(id)),
                  (backgrounds_front, backgrounds_back))

    template_data['muscle_backgrounds_front'] = backgrounds[0]
    template_data['muscle_backgrounds_back'] = backgrounds[1]

    # 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():
        logs = WorkoutLog.objects.filter(user=request.user, exercise=exercise)
        entry_log, chart_data = 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")

    return render(request, 'exercise/view.html', template_data)
Beispiel #3
0
    def test_equipmet_cache_update(self):
        '''
        Test that the template cache for the overview is correctly reseted when
        performing certain operations
        '''

        self.assertFalse(cache.get(get_template_cache_name('equipment-overview', 2)))

        self.client.get(reverse('exercise:equipment:overview'))
        self.client.get(reverse('exercise:exercise:view', kwargs={'id': 2}))

        old_exercise = cache.get(cache_mapper.get_exercise_key(2))
        old_overview = cache.get(get_template_cache_name('equipment-overview', 2))

        exercise = Exercise.objects.get(pk=2)
        exercise.name = 'Very cool exercise 2'
        exercise.description = 'New description'
        exercise.equipment.add(Equipment.objects.get(pk=2))
        exercise.save()

        self.assertFalse(cache.get(get_template_cache_name('equipment-overview', 2)))

        self.client.get(reverse('exercise:equipment:overview'))
        self.client.get(reverse('exercise:exercise:view', kwargs={'id': 2}))

        new_exercise = cache.get(cache_mapper.get_exercise_key(2))
        new_overview = cache.get(get_template_cache_name('equipment-overview', 2))

        self.assertNotEqual(old_exercise.name, new_exercise.name)
        self.assertNotEqual(old_overview, new_overview)
Beispiel #4
0
    def test_overview_cache_update(self):
        """
        Test that the template cache for the overview is correctly reseted when
        performing certain operations
        """
        self.assertFalse(cache.get(cache_mapper.get_exercise_key(2)))
        self.assertFalse(cache.get(cache_mapper.get_exercise_muscle_bg_key(2)))
        self.assertFalse(cache.get(get_template_cache_name("muscle-overview", 2)))
        self.assertFalse(cache.get(get_template_cache_name("muscle-overview-mobile", 2)))
        self.assertFalse(cache.get(get_template_cache_name("muscle-overview-search", 2)))
        self.assertFalse(cache.get(get_template_cache_name("exercise-overview", 2)))
        self.assertFalse(cache.get(get_template_cache_name("exercise-detail-header", 2, 2)))
        self.assertFalse(cache.get(get_template_cache_name("exercise-detail-muscles", 2, 2)))

        self.client.get(reverse("exercise:exercise:overview"))
        self.client.get(reverse("exercise:exercise:view", kwargs={"id": 2}))

        old_exercise = cache.get(cache_mapper.get_exercise_key(2))
        old_exercise_bg = cache.get(cache_mapper.get_exercise_muscle_bg_key(2))
        old_muscle_overview = cache.get(get_template_cache_name("muscle-overview", 2))
        old_exercise_overview = cache.get(get_template_cache_name("exercise-overview", 2))
        old_exercise_overview_mobile = cache.get(get_template_cache_name("exercise-overview-mobile", 2))
        old_detail_header = cache.get(get_template_cache_name("exercise-detail-header", 2, 2))
        old_detail_muscles = cache.get(get_template_cache_name("exercise-detail-muscles", 2, 2))

        exercise = Exercise.objects.get(pk=2)
        exercise.name = "Very cool exercise 2"
        exercise.description = "New description"
        exercise.muscles_secondary.add(Muscle.objects.get(pk=2))
        exercise.save()

        self.assertFalse(cache.get(cache_mapper.get_exercise_key(2)))
        self.assertFalse(cache.get(cache_mapper.get_exercise_muscle_bg_key(2)))
        self.assertFalse(cache.get(get_template_cache_name("muscle-overview", 2)))
        self.assertFalse(cache.get(get_template_cache_name("exercise-overview", 2)))
        self.assertFalse(cache.get(get_template_cache_name("exercise-overview-mobile", 2)))
        self.assertFalse(cache.get(get_template_cache_name("exercise-detail-header", 2, 2)))
        self.assertFalse(cache.get(get_template_cache_name("exercise-detail-muscles", 2, 2)))

        self.client.get(reverse("exercise:exercise:overview"))
        self.client.get(reverse("exercise:muscle:overview"))
        self.client.get(reverse("exercise:exercise:view", kwargs={"id": 2}))

        new_exercise = cache.get(cache_mapper.get_exercise_key(2))
        new_exercise_bg = cache.get(cache_mapper.get_exercise_muscle_bg_key(2))
        new_muscle_overview = cache.get(get_template_cache_name("muscle-overview", 2))
        new_exercise_overview = cache.get(get_template_cache_name("exercise-overview", 2))
        new_exercise_overview_mobile = cache.get(get_template_cache_name("exercise-overview-mobile", 2))
        new_detail_header = cache.get(get_template_cache_name("exercise-detail-header", 2, 2))
        new_detail_muscles = cache.get(get_template_cache_name("exercise-detail-muscles", 2, 2))

        self.assertNotEqual(old_exercise.name, new_exercise.name)
        if not self.is_mobile:
            self.assertNotEqual(old_exercise_bg, new_exercise_bg)
            self.assertNotEqual(old_exercise_overview, new_exercise_overview)
            self.assertNotEqual(old_muscle_overview, new_muscle_overview)
            self.assertNotEqual(old_detail_header, new_detail_header)
            self.assertNotEqual(old_detail_muscles, new_detail_muscles)
        else:
            self.assertNotEqual(old_exercise_overview_mobile, new_exercise_overview_mobile)
Beispiel #5
0
    def delete(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''

        # Cached objects
        cache.delete(cache_mapper.get_exercise_key(self))
        cache.delete(cache_mapper.get_exercise_muscle_bg_key(self))

        # Cached template fragments
        for language in Language.objects.all():
            delete_template_fragment_cache('muscle-overview', language.id)
            delete_template_fragment_cache('exercise-overview', language.id)
            delete_template_fragment_cache('exercise-overview-mobile',
                                           language.id)
            delete_template_fragment_cache('exercise-detail-header', self.id,
                                           language.id)
            delete_template_fragment_cache('exercise-detail-muscles', self.id,
                                           language.id)
            delete_template_fragment_cache('equipment-overview', language.id)

        # Cached workouts
        for set in self.set_set.all():
            reset_workout_canonical_form(set.exerciseday.training.pk)

        super(Exercise, self).delete(*args, **kwargs)
Beispiel #6
0
    def delete(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''

        # Cached objects
        cache.delete(cache_mapper.get_exercise_key(self))
        cache.delete(cache_mapper.get_exercise_muscle_bg_key(self))

        # Cached template fragments
        for language in Language.objects.all():
            delete_template_fragment_cache('muscle-overview', language.id)
            delete_template_fragment_cache('exercise-overview', language.id)
            delete_template_fragment_cache('exercise-overview-mobile', language.id)
            delete_template_fragment_cache('exercise-overview-search', language.id)
            delete_template_fragment_cache('exercise-detail-header', self.id, language.id)
            delete_template_fragment_cache('exercise-detail-muscles', self.id, language.id)
            delete_template_fragment_cache('equipment-overview', language.id)
            delete_template_fragment_cache('equipment-overview-mobile', language.id)

        # Cached workouts
        for set in self.set_set.all():
            reset_workout_canonical_form(set.exerciseday.training.pk)

        super(Exercise, self).delete(*args, **kwargs)
Beispiel #7
0
    def test_overview_cache_update(self):
        '''
        Test that the template cache for the overview is correctly reseted when
        performing certain operations
        '''

        self.client.get(reverse('exercise-overview'))
        self.client.get(reverse('exercise-view', kwargs={'id': 2}))

        old_exercise = cache.get(cache_mapper.get_exercise_key(2))
        old_exercise_bg = cache.get(cache_mapper.get_exercise_muscle_bg_key(2))
        old_muscle_overview = cache.get(get_template_cache_name('muscle-overview', 2))
        old_exercise_overview = cache.get(get_template_cache_name('exercise-overview', 2))
        old_detail_header = cache.get(get_template_cache_name('exercise-detail-header', 2, 2))
        old_detail_muscles = cache.get(get_template_cache_name('exercise-detail-muscles', 2, 2))

        exercise = Exercise.objects.get(pk=2)
        exercise.name = 'Very cool exercise 2'
        exercise.description = 'New description'
        exercise.muscles_secondary.add(Muscle.objects.get(pk=2))
        exercise.save()

        self.assertFalse(cache.get(cache_mapper.get_exercise_key(2)))
        self.assertFalse(cache.get(cache_mapper.get_exercise_muscle_bg_key(2)))
        self.assertFalse(cache.get(get_template_cache_name('muscle-overview', 2)))
        self.assertFalse(cache.get(get_template_cache_name('exercise-overview', 2)))
        self.assertFalse(cache.get(get_template_cache_name('exercise-detail-header', 2, 2)))
        self.assertFalse(cache.get(get_template_cache_name('exercise-detail-muscles', 2, 2)))

        self.client.get(reverse('exercise-overview'))
        self.client.get(reverse('muscle-overview'))
        self.client.get(reverse('exercise-view', kwargs={'id': 2}))

        new_exercise = cache.get(cache_mapper.get_exercise_key(2))
        new_exercise_bg = cache.get(cache_mapper.get_exercise_muscle_bg_key(2))
        new_muscle_overview = cache.get(get_template_cache_name('muscle-overview', 2))
        new_exercise_overview = cache.get(get_template_cache_name('exercise-overview', 2))
        new_detail_header = cache.get(get_template_cache_name('exercise-detail-header', 2, 2))
        new_detail_muscles = cache.get(get_template_cache_name('exercise-detail-muscles', 2, 2))

        self.assertNotEqual(old_exercise.name, new_exercise.name)
        self.assertNotEqual(old_exercise_bg, new_exercise_bg)
        self.assertNotEqual(old_muscle_overview, new_muscle_overview)
        self.assertNotEqual(old_exercise_overview, new_exercise_overview)
        self.assertNotEqual(old_detail_header, new_detail_header)
        self.assertNotEqual(old_detail_muscles, new_detail_muscles)
Beispiel #8
0
    def test_equipmet_cache_update(self):
        """
        Test that the template cache for the overview is correctly reseted when
        performing certain operations
        """

        self.assertFalse(cache.get(get_template_cache_name("equipment-overview", 2)))
        self.assertFalse(cache.get(get_template_cache_name("equipment-overview-mobile", 2)))
        self.assertFalse(cache.get(get_template_cache_name("exercise-overview-search", 2)))

        self.client.get(reverse("equipment-overview"))
        self.client.get(reverse("exercise-view", kwargs={"id": 2}))

        old_exercise = cache.get(cache_mapper.get_exercise_key(2))
        old_overview = cache.get(get_template_cache_name("equipment-overview", 2))
        old_overview_mobile = cache.get(get_template_cache_name("equipment-overview-mobile", 2))
        old_search = cache.get(get_template_cache_name("exercise-overview-search", 2))

        exercise = Exercise.objects.get(pk=2)
        exercise.name = "Very cool exercise 2"
        exercise.description = "New description"
        exercise.equipment.add(Equipment.objects.get(pk=2))
        exercise.save()

        self.assertFalse(cache.get(get_template_cache_name("equipment-overview", 2)))
        self.assertFalse(cache.get(get_template_cache_name("equipment-overview-mobile", 2)))
        self.assertFalse(cache.get(get_template_cache_name("exercise-overview-search", 2)))

        self.client.get(reverse("equipment-overview"))
        self.client.get(reverse("exercise-view", kwargs={"id": 2}))

        new_exercise = cache.get(cache_mapper.get_exercise_key(2))
        new_overview = cache.get(get_template_cache_name("equipment-overview", 2))
        new_overview_mobile = cache.get(get_template_cache_name("equipment-overview-mobile", 2))
        new_search = cache.get(get_template_cache_name("exercise-overview-search", 2))

        self.assertNotEqual(old_exercise.name, new_exercise.name)
        if not self.is_mobile:
            self.assertNotEqual(old_overview, new_overview)
        else:
            self.assertNotEqual(old_overview_mobile, new_overview_mobile)
            self.assertNotEqual(old_search, new_search)
Beispiel #9
0
    def delete(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''

        # Cached objects
        cache.delete(cache_mapper.get_exercise_key(self))
        cache.delete(cache_mapper.get_exercise_muscle_bg_key(self))

        # Cached template fragments
        delete_template_fragment_cache('muscle-overview', self.language_id)
        delete_template_fragment_cache('exercise-overview', self.language_id)
        delete_template_fragment_cache('exercise-detail-heder', self.language_id)
        delete_template_fragment_cache('exercise-detail-muscles', self.language_id)

        super(Exercise, self).delete(*args, **kwargs)
Beispiel #10
0
def view(request, id, slug=None):
    '''
    Detail view for an exercise
    '''

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

    # Load the exercise itself
    exercise = cache.get(cache_mapper.get_exercise_key(int(id)))
    if not exercise:
        exercise = get_object_or_404(Exercise, pk=id)
        cache.set(cache_mapper.get_exercise_key(exercise), exercise)

    template_data['exercise'] = exercise

    # Create the backgrounds that show what muscles the exercise works on
    backgrounds = cache.get(cache_mapper.get_exercise_muscle_bg_key(int(id)))
    if not backgrounds:
        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')
        backgrounds = (backgrounds_front, backgrounds_back)

        cache.set(cache_mapper.get_exercise_muscle_bg_key(int(id)),
                  (backgrounds_front, backgrounds_back))

    template_data['muscle_backgrounds_front'] = backgrounds[0]
    template_data['muscle_backgrounds_back'] = backgrounds[1]

    # 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():
        logs = WorkoutLog.objects.filter(user=request.user, exercise=exercise)
        entry_log, chart_data = 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")

    return render(request, 'exercise/view.html', template_data)
Beispiel #11
0
    def test_overview_cache_update(self):
        '''
        Test that the template cache for the overview is correctly reseted when
        performing certain operations
        '''
        self.assertFalse(cache.get(cache_mapper.get_exercise_key(2)))
        self.assertFalse(cache.get(cache_mapper.get_exercise_muscle_bg_key(2)))
        self.assertFalse(
            cache.get(get_template_cache_name('muscle-overview', 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('muscle-overview-mobile', 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('muscle-overview-search', 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('exercise-overview', 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('exercise-detail-header', 2, 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('exercise-detail-muscles', 2,
                                              2)))

        self.client.get(reverse('exercise-overview'))
        self.client.get(reverse('exercise-view', kwargs={'id': 2}))

        old_exercise = cache.get(cache_mapper.get_exercise_key(2))
        old_exercise_bg = cache.get(cache_mapper.get_exercise_muscle_bg_key(2))
        old_muscle_overview = cache.get(
            get_template_cache_name('muscle-overview', 2))
        old_exercise_overview = cache.get(
            get_template_cache_name('exercise-overview', 2))
        old_exercise_overview_mobile = cache.get(
            get_template_cache_name('exercise-overview-mobile', 2))
        old_exercise_overview_search = cache.get(
            get_template_cache_name('exercise-overview-search', 2))
        old_detail_header = cache.get(
            get_template_cache_name('exercise-detail-header', 2, 2))
        old_detail_muscles = cache.get(
            get_template_cache_name('exercise-detail-muscles', 2, 2))

        exercise = Exercise.objects.get(pk=2)
        exercise.name = 'Very cool exercise 2'
        exercise.description = 'New description'
        exercise.muscles_secondary.add(Muscle.objects.get(pk=2))
        exercise.save()

        self.assertFalse(cache.get(cache_mapper.get_exercise_key(2)))
        self.assertFalse(cache.get(cache_mapper.get_exercise_muscle_bg_key(2)))
        self.assertFalse(
            cache.get(get_template_cache_name('muscle-overview', 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('exercise-overview', 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('exercise-overview-mobile', 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('exercise-overview-search', 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('exercise-detail-header', 2, 2)))
        self.assertFalse(
            cache.get(get_template_cache_name('exercise-detail-muscles', 2,
                                              2)))

        self.client.get(reverse('exercise-overview'))
        self.client.get(reverse('muscle-overview'))
        self.client.get(reverse('exercise-view', kwargs={'id': 2}))

        new_exercise = cache.get(cache_mapper.get_exercise_key(2))
        new_exercise_bg = cache.get(cache_mapper.get_exercise_muscle_bg_key(2))
        new_muscle_overview = cache.get(
            get_template_cache_name('muscle-overview', 2))
        new_exercise_overview = cache.get(
            get_template_cache_name('exercise-overview', 2))
        new_exercise_overview_mobile = cache.get(
            get_template_cache_name('exercise-overview-mobile', 2))
        new_exercise_overview_search = cache.get(
            get_template_cache_name('exercise-overview-search', 2))
        new_detail_header = cache.get(
            get_template_cache_name('exercise-detail-header', 2, 2))
        new_detail_muscles = cache.get(
            get_template_cache_name('exercise-detail-muscles', 2, 2))

        self.assertNotEqual(old_exercise.name, new_exercise.name)
        if not self.is_mobile:
            self.assertNotEqual(old_exercise_bg, new_exercise_bg)
            self.assertNotEqual(old_exercise_overview, new_exercise_overview)
            self.assertNotEqual(old_muscle_overview, new_muscle_overview)
            self.assertNotEqual(old_detail_header, new_detail_header)
            self.assertNotEqual(old_detail_muscles, new_detail_muscles)
        else:
            self.assertNotEqual(old_exercise_overview_mobile,
                                new_exercise_overview_mobile)
            self.assertNotEqual(old_exercise_overview_search,
                                new_exercise_overview_search)