Exemplo n.º 1
0
    def delete(self, *args, **kwargs):
        """
        Reset all cached infos
        """
        for language in Language.objects.all():
            delete_template_fragment_cache('exercise-overview', language.id)

        super(ExerciseCategory, self).delete(*args, **kwargs)
Exemplo n.º 2
0
def reset_muscle_cache(sender, instance, **kwargs):
    exercises = Exercise.objects.filter(Q(muscles=instance) | Q(muscles_secondary=instance)).all()
    languages = Language.objects.all()

    for exercise in exercises:
        for language in languages:
            delete_template_fragment_cache('exercise-detail-muscles',
                                           exercise.id, language.id)
Exemplo n.º 3
0
    def delete(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''
        for language in Language.objects.all():
            delete_template_fragment_cache('exercise-overview', language.id)
            delete_template_fragment_cache('exercise-overview-mobile', language.id)

        super(ExerciseCategory, self).delete(*args, **kwargs)
Exemplo n.º 4
0
    def save(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''

        super(ExerciseCategory, self).save(*args, **kwargs)

        # Cached template fragments
        for language in Language.objects.all():
            delete_template_fragment_cache('exercise-overview', language.id)
            delete_template_fragment_cache('exercise-overview-mobile', language.id)
Exemplo n.º 5
0
    def delete(self, *args, **kwargs):
        """
        Reset all cached infos
        """

        # Cached objects
        cache.delete(cache_mapper.get_language_config_key(self.language, self.item))

        # Cached template fragments
        delete_template_fragment_cache("muscle-overview", self.language_id)
        delete_template_fragment_cache("exercise-overview", self.language_id)

        super(LanguageConfig, self).delete(*args, **kwargs)
Exemplo n.º 6
0
    def save(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''

        super(LanguageConfig, self).save(*args, **kwargs)

        # Cached objects
        cache.delete(cache_mapper.get_language_config_key(self.language, self.item))

        # Cached template fragments
        delete_template_fragment_cache('muscle-overview', self.language_id)
        delete_template_fragment_cache('exercise-overview', self.language_id)
Exemplo n.º 7
0
    def delete(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''

        # Cached objects
        cache.delete(cache_mapper.get_language_config_key(self.language, self.item))

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

        super(LanguageConfig, self).delete(*args, **kwargs)
Exemplo n.º 8
0
    def save(self, *args, **kwargs):
        '''
        Only one image can be marked as main picture at a time
        '''
        if self.is_main:
            ExerciseImage.objects.filter(exercise=self.exercise).update(is_main=False)
            self.is_main = True
        else:
            if ExerciseImage.objects.accepted().filter(exercise=self.exercise).count() == 0 \
               or not ExerciseImage.objects.accepted() \
                            .filter(exercise=self.exercise, is_main=True)\
                            .count():
                self.is_main = True

        #
        # Reset all cached infos
        #
        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('equipment-overview', language.id)

        # And go on
        super(ExerciseImage, self).save(*args, **kwargs)
Exemplo n.º 9
0
    def delete(self, *args, **kwargs):
        """
        Reset all cached infos
        """
        super(ExerciseImage, self).delete(*args, **kwargs)

        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('equipment-overview', language.id)

        # Make sure there is always a main image
        if not ExerciseImage.objects.accepted() \
                .filter(exercise=self.exercise, is_main=True).count() \
           and ExerciseImage.objects.accepted() \
                .filter(exercise=self.exercise) \
                .filter(is_main=False) \
                .count():

            image = ExerciseImage.objects.accepted() \
                .filter(exercise=self.exercise, is_main=False)[0]
            image.is_main = True
            image.save()
Exemplo n.º 10
0
    def save(self, *args, **kwargs):
        """
        Only one image can be marked as main picture at a time
        """
        if self.is_main:
            ExerciseImage.objects.filter(exercise=self.exercise).update(
                is_main=False)
            self.is_main = True
        else:
            if ExerciseImage.objects.accepted().filter(exercise=self.exercise).count() == 0 \
               or not ExerciseImage.objects.accepted() \
                            .filter(exercise=self.exercise, is_main=True)\
                            .count():
                self.is_main = True

        #
        # Reset all cached infos
        #
        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('equipment-overview', language.id)

        # And go on
        super(ExerciseImage, self).save(*args, **kwargs)
Exemplo n.º 11
0
    def handle(self, *args, **options):
        '''
        Process the options
        '''

        if (not options['clear_template'] and not options['clear_workout']
                and not options['clear_all']):
            raise CommandError(
                'Please select what cache you need to delete, see help')

        # Exercises, cached template fragments
        if options['clear_template']:
            if int(options['verbosity']) >= 2:
                self.stdout.write("*** Clearing templates")

            for user in User.objects.all():
                if int(options['verbosity']) >= 2:
                    self.stdout.write("* Processing user {0}".format(
                        user.username))

                for entry in WorkoutLog.objects.filter(user=user).dates(
                        'date', 'year'):

                    if int(options['verbosity']) >= 3:
                        self.stdout.write("  Year {0}".format(entry.year))
                    for month in WorkoutLog.objects.filter(
                            user=user,
                            date__year=entry.year).dates('date', 'month'):
                        if int(options['verbosity']) >= 3:
                            self.stdout.write("    Month {0}".format(
                                entry.month))
                        reset_workout_log(user.id, entry.year, entry.month)
                        for day in WorkoutLog.objects.filter(
                                user=user,
                                date__year=entry.year,
                                date__month=month.month).dates('date', 'day'):
                            if int(options['verbosity']) >= 3:
                                self.stdout.write("      Day {0}".format(
                                    day.day))
                            reset_workout_log(user.id, entry.year, entry.month,
                                              day)

            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('equipment-overview',
                                               language.id)

        # Workout canonical form
        if options['clear_workout']:
            for w in Workout.objects.all():
                reset_workout_canonical_form(w.pk)

        # Nuclear option, clear all
        if options['clear_all']:
            cache.clear()
Exemplo n.º 12
0
def delete_muscle_cache(sender, instance, **kwargs):
    '''
    Delete the cache when delete and save actiona are performed on the
    muscle model.
    '''
    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('equipment-overview', language.id)
Exemplo n.º 13
0
    def handle(self, *args, **options):
        '''
        Process the options
        '''

        if (not options['clear_template']
                and not options['clear_workout']
                and not options['clear_all']):
            raise CommandError('Please select what cache you need to delete, see help')

        # Exercises, cached template fragments
        if options['clear_template']:
            if int(options['verbosity']) >= 2:
                self.stdout.write("*** Clearing templates")

            for user in User.objects.all():
                if int(options['verbosity']) >= 2:
                    self.stdout.write("* Processing user {0}".format(user.username))

                for entry in WorkoutLog.objects.filter(user=user).dates('date', 'year'):

                    if int(options['verbosity']) >= 3:
                        self.stdout.write("  Year {0}".format(entry.year))
                    for month in WorkoutLog.objects.filter(user=user,
                                                           date__year=entry.year).dates('date',
                                                                                        'month'):
                        if int(options['verbosity']) >= 3:
                            self.stdout.write("    Month {0}".format(entry.month))
                        reset_workout_log(user.id, entry.year, entry.month)
                        for day in WorkoutLog.objects.filter(user=user,
                                                             date__year=entry.year,
                                                             date__month=month.month).dates('date',
                                                                                            'day'):
                            if int(options['verbosity']) >= 3:
                                self.stdout.write("      Day {0}".format(day.day))
                            reset_workout_log(user.id, entry.year, entry.month, day)

            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('equipment-overview', language.id)

        # Workout canonical form
        if options['clear_workout']:
            for w in Workout.objects.all():
                reset_workout_canonical_form(w.pk)

        # Nuclear option, clear all
        if options['clear_all']:
            cache.clear()
Exemplo n.º 14
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)
Exemplo n.º 15
0
    def delete(self, *args, **kwargs):
        """
        Reset cached information on delete
        """
        for language in Language.objects.all():
            delete_template_fragment_cache('muscle-overview', language.id)
            delete_template_fragment_cache('equipment-overview', language.id)
            delete_template_fragment_cache('exercise-overview', language.id)
            delete_template_fragment_cache('exercise-overview-mobile',
                                           language.id)

        exercise_container = Exercise.objects.filter(muscles=self).iterator()
        for exercise in exercise_container:
            cache.delete(cache_mapper.get_exercise_muscle_bg_key(exercise.pk))
            for set in exercise.set_set.all():
                reset_workout_canonical_form(set.exerciseday.training.pk)

        super(Muscle, self).delete(*args, **kwargs)
Exemplo n.º 16
0
    def delete(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''

        # Cached objects
        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('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)
Exemplo n.º 17
0
    def delete(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''

        # Cached objects
        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('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)
Exemplo n.º 18
0
    def save(self, *args, **kwargs):
        """
        Reset all cached infos
        """
        self.name = smart_capitalize(self.name_original)
        super(Exercise, self).save(*args, **kwargs)

        # Cached objects
        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('equipment-overview', language.id)

        # Cached workouts
        for set in self.set_set.all():
            reset_workout_canonical_form(set.exerciseday.training_id)
Exemplo n.º 19
0
    def delete(self, *args, **kwargs):
        """
        Reset all cached infos
        """

        # 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('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)
Exemplo n.º 20
0
    def delete(self, *args, **kwargs):
        '''
        Reset all cached infos
        '''
        super(ExerciseImage, self).delete(*args, **kwargs)

        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('equipment-overview', language.id)

        # Make sure there is always a main image
        if not ExerciseImage.objects.accepted() \
                .filter(exercise=self.exercise, is_main=True).count() \
           and ExerciseImage.objects.accepted() \
                .filter(exercise=self.exercise) \
                .filter(is_main=False) \
                .count():

                image = ExerciseImage.objects.accepted() \
                    .filter(exercise=self.exercise, is_main=False)[0]
                image.is_main = True
                image.save()
Exemplo n.º 21
0
def reset_day_template_cache(day_id):
    delete_template_fragment_cache('day-view', day_id)
Exemplo n.º 22
0
    def handle(self, *args, **options):
        '''
        Process the options
        '''

        if not options['clear_template'] and not options['clear_workout']:
            raise CommandError('Please select what cache you need to delete, see help')

        # Exercises, cached template fragments
        if options['clear_template']:
            for user in User.objects.all():
                for entry in WorkoutLog.objects.dates('date', 'year'):
                    for month in range(1, 13):
                        # print("User {0}, year {1}, month {2}".format(user.pk, entry.year, month))
                        reset_workout_log(user.id, entry.year, month)

            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('equipment-overview', language.id)

            for language in Language.objects.all():
                for exercise in Exercise.objects.all():
                    delete_template_fragment_cache('exercise-detail-header',
                                                   exercise.id,
                                                   language.id)
                    delete_template_fragment_cache('exercise-detail-muscles',
                                                   exercise.id,
                                                   language.id)
        # Workout canonical form
        if options['clear_workout']:
            for w in Workout.objects.all():
                reset_workout_canonical_form(w.pk)
Exemplo n.º 23
0
    def handle(self, *args, **options):
        '''
        Process the options
        '''

        if not options['clear_template'] and not options['clear_workout']:
            raise CommandError('Please select what cache you need to delete, see help')

        # Exercises, cached template fragments
        if options['clear_template']:
            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('equipment-overview', language.id)

            for language in Language.objects.all():
                for exercise in Exercise.objects.all():
                    delete_template_fragment_cache('exercise-detail-header',
                                                   exercise.id,
                                                   language.id)
                    delete_template_fragment_cache('exercise-detail-muscles',
                                                   exercise.id,
                                                   language.id)
        # Workout canonical form
        if options['clear_workout']:
            for w in Workout.objects.all():
                reset_workout_canonical_form(w.pk)