From be083e81cbeb95321ffa462f4115202e7cefb05d Mon Sep 17 00:00:00 2001 From: Joshua Hairston Date: Thu, 19 Sep 2024 12:25:50 -0400 Subject: [PATCH] black formatted --- config/api_router.py | 17 ++- config/asgi.py | 1 + config/settings/base.py | 1 + config/settings/local.py | 7 +- config/wsgi.py | 1 + teleband/assignments/admin.py | 41 ++++-- teleband/assignments/api/serializers.py | 76 +++++++--- .../0016_alter_activity_part_type.py | 14 +- .../migrations/0017_seed_more_activities.py | 3 +- ...n_part_type_to_assignment_20220617_2211.py | 14 +- .../migrations/0019_add_connect.py | 23 ++- .../migrations/0020_auto_20230408_1952.py | 135 +++++++++++++----- .../migrations/0021_auto_20230517_1130.py | 22 +-- .../0022_move_number_of_submissions.py | 10 +- .../migrations/0023_assignment_piece_plan.py | 13 +- ...4_add_activity_type_and_category_fields.py | 10 +- ...ctivity_type_and_category_20230613_1311.py | 8 +- .../migrations/0026_assignment_piece.py | 15 +- ...grate_piece_to_assignment_20230613_1319.py | 8 +- .../migrations/0028_add_assignment_group.py | 38 +++-- .../migrations/0029_pieceplan_type.py | 6 +- .../0030_alter_assignmentgroup_type.py | 6 +- .../0031_default_piece_plans_20230920_2336.py | 2 +- .../migrations/0032_auto_20240311_1235.py | 62 ++++---- .../migrations/0033_auto_20240312_2321.py | 19 +-- .../migrations/0034_auto_20240315_1547.py | 11 +- .../migrations/0035_dedupe_assignments.py | 33 +++-- ...ignment_unique_assignment_20240320_1310.py | 9 +- teleband/assignments/models.py | 42 +++--- .../0003_set_site_domain_and_name.py | 1 + teleband/courses/admin.py | 1 + teleband/courses/api/views.py | 26 ++-- teleband/courses/helper.py | 46 ++++-- .../migrations/0003_auto_20220110_2052.py | 9 +- .../0006_course_can_edit_instruments.py | 6 +- .../0004_instrument_midi_program_number.py | 26 ++-- teleband/instruments/tests/test_drf_urls.py | 5 +- teleband/musics/api/serializers.py | 8 +- ...011_seed_piece_parts_parttranspositions.py | 4 +- teleband/musics/migrations/0012_piece_slug.py | 6 +- .../migrations/0013_assign_piece_slugs.py | 2 +- .../migrations/0014_alter_piece_slug.py | 6 +- .../migrations/0015_auto_20220206_2027.py | 14 +- .../migrations/0016_seed_pieces_later.py | 3 - .../0017_seed_combined_part_20220720_1413.py | 6 +- .../musics/migrations/0018_seed_more_music.py | 5 +- .../0022_part_chord_scale_pattern.py | 6 +- .../0024_auto_20231030_2217_piece_slugs.py | 3 +- .../migrations/0025_auto_20240223_1015.py | 2 +- .../0026_fix_deep_river_20240315_1420.py | 35 +++-- ..._deep_river_color_pattern_20240317_1712.py | 16 ++- teleband/musics/models.py | 7 +- teleband/submissions/api/serializers.py | 29 +++- .../migrations/0007_auto_20220501_1627.py | 38 +++-- .../0008_alter_submission_assignment.py | 14 +- .../migrations/0009_submission_index.py | 6 +- teleband/submissions/models.py | 4 +- teleband/users/admin.py | 1 + teleband/users/api/views.py | 8 +- ...009_data_migration_teacher_django_group.py | 3 +- .../migrations/0010_alter_user_external_id.py | 13 +- teleband/users/tests/test_forms.py | 1 + teleband/utils/migration_helpers.py | 29 ++-- 63 files changed, 678 insertions(+), 358 deletions(-) diff --git a/config/api_router.py b/config/api_router.py index 8690a70..63fa6c3 100644 --- a/config/api_router.py +++ b/config/api_router.py @@ -6,8 +6,17 @@ from teleband.users.api.views import UserViewSet from teleband.courses.api.views import EnrollmentViewSet, CourseViewSet -from teleband.assignments.api.views import AssignmentViewSet, ActivityViewSet, PiecePlanViewSet -from teleband.submissions.api.views import GradeViewSet, SubmissionViewSet, AttachmentViewSet, TeacherSubmissionViewSet +from teleband.assignments.api.views import ( + AssignmentViewSet, + ActivityViewSet, + PiecePlanViewSet, +) +from teleband.submissions.api.views import ( + GradeViewSet, + SubmissionViewSet, + AttachmentViewSet, + TeacherSubmissionViewSet, +) from teleband.musics.api.views import PieceViewSet from teleband.instruments.api.views import InstrumentViewSet @@ -28,7 +37,9 @@ courses_router = nested_cls(router, "courses", lookup="course_slug") courses_router.register("assignments", AssignmentViewSet) # option basename omitted courses_router.register("activities", ActivityViewSet) # option basename omitted -courses_router.register("submissions", TeacherSubmissionViewSet) # option basename omitted +courses_router.register( + "submissions", TeacherSubmissionViewSet +) # option basename omitted courses_router.register("grades", GradeViewSet) # option basename omitted courses_router.register("piece-plans", PiecePlanViewSet) diff --git a/config/asgi.py b/config/asgi.py index c94ec0a..2d41710 100644 --- a/config/asgi.py +++ b/config/asgi.py @@ -7,6 +7,7 @@ https://docs.djangoproject.com/en/dev/howto/deployment/asgi/ """ + import os import sys from pathlib import Path diff --git a/config/settings/base.py b/config/settings/base.py index dfcefa2..14fe04a 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -1,6 +1,7 @@ """ Base settings to build other settings files upon. """ + from pathlib import Path import environ diff --git a/config/settings/local.py b/config/settings/local.py index ffb2173..297c550 100644 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -61,7 +61,12 @@ # django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup # Your stuff... # CORS_ALLOW_ALL_ORIGINS = True -CORS_ALLOWED_ORIGIN_REGEXES = [r'{}'.format(s) for s in env.list("CORS_ALLOWED_ORIGIN_REGEXES", default=[r"^http://localhost:3000$"])] +CORS_ALLOWED_ORIGIN_REGEXES = [ + r"{}".format(s) + for s in env.list( + "CORS_ALLOWED_ORIGIN_REGEXES", default=[r"^http://localhost:3000$"] + ) +] # CORS_ALLOWED_ORIGIN_REGEXES = [ # r"^http://localhost:3000$", # works for local dev # ] diff --git a/config/wsgi.py b/config/wsgi.py index 41cae32..9a6b69b 100644 --- a/config/wsgi.py +++ b/config/wsgi.py @@ -13,6 +13,7 @@ framework. """ + import os import sys from pathlib import Path diff --git a/teleband/assignments/admin.py b/teleband/assignments/admin.py index 42e2d18..7e93122 100644 --- a/teleband/assignments/admin.py +++ b/teleband/assignments/admin.py @@ -1,9 +1,17 @@ from django.contrib import admin from reversion.admin import VersionAdmin -from .models import ActivityCategory, ActivityType, Activity, \ - Assignment, Curriculum, CurriculumEntry, \ - PiecePlan, PlannedActivity, AssignmentGroup +from .models import ( + ActivityCategory, + ActivityType, + Activity, + Assignment, + Curriculum, + CurriculumEntry, + PiecePlan, + PlannedActivity, + AssignmentGroup, +) @admin.register(ActivityCategory) @@ -47,17 +55,19 @@ class AssignmentAdmin(VersionAdmin): date_hierarchy = "created_at" save_as = True + class PiecePlanActivityInline(admin.TabularInline): model = PlannedActivity extra = 0 ordering = ("order",) + @admin.register(PiecePlan) class PiecePlanAdmin(VersionAdmin): list_display = ( - "id", + "id", "name", - "piece", + "piece", "type", ) list_filter = ( @@ -68,27 +78,28 @@ class PiecePlanAdmin(VersionAdmin): raw_id_fields = ("activities",) save_as = True + class AssignmentInline(admin.TabularInline): model = Assignment extra = 0 ordering = ("-id",) + @admin.register(AssignmentGroup) class AssignmentGroupAdmin(VersionAdmin): list_display = ( - "id", - "type", - ) - list_filter = ( + "id", "type", ) + list_filter = ("type",) inlines = (AssignmentInline,) + # @admin.register(PlannedActivity) # class PlannedActivityAdmin(VersionAdmin): # list_display = ( -# "id", -# "piece_plan", +# "id", +# "piece_plan", # "activity", # "order", # ) @@ -97,18 +108,20 @@ class AssignmentGroupAdmin(VersionAdmin): # "activity", # ) + class CurriculumEntryInline(admin.TabularInline): model = CurriculumEntry extra = 0 ordering = ("order",) + @admin.register(Curriculum) class CurriculumAdmin(VersionAdmin): list_display = ( - "id", + "id", "name", "course", - "ordered", + "ordered", ) list_filter = ( "course", @@ -116,4 +129,4 @@ class CurriculumAdmin(VersionAdmin): ) inlines = (CurriculumEntryInline,) raw_id_fields = ("piece_plans",) - save_as = True \ No newline at end of file + save_as = True diff --git a/teleband/assignments/api/serializers.py b/teleband/assignments/api/serializers.py index f381121..22c73c2 100644 --- a/teleband/assignments/api/serializers.py +++ b/teleband/assignments/api/serializers.py @@ -1,11 +1,21 @@ from rest_framework import serializers -from teleband.assignments.models import Assignment, Activity, ActivityType, AssignmentGroup, PiecePlan +from teleband.assignments.models import ( + Assignment, + Activity, + ActivityType, + AssignmentGroup, + PiecePlan, +) from teleband.courses.api.serializers import EnrollmentSerializer from teleband.instruments.api.serializers import InstrumentSerializer from teleband.submissions.api.serializers import SubmissionSerializer from teleband.utils.serializers import GenericNameSerializer -from teleband.musics.api.serializers import PartTranspositionSerializer, PartSerializer, PieceSerializer +from teleband.musics.api.serializers import ( + PartTranspositionSerializer, + PartSerializer, + PieceSerializer, +) class ActivityTypeSerializer(serializers.ModelSerializer): @@ -32,10 +42,15 @@ class GroupSerializer(serializers.ModelSerializer): def get_members(self, obj): assignments = Assignment.objects.filter(group=obj) assignment_enrollments = [(a, a.enrollment) for a in assignments] - member_list = [{"enrollment_id": ae[1].id, - "enrollment_username": ae[1].user.username, - "activity_type_name": ae[0].activity.activity_type_name, - "assignment_submitted": bool(ae[0].submissions.count())} for ae in assignment_enrollments] + member_list = [ + { + "enrollment_id": ae[1].id, + "enrollment_username": ae[1].user.username, + "activity_type_name": ae[0].activity.activity_type_name, + "assignment_submitted": bool(ae[0].submissions.count()), + } + for ae in assignment_enrollments + ] return member_list class Meta: @@ -53,7 +68,16 @@ class AssignmentSerializer(serializers.ModelSerializer): class Meta: model = Assignment # fields = ["activity", "deadline", "instrument", "id", "url"] - fields = ["activity", "deadline", "instrument", "part", "id", "enrollment", "submissions", "group"] + fields = [ + "activity", + "deadline", + "instrument", + "part", + "id", + "enrollment", + "submissions", + "group", + ] extra_kwargs = { "url": {"view_name": "api:assignment-detail", "lookup_field": "id"}, @@ -61,23 +85,28 @@ class Meta: # def get_fields(self): # fields = super().get_fields() - # if not self.instance.group: + # if not self.instance.group: # del fields['group'] - # return fields - + # return fields class AssignmentViewSetSerializer(serializers.ModelSerializer): activity = serializers.PrimaryKeyRelatedField(queryset=Activity.objects.all()) - activity_type_name = serializers.CharField(source="activity.activity_type_name", read_only=True) - activity_type_category = serializers.CharField(source="activity.category", read_only=True) + activity_type_name = serializers.CharField( + source="activity.activity_type_name", read_only=True + ) + activity_type_category = serializers.CharField( + source="activity.category", read_only=True + ) activity_body = serializers.CharField(source="activity.body", read_only=True) part_type = serializers.CharField(source="activity.part_type.name", read_only=True) piece_name = serializers.SlugField(source="piece.name", read_only=True) piece_id = serializers.IntegerField(source="piece.id", read_only=True) piece_slug = serializers.SlugField(source="piece.slug", read_only=True) instrument = serializers.CharField(source="instrument.name", read_only=True) - transposition = serializers.CharField(source="instrument.transposition.name", read_only=True) + transposition = serializers.CharField( + source="instrument.transposition.name", read_only=True + ) group = GroupSerializer() # instrument = InstrumentSerializer() part = PartSerializer() @@ -88,8 +117,22 @@ class Meta: model = Assignment # fields = ["activity", "deadline", "instrument", "id", "url"] # fields = ["activity", "deadline", "instrument", "part", "id", "enrollment", "submissions"] - fields = ["id", "activity", "activity_type_name", "activity_type_category", "activity_body", "part_type", - "piece_name", "piece_id", "piece_slug", "instrument", "transposition", "group", "part", "submissions"] + fields = [ + "id", + "activity", + "activity_type_name", + "activity_type_category", + "activity_body", + "part_type", + "piece_name", + "piece_id", + "piece_slug", + "instrument", + "transposition", + "group", + "part", + "submissions", + ] extra_kwargs = { "url": {"view_name": "api:assignment-detail", "lookup_field": "id"}, @@ -116,6 +159,7 @@ class Meta: "url": {"view_name": "api:assignment-detail", "lookup_field": "id"}, } + class PiecePlanSerializer(serializers.ModelSerializer): id = serializers.IntegerField() type = serializers.CharField() @@ -129,4 +173,4 @@ class Meta: # extra_kwargs = { # "url": {"view_name": "api:pieceplan-detail", "lookup_field": "id"}, - # } \ No newline at end of file + # } diff --git a/teleband/assignments/migrations/0016_alter_activity_part_type.py b/teleband/assignments/migrations/0016_alter_activity_part_type.py index 713a04f..9aec693 100644 --- a/teleband/assignments/migrations/0016_alter_activity_part_type.py +++ b/teleband/assignments/migrations/0016_alter_activity_part_type.py @@ -7,14 +7,18 @@ class Migration(migrations.Migration): dependencies = [ - ('musics', '0015_auto_20220206_2027'), - ('assignments', '0015_seed_activities'), + ("musics", "0015_auto_20220206_2027"), + ("assignments", "0015_seed_activities"), ] operations = [ migrations.AlterField( - model_name='activity', - name='part_type', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='musics.parttype'), + model_name="activity", + name="part_type", + field=models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="musics.parttype", + ), ), ] diff --git a/teleband/assignments/migrations/0017_seed_more_activities.py b/teleband/assignments/migrations/0017_seed_more_activities.py index bec2620..00fe98e 100644 --- a/teleband/assignments/migrations/0017_seed_more_activities.py +++ b/teleband/assignments/migrations/0017_seed_more_activities.py @@ -2,6 +2,7 @@ from django.db import migrations + def update_site_forward(apps, schema_editor): """Set site domain and name.""" Activity = apps.get_model("assignments", "Activity") @@ -28,7 +29,7 @@ def update_site_forward(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('assignments', '0016_alter_activity_part_type'), + ("assignments", "0016_alter_activity_part_type"), ] operations = [migrations.RunPython(update_site_forward, migrations.RunPython.noop)] diff --git a/teleband/assignments/migrations/0018_assign_part_type_to_assignment_20220617_2211.py b/teleband/assignments/migrations/0018_assign_part_type_to_assignment_20220617_2211.py index 67fc2d5..12de4e9 100644 --- a/teleband/assignments/migrations/0018_assign_part_type_to_assignment_20220617_2211.py +++ b/teleband/assignments/migrations/0018_assign_part_type_to_assignment_20220617_2211.py @@ -9,18 +9,22 @@ def assign_part_type(apps, schema_editor): ActivityType = apps.get_model("assignments", "ActivityType") PartType = apps.get_model("musics", "PartType") combined_part_type = PartType.objects.get(name="Combined") - record = Activity.objects.get(activity_type=ActivityType.objects.get(name="Creativity"),) - record.part_type=combined_part_type + record = Activity.objects.get( + activity_type=ActivityType.objects.get(name="Creativity"), + ) + record.part_type = combined_part_type record.save() - record = Activity.objects.get(activity_type=ActivityType.objects.get(name="Reflection"),) - record.part_type=combined_part_type + record = Activity.objects.get( + activity_type=ActivityType.objects.get(name="Reflection"), + ) + record.part_type = combined_part_type record.save() class Migration(migrations.Migration): dependencies = [ - ('assignments', '0017_seed_more_activities'), + ("assignments", "0017_seed_more_activities"), ] operations = [migrations.RunPython(assign_part_type, migrations.RunPython.noop)] diff --git a/teleband/assignments/migrations/0019_add_connect.py b/teleband/assignments/migrations/0019_add_connect.py index 8ea6738..7974317 100644 --- a/teleband/assignments/migrations/0019_add_connect.py +++ b/teleband/assignments/migrations/0019_add_connect.py @@ -2,39 +2,34 @@ from django.db import migrations + def update_site_forward(apps, schema_editor): Activity = apps.get_model("assignments", "Activity") ActivityType = apps.get_model("assignments", "ActivityType") ActivityCategory = apps.get_model("assignments", "ActivityCategory") - ActivityCategory.objects.update_or_create( - name="Connect Benjamin" - ) + ActivityCategory.objects.update_or_create(name="Connect Benjamin") - ActivityCategory.objects.update_or_create( - name="Connect Danyew" - ) + ActivityCategory.objects.update_or_create(name="Connect Danyew") - ActivityCategory.objects.update_or_create( - name="Connect Green" - ) + ActivityCategory.objects.update_or_create(name="Connect Green") ActivityType.objects.update_or_create( name="Connect Benjamin", - category = ActivityCategory.objects.get(name="Connect Benjamin"), + category=ActivityCategory.objects.get(name="Connect Benjamin"), ) ActivityType.objects.update_or_create( name="Connect Danyew", - category = ActivityCategory.objects.get(name="Connect Danyew"), + category=ActivityCategory.objects.get(name="Connect Danyew"), ) ActivityType.objects.update_or_create( name="Connect Green", - category = ActivityCategory.objects.get(name="Connect Green"), + category=ActivityCategory.objects.get(name="Connect Green"), ) Activity.objects.update_or_create( activity_type=ActivityType.objects.get(name="Connect Benjamin"), - body="INSTRUCTIONS: 1) Watch the Video. 2) Based on Mr. Benjamin's suggestions in the video, write about a specific executive skill you changed or modified in order to perform \"The Favorite.\"", + body='INSTRUCTIONS: 1) Watch the Video. 2) Based on Mr. Benjamin\'s suggestions in the video, write about a specific executive skill you changed or modified in order to perform "The Favorite."', ) Activity.objects.update_or_create( @@ -51,7 +46,7 @@ def update_site_forward(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('assignments', '0018_assign_part_type_to_assignment_20220617_2211'), + ("assignments", "0018_assign_part_type_to_assignment_20220617_2211"), ] operations = [migrations.RunPython(update_site_forward, migrations.RunPython.noop)] diff --git a/teleband/assignments/migrations/0020_auto_20230408_1952.py b/teleband/assignments/migrations/0020_auto_20230408_1952.py index 5a83db4..325b5c8 100644 --- a/teleband/assignments/migrations/0020_auto_20230408_1952.py +++ b/teleband/assignments/migrations/0020_auto_20230408_1952.py @@ -7,67 +7,134 @@ class Migration(migrations.Migration): dependencies = [ - ('musics', '0018_seed_more_music'), - ('courses', '0005_data_migration_demo_course'), - ('assignments', '0019_add_connect'), + ("musics", "0018_seed_more_music"), + ("courses", "0005_data_migration_demo_course"), + ("assignments", "0019_add_connect"), ] operations = [ migrations.CreateModel( - name='Curriculum', + name="Curriculum", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=255)), - ('course', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='courses.course')), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=255)), + ( + "course", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="courses.course" + ), + ), ], ), migrations.CreateModel( - name='PiecePlan', + name="PiecePlan", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=255)), - ('ordered', models.BooleanField(default=False)), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=255)), + ("ordered", models.BooleanField(default=False)), ], ), migrations.CreateModel( - name='PiecePlanActivity', + name="PiecePlanActivity", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('order', models.PositiveIntegerField()), - ('activity', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.activity')), - ('piece_plan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.pieceplan')), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("order", models.PositiveIntegerField()), + ( + "activity", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="assignments.activity", + ), + ), + ( + "piece_plan", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="assignments.pieceplan", + ), + ), ], options={ - 'ordering': ['order'], - 'unique_together': {('piece_plan', 'activity')}, + "ordering": ["order"], + "unique_together": {("piece_plan", "activity")}, }, ), migrations.AddField( - model_name='pieceplan', - name='activities', - field=models.ManyToManyField(through='assignments.PiecePlanActivity', to='assignments.Activity'), + model_name="pieceplan", + name="activities", + field=models.ManyToManyField( + through="assignments.PiecePlanActivity", to="assignments.Activity" + ), ), migrations.AddField( - model_name='pieceplan', - name='piece', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='musics.piece'), + model_name="pieceplan", + name="piece", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="musics.piece" + ), ), migrations.CreateModel( - name='CurriculumPiecePlan', + name="CurriculumPiecePlan", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('order', models.PositiveIntegerField()), - ('curriculum', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.curriculum')), - ('piece_plan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.pieceplan')), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("order", models.PositiveIntegerField()), + ( + "curriculum", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="assignments.curriculum", + ), + ), + ( + "piece_plan", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="assignments.pieceplan", + ), + ), ], options={ - 'ordering': ['order'], - 'unique_together': {('curriculum', 'piece_plan')}, + "ordering": ["order"], + "unique_together": {("curriculum", "piece_plan")}, }, ), migrations.AddField( - model_name='curriculum', - name='piece_plans', - field=models.ManyToManyField(through='assignments.CurriculumPiecePlan', to='assignments.PiecePlan'), + model_name="curriculum", + name="piece_plans", + field=models.ManyToManyField( + through="assignments.CurriculumPiecePlan", to="assignments.PiecePlan" + ), ), ] diff --git a/teleband/assignments/migrations/0021_auto_20230517_1130.py b/teleband/assignments/migrations/0021_auto_20230517_1130.py index 993d13b..f6bebc1 100644 --- a/teleband/assignments/migrations/0021_auto_20230517_1130.py +++ b/teleband/assignments/migrations/0021_auto_20230517_1130.py @@ -6,30 +6,30 @@ class Migration(migrations.Migration): dependencies = [ - ('assignments', '0020_auto_20230408_1952'), + ("assignments", "0020_auto_20230408_1952"), ] operations = [ migrations.RenameModel( - old_name='CurriculumPiecePlan', - new_name='CurriculumEntry', + old_name="CurriculumPiecePlan", + new_name="CurriculumEntry", ), migrations.RenameModel( - old_name='PiecePlanActivity', - new_name='PlannedActivity', + old_name="PiecePlanActivity", + new_name="PlannedActivity", ), migrations.RemoveField( - model_name='pieceplan', - name='ordered', + model_name="pieceplan", + name="ordered", ), migrations.AddField( - model_name='activitytype', - name='number_of_submissions', + model_name="activitytype", + name="number_of_submissions", field=models.PositiveIntegerField(default=1), ), migrations.AddField( - model_name='curriculum', - name='ordered', + model_name="curriculum", + name="ordered", field=models.BooleanField(default=False), ), ] diff --git a/teleband/assignments/migrations/0022_move_number_of_submissions.py b/teleband/assignments/migrations/0022_move_number_of_submissions.py index 915a46d..daf6188 100644 --- a/teleband/assignments/migrations/0022_move_number_of_submissions.py +++ b/teleband/assignments/migrations/0022_move_number_of_submissions.py @@ -6,17 +6,17 @@ class Migration(migrations.Migration): dependencies = [ - ('assignments', '0021_auto_20230517_1130'), + ("assignments", "0021_auto_20230517_1130"), ] operations = [ migrations.RemoveField( - model_name='activitytype', - name='number_of_submissions', + model_name="activitytype", + name="number_of_submissions", ), migrations.AddField( - model_name='activity', - name='number_of_submissions', + model_name="activity", + name="number_of_submissions", field=models.PositiveIntegerField(default=1), ), ] diff --git a/teleband/assignments/migrations/0023_assignment_piece_plan.py b/teleband/assignments/migrations/0023_assignment_piece_plan.py index c2d2f38..b3bab25 100644 --- a/teleband/assignments/migrations/0023_assignment_piece_plan.py +++ b/teleband/assignments/migrations/0023_assignment_piece_plan.py @@ -7,13 +7,18 @@ class Migration(migrations.Migration): dependencies = [ - ('assignments', '0022_move_number_of_submissions'), + ("assignments", "0022_move_number_of_submissions"), ] operations = [ migrations.AddField( - model_name='assignment', - name='piece_plan', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='assignments.pieceplan'), + model_name="assignment", + name="piece_plan", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="assignments.pieceplan", + ), ), ] diff --git a/teleband/assignments/migrations/0024_add_activity_type_and_category_fields.py b/teleband/assignments/migrations/0024_add_activity_type_and_category_fields.py index dacad23..6060e8d 100644 --- a/teleband/assignments/migrations/0024_add_activity_type_and_category_fields.py +++ b/teleband/assignments/migrations/0024_add_activity_type_and_category_fields.py @@ -6,18 +6,18 @@ class Migration(migrations.Migration): dependencies = [ - ('assignments', '0023_assignment_piece_plan'), + ("assignments", "0023_assignment_piece_plan"), ] operations = [ migrations.AddField( - model_name='activity', - name='activity_type_name', + model_name="activity", + name="activity_type_name", field=models.CharField(blank=True, max_length=255, null=True), ), migrations.AddField( - model_name='activity', - name='category', + model_name="activity", + name="category", field=models.CharField(blank=True, max_length=255, null=True), ), ] diff --git a/teleband/assignments/migrations/0025_migrate_activity_type_and_category_20230613_1311.py b/teleband/assignments/migrations/0025_migrate_activity_type_and_category_20230613_1311.py index e512750..844a952 100644 --- a/teleband/assignments/migrations/0025_migrate_activity_type_and_category_20230613_1311.py +++ b/teleband/assignments/migrations/0025_migrate_activity_type_and_category_20230613_1311.py @@ -2,6 +2,7 @@ from django.db import migrations + def move_type_and_category(apps, schema_editor): Activity = apps.get_model("assignments", "Activity") ActivityType = apps.get_model("assignments", "ActivityType") @@ -11,12 +12,11 @@ def move_type_and_category(apps, schema_editor): activity.category = activity.activity_type.category.name activity.save() + class Migration(migrations.Migration): dependencies = [ - ('assignments', '0024_add_activity_type_and_category_fields'), + ("assignments", "0024_add_activity_type_and_category_fields"), ] - operations = [ - migrations.RunPython(move_type_and_category) - ] + operations = [migrations.RunPython(move_type_and_category)] diff --git a/teleband/assignments/migrations/0026_assignment_piece.py b/teleband/assignments/migrations/0026_assignment_piece.py index cf9feb4..02dddcc 100644 --- a/teleband/assignments/migrations/0026_assignment_piece.py +++ b/teleband/assignments/migrations/0026_assignment_piece.py @@ -7,14 +7,19 @@ class Migration(migrations.Migration): dependencies = [ - ('musics', '0018_seed_more_music'), - ('assignments', '0025_migrate_activity_type_and_category_20230613_1311'), + ("musics", "0018_seed_more_music"), + ("assignments", "0025_migrate_activity_type_and_category_20230613_1311"), ] operations = [ migrations.AddField( - model_name='assignment', - name='piece', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='musics.piece'), + model_name="assignment", + name="piece", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="musics.piece", + ), ), ] diff --git a/teleband/assignments/migrations/0027_migrate_piece_to_assignment_20230613_1319.py b/teleband/assignments/migrations/0027_migrate_piece_to_assignment_20230613_1319.py index 97145c9..533fee2 100644 --- a/teleband/assignments/migrations/0027_migrate_piece_to_assignment_20230613_1319.py +++ b/teleband/assignments/migrations/0027_migrate_piece_to_assignment_20230613_1319.py @@ -2,6 +2,7 @@ from django.db import migrations + def move_piece_to_assignment(apps, schema_editor): Assignment = apps.get_model("assignments", "Assignment") Part = apps.get_model("musics", "Part") @@ -9,12 +10,11 @@ def move_piece_to_assignment(apps, schema_editor): assignment.piece = assignment.part.piece assignment.save() + class Migration(migrations.Migration): dependencies = [ - ('assignments', '0026_assignment_piece'), + ("assignments", "0026_assignment_piece"), ] - operations = [ - migrations.RunPython(move_piece_to_assignment) - ] + operations = [migrations.RunPython(move_piece_to_assignment)] diff --git a/teleband/assignments/migrations/0028_add_assignment_group.py b/teleband/assignments/migrations/0028_add_assignment_group.py index 95d4a76..f1893ed 100644 --- a/teleband/assignments/migrations/0028_add_assignment_group.py +++ b/teleband/assignments/migrations/0028_add_assignment_group.py @@ -7,28 +7,44 @@ class Migration(migrations.Migration): dependencies = [ - ('assignments', '0027_migrate_piece_to_assignment_20230613_1319'), + ("assignments", "0027_migrate_piece_to_assignment_20230613_1319"), ] operations = [ migrations.CreateModel( - name='AssignmentGroup', + name="AssignmentGroup", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('type', models.CharField(max_length=255)), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("type", models.CharField(max_length=255)), ], ), migrations.AlterModelOptions( - name='curriculum', - options={'verbose_name': 'Curriculum', 'verbose_name_plural': 'Curricula'}, + name="curriculum", + options={"verbose_name": "Curriculum", "verbose_name_plural": "Curricula"}, ), migrations.AlterModelOptions( - name='plannedactivity', - options={'ordering': ['piece_plan__name', 'order'], 'verbose_name_plural': 'Planned Activities'}, + name="plannedactivity", + options={ + "ordering": ["piece_plan__name", "order"], + "verbose_name_plural": "Planned Activities", + }, ), migrations.AddField( - model_name='assignment', - name='group', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='assignments.assignmentgroup'), + model_name="assignment", + name="group", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="assignments.assignmentgroup", + ), ), ] diff --git a/teleband/assignments/migrations/0029_pieceplan_type.py b/teleband/assignments/migrations/0029_pieceplan_type.py index 44ad1ee..2798e24 100644 --- a/teleband/assignments/migrations/0029_pieceplan_type.py +++ b/teleband/assignments/migrations/0029_pieceplan_type.py @@ -6,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('assignments', '0028_add_assignment_group'), + ("assignments", "0028_add_assignment_group"), ] operations = [ migrations.AddField( - model_name='pieceplan', - name='type', + model_name="pieceplan", + name="type", field=models.CharField(blank=True, max_length=255, null=True), ), ] diff --git a/teleband/assignments/migrations/0030_alter_assignmentgroup_type.py b/teleband/assignments/migrations/0030_alter_assignmentgroup_type.py index 8371749..f92e0ed 100644 --- a/teleband/assignments/migrations/0030_alter_assignmentgroup_type.py +++ b/teleband/assignments/migrations/0030_alter_assignmentgroup_type.py @@ -6,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('assignments', '0029_pieceplan_type'), + ("assignments", "0029_pieceplan_type"), ] operations = [ migrations.AlterField( - model_name='assignmentgroup', - name='type', + model_name="assignmentgroup", + name="type", field=models.CharField(blank=True, max_length=255, null=True), ), ] diff --git a/teleband/assignments/migrations/0031_default_piece_plans_20230920_2336.py b/teleband/assignments/migrations/0031_default_piece_plans_20230920_2336.py index cac79a8..600d370 100644 --- a/teleband/assignments/migrations/0031_default_piece_plans_20230920_2336.py +++ b/teleband/assignments/migrations/0031_default_piece_plans_20230920_2336.py @@ -137,7 +137,7 @@ def update_site_forward(apps, schema_editor): category=act_cat.name, body="Now that you have learned this tune, write about what you have learned about playing your instrument.", ) - + Piece = apps.get_model("musics", "Piece") PiecePlan = apps.get_model("assignments", "PiecePlan") PlannedActivity = apps.get_model("assignments", "PlannedActivity") diff --git a/teleband/assignments/migrations/0032_auto_20240311_1235.py b/teleband/assignments/migrations/0032_auto_20240311_1235.py index 30dc16e..ce72c71 100644 --- a/teleband/assignments/migrations/0032_auto_20240311_1235.py +++ b/teleband/assignments/migrations/0032_auto_20240311_1235.py @@ -2,63 +2,67 @@ from django.db import migrations -NEA_CONDITIONS = ['Aural', 'Theoretical', 'Exploratory'] +NEA_CONDITIONS = ["Aural", "Theoretical", "Exploratory"] NEA_INSTRUCTIONS = { - 'Aural': '

