Deep audit identified 106 findings; 102 fixed, 4 deferred. Covers 8 areas: - Settings & deploy: env-gated DEBUG/SECRET_KEY, HTTPS headers, gunicorn, celery worker - Auth (registered_user): password write_only, request.data fixes, transaction safety, proper HTTP status codes - Workout app: IDOR protection, get_object_or_404, prefetch_related N+1 fixes, transaction.atomic - Video/scripts: path traversal sanitization, HLS trigger guard, auth on cache wipe - Models (exercise/equipment/muscle/superset): null-safe __str__, stable IDs, prefetch support - Generator views: helper for registered_user lookup, logger.exception, bulk_update, transaction wrapping - Generator core (rules/selector/generator): push-pull ratio, type affinity normalization, modality checks, side-pair exact match, word-boundary regex, equipment cache clearing - Generator services (plan_builder/analyzer/normalizer): transaction.atomic, muscle cache, bulk_update, glutes classification fix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
99 lines
3.5 KiB
Python
99 lines
3.5 KiB
Python
from django.db import models
|
|
from django.conf import settings
|
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
|
|
|
|
|
DIFFICULTY_CHOICES = [
|
|
('beginner', 'Beginner'),
|
|
('intermediate', 'Intermediate'),
|
|
('advanced', 'Advanced'),
|
|
]
|
|
|
|
TIER_CHOICES = [
|
|
('primary', 'Primary'),
|
|
('secondary', 'Secondary'),
|
|
('accessory', 'Accessory'),
|
|
]
|
|
|
|
IMPACT_CHOICES = [
|
|
('none', 'None'),
|
|
('low', 'Low'),
|
|
('medium', 'Medium'),
|
|
('high', 'High'),
|
|
]
|
|
|
|
STRETCH_POSITION_CHOICES = [
|
|
('lengthened', 'Lengthened'),
|
|
('mid', 'Mid-range'),
|
|
('shortened', 'Shortened'),
|
|
]
|
|
|
|
|
|
# Create your models here.
|
|
class Exercise(models.Model):
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
name = models.CharField(max_length=512, default='')
|
|
description = models.CharField(null=True, blank=True, max_length=1024)
|
|
side = models.CharField(null=True, blank=True, max_length=64)
|
|
is_two_dumbbells = models.BooleanField(default=False)
|
|
is_trackable_distance = models.BooleanField(default=False)
|
|
is_alternating = models.BooleanField(default=False)
|
|
is_weight = models.BooleanField(default=False)
|
|
is_distance = models.BooleanField(default=False)
|
|
is_duration = models.BooleanField(default=False)
|
|
is_reps = models.BooleanField(default=False)
|
|
joints_used = models.CharField(null=True, blank=True, max_length=255)
|
|
movement_patterns = models.CharField(null=True, blank=True, max_length=255)
|
|
equipment_required = models.CharField(null=True, blank=True, max_length=255)
|
|
muscle_groups = models.CharField(null=True, blank=True, max_length=255)
|
|
synonyms = models.CharField(null=True, blank=True, max_length=255)
|
|
estimated_rep_duration = models.FloatField(null=True, blank=True)
|
|
video_override = models.CharField(null=True, blank=True, max_length=255)
|
|
|
|
# New fields for workout generation quality
|
|
is_compound = models.BooleanField(default=False)
|
|
difficulty_level = models.CharField(
|
|
max_length=16, choices=DIFFICULTY_CHOICES, null=True, blank=True
|
|
)
|
|
exercise_tier = models.CharField(
|
|
max_length=16, choices=TIER_CHOICES, null=True, blank=True
|
|
)
|
|
complexity_rating = models.IntegerField(
|
|
null=True, blank=True,
|
|
validators=[MinValueValidator(1), MaxValueValidator(5)]
|
|
)
|
|
hr_elevation_rating = models.IntegerField(
|
|
null=True, blank=True,
|
|
validators=[MinValueValidator(1), MaxValueValidator(10)]
|
|
)
|
|
impact_level = models.CharField(
|
|
max_length=8, choices=IMPACT_CHOICES, null=True, blank=True
|
|
)
|
|
stretch_position = models.CharField(
|
|
max_length=16, choices=STRETCH_POSITION_CHOICES, null=True, blank=True
|
|
)
|
|
progression_of = models.ForeignKey(
|
|
'self', null=True, blank=True, on_delete=models.SET_NULL,
|
|
related_name='progressions'
|
|
)
|
|
|
|
class Meta:
|
|
ordering = ('name',)
|
|
|
|
def __str__(self):
|
|
return (self.name or 'Unnamed') + " --------- " + (self.description or "NA")
|
|
|
|
def video_url(self):
|
|
if self.video_override is not None and len(self.video_override) > 0:
|
|
return '/media/videos/'+ self.video_override +'_720p.m3u8'
|
|
else:
|
|
name = (self.name or '').replace(" ", "_")
|
|
name = name.replace("'", "")
|
|
return '/media/hls/'+ name + ".mp4" +'_720p.m3u8'
|
|
|
|
def audio_url(self):
|
|
return "/media/exercise_audio/" + (self.name or '').replace(" ", "_") + ".m4a"
|
|
|
|
def transition_url(self):
|
|
return "/media/transitions_audio/" + self.name.replace(" ", "_") + ".m4a" |