diff --git a/poetry.lock b/poetry.lock index 0101d17..276da8d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -91,6 +91,14 @@ sqlparse = ">=0.2.2" argon2 = ["argon2-cffi (>=16.1.0)"] bcrypt = ["bcrypt"] +[[package]] +name = "django-crispy-forms" +version = "1.10.0" +description = "Best way to have Django DRY forms" +category = "main" +optional = false +python-versions = ">=3.5" + [[package]] name = "filelock" version = "3.0.12" @@ -294,7 +302,7 @@ testing = ["coverage (>=4)", "coverage-enable-subprocess (>=1)", "flaky (>=3)", [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "c30849d31e4af28a2048d39ee36777d08501143c80e1fd08fa2f1c04108a92ce" +content-hash = "cdf8eea1e8834cd9a055fdbb2d4d4edf58111c8666e92542f4e6f2e0359bc499" [metadata.files] appdirs = [ @@ -365,6 +373,10 @@ django = [ {file = "Django-3.1.3-py3-none-any.whl", hash = "sha256:14a4b7cd77297fba516fc0d92444cc2e2e388aa9de32d7a68d4a83d58f5a4927"}, {file = "Django-3.1.3.tar.gz", hash = "sha256:14b87775ffedab2ef6299b73343d1b4b41e5d4e2aa58c6581f114dbec01e3f8f"}, ] +django-crispy-forms = [ + {file = "django-crispy-forms-1.10.0.tar.gz", hash = "sha256:d3f808d20cafe20fd38a49a47e72db1fd519fcf31bef4f47f008619336a3ebff"}, + {file = "django_crispy_forms-1.10.0-py3-none-any.whl", hash = "sha256:92ed3fdc52c08d21d60adbb9de24e432c590e66e894f43cee0974fc959209976"}, +] filelock = [ {file = "filelock-3.0.12-py3-none-any.whl", hash = "sha256:929b7d63ec5b7d6b71b0fa5ac14e030b3f70b75747cef1b10da9b879fef15836"}, {file = "filelock-3.0.12.tar.gz", hash = "sha256:18d82244ee114f543149c66a6e0c14e9c4f8a1044b5cdaadd0f82159d6a6ff59"}, diff --git a/pyproject.toml b/pyproject.toml index 4958ae1..c05c58a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ authors = ["Gabriel Augendre "] [tool.poetry.dependencies] python = "^3.9" Django = "^3.1.3" +django-crispy-forms = "^1.10.0" [tool.poetry.dev-dependencies] pytest = "^6.1" diff --git a/src/exercises/admin.py b/src/exercises/admin.py index 9c2c6e7..e2f2363 100644 --- a/src/exercises/admin.py +++ b/src/exercises/admin.py @@ -12,3 +12,5 @@ class BodyRegionAdmin(admin.ModelAdmin): @register(Exercise) class ExerciseAdmin(admin.ModelAdmin): list_display = ["name", "get_body_regions", "rating"] + list_filter = ["body_regions", "rating"] + search_fields = ["name"] diff --git a/src/exercises/forms.py b/src/exercises/forms.py index 109b5ec..508375c 100644 --- a/src/exercises/forms.py +++ b/src/exercises/forms.py @@ -1,13 +1,33 @@ from django import forms +from django.core.validators import MinValueValidator + +from exercises.models import BodyRegion, Exercise class QueryForm(forms.Form): CARDIO_CHOICE = "cardio" STRENGTHENING_CHOICE = "strengthening" BALANCED_CHOICE = "balanced" + EVERYTHING_CHOICE = "everything" RATING_CHOICES = [ (CARDIO_CHOICE, "Cardio"), (STRENGTHENING_CHOICE, "Strengthening"), (BALANCED_CHOICE, "Balanced"), + (EVERYTHING_CHOICE, "Everything"), ] - rating = forms.ChoiceField(choices=RATING_CHOICES, widget=forms.RadioSelect) + rating = forms.ChoiceField( + choices=RATING_CHOICES, + widget=forms.RadioSelect, + initial=EVERYTHING_CHOICE, + label="Catégorie", + ) + body_regions = forms.ModelMultipleChoiceField( + BodyRegion.objects.filter( + id__in=Exercise.objects.values_list("body_regions", flat=True).distinct() + ).order_by("name"), + required=False, + label="Région du corps", + ) + number_of_exercises = forms.IntegerField( + validators=[MinValueValidator(1)], initial=5, label="Nombre" + ) diff --git a/src/exercises/static/exercises/style.css b/src/exercises/static/exercises/style.css new file mode 100644 index 0000000..e69de29 diff --git a/src/exercises/templates/exercises/base.html b/src/exercises/templates/exercises/base.html index 6311ac0..96e656e 100644 --- a/src/exercises/templates/exercises/base.html +++ b/src/exercises/templates/exercises/base.html @@ -1,12 +1,20 @@ +{% load static %} - + + + {% block title %}{% endblock %} -{% block content %} -{% endblock %} +
+ {% block content %} + {% endblock %} +
diff --git a/src/exercises/templates/exercises/exercise_list.html b/src/exercises/templates/exercises/exercise_list.html index bd9b1f6..d45c0b6 100644 --- a/src/exercises/templates/exercises/exercise_list.html +++ b/src/exercises/templates/exercises/exercise_list.html @@ -1,16 +1,23 @@ {% extends "exercises/base.html" %} +{% load crispy_forms_filters %} + {% block title %} - Random exercises + Exercices {% endblock %} {% block content %} -

Random exercises

-