INSTRUCTIONS

  1. Now that you know the melody and bass line, think like a composer and create a counter-melody that would sound good when played with the melody and bass line.
  2. To practice creating a counter-melody, first review the main melody and bass line by performing them with the accompaniment track.
  3. Experiment with changing just a few notes from the melody. Continue until you are comfortable with your counter-melody. Optional: practice playing with the recording of the melody so you can hear how your counter-melody sounds with the original melody. Record your counter-melody with the accompaniment track and submit for review. Notate your counter-melody.
', - 'Theoretical': '

INSTRUCTIONS

Follow the steps below to compose a 16-bar melody.
  1. In the Steps below, write four-bar phrases using half notes, quarter notes, eighth notes, and rests.
    • NOTE: The rests in each bar are color-coordinated (red, green, and blue) so you know from which note bins to choose your notes.
  2. In the "Combined" Step, review all sixteen bars of music you have composed. You can edit this if you wish.
  3. Record your composition and submit for review.
', - 'Exploratory': '

INSTRUCTIONS

  1. Write three, one-bar motives using the note bins provided. You may use half notes, quarter notes, eighth notes, and rests. When you have written all three motives, select "Begin Composing." The computer will generate variations of your motives which you can use in the next step. The generated variations will be grouped under tabs labeled with the bin name (e.g. "Tonic").
  2. Draft your melody by:
    1. choosing a bin and clicking its tab to see your motive along with the generated variations.
      • NOTE: The blank staff is color-coordinated with the motives (red, green, and blue).
    2. Find a your preferred measure in in the Variations tab and click anywhere in that measure.
    3. Click in a measure in the blank staff into which you want the notes to be copied.
  3. You may edit your final composition draft if you wish.
  4. Record your composition and submit for review.
