diff --git a/db.sqlite3 b/db.sqlite3 index a2ae44a3236ea3f403046c24a13c11707437cea7..d5b662d186ea31f45cd6375642f024d3033c0174 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/gymapp/__pycache__/__init__.cpython-310.pyc b/gymapp/__pycache__/__init__.cpython-310.pyc index 666bc96845a78c21461322770bea24690e4245b1..3833fda7aa71c02fbf6a2ee5ce1796a67d79985f 100644 Binary files a/gymapp/__pycache__/__init__.cpython-310.pyc and b/gymapp/__pycache__/__init__.cpython-310.pyc differ diff --git a/homeapp/__pycache__/views.cpython-310.pyc b/homeapp/__pycache__/views.cpython-310.pyc index 296d724deed4184ab577fec37c9696ee0262889b..09dbb128bc8dbc41d6f7d9720ebc17eb4555af0d 100644 Binary files a/homeapp/__pycache__/views.cpython-310.pyc and b/homeapp/__pycache__/views.cpython-310.pyc differ diff --git a/homeapp/views.py b/homeapp/views.py index 755b80b39db60f48801a66ae954e7b8d7b6633f9..36cb6d6cdc0d591e2c292c8c0608e3fba2cf1f76 100644 --- a/homeapp/views.py +++ b/homeapp/views.py @@ -20,7 +20,7 @@ def contact(request): email = form.cleaned_data['email'] message = name + ':\n' + form.cleaned_data['message'] try: - send_mail(subject, message, email, ['My']) + send_mail(subject, message, email, ['so00647@surrey.ac.uk']) except BadHeaderError(): messages.add_message(request, messages.ERROR, 'Message Not Sent') return HttpResponse("Invalid header found.") diff --git a/trackerapp/__pycache__/__init__.cpython-310.pyc b/trackerapp/__pycache__/__init__.cpython-310.pyc index 0c449de316b3bc65bf9e830342afd4b0cacc069c..bac0ff2dcbb91cddd76e660d5aac835a9a52a5ca 100644 Binary files a/trackerapp/__pycache__/__init__.cpython-310.pyc and b/trackerapp/__pycache__/__init__.cpython-310.pyc differ diff --git a/trackerapp/__pycache__/forms.cpython-310.pyc b/trackerapp/__pycache__/forms.cpython-310.pyc index ae2d0dccf51ddb69661e5ddd3c76e22b54dd4013..f573af21cdd39d7f8960202a925d191d1ef09332 100644 Binary files a/trackerapp/__pycache__/forms.cpython-310.pyc and b/trackerapp/__pycache__/forms.cpython-310.pyc differ diff --git a/trackerapp/__pycache__/models.cpython-310.pyc b/trackerapp/__pycache__/models.cpython-310.pyc index 84a554fa244aa1015b3c056792967e49b856c177..63a4c3db3074499e3a56b54077552cbe540696eb 100644 Binary files a/trackerapp/__pycache__/models.cpython-310.pyc and b/trackerapp/__pycache__/models.cpython-310.pyc differ diff --git a/trackerapp/__pycache__/urls.cpython-310.pyc b/trackerapp/__pycache__/urls.cpython-310.pyc index f76da26aef7da98c7da2ef0a91c6b10cb51e9a40..2b9b011d2fd7ed51da148659cb42df4f0a0bd526 100644 Binary files a/trackerapp/__pycache__/urls.cpython-310.pyc and b/trackerapp/__pycache__/urls.cpython-310.pyc differ diff --git a/trackerapp/__pycache__/views.cpython-310.pyc b/trackerapp/__pycache__/views.cpython-310.pyc index 313c61e74036e97eedfeae17dcbc06946de4d98e..e6deb63d294d9e91c5c811c1526e55996016638e 100644 Binary files a/trackerapp/__pycache__/views.cpython-310.pyc and b/trackerapp/__pycache__/views.cpython-310.pyc differ diff --git a/trackerapp/forms.py b/trackerapp/forms.py index 4160775610c7544f9c956e3ae2339d907eef602e..35603d0bef9c12b7194b9c3e5d6986914f358d18 100644 --- a/trackerapp/forms.py +++ b/trackerapp/forms.py @@ -1,5 +1,5 @@ from django import forms -from .models import Plan, Workout +from .models import Plan, Workout, Exercise # plan form creation class PlanForm(forms.ModelForm): @@ -28,17 +28,48 @@ class WorkoutForm(forms.ModelForm): class Meta: model = Workout - weekdays = forms.MultipleChoiceField(choices = Workout.WEEK_DAYS, - widget = forms.RadioSelect(attrs={ - 'class' : 'formfield'})) + weekday = forms.ChoiceField(widget=forms.Select(choices=Workout.WEEKDAYS)) - fields = ['name', 'weekdays'] + fields = ['name', 'weekday', 'plan'] widgets = { 'name' : forms.TextInput(attrs={ 'class' : 'formfield', 'placeholder' : 'Workout Name', - }), + }), + 'plan' : forms.HiddenInput(), } - + +# exercise form creation + class ExerciseForm(forms.ModelForm): + + #Meta Class + class Meta: + model = Exercise + type = forms.ChoiceField(widget=forms.Select(choices=Exercise.TYPES)) + fields = ['name', 'type', 'set_repCount', 'workingWeight', 'workingTime', 'restTime', 'workout'] + + widgets = { + 'name' : forms.TextInput(attrs={ + 'class' : 'formfield', + 'placeholder' : 'Exercise Name', + }), + 'set_repCount' : forms.TextInput(attrs={ + 'class' : 'formfield', + 'placeholder' : 'e.g. 100kg, 100lbs(Optional)', + }), + 'workingWeight' : forms.TextInput(attrs={ + 'class' : 'formfield', + 'placeholder' : 'Format: "Set Number"x"Rep Number e.g. 5x5"(Optional)', + }), + 'workingTime' : forms.TimeInput(attrs={ + 'class' : 'formfield', + 'placeholder' : 'Format: minutes:seconds(Optional)', + }), + 'restTime' : forms.TimeInput(attrs={ + 'class' : 'formfield', + 'placeholder' : 'Format: minutes:seconds(Optional)', + }), + 'workout' : forms.HiddenInput() + } \ No newline at end of file diff --git a/trackerapp/management/commands/__pycache__/seed.cpython-310.pyc b/trackerapp/management/commands/__pycache__/seed.cpython-310.pyc index 5a480b20af26037ff28f9985ee4a5db6866ec3cb..1dc651e47c81ce702750d584ce88c67b94d1884b 100644 Binary files a/trackerapp/management/commands/__pycache__/seed.cpython-310.pyc and b/trackerapp/management/commands/__pycache__/seed.cpython-310.pyc differ diff --git a/trackerapp/management/commands/seed.py b/trackerapp/management/commands/seed.py index ec869503ef27cc37d492ba5bae93a2e57078b9ff..99fbf995661c109a7b44d894709ea428dd34c354 100644 --- a/trackerapp/management/commands/seed.py +++ b/trackerapp/management/commands/seed.py @@ -5,9 +5,9 @@ class Command(BaseCommand): def handle(self, *args, **options): Plan.objects.all().delete() - p = Plan(name = "Full Body", description = "A quicker workout covering all muscle groups for people with less time") + p = Plan(name = "Full Body", description = "A quicker workout covering all muscle groups") p.save() - p = Plan(name = "PPL", description = "A higher volume workout that focuses on different muscle groups per day") + p = Plan(name = "PPL", description = "A higher volume workout that focuses on specific muscle groups") p.save() self.stdout.write('Done') \ No newline at end of file diff --git a/trackerapp/migrations/0006_exercise_remove_workout_weekdays_workout_plan_and_more.py b/trackerapp/migrations/0006_exercise_remove_workout_weekdays_workout_plan_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..063e36f8766cbed0507fc367c25416032fceb623 --- /dev/null +++ b/trackerapp/migrations/0006_exercise_remove_workout_weekdays_workout_plan_and_more.py @@ -0,0 +1,41 @@ +# Generated by Django 4.1.3 on 2022-12-05 16:01 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('trackerapp', '0005_alter_plan_name'), + ] + + operations = [ + migrations.CreateModel( + name='Exercise', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=128)), + ('type', models.CharField(choices=[('resistance', 'Resistance'), ('mobility', 'Mobility'), ('cardio', 'Cardio')], default='resistance', max_length=10)), + ('set_repCount', models.CharField(blank=True, max_length=3)), + ('workingWeight', models.CharField(blank=True, max_length=16)), + ('workingTime', models.DurationField(blank=True)), + ('restTime', models.DurationField(blank=True)), + ], + ), + migrations.RemoveField( + model_name='workout', + name='weekdays', + ), + migrations.AddField( + model_name='workout', + name='plan', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.PROTECT, to='trackerapp.plan'), + preserve_default=False, + ), + migrations.AlterField( + model_name='workout', + name='name', + field=models.CharField(max_length=128, unique=True), + ), + ] diff --git a/trackerapp/migrations/0007_workout_weekday.py b/trackerapp/migrations/0007_workout_weekday.py new file mode 100644 index 0000000000000000000000000000000000000000..5ab3e4dce987af3eface3da14b3b0137bffcb4ba --- /dev/null +++ b/trackerapp/migrations/0007_workout_weekday.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.3 on 2022-12-05 16:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('trackerapp', '0006_exercise_remove_workout_weekdays_workout_plan_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='workout', + name='weekday', + field=models.CharField(choices=[('monday', 'Monday'), ('tuesday', 'Tuesday'), ('wednesday', 'Wednesday'), ('thursday', 'Thursday'), ('friday', 'Friday'), ('saturday', 'Saturday'), ('sunday', 'Sunday')], default='monday', max_length=9), + ), + ] diff --git a/trackerapp/migrations/0008_alter_workout_plan_alter_workout_weekday.py b/trackerapp/migrations/0008_alter_workout_plan_alter_workout_weekday.py new file mode 100644 index 0000000000000000000000000000000000000000..d2ee5aeac116f60351fc010880bebc1a23c795b4 --- /dev/null +++ b/trackerapp/migrations/0008_alter_workout_plan_alter_workout_weekday.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1.3 on 2022-12-06 04:19 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('trackerapp', '0007_workout_weekday'), + ] + + operations = [ + migrations.AlterField( + model_name='workout', + name='plan', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='trackerapp.plan'), + ), + migrations.AlterField( + model_name='workout', + name='weekday', + field=models.CharField(choices=[('Monday', 'Monday'), ('Tuesday', 'Tuesday'), ('Wednesday', 'Wednesday'), ('Thursday', 'Thursday'), ('Friday', 'Friday'), ('Saturday', 'Saturday'), ('Sunday', 'Sunday')], default='monday', max_length=9), + ), + ] diff --git a/trackerapp/migrations/0009_exercise_workout.py b/trackerapp/migrations/0009_exercise_workout.py new file mode 100644 index 0000000000000000000000000000000000000000..b7942aaacefba86690b3a3bb59933fff1e3975d0 --- /dev/null +++ b/trackerapp/migrations/0009_exercise_workout.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.3 on 2022-12-06 04:22 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('trackerapp', '0008_alter_workout_plan_alter_workout_weekday'), + ] + + operations = [ + migrations.AddField( + model_name='exercise', + name='workout', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='trackerapp.workout'), + preserve_default=False, + ), + ] diff --git a/trackerapp/migrations/0010_alter_exercise_name.py b/trackerapp/migrations/0010_alter_exercise_name.py new file mode 100644 index 0000000000000000000000000000000000000000..2a5d61ed83379902dd114c9e5a07ecdefac3cb21 --- /dev/null +++ b/trackerapp/migrations/0010_alter_exercise_name.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.3 on 2022-12-06 04:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('trackerapp', '0009_exercise_workout'), + ] + + operations = [ + migrations.AlterField( + model_name='exercise', + name='name', + field=models.CharField(max_length=128, unique=True), + ), + ] diff --git a/trackerapp/migrations/0011_alter_exercise_type.py b/trackerapp/migrations/0011_alter_exercise_type.py new file mode 100644 index 0000000000000000000000000000000000000000..8bc15ab2be823db8ad9cdfe003234c98780823ab --- /dev/null +++ b/trackerapp/migrations/0011_alter_exercise_type.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.3 on 2022-12-06 12:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('trackerapp', '0010_alter_exercise_name'), + ] + + operations = [ + migrations.AlterField( + model_name='exercise', + name='type', + field=models.CharField(choices=[('Resistance', 'Resistance'), ('Mobility', 'Mobility'), ('Cardio', 'Cardio')], default='resistance', max_length=10), + ), + ] diff --git a/trackerapp/migrations/__pycache__/0006_exercise_remove_workout_weekdays_workout_plan_and_more.cpython-310.pyc b/trackerapp/migrations/__pycache__/0006_exercise_remove_workout_weekdays_workout_plan_and_more.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6d0553fc8166fd910d80efcb61f492d79a3e0626 Binary files /dev/null and b/trackerapp/migrations/__pycache__/0006_exercise_remove_workout_weekdays_workout_plan_and_more.cpython-310.pyc differ diff --git a/trackerapp/migrations/__pycache__/0007_workout_weekday.cpython-310.pyc b/trackerapp/migrations/__pycache__/0007_workout_weekday.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d29a94683d9107e0311c23c5b4a0421e7eb9800b Binary files /dev/null and b/trackerapp/migrations/__pycache__/0007_workout_weekday.cpython-310.pyc differ diff --git a/trackerapp/migrations/__pycache__/0008_alter_workout_plan_alter_workout_weekday.cpython-310.pyc b/trackerapp/migrations/__pycache__/0008_alter_workout_plan_alter_workout_weekday.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b1eb6894533d82c573e5c5d2ed9a0986690b2969 Binary files /dev/null and b/trackerapp/migrations/__pycache__/0008_alter_workout_plan_alter_workout_weekday.cpython-310.pyc differ diff --git a/trackerapp/migrations/__pycache__/0009_exercise_workout.cpython-310.pyc b/trackerapp/migrations/__pycache__/0009_exercise_workout.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..40a258db8a6c32e10134faeafa44c23d5d160e90 Binary files /dev/null and b/trackerapp/migrations/__pycache__/0009_exercise_workout.cpython-310.pyc differ diff --git a/trackerapp/migrations/__pycache__/0010_alter_exercise_name.cpython-310.pyc b/trackerapp/migrations/__pycache__/0010_alter_exercise_name.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bcee5c3aa51b06319a1f2662fb6c243842ceab07 Binary files /dev/null and b/trackerapp/migrations/__pycache__/0010_alter_exercise_name.cpython-310.pyc differ diff --git a/trackerapp/migrations/__pycache__/0011_alter_exercise_type.cpython-310.pyc b/trackerapp/migrations/__pycache__/0011_alter_exercise_type.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0d0d8988bf8a3cc51b70bf5a6bb84d1aee8a3f03 Binary files /dev/null and b/trackerapp/migrations/__pycache__/0011_alter_exercise_type.cpython-310.pyc differ diff --git a/trackerapp/models.py b/trackerapp/models.py index 89f86e16ec7accc8f4e92363e0701f664f03ca42..5a40d9fd7dba15acda480fd86d5c3ef746081397 100644 --- a/trackerapp/models.py +++ b/trackerapp/models.py @@ -1,27 +1,53 @@ from django.db import models class Plan(models.Model): - name = models.CharField(max_length = 128, unique = True) + name = models.CharField(max_length = 128, + unique = True, + blank = False) description = models.TextField() class Meta: indexes = [models.Index(fields=['name']),] class Workout(models.Model): - WEEK_DAYS = ( - ("monday", "Monday"), - ("tuesday", "Tuesday"), - ("wednesday", "Wednesday"), - ("thursday", "Thursday"), - ("friday", "Friday"), - ("saturday", "Saturday"), - ("sunday", "Saturday"), + + WEEKDAYS = ( + ("Monday", "Monday"), + ("Tuesday", "Tuesday"), + ("Wednesday", "Wednesday"), + ("Thursday", "Thursday"), + ("Friday", "Friday"), + ("Saturday", "Saturday"), + ("Sunday", "Sunday"), ) - name = models.CharField(max_length = 128) - weekdays = models.CharField(max_length = 9, - choices = WEEK_DAYS, - default = "monday") + name = models.CharField(max_length = 128, + unique = True, + blank = False) + weekday = models.CharField(max_length = 9, + choices = WEEKDAYS, + default = "monday") + plan = models.ForeignKey(Plan, on_delete=models.CASCADE) + +class Exercise(models.Model): + TYPES = ( + ("Resistance", "Resistance"), + ("Mobility", "Mobility"), + ("Cardio", "Cardio"), + ) + + name = models.CharField(max_length = 128, + unique = True, + blank = False) + type = models.CharField(max_length = 10, + choices = TYPES, + default = "resistance") + set_repCount = models.CharField(max_length = 3, blank=True) + workingWeight = models.CharField(max_length = 16, blank=True) + workingTime = models.DurationField(blank=True) + restTime = models.DurationField(blank=True) + workout = models.ForeignKey(Workout, on_delete=models.CASCADE) + diff --git a/trackerapp/templates/trackerapp/detail_view.html b/trackerapp/templates/trackerapp/detail_view.html index 7f0bcdda6d3648d13a1773cd806647e40b77d855..c489f0b9f109c6e76a32128677c6d8bbb641b8d2 100644 --- a/trackerapp/templates/trackerapp/detail_view.html +++ b/trackerapp/templates/trackerapp/detail_view.html @@ -1,11 +1,15 @@ {% extends "base.html" %} {% block content %} <body> + <h2>{{ plan.name }}</h2> <p> {{ plan.description }}</p> <input type="button" onclick="location.href='{% url 'tracker_update' plan.id %}';" value="Edit" /> <input type="button" onclick="location.href='{% url 'tracker_delete' plan.id %}';" value="Delete" /> + <hr/> + {% include 'trackerapp/workouts_index.html' with pid=plan.id%} + <input type="button" onclick="location.href='{% url 'workouts_new' pid=plan.id %}';" value="Add Workout"/> </body> {% endblock content %} \ No newline at end of file diff --git a/trackerapp/templates/trackerapp/index.html b/trackerapp/templates/trackerapp/index.html index 9a98660f9794dbf3a388ce18cb1785cfb83eea78..f0b1ecf5f965c95bb4ffaedae13510d0bd2ad151 100644 --- a/trackerapp/templates/trackerapp/index.html +++ b/trackerapp/templates/trackerapp/index.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends "base.html" %} {% block content %} <h2>Workout Plans</h2> <table> @@ -14,11 +14,11 @@ </a> </td> <td> - {{ plan.description | truncatechars:25}} + {{ plan.description | truncatechars:128}} </td> </tr> {% endfor %} </table> <input type="button" - onclick="location.href='{% url 'tracker_new' %}';" value="New"/> + onclick="location.href='{% url 'tracker_new' %}';" value="Create new workout plan"/> {% endblock content %} \ No newline at end of file diff --git a/trackerapp/templates/trackerapp/workouts_create_view.html b/trackerapp/templates/trackerapp/workouts_create_view.html new file mode 100644 index 0000000000000000000000000000000000000000..f203ac01a3698d78b52658ae47b59016c80e4dbf --- /dev/null +++ b/trackerapp/templates/trackerapp/workouts_create_view.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% block content %} +<h2>Enter a new workout</h2> +<form method="POST" enctype="multipart/form-data"> + <!-- Security token --> + {% csrf_token %} + <!-- Using the formset --> + {{ form.as_p }} + <input type="submit" value="Submit"> +</form> +{% endblock content %} diff --git a/trackerapp/templates/trackerapp/workouts_detail_view.html b/trackerapp/templates/trackerapp/workouts_detail_view.html new file mode 100644 index 0000000000000000000000000000000000000000..c6f3eb6df00223219578d5cb211d08683ccf2eaf --- /dev/null +++ b/trackerapp/templates/trackerapp/workouts_detail_view.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% block content %} + <body> + <h2>{{ plan.name }}</h2> + <h3>{{ workout.name }}</h3> + <p> {{ workout.weekday }}</p> + <input type="button" onclick="location.href='{% url 'workouts_update' wid=workout.id %}';" + value="Edit" /> + <input type="button" onclick="location.href='{% url 'workouts_delete' wid=workout.id %}';" + value="Delete" /> + <hr/> + + </body> +{% endblock content %} \ No newline at end of file diff --git a/trackerapp/templates/trackerapp/workouts_index.html b/trackerapp/templates/trackerapp/workouts_index.html new file mode 100644 index 0000000000000000000000000000000000000000..ea68a2cb9d51f5a93d7f2415a2de47c8facf3872 --- /dev/null +++ b/trackerapp/templates/trackerapp/workouts_index.html @@ -0,0 +1,19 @@ +<h2>Workouts List</h2> +<table> + <tr> + <th>Name</th> + <th>Week Day</th> + </tr> + {% for workout in workout_list %} + <tr> + <td> + <a href="{% url 'workouts_detail' workout.id %}"> + {{ workout.name }} + </a> + </td> + <td> + {{ workout.weekday }} + </td> + </tr> + {% endfor %} +</table> \ No newline at end of file diff --git a/trackerapp/templates/trackerapp/workouts_update_view.html b/trackerapp/templates/trackerapp/workouts_update_view.html new file mode 100644 index 0000000000000000000000000000000000000000..3a6aeb029eb62913eca9d75f08e0f4643e6ae2aa --- /dev/null +++ b/trackerapp/templates/trackerapp/workouts_update_view.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% block content %} +<h2>Update your workout</h2> +<form method="POST" enctype="multipart/form-data"> + <!-- Security token --> + {% csrf_token %} + <!-- Using the formset --> + {{ form.as_p }} + <input type="submit" value="Update"> +</form> +{% endblock content %} \ No newline at end of file diff --git a/trackerapp/tests.py b/trackerapp/tests.py index 4e86396b5cf4f66ab6bb332214bf0ef605cc744d..681a5b6279495bf552da6d1b85412f11da06de83 100644 --- a/trackerapp/tests.py +++ b/trackerapp/tests.py @@ -2,7 +2,9 @@ from django.db.backends.sqlite3.base import IntegrityError from django.db import transaction from django.test import TestCase from django.urls import reverse -from .models import Plan +from .models import Plan, Workout +from .forms import WorkoutForm + class PlanTests(TestCase): @classmethod @@ -37,4 +39,22 @@ class PlanTests(TestCase): } response = self.client.post(reverse('tracker_new'), data=data) print(db_count) - self.assertEqual(Plan.objects.count(), db_count+1) \ No newline at end of file + self.assertEqual(Plan.objects.count(), db_count+1) + + def test_post_create_workout(self): + data = { + "name" : "Full Body 1", + "weekday" : "Monday", + "plan" : Plan.objects.get(pk=1) + } + form = WorkoutForm(data) + self.assertTrue(form.is_valid()) + + def test_post_create_empty_workout(self): + data = { + "name" : "", + "weekday" : "Monday", + "plan" : Plan.objects.get(pk=1) + } + form = WorkoutForm(data) + self.assertFalse(form.is_valid()) \ No newline at end of file diff --git a/trackerapp/urls.py b/trackerapp/urls.py index 6ed0a93f789e9eb2c0ff2c20a142e3774d97d11f..8391decb6380b0e21c181dccc6733a2e77879967 100644 --- a/trackerapp/urls.py +++ b/trackerapp/urls.py @@ -2,14 +2,29 @@ from django.urls import path from . import views urlpatterns = [ - # workout lists + # workout plan lists path('', views.index_view, name='tracker_index'), + # workout plan details (shows list of workouts over the course of a week) + path('<int:pk>', views.PlanDetailView, name='tracker_detail'), + # create new workout plans + path('new', views.create_view, name='tracker_new'), + # edit workout plans + path('<int:pid>/edit', views.update_view, name='tracker_update'), + # delete workout plans + path('<int:pid>/delete', views.delete_view, name='tracker_delete'), + # view individual workouts + path('<int:pid>/workouts', views.WorkoutListView, name='workouts_index'), # workout details (shows list of exercises) - path('<int:nid>', views.detail_view, name='tracker_detail'), + path('workouts/<int:wid>', views.WorkoutDetailView, name='workouts_detail'), # create new workouts - path('new', views.create_view, name='tracker_new'), - # edit workouts - path('edit/<int:nid>', views.update_view, name='tracker_update'), + path('<int:pid>/workouts/new', views.CreateWorkoutsView, name='workouts_new'), + # update new workouts + path('workouts/<int:wid>/edit', views.UpdateWorkoutsView, name='workouts_update'), # delete workouts - path('delete/<int:nid>', views.delete_view, name='tracker_delete'), + path('workouts/<int:wid>/delete', views.DeleteWorkoutView, name='workouts_delete'), + # exercise list + # exercise details + # create new exercise + # edit exercise + # delete exercise ] diff --git a/trackerapp/views.py b/trackerapp/views.py index e5dc45a5f0f92b85a98fbeb1294503d6e592a5e0..5ce11938c36e1655455685b1316cd45d28b6b1d7 100644 --- a/trackerapp/views.py +++ b/trackerapp/views.py @@ -1,5 +1,6 @@ from django.shortcuts import get_object_or_404, render, redirect from django.http import HttpResponse +from django.urls import reverse_lazy from django.contrib import messages from .forms import PlanForm, WorkoutForm from .models import Plan, Workout @@ -10,11 +11,23 @@ def index_view(request): context["plan_list"] = Plan.objects.all() return render(request, "trackerapp/index.html", context) -def detail_view(request, nid): +def WorkoutListView(request, pid): context = {} - context["plan"] = get_object_or_404(Plan, pk=nid) + context["workout_list"] = Workout.objects.filter(plan__id=pid) + return render(request, "trackerapp/workouts_index.html", context) + +def PlanDetailView(request, pk): + context = {} + context["plan"] = Plan.objects.get(id=pk) + context["workout_list"] = Workout.objects.filter(plan__id=pk) return render(request, "trackerapp/detail_view.html", context) +def WorkoutDetailView(request, wid): + context = {} + context["plan"] = Plan.objects.all() + context["workout"] = Workout.objects.get(id=wid) + return render(request, "trackerapp/workouts_detail_view.html", context) + def create_view(request): context = {} form = PlanForm(request.POST or None) @@ -29,21 +42,54 @@ def create_view(request): context['form'] = form return render(request, "trackerapp/create_view.html", context) -def update_view(request, nid): +def CreateWorkoutsView(request, pid): + context = {} + form = WorkoutForm(request.POST or None) + if(request.method == 'POST'): + if(form.is_valid()): + form.save() + return redirect('tracker_detail', pk = pid) + + context['form'] = form + context['form'].fields['plan'].initial = pid + return render(request, "trackerapp/workouts_create_view.html", context) + +def UpdateWorkoutsView(request, wid): context = {} - obj = get_object_or_404(Plan, id = nid) + obj = get_object_or_404(Workout, id = wid) + form = WorkoutForm(request.POST or None, instance = obj) + if(request.method == 'POST'): + if form.is_valid(): + form.save() + messages.add_message(request, messages.SUCCESS, 'Workout Plan Updated') + return redirect('workouts_detail', wid = wid) + + context['form'] = form + return render(request, "trackerapp/workouts_update_view.html", context) + +def update_view(request, pid): + context = {} + obj = get_object_or_404(Plan, id = pid) form = PlanForm(request.POST or None, instance = obj) if form.is_valid(): form.save() messages.add_message(request, messages.SUCCESS, 'Workout Plan Updated') - return redirect('tracker_detail', nid = nid) + return redirect('tracker_detail', pid = pid) context['form'] = form return render(request, "trackerapp/update_view.html", context) -def delete_view(request, nid): - obj = get_object_or_404(Plan, id = nid) +def delete_view(request, pid): + obj = get_object_or_404(Plan, id = pid) obj.delete() messages.add_message(request, messages.SUCCESS, 'Workout Plan Deleted') - return redirect('tracker_index') \ No newline at end of file + return redirect('tracker_index') + +def DeleteWorkoutView(request, wid): + workout = Workout.objects.get(pk=wid) + pid = workout.plan_id + workout.delete() + return redirect('tracker_detail', pid) + + \ No newline at end of file