', + "Aural": "

INSTRUCTIONS

  1. Now that you know the melody and bass line, think like a composer and create a counter-melody that would sound good when played with the melody and bass line.
  2. To practice creating a counter-melody, first review the main melody and bass line by performing them with the accompaniment track.
  3. Experiment with changing just a few notes from the melody. Continue until you are comfortable with your counter-melody. Optional: practice playing with the recording of the melody so you can hear how your counter-melody sounds with the original melody. Record your counter-melody with the accompaniment track and submit for review. Notate your counter-melody.
", + "Theoretical": '

INSTRUCTIONS

Follow the steps below to compose a 16-bar melody.
  1. In the Steps below, write four-bar phrases using half notes, quarter notes, eighth notes, and rests.
    • NOTE: The rests in each bar are color-coordinated (red, green, and blue) so you know from which note bins to choose your notes.
  2. In the "Combined" Step, review all sixteen bars of music you have composed. You can edit this if you wish.
  3. Record your composition and submit for review.
', + "Exploratory": '

INSTRUCTIONS

  1. Write three, one-bar motives using the note bins provided. You may use half notes, quarter notes, eighth notes, and rests. When you have written all three motives, select "Begin Composing." The computer will generate variations of your motives which you can use in the next step. The generated variations will be grouped under tabs labeled with the bin name (e.g. "Tonic").
  2. Draft your melody by:
    1. choosing a bin and clicking its tab to see your motive along with the generated variations.
      • NOTE: The blank staff is color-coordinated with the motives (red, green, and blue).
    2. Find a your preferred measure in in the Variations tab and click anywhere in that measure.
    3. Click in a measure in the blank staff into which you want the notes to be copied.
  3. You may edit your final composition draft if you wish.
  4. Record your composition and submit for review.
', } NEA_ACT_TYPES = [ - 'Melody', - 'Bassline', - 'Create', - 'MelodyPost', - 'BasslinePost', - 'Reflection', + "Melody", + "Bassline", + "Create", + "MelodyPost", + "BasslinePost", + "Reflection", ] NEA_CURRICULA = { - 'Freedom 2040 (Band)': [*NEA_ACT_TYPES, 'Connect Green'], - 'Freedom 2040 (Orchestra)': [*NEA_ACT_TYPES, 'Connect Green'], - 'Down by the Riverside': [*NEA_ACT_TYPES, 'Connect Danyew'], - 'Deep River': [*NEA_ACT_TYPES, 'Connect Danyew'], + "Freedom 2040 (Band)": [*NEA_ACT_TYPES, "Connect Green"], + "Freedom 2040 (Orchestra)": [*NEA_ACT_TYPES, "Connect Green"], + "Down by the Riverside": [*NEA_ACT_TYPES, "Connect Danyew"], + "Deep River": [*NEA_ACT_TYPES, "Connect Danyew"], } + def add_post_perform(apps, schema_editor): Activity = apps.get_model("assignments", "Activity") ActivityCategory = apps.get_model("assignments", "ActivityCategory") ActivityType = apps.get_model("assignments", "ActivityType") PartType = apps.get_model("musics", "PartType") - + melody = PartType.objects.get(name="Melody") bassline = PartType.objects.get(name="Bassline") - + ctgy, ctgy_created = ActivityCategory.objects.update_or_create(name="PerformPost") - melody_act_typ, melody_act_typ_created = ActivityType.objects.update_or_create(name="MelodyPost", category=ctgy) - bassline_act_typ, bassline_act_typ_created = ActivityType.objects.update_or_create(name="BasslinePost", category=ctgy) + melody_act_typ, melody_act_typ_created = ActivityType.objects.update_or_create( + name="MelodyPost", category=ctgy + ) + bassline_act_typ, bassline_act_typ_created = ActivityType.objects.update_or_create( + name="BasslinePost", category=ctgy + ) melody_act, me_created = Activity.objects.update_or_create( activity_type=melody_act_typ, body="Please record yourself performing the melody again (now that you have completed the other activities).", part_type=melody, activity_type_name=melody_act_typ.name, - category=ctgy.name + category=ctgy.name, ) bassline_act, me_created = Activity.objects.update_or_create( activity_type=bassline_act_typ, body="Please record yourself performing the bassline again (now that you have completed the other activities).", part_type=bassline, activity_type_name=bassline_act_typ.name, - category=ctgy.name + category=ctgy.name, ) - def add_NEA_create_act_types(apps, schema_editor): Activity = apps.get_model("assignments", "Activity") ActivityCategory = apps.get_model("assignments", "ActivityCategory") ActivityType = apps.get_model("assignments", "ActivityType") PartType = apps.get_model("musics", "PartType") - + melody = PartType.objects.get(name="Melody") create_ctgy = ActivityCategory.objects.get(name="Create") @@ -73,9 +77,9 @@ def add_NEA_create_act_types(apps, schema_editor): body=NEA_INSTRUCTIONS[condition], part_type=melody, activity_type_name=act_type.name, - category=create_ctgy.name + category=create_ctgy.name, ) - + def create_NEA_plans(apps, schema_editor): Activity = apps.get_model("assignments", "Activity") @@ -92,8 +96,10 @@ def create_NEA_plans(apps, schema_editor): for cond in NEA_CONDITIONS: for piece_name, act_type_names in NEA_CURRICULA.items(): piece = Piece.objects.get(name=piece_name) - curriculum, curr_created = Curriculum.objects.update_or_create(name=f"NEA-{piece.name}-{cond}", course=course) - + curriculum, curr_created = Curriculum.objects.update_or_create( + name=f"NEA-{piece.name}-{cond}", course=course + ) + # new_create_act = Activity.objects.get(activity_type=act_type) new_plan, np_created = PiecePlan.objects.update_or_create( name=f"NEA-{piece.name}-{cond}", @@ -101,11 +107,11 @@ def create_NEA_plans(apps, schema_editor): ) for i, act_type_name in enumerate(act_type_names): act_type = None - if act_type_name == 'Create': + if act_type_name == "Create": act_type = ActivityType.objects.get(name=cond) else: act_type = ActivityType.objects.get(name=act_type_name) - + activity = Activity.objects.get( activity_type=act_type, ) diff --git a/teleband/assignments/migrations/0033_auto_20240312_2321.py b/teleband/assignments/migrations/0033_auto_20240312_2321.py index 8e4f6a4..e0526fb 100644 --- a/teleband/assignments/migrations/0033_auto_20240312_2321.py +++ b/teleband/assignments/migrations/0033_auto_20240312_2321.py @@ -18,10 +18,11 @@ "Freedom 2040 (Orchestra)", "Down by the Riverside", "Deep River", - "I Want to be Ready" + "I Want to be Ready", ] -NEA_CONDITIONS = ['Aural', 'Theoretical', 'Exploratory'] +NEA_CONDITIONS = ["Aural", "Theoretical", "Exploratory"] + def add_demos(apps, schema_editor): Course = apps.get_model("courses", "Course") @@ -32,7 +33,7 @@ def add_demos(apps, schema_editor): Role = apps.get_model("users", "Role") User = apps.get_model("users", "User") - owner=User.objects.get(username=DEMO_USERS[0]) + owner = User.objects.get(username=DEMO_USERS[0]) student_role = Role.objects.get(name="Student") for condition in NEA_CONDITIONS: @@ -60,9 +61,9 @@ def add_demos(apps, schema_editor): print(f"IntegrityError: {e}") for piece_name in NEA_CREATE_DEMO_PIECES: - if piece_name=="I Want to be Ready" and condition != 'Aural': + if piece_name == "I Want to be Ready" and condition != "Aural": pass - + piece = Piece.objects.get(name=piece_name) piece_plan, p_created = PiecePlan.objects.update_or_create( name=f"NEA-{piece.name}-{condition}", @@ -77,10 +78,10 @@ def add_demos(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('assignments', '0032_auto_20240311_1235'), - ('users', '0007_user_instrument'), - ('courses', '0006_course_can_edit_instruments'), - ('instruments', '0004_instrument_midi_program_number'), + ("assignments", "0032_auto_20240311_1235"), + ("users", "0007_user_instrument"), + ("courses", "0006_course_can_edit_instruments"), + ("instruments", "0004_instrument_midi_program_number"), ] operations = [ diff --git a/teleband/assignments/migrations/0034_auto_20240315_1547.py b/teleband/assignments/migrations/0034_auto_20240315_1547.py index 39d9cec..c57ba07 100644 --- a/teleband/assignments/migrations/0034_auto_20240315_1547.py +++ b/teleband/assignments/migrations/0034_auto_20240315_1547.py @@ -2,33 +2,34 @@ from django.db import migrations + def fix_instructions(apps, schema_editor): Activity = apps.get_model("assignments", "Activity") ActivityCategory = apps.get_model("assignments", "ActivityCategory") ActivityType = apps.get_model("assignments", "ActivityType") PartType = apps.get_model("musics", "PartType") - + melody = PartType.objects.get(name="Melody") create_ctgy = ActivityCategory.objects.get(name="Create") act_type, act_t_created = ActivityType.objects.update_or_create( - name='Exploratory', + name="Exploratory", category=create_ctgy, ) exploratory, e_created = Activity.objects.get_or_create( activity_type=act_type, part_type=melody, activity_type_name=act_type.name, - category=create_ctgy.name + category=create_ctgy.name, ) - exploratory.body='

INSTRUCTIONS

  1. Write three, one-bar motives using the note bins provided. You may use half notes, quarter notes, eighth notes, and rests. When you have written all three motives, select "Begin Composing." The computer will generate variations of your motives which you can use in the next step. The generated variations will be grouped under tabs labeled with the bin name (e.g. "Tonic").
  2. Draft your melody by:
    1. Choosing a bin and clicking its tab to see your motive along with the generated variations.
      • NOTE: The blank staff is color-coordinated with the motives (red, green, and blue).
    2. Find a your preferred measure in in the Variations tab and click anywhere in that measure.
    3. Click in a measure in the blank staff into which you want the notes to be copied.
  3. You may edit your final composition draft if you wish.
  4. Record your composition and submit for review.
    • NOTE: When you click the record (microphone) button, the accompaniment track will play. The accompaniment track provides two measures of rest. Wait until the third measure before you begin playing your melody.
' + exploratory.body = '

INSTRUCTIONS

  1. Write three, one-bar motives using the note bins provided. You may use half notes, quarter notes, eighth notes, and rests. When you have written all three motives, select "Begin Composing." The computer will generate variations of your motives which you can use in the next step. The generated variations will be grouped under tabs labeled with the bin name (e.g. "Tonic").
  2. Draft your melody by:
    1. Choosing a bin and clicking its tab to see your motive along with the generated variations.
      • NOTE: The blank staff is color-coordinated with the motives (red, green, and blue).
    2. Find a your preferred measure in in the Variations tab and click anywhere in that measure.
    3. Click in a measure in the blank staff into which you want the notes to be copied.
  3. You may edit your final composition draft if you wish.
  4. Record your composition and submit for review.
    • NOTE: When you click the record (microphone) button, the accompaniment track will play. The accompaniment track provides two measures of rest. Wait until the third measure before you begin playing your melody.
' exploratory.save() class Migration(migrations.Migration): dependencies = [ - ('assignments', '0033_auto_20240312_2321'), + ("assignments", "0033_auto_20240312_2321"), ] operations = [ diff --git a/teleband/assignments/migrations/0035_dedupe_assignments.py b/teleband/assignments/migrations/0035_dedupe_assignments.py index 0123c65..32f23a8 100644 --- a/teleband/assignments/migrations/0035_dedupe_assignments.py +++ b/teleband/assignments/migrations/0035_dedupe_assignments.py @@ -1,10 +1,11 @@ from django.db import migrations, models + def remove_dupes(apps, schema_editor): - Activity = apps.get_model('assignments', 'Activity') - Course = apps.get_model('courses', 'Course') + Activity = apps.get_model("assignments", "Activity") + Course = apps.get_model("courses", "Course") # Enrollment = apps.get_model('courses', 'Enrollment') - Piece = apps.get_model('musics', 'Piece') + Piece = apps.get_model("musics", "Piece") # check each course for duplicate assignments for c in Course.objects.all(): @@ -17,42 +18,47 @@ def remove_dupes(apps, schema_editor): # ...they are for the same piece for p in Piece.objects.all(): - dupes = e.assignment_set.filter(activity=act, piece=p).order_by('-created_at') + dupes = e.assignment_set.filter(activity=act, piece=p).order_by( + "-created_at" + ) if dupes.count() > 1: delete_dupes(dupes) - -''' + + +""" given a queryset of assignments that all have the same enrollment (student), activity, and piece, find the one with the most recent submission, and delete the others. -''' +""" + + def delete_dupes(dupes): # assume the first assignment is the one with the most recent submission assn_w_max_sub_date = dupes[0] max_sub_for_assn = None - if assn_w_max_sub_date.submissions.order_by('-submitted').count() > 0: - max_sub_for_assn = assn_w_max_sub_date.submissions.order_by('-submitted')[0] + if assn_w_max_sub_date.submissions.order_by("-submitted").count() > 0: + max_sub_for_assn = assn_w_max_sub_date.submissions.order_by("-submitted")[0] to_remove = [] # loop over the rest of the assignments to see if any has a more recent submission for d in dupes[1:]: - # either this assn has no submissions and we can remove this assn, + # either this assn has no submissions and we can remove this assn, # or this assn has a more recent submission and we need to remove previous max assn # or this assn's most recent sub is older and we need to remove this assn if d.submissions.count() == 0: to_remove.append(d) continue else: - most_recent_sub = d.submissions.order_by('-submitted')[0] + most_recent_sub = d.submissions.order_by("-submitted")[0] if max_sub_for_assn is None or most_recent_sub.submitted > max_sub_for_assn: to_remove.append(assn_w_max_sub_date) assn_w_max_sub_date = d max_sub_for_assn = most_recent_sub else: to_remove.append(d) - + for r in to_remove: subs = r.submissions.all() for sub in subs: @@ -63,10 +69,11 @@ def delete_dupes(dupes): subs.delete() r.delete() + class Migration(migrations.Migration): dependencies = [ - ('assignments', '0034_auto_20240315_1547'), + ("assignments", "0034_auto_20240315_1547"), ] operations = [ diff --git a/teleband/assignments/migrations/0036_assignment_unique_assignment_20240320_1310.py b/teleband/assignments/migrations/0036_assignment_unique_assignment_20240320_1310.py index fb8d776..e51b5df 100644 --- a/teleband/assignments/migrations/0036_assignment_unique_assignment_20240320_1310.py +++ b/teleband/assignments/migrations/0036_assignment_unique_assignment_20240320_1310.py @@ -1,15 +1,18 @@ from django.db import migrations, models + class Migration(migrations.Migration): dependencies = [ - ('assignments', '0035_dedupe_assignments'), + ("assignments", "0035_dedupe_assignments"), ] operations = [ # migrations.RunPython(remove_dupes, migrations.RunPython.noop), migrations.AddConstraint( - model_name='assignment', - constraint=models.UniqueConstraint(fields=('activity', 'enrollment', 'piece'), name='unique_assignment'), + model_name="assignment", + constraint=models.UniqueConstraint( + fields=("activity", "enrollment", "piece"), name="unique_assignment" + ), ), ] diff --git a/teleband/assignments/models.py b/teleband/assignments/models.py index ae31fa8..a095b8e 100644 --- a/teleband/assignments/models.py +++ b/teleband/assignments/models.py @@ -1,9 +1,8 @@ from django.db import models -from django.conf import settings from teleband.courses.models import Course, Enrollment from teleband.instruments.models import Instrument -from teleband.musics.models import PartType, Part, Piece +from teleband.musics.models import Part, PartType, Piece class ActivityCategory(models.Model): @@ -22,7 +21,6 @@ class ActivityType(models.Model): name = models.CharField(unique=True, max_length=255) category = models.ForeignKey(ActivityCategory, on_delete=models.PROTECT) - class Meta: verbose_name = "Activity Type" @@ -61,15 +59,17 @@ def assign(self, enrollment, instrument, deadline=None): piece = self.piece for activity in self.activities.all(): part = Part.for_activity(activity, piece) - assignments.append(Assignment.objects.create( - activity=activity, - enrollment=enrollment, - part=part, - instrument=instrument, - piece_plan=self, - deadline=deadline, - piece=self.piece, - )) + assignments.append( + Assignment.objects.create( + activity=activity, + enrollment=enrollment, + part=part, + instrument=instrument, + piece_plan=self, + deadline=deadline, + piece=self.piece, + ) + ) return assignments def __str__(self): @@ -86,9 +86,13 @@ class Assignment(models.Model): part = models.ForeignKey(Part, on_delete=models.PROTECT) deadline = models.DateField(null=True, blank=True) instrument = models.ForeignKey(Instrument, on_delete=models.PROTECT) - piece_plan = models.ForeignKey(PiecePlan, on_delete=models.PROTECT, null=True, blank=True) + piece_plan = models.ForeignKey( + PiecePlan, on_delete=models.PROTECT, null=True, blank=True + ) piece = models.ForeignKey(Piece, on_delete=models.PROTECT, null=True, blank=True) - group = models.ForeignKey("AssignmentGroup", on_delete=models.PROTECT, null=True, blank=True) + group = models.ForeignKey( + "AssignmentGroup", on_delete=models.PROTECT, null=True, blank=True + ) created_at = models.DateTimeField(auto_now_add=True) @@ -96,17 +100,19 @@ class Meta: # FIXME: do this with https://docs.djangoproject.com/en/5.0/ref/models/options/#unique-together instead. # nevermind, this may be deprecated constraints = [ - models.UniqueConstraint(fields=["activity", "enrollment", "piece"], name="unique_assignment") + models.UniqueConstraint( + fields=["activity", "enrollment", "piece"], name="unique_assignment" + ) ] def __str__(self): return f"[{self.enrollment.user.username}] {self.activity.id} {self.piece}" - + class AssignmentGroup(models.Model): type = models.CharField(max_length=255, null=True, blank=True) - + class PlannedActivity(models.Model): @@ -137,6 +143,7 @@ class Meta: def __str__(self): return f"{self.name}: {self.course.name}" + class CurriculumEntry(models.Model): curriculum = models.ForeignKey(Curriculum, on_delete=models.CASCADE) @@ -149,4 +156,3 @@ class Meta: def __str__(self): return f"{self.curriculum.name}: {self.piece_plan.name}" - diff --git a/teleband/contrib/sites/migrations/0003_set_site_domain_and_name.py b/teleband/contrib/sites/migrations/0003_set_site_domain_and_name.py index 223f106..7098d48 100644 --- a/teleband/contrib/sites/migrations/0003_set_site_domain_and_name.py +++ b/teleband/contrib/sites/migrations/0003_set_site_domain_and_name.py @@ -3,6 +3,7 @@ http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django """ + from django.conf import settings from django.db import migrations diff --git a/teleband/courses/admin.py b/teleband/courses/admin.py index db36a96..6434faf 100644 --- a/teleband/courses/admin.py +++ b/teleband/courses/admin.py @@ -8,6 +8,7 @@ class EnrollmentInline(admin.TabularInline): model = Enrollment extra = 0 + @admin.register(Course) class CourseAdmin(VersionAdmin): list_display = ("id", "name", "slug", "owner") diff --git a/teleband/courses/api/views.py b/teleband/courses/api/views.py index bd4b9b7..2d5f6f6 100644 --- a/teleband/courses/api/views.py +++ b/teleband/courses/api/views.py @@ -33,7 +33,13 @@ from teleband.users.api.serializers import UserSerializer from teleband.courses.models import Enrollment, Course -from teleband.assignments.models import Assignment, Activity, PiecePlan, Curriculum, AssignmentGroup +from teleband.assignments.models import ( + Assignment, + Activity, + PiecePlan, + Curriculum, + AssignmentGroup, +) from teleband.musics.models import PartType, Piece, Part from teleband.users.models import Role from teleband.utils.permissions import IsTeacher @@ -252,7 +258,9 @@ def assign_piece_plan(self, request, **kwargs): piece_plan = PiecePlan.objects.get(pk=parsed["piece_plan_id"]) except PiecePlan.DoesNotExist: logger.info( - "Attempt to assign non-existent piece plan {}".format(parsed["piece_plan_id"]) + "Attempt to assign non-existent piece plan {}".format( + parsed["piece_plan_id"] + ) ) return Response(status=status.HTTP_404_NOT_FOUND) @@ -289,7 +297,6 @@ def assign_piece_plan(self, request, **kwargs): ) return Response(status=status.HTTP_200_OK, data=serializer.data) - @action(detail=True, methods=["post"]) def assign(self, request, **kwargs): parsed = request.data @@ -345,7 +352,9 @@ def assign_curriculum(self, request, **kwargs): curriculum = Curriculum.objects.get(pk=parsed["curriculum_id"]) except Curriculum.DoesNotExist: logger.info( - "Attempt to assign non-existent curriculum {}".format(parsed["curriculum_id"]) + "Attempt to assign non-existent curriculum {}".format( + parsed["curriculum_id"] + ) ) return Response(status=status.HTTP_404_NOT_FOUND) @@ -374,7 +383,6 @@ def assign_curriculum(self, request, **kwargs): ) return Response(status=status.HTTP_200_OK, data=serializer.data) - @action(detail=True, methods=["post"]) def unassign(self, request, **kwargs): parsed = request.data @@ -422,24 +430,24 @@ def change_piece_instrument(self, request, **kwargs): if piece_id is None: return Response( status=status.HTTP_400_BAD_REQUEST, - data={"error": "Piece Id missing from PATCH request"} + data={"error": "Piece Id missing from PATCH request"}, ) instrument_id = request.data.get("instrument_id") if instrument_id is None: return Response( status=status.HTTP_400_BAD_REQUEST, - data={"error": "Instrument ID missing from PATCH request"} + data={"error": "Instrument ID missing from PATCH request"}, ) course = self.get_object() if not course.can_edit_instruments: return Response( status=status.HTTP_403_FORBIDDEN, - data={"error": "No permission to change instrument"} + data={"error": "No permission to change instrument"}, ) - instrument = Instrument.objects.get(pk=instrument_id); + instrument = Instrument.objects.get(pk=instrument_id) piece = Piece.objects.get(pk=piece_id) assignments = Assignment.objects.filter(piece=piece, enrollment__course=course) diff --git a/teleband/courses/helper.py b/teleband/courses/helper.py index c8464a9..185695e 100644 --- a/teleband/courses/helper.py +++ b/teleband/courses/helper.py @@ -1,10 +1,16 @@ - from django.db import IntegrityError from teleband.courses.models import Enrollment, Course from teleband.musics.models import Piece, Part -from teleband.assignments.models import Activity, ActivityType, Assignment, AssignmentGroup, PiecePlan +from teleband.assignments.models import ( + Activity, + ActivityType, + Assignment, + AssignmentGroup, + PiecePlan, +) import random + def assign_all_piece_activities(course, piece, deadline=None): assignments = [] for activity in Activity.objects.filter( @@ -43,12 +49,14 @@ def assign_piece_plan(course, piece_plan, deadline=None): return assign_telephone_fixed(course, piece_plan, deadline) # else: # raise Exception("Unknown piece plan type") - + def assign_vanilla_piece_plan(course, piece_plan, deadline=None): assignments = [] for activity in piece_plan.activities.all(): - assignments += assign_one_piece_activity(course, piece_plan.piece, activity, deadline, piece_plan) + assignments += assign_one_piece_activity( + course, piece_plan.piece, activity, deadline, piece_plan + ) return assignments @@ -58,22 +66,27 @@ class AssignmentGroupSizeException(Exception): def assign_telephone_fixed(course, piece_plan, deadline=None): num_activities = piece_plan.activities.count() - num_enrollments = Enrollment.objects.filter(course=course, role__name="Student").count() + num_enrollments = Enrollment.objects.filter( + course=course, role__name="Student" + ).count() excess_enrollments = num_enrollments % num_activities if num_enrollments < num_activities: raise AssignmentGroupSizeException() - + # split the enrollments into groups of num_activities at random # and then assign the excess enrollments to the last group enrollments = list(Enrollment.objects.filter(course=course, role__name="Student")) random.shuffle(enrollments) final_group = [] if excess_enrollments == 0 else enrollments[-excess_enrollments:] - groups = [enrollments[i:i + num_activities] for i in range(0, len(enrollments) - excess_enrollments, num_activities)] + groups = [ + enrollments[i : i + num_activities] + for i in range(0, len(enrollments) - excess_enrollments, num_activities) + ] if excess_enrollments != 0: - used_enrollments = enrollments[0:len(enrollments) - excess_enrollments] + used_enrollments = enrollments[0 : len(enrollments) - excess_enrollments] random.shuffle(used_enrollments) - final_group += used_enrollments[0:num_activities - excess_enrollments] + final_group += used_enrollments[0 : num_activities - excess_enrollments] groups.append(final_group) # create an assignment group for each group of enrollments @@ -84,7 +97,7 @@ def assign_telephone_fixed(course, piece_plan, deadline=None): for group in groups: assignment_group = AssignmentGroup.objects.create(type="telephone_fixed") group_assignments = [] - for (e, a) in zip(group, piece_plan.activities.all()): + for e, a in zip(group, piece_plan.activities.all()): part = Part.for_activity(a, piece) group_assignments.append( Assignment.objects.create( @@ -94,17 +107,23 @@ def assign_telephone_fixed(course, piece_plan, deadline=None): instrument=e.instrument if e.instrument else e.user.instrument, piece_plan=piece_plan, piece=piece, - group=assignment_group + group=assignment_group, ) ) assignments += group_assignments return assignments -def assign_curriculum(course, curriculum, deadline=None): +def assign_curriculum(course, curriculum, deadline=None): # for each piece plan in the curriculum, assign all planned activities # in the piece plan. - return sum((assign_piece_plan(course, piece_plan, deadline) for piece_plan in curriculum.piece_plans.all()), []) + return sum( + ( + assign_piece_plan(course, piece_plan, deadline) + for piece_plan in curriculum.piece_plans.all() + ), + [], + ) def get_query_type_names(piece): @@ -132,4 +151,3 @@ def get_query_type_names(piece): if piece.name in connects: query_type_names.append(connects[piece.name]) return query_type_names - diff --git a/teleband/courses/migrations/0003_auto_20220110_2052.py b/teleband/courses/migrations/0003_auto_20220110_2052.py index 20942bb..542f6e7 100644 --- a/teleband/courses/migrations/0003_auto_20220110_2052.py +++ b/teleband/courses/migrations/0003_auto_20220110_2052.py @@ -5,6 +5,7 @@ import django.db.models.deletion from zoneinfo import ZoneInfo + class Migration(migrations.Migration): dependencies = [ @@ -17,7 +18,9 @@ class Migration(migrations.Migration): model_name="course", name="end_date", field=models.DateField( - default=datetime.datetime(2022, 1, 11, 1, 52, 38, 716619, tzinfo=ZoneInfo("UTC")) + default=datetime.datetime( + 2022, 1, 11, 1, 52, 38, 716619, tzinfo=ZoneInfo("UTC") + ) ), preserve_default=False, ), @@ -25,7 +28,9 @@ class Migration(migrations.Migration): model_name="course", name="start_date", field=models.DateField( - default=datetime.datetime(2022, 1, 11, 1, 52, 44, 131728, tzinfo=ZoneInfo("UTC")) + default=datetime.datetime( + 2022, 1, 11, 1, 52, 44, 131728, tzinfo=ZoneInfo("UTC") + ) ), preserve_default=False, ), diff --git a/teleband/courses/migrations/0006_course_can_edit_instruments.py b/teleband/courses/migrations/0006_course_can_edit_instruments.py index 8843634..b6326b6 100644 --- a/teleband/courses/migrations/0006_course_can_edit_instruments.py +++ b/teleband/courses/migrations/0006_course_can_edit_instruments.py @@ -6,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('courses', '0005_data_migration_demo_course'), + ("courses", "0005_data_migration_demo_course"), ] operations = [ migrations.AddField( - model_name='course', - name='can_edit_instruments', + model_name="course", + name="can_edit_instruments", field=models.BooleanField(default=False), ), ] diff --git a/teleband/instruments/migrations/0004_instrument_midi_program_number.py b/teleband/instruments/migrations/0004_instrument_midi_program_number.py index b90d0e3..81072c4 100644 --- a/teleband/instruments/migrations/0004_instrument_midi_program_number.py +++ b/teleband/instruments/migrations/0004_instrument_midi_program_number.py @@ -2,9 +2,10 @@ from django.db import migrations, models + def initial_instrument_program_numbers(apps, schema_editor): INSTRUMENT_PNS = { - "Viola": 42, + "Viola": 42, "Baritone TC": 58, "Bass Clarinet": 72, "Bb Clarinet": 72, @@ -13,18 +14,18 @@ def initial_instrument_program_numbers(apps, schema_editor): "Bb Tenor Saxophone": 67, "Bb Trumpet": 57, "Bassoon": 71, - "Cello": 43, + "Cello": 43, "Euphonium BC": 58, "Trombone": 58, - "Bass": 33, + "Bass": 33, "Bass Trombone": 58, "Contrabassoon": 71, "String Bass": 33, - "Tuba": 59, - "Oboe": 69, + "Tuba": 59, + "Oboe": 69, "Percussion": 13, - "Piano": 1, - "Flute": 74, + "Piano": 1, + "Flute": 74, "Piccolo": 73, "Violin": 41, "Contrabass Clarinet": 72, @@ -42,17 +43,20 @@ def initial_instrument_program_numbers(apps, schema_editor): instrument.midi_program_number = program_number instrument.save() + class Migration(migrations.Migration): dependencies = [ - ('instruments', '0003_data_migration_seed_instruments'), + ("instruments", "0003_data_migration_seed_instruments"), ] operations = [ migrations.AddField( - model_name='instrument', - name='midi_program_number', + model_name="instrument", + name="midi_program_number", field=models.PositiveSmallIntegerField(blank=True, null=True), ), - migrations.RunPython(initial_instrument_program_numbers, migrations.RunPython.noop) + migrations.RunPython( + initial_instrument_program_numbers, migrations.RunPython.noop + ), ] diff --git a/teleband/instruments/tests/test_drf_urls.py b/teleband/instruments/tests/test_drf_urls.py index 0a4097f..87be635 100644 --- a/teleband/instruments/tests/test_drf_urls.py +++ b/teleband/instruments/tests/test_drf_urls.py @@ -11,7 +11,10 @@ def test_instrument_detail(instrument: Instrument): reverse("api:instrument-detail", kwargs={"id": instrument.id}) == f"/api/instruments/{instrument.id}/" ) - assert resolve(f"/api/instruments/{instrument.id}/").view_name == "api:instrument-detail" + assert ( + resolve(f"/api/instruments/{instrument.id}/").view_name + == "api:instrument-detail" + ) def test_instrument_list(): diff --git a/teleband/musics/api/serializers.py b/teleband/musics/api/serializers.py index db336be..ea39d8e 100644 --- a/teleband/musics/api/serializers.py +++ b/teleband/musics/api/serializers.py @@ -51,7 +51,13 @@ class PartSerializer(serializers.ModelSerializer): class Meta: model = Part - fields = ["name", "piece", "transpositions", "sample_audio", "chord_scale_pattern"] + fields = [ + "name", + "piece", + "transpositions", + "sample_audio", + "chord_scale_pattern", + ] class PartTranspositionSerializer(serializers.ModelSerializer): diff --git a/teleband/musics/migrations/0011_seed_piece_parts_parttranspositions.py b/teleband/musics/migrations/0011_seed_piece_parts_parttranspositions.py index 52cdd45..a60be04 100644 --- a/teleband/musics/migrations/0011_seed_piece_parts_parttranspositions.py +++ b/teleband/musics/migrations/0011_seed_piece_parts_parttranspositions.py @@ -10,4 +10,6 @@ class Migration(migrations.Migration): ("instruments", "0003_data_migration_seed_instruments"), ] - operations = [migrations.RunPython(migrations.RunPython.noop, migrations.RunPython.noop)] + operations = [ + migrations.RunPython(migrations.RunPython.noop, migrations.RunPython.noop) + ] diff --git a/teleband/musics/migrations/0012_piece_slug.py b/teleband/musics/migrations/0012_piece_slug.py index a428a24..ab71c76 100644 --- a/teleband/musics/migrations/0012_piece_slug.py +++ b/teleband/musics/migrations/0012_piece_slug.py @@ -6,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('musics', '0011_seed_piece_parts_parttranspositions'), + ("musics", "0011_seed_piece_parts_parttranspositions"), ] operations = [ migrations.AddField( - model_name='piece', - name='slug', + model_name="piece", + name="slug", field=models.SlugField(null=True), ), ] diff --git a/teleband/musics/migrations/0013_assign_piece_slugs.py b/teleband/musics/migrations/0013_assign_piece_slugs.py index 499e0b4..f590655 100644 --- a/teleband/musics/migrations/0013_assign_piece_slugs.py +++ b/teleband/musics/migrations/0013_assign_piece_slugs.py @@ -16,7 +16,7 @@ def update_site_forward(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('musics', '0012_piece_slug'), + ("musics", "0012_piece_slug"), ] operations = [migrations.RunPython(update_site_forward, migrations.RunPython.noop)] diff --git a/teleband/musics/migrations/0014_alter_piece_slug.py b/teleband/musics/migrations/0014_alter_piece_slug.py index f486b48..8d5a168 100644 --- a/teleband/musics/migrations/0014_alter_piece_slug.py +++ b/teleband/musics/migrations/0014_alter_piece_slug.py @@ -6,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('musics', '0013_assign_piece_slugs'), + ("musics", "0013_assign_piece_slugs"), ] operations = [ migrations.AlterField( - model_name='piece', - name='slug', + model_name="piece", + name="slug", field=models.SlugField(), ), ] diff --git a/teleband/musics/migrations/0015_auto_20220206_2027.py b/teleband/musics/migrations/0015_auto_20220206_2027.py index 1aab9ad..648b2a6 100644 --- a/teleband/musics/migrations/0015_auto_20220206_2027.py +++ b/teleband/musics/migrations/0015_auto_20220206_2027.py @@ -6,18 +6,18 @@ class Migration(migrations.Migration): dependencies = [ - ('musics', '0014_alter_piece_slug'), + ("musics", "0014_alter_piece_slug"), ] operations = [ migrations.AddField( - model_name='part', - name='sample_audio', - field=models.FileField(blank=True, upload_to='sample_audio/'), + model_name="part", + name="sample_audio", + field=models.FileField(blank=True, upload_to="sample_audio/"), ), migrations.AddField( - model_name='piece', - name='accompaniment', - field=models.FileField(blank=True, upload_to='accompaniments/'), + model_name="piece", + name="accompaniment", + field=models.FileField(blank=True, upload_to="accompaniments/"), ), ] diff --git a/teleband/musics/migrations/0016_seed_pieces_later.py b/teleband/musics/migrations/0016_seed_pieces_later.py index 15732a5..2165839 100644 --- a/teleband/musics/migrations/0016_seed_pieces_later.py +++ b/teleband/musics/migrations/0016_seed_pieces_later.py @@ -103,9 +103,6 @@ } - - - def update_site_forward(apps, schema_editor): Piece = apps.get_model("musics", "Piece") already_at_piece = Piece.objects.filter(name="Air for Band").exists() diff --git a/teleband/musics/migrations/0017_seed_combined_part_20220720_1413.py b/teleband/musics/migrations/0017_seed_combined_part_20220720_1413.py index e7df68a..f5824d8 100644 --- a/teleband/musics/migrations/0017_seed_combined_part_20220720_1413.py +++ b/teleband/musics/migrations/0017_seed_combined_part_20220720_1413.py @@ -73,15 +73,11 @@ def update_site_forward(apps, schema_editor): for part in data["parts"]: create_part_et_al(apps, part, piece) - - - - class Migration(migrations.Migration): dependencies = [ - ('musics', '0016_seed_pieces_later'), + ("musics", "0016_seed_pieces_later"), ] operations = [migrations.RunPython(update_site_forward, migrations.RunPython.noop)] diff --git a/teleband/musics/migrations/0018_seed_more_music.py b/teleband/musics/migrations/0018_seed_more_music.py index 7932104..5a450c1 100644 --- a/teleband/musics/migrations/0018_seed_more_music.py +++ b/teleband/musics/migrations/0018_seed_more_music.py @@ -701,6 +701,7 @@ }, } + def update_site_forward(apps, schema_editor): Piece = apps.get_model("musics", "Piece") if Piece.objects.filter(name=data[0]["name"]).exists(): @@ -712,11 +713,11 @@ def update_site_forward(apps, schema_editor): t["flatio"] = json.dumps(flatios[part["name"]][t["transposition"]]) create_piece_et_al(apps, piece) + class Migration(migrations.Migration): dependencies = [ - ('musics', '0017_seed_combined_part_20220720_1413'), + ("musics", "0017_seed_combined_part_20220720_1413"), ] operations = [migrations.RunPython(update_site_forward, migrations.RunPython.noop)] - diff --git a/teleband/musics/migrations/0022_part_chord_scale_pattern.py b/teleband/musics/migrations/0022_part_chord_scale_pattern.py index 788b42f..5e58773 100644 --- a/teleband/musics/migrations/0022_part_chord_scale_pattern.py +++ b/teleband/musics/migrations/0022_part_chord_scale_pattern.py @@ -6,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('musics', '0021_auto_20230920_add_sample_audio'), + ("musics", "0021_auto_20230920_add_sample_audio"), ] operations = [ migrations.AddField( - model_name='part', - name='chord_scale_pattern', + model_name="part", + name="chord_scale_pattern", field=models.JSONField(blank=True, null=True), ), ] diff --git a/teleband/musics/migrations/0024_auto_20231030_2217_piece_slugs.py b/teleband/musics/migrations/0024_auto_20231030_2217_piece_slugs.py index b0edd1a..6ee7d99 100644 --- a/teleband/musics/migrations/0024_auto_20231030_2217_piece_slugs.py +++ b/teleband/musics/migrations/0024_auto_20231030_2217_piece_slugs.py @@ -11,10 +11,11 @@ def update_site_forward(apps, schema_editor): generate_slug_from_name(piece, Piece) piece.save() + class Migration(migrations.Migration): dependencies = [ - ('musics', '0023_seedchord_scale_patterns_20231019_1228'), + ("musics", "0023_seedchord_scale_patterns_20231019_1228"), ] operations = [migrations.RunPython(update_site_forward, migrations.RunPython.noop)] diff --git a/teleband/musics/migrations/0025_auto_20240223_1015.py b/teleband/musics/migrations/0025_auto_20240223_1015.py index 8d3a75c..23d2056 100644 --- a/teleband/musics/migrations/0025_auto_20240223_1015.py +++ b/teleband/musics/migrations/0025_auto_20240223_1015.py @@ -24,7 +24,7 @@ def update_site_forward(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('musics', '0024_auto_20231030_2217_piece_slugs'), + ("musics", "0024_auto_20231030_2217_piece_slugs"), ] operations = [migrations.RunPython(update_site_forward, migrations.RunPython.noop)] diff --git a/teleband/musics/migrations/0026_fix_deep_river_20240315_1420.py b/teleband/musics/migrations/0026_fix_deep_river_20240315_1420.py index 9d25a60..30b065e 100644 --- a/teleband/musics/migrations/0026_fix_deep_river_20240315_1420.py +++ b/teleband/musics/migrations/0026_fix_deep_river_20240315_1420.py @@ -9,29 +9,42 @@ def update_site_forward(apps, schema_editor): PartTransposition = apps.get_model("musics", "PartTransposition") PartType = apps.get_model("musics", "PartType") Transposition = apps.get_model("instruments", "Transposition") - - deep_river, deep_river_created = Piece.objects.get_or_create(name="Deep River") + + deep_river, deep_river_created = Piece.objects.get_or_create(name="Deep River") melody, melody_created = PartType.objects.get_or_create(name="Melody") bassline, bassline_created = PartType.objects.get_or_create(name="Bassline") - dr_melody, dr_melody_created = Part.objects.get_or_create(piece=deep_river, part_type=melody) - dr_bassline, dr_bassline_created = Part.objects.get_or_create(piece=deep_river, part_type=bassline) - - concert_tc, concert_tc_created = Transposition.objects.get_or_create(name="Concert Pitch TC") - concert_bc, concert_bc_created = Transposition.objects.get_or_create(name="Concert Pitch BC") - - dr_melody_tc, dr_melody_tc_created = PartTransposition.objects.get_or_create(part=dr_melody, transposition=concert_tc) + dr_melody, dr_melody_created = Part.objects.get_or_create( + piece=deep_river, part_type=melody + ) + dr_bassline, dr_bassline_created = Part.objects.get_or_create( + piece=deep_river, part_type=bassline + ) + + concert_tc, concert_tc_created = Transposition.objects.get_or_create( + name="Concert Pitch TC" + ) + concert_bc, concert_bc_created = Transposition.objects.get_or_create( + name="Concert Pitch BC" + ) + + dr_melody_tc, dr_melody_tc_created = PartTransposition.objects.get_or_create( + part=dr_melody, transposition=concert_tc + ) dr_melody_tc.flatio = '{"scoreId": "65f3164ea114758e30975d47", "sharingKey": "89b9d230dddd45edd858af771f3630b148705b2f5fa361678cf46864697cee3611f4dd49494c307513e8d261f65221692de79b474882560b649249fe2f2ad7b2"}' dr_melody_tc.save() - dr_bassline_bc, dr_bassline_bc_created = PartTransposition.objects.get_or_create(part=dr_bassline, transposition=concert_bc) + dr_bassline_bc, dr_bassline_bc_created = PartTransposition.objects.get_or_create( + part=dr_bassline, transposition=concert_bc + ) dr_bassline_bc.flatio = '{"scoreId": "65f317750f4bde10c7aff326", "sharingKey": "6a9ecd6102c4d6be5b104679a0d74def797b7022ffa45c8cdb75aa1f2aec952eb94684b32333a67056eb7a115f69b4ba13023b6faa1ecda35a0154e131b85210"}' dr_bassline_bc.save() + class Migration(migrations.Migration): dependencies = [ - ('musics', '0025_auto_20240223_1015'), + ("musics", "0025_auto_20240223_1015"), ] operations = [migrations.RunPython(update_site_forward, migrations.RunPython.noop)] diff --git a/teleband/musics/migrations/0027_correct_accompaniment_2040_and_deep_river_color_pattern_20240317_1712.py b/teleband/musics/migrations/0027_correct_accompaniment_2040_and_deep_river_color_pattern_20240317_1712.py index 41c373d..3dd8c36 100644 --- a/teleband/musics/migrations/0027_correct_accompaniment_2040_and_deep_river_color_pattern_20240317_1712.py +++ b/teleband/musics/migrations/0027_correct_accompaniment_2040_and_deep_river_color_pattern_20240317_1712.py @@ -2,10 +2,15 @@ from django.db import migrations + def update_site_forward(apps, schema_editor): Piece = apps.get_model("musics", "Piece") - orc_2040, orc_2040_created = Piece.objects.get_or_create(name="Freedom 2040 (Orchestra)") - orc_2040.accompaniment = "accompaniments/Freedom_2040_-Orchestra-_-Accompaniment_F_.mp3" + orc_2040, orc_2040_created = Piece.objects.get_or_create( + name="Freedom 2040 (Orchestra)" + ) + orc_2040.accompaniment = ( + "accompaniments/Freedom_2040_-Orchestra-_-Accompaniment_F_.mp3" + ) orc_2040.save() Part = apps.get_model("musics", "Part") @@ -13,14 +18,17 @@ def update_site_forward(apps, schema_editor): deep_river, deep_river_created = Piece.objects.get_or_create(name="Deep River") melody, melody_created = PartType.objects.get_or_create(name="Melody") - dr_melody, dr_melody_created = Part.objects.get_or_create(piece=deep_river, part_type=melody) + dr_melody, dr_melody_created = Part.objects.get_or_create( + piece=deep_river, part_type=melody + ) deep_river_corrected = '["tonic", "subdominant", "tonic", "dominant", "tonic", "subdominant", "dominant", "tonic"]' dr_melody.chord_scale_pattern = deep_river_corrected + class Migration(migrations.Migration): dependencies = [ - ('musics', '0026_fix_deep_river_20240315_1420'), + ("musics", "0026_fix_deep_river_20240315_1420"), ] operations = [migrations.RunPython(update_site_forward, migrations.RunPython.noop)] diff --git a/teleband/musics/models.py b/teleband/musics/models.py index 5a024d6..cd6effa 100644 --- a/teleband/musics/models.py +++ b/teleband/musics/models.py @@ -60,12 +60,15 @@ class Part(models.Model): part_type = models.ForeignKey(PartType, on_delete=models.PROTECT) piece = models.ForeignKey(Piece, related_name="parts", on_delete=models.PROTECT) sample_audio = models.FileField(blank=True, upload_to="sample_audio/") - chord_scale_pattern = models.JSONField(blank=True,null=True) + chord_scale_pattern = models.JSONField(blank=True, null=True) def for_activity(activity, piece): # Get this piece’s part for this kind of activity kwargs = {"piece": piece} - if activity.part_type and piece.parts.filter(part_type=activity.part_type).exists(): + if ( + activity.part_type + and piece.parts.filter(part_type=activity.part_type).exists() + ): kwargs["part_type"] = activity.part_type # TODO: should we have an else for when it's null? I think so, here it is. else: diff --git a/teleband/submissions/api/serializers.py b/teleband/submissions/api/serializers.py index da2c7e2..c619676 100644 --- a/teleband/submissions/api/serializers.py +++ b/teleband/submissions/api/serializers.py @@ -1,25 +1,46 @@ from rest_framework import serializers from teleband.submissions.models import Grade, Submission, SubmissionAttachment + # from teleband.assignments.api.serializers import AssignmentSerializer + class AttachmentSerializer(serializers.ModelSerializer): class Meta: model = SubmissionAttachment fields = ["id", "file", "submitted"] + class SubmissionSerializer(serializers.ModelSerializer): - attachments = AttachmentSerializer(many=True,required=False) + attachments = AttachmentSerializer(many=True, required=False) + class Meta: model = Submission - fields = ["id", "submitted", "content", "grade", "self_grade", "attachments", "index"] + fields = [ + "id", + "submitted", + "content", + "grade", + "self_grade", + "attachments", + "index", + ] # extra_kwargs = { # "assignment": {"view_name": "api:assignment-detail", "lookup_field": "id"}, # } + class GradeSerializer(serializers.ModelSerializer): class Meta: model = Grade - fields = ["id", "rhythm", "tone", "expression", "created_at", "grader", "student_submission", "own_submission"] - + fields = [ + "id", + "rhythm", + "tone", + "expression", + "created_at", + "grader", + "student_submission", + "own_submission", + ] diff --git a/teleband/submissions/migrations/0007_auto_20220501_1627.py b/teleband/submissions/migrations/0007_auto_20220501_1627.py index 0ca6b04..d500f57 100644 --- a/teleband/submissions/migrations/0007_auto_20220501_1627.py +++ b/teleband/submissions/migrations/0007_auto_20220501_1627.py @@ -7,26 +7,42 @@ class Migration(migrations.Migration): dependencies = [ - ('submissions', '0006_submissionattachment_submitted'), + ("submissions", "0006_submissionattachment_submitted"), ] operations = [ migrations.AlterModelOptions( - name='submissionattachment', - options={'ordering': ['-submitted'], 'verbose_name': 'Submission Attachment', 'verbose_name_plural': 'Submission Attachments'}, + name="submissionattachment", + options={ + "ordering": ["-submitted"], + "verbose_name": "Submission Attachment", + "verbose_name_plural": "Submission Attachments", + }, ), migrations.RemoveField( - model_name='grade', - name='submission', + model_name="grade", + name="submission", ), migrations.AddField( - model_name='submission', - name='grade', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='student_submission', to='submissions.grade'), + model_name="submission", + name="grade", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="student_submission", + to="submissions.grade", + ), ), migrations.AddField( - model_name='submission', - name='self_grade', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='own_submission', to='submissions.grade'), + model_name="submission", + name="self_grade", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="own_submission", + to="submissions.grade", + ), ), ] diff --git a/teleband/submissions/migrations/0008_alter_submission_assignment.py b/teleband/submissions/migrations/0008_alter_submission_assignment.py index 349522b..dcbadd5 100644 --- a/teleband/submissions/migrations/0008_alter_submission_assignment.py +++ b/teleband/submissions/migrations/0008_alter_submission_assignment.py @@ -7,14 +7,18 @@ class Migration(migrations.Migration): dependencies = [ - ('assignments', '0021_auto_20230517_1130'), - ('submissions', '0007_auto_20220501_1627'), + ("assignments", "0021_auto_20230517_1130"), + ("submissions", "0007_auto_20220501_1627"), ] operations = [ migrations.AlterField( - model_name='submission', - name='assignment', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='submissions', to='assignments.assignment'), + model_name="submission", + name="assignment", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="submissions", + to="assignments.assignment", + ), ), ] diff --git a/teleband/submissions/migrations/0009_submission_index.py b/teleband/submissions/migrations/0009_submission_index.py index f851a04..9c1248c 100644 --- a/teleband/submissions/migrations/0009_submission_index.py +++ b/teleband/submissions/migrations/0009_submission_index.py @@ -6,13 +6,13 @@ class Migration(migrations.Migration): dependencies = [ - ('submissions', '0008_alter_submission_assignment'), + ("submissions", "0008_alter_submission_assignment"), ] operations = [ migrations.AddField( - model_name='submission', - name='index', + model_name="submission", + name="index", field=models.PositiveIntegerField(default=0), ), ] diff --git a/teleband/submissions/models.py b/teleband/submissions/models.py index 8de7f7c..fb67d07 100644 --- a/teleband/submissions/models.py +++ b/teleband/submissions/models.py @@ -31,7 +31,9 @@ class Submission(models.Model): null=True, related_name="own_submission", ) - assignment = models.ForeignKey(Assignment, on_delete=models.PROTECT, related_name="submissions") + assignment = models.ForeignKey( + Assignment, on_delete=models.PROTECT, related_name="submissions" + ) index = models.PositiveIntegerField(default=0) submitted = models.DateTimeField(auto_now_add=True) content = models.TextField(blank=True) diff --git a/teleband/users/admin.py b/teleband/users/admin.py index b7f35d2..1112a8d 100644 --- a/teleband/users/admin.py +++ b/teleband/users/admin.py @@ -16,6 +16,7 @@ class EnrollmentInline(admin.TabularInline): model = Enrollment extra = 0 + @admin.register(User) class UserAdmin(auth_admin.UserAdmin): diff --git a/teleband/users/api/views.py b/teleband/users/api/views.py index 89cfb90..988cdc0 100644 --- a/teleband/users/api/views.py +++ b/teleband/users/api/views.py @@ -92,13 +92,13 @@ def bulk_create_teachers(self, request): validate_email(invitee) CleanEmailMixin().validate_invitation(invitee) invite = Invitation.create(invitee, group=teacher_group) - except (ValidationError): + except ValidationError: response["invalid"].append({invitee: "invalid email"}) - except (AlreadyAccepted): + except AlreadyAccepted: response["invalid"].append({invitee: "already accepted"}) - except (AlreadyInvited): + except AlreadyInvited: response["invalid"].append({invitee: "pending invite"}) - except (UserRegisteredEmail): + except UserRegisteredEmail: response["invalid"].append({invitee: "user registered email"}) else: invite.send_invitation(request) diff --git a/teleband/users/migrations/0009_data_migration_teacher_django_group.py b/teleband/users/migrations/0009_data_migration_teacher_django_group.py index 3208e03..51d9c69 100644 --- a/teleband/users/migrations/0009_data_migration_teacher_django_group.py +++ b/teleband/users/migrations/0009_data_migration_teacher_django_group.py @@ -2,6 +2,7 @@ from django.db import migrations + def add_demo_to_group(apps, schema_editor): User = apps.get_model("users", "User") demodave = User.objects.filter(username="demodave").first() @@ -19,7 +20,7 @@ def add_demo_to_group(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('users', '0008_user_external_id'), + ("users", "0008_user_external_id"), ] operations = [migrations.RunPython(add_demo_to_group, migrations.RunPython.noop)] diff --git a/teleband/users/migrations/0010_alter_user_external_id.py b/teleband/users/migrations/0010_alter_user_external_id.py index 5c25544..41ebefd 100644 --- a/teleband/users/migrations/0010_alter_user_external_id.py +++ b/teleband/users/migrations/0010_alter_user_external_id.py @@ -6,13 +6,18 @@ class Migration(migrations.Migration): dependencies = [ - ('users', '0009_data_migration_teacher_django_group'), + ("users", "0009_data_migration_teacher_django_group"), ] operations = [ migrations.AlterField( - model_name='user', - name='external_id', - field=models.CharField(blank=True, help_text="Any string that is meaningful to the user's educational institution.", max_length=255, verbose_name='External ID'), + model_name="user", + name="external_id", + field=models.CharField( + blank=True, + help_text="Any string that is meaningful to the user's educational institution.", + max_length=255, + verbose_name="External ID", + ), ), ] diff --git a/teleband/users/tests/test_forms.py b/teleband/users/tests/test_forms.py index 7f00be4..1d76221 100644 --- a/teleband/users/tests/test_forms.py +++ b/teleband/users/tests/test_forms.py @@ -1,6 +1,7 @@ """ Module for all Form Tests. """ + import pytest from django.utils.translation import gettext_lazy as _ diff --git a/teleband/utils/migration_helpers.py b/teleband/utils/migration_helpers.py index 5b48c8a..c00bab0 100644 --- a/teleband/utils/migration_helpers.py +++ b/teleband/utils/migration_helpers.py @@ -3,34 +3,39 @@ def create_part_et_al(apps, part, piece): PartType = apps.get_model("musics", "PartType") PartTransposition = apps.get_model("musics", "PartTransposition") Transposition = apps.get_model("instruments", "Transposition") - name = part['name'] - part_type = PartType.objects.get(name=part['part_type']) + name = part["name"] + part_type = PartType.objects.get(name=part["part_type"]) # print('\n\n\n\n\n===========\npart, piece') # print(part, piece) new_part = Part.objects.create(name=name, piece=piece, part_type=part_type) - for t in part['transpositions']: - transposition = Transposition.objects.get(name=t['transposition']) - part_trans = PartTransposition.objects.create(part=new_part,transposition=transposition, flatio=t["flatio"]) + for t in part["transpositions"]: + transposition = Transposition.objects.get(name=t["transposition"]) + part_trans = PartTransposition.objects.create( + part=new_part, transposition=transposition, flatio=t["flatio"] + ) new_part.transpositions.add(part_trans) new_part.save() piece.parts.add(new_part) + def create_piece_et_al(apps, data): Piece = apps.get_model("musics", "Piece") EnsembleType = apps.get_model("musics", "EnsembleType") # print('\n\n\n\n\n===========\ndata') # print(data) - already_at_piece = Piece.objects.filter(name=data['name']).exists() + already_at_piece = Piece.objects.filter(name=data["name"]).exists() piece = None if not already_at_piece: - piece = Piece.objects.create(name=data['name'], ensemble_type=EnsembleType.objects.get(name=data['ensemble_type'])) - if 'video' in data: - piece.video = data['video'] + piece = Piece.objects.create( + name=data["name"], + ensemble_type=EnsembleType.objects.get(name=data["ensemble_type"]), + ) + if "video" in data: + piece.video = data["video"] else: piece = Piece.objects.get(name="Air for Band") - piece.accompaniment = data['accompaniment'] + piece.accompaniment = data["accompaniment"] piece.save() - part_data = data['parts'] + part_data = data["parts"] for part in part_data: create_part_et_al(apps, part, piece) - \ No newline at end of file