diff --git a/backend/experiment/admin.py b/backend/experiment/admin.py index d46a5010e..225143011 100644 --- a/backend/experiment/admin.py +++ b/backend/experiment/admin.py @@ -53,7 +53,7 @@ class ExperimentAdmin(InlineActionsModelAdminMixin, admin.ModelAdmin): search_fields = ['name'] inline_actions = ['export', 'export_csv'] fields = ['name', 'description', 'image', - 'slug', 'url', 'hashtag', 'theme_config', + 'slug', 'url', 'hashtag', 'theme_config', 'language', 'active', 'rules', 'rounds', 'bonus_points', 'playlists', 'consent'] @@ -104,7 +104,7 @@ def export(self, request, obj, parent_obj=None): # create forced download response response = HttpResponse(zip_buffer.getbuffer()) response['Content-Type'] = 'application/x-zip-compressed' - response['Content-Disposition'] = 'attachment; filename="'+obj.slug+'-'+timezone.now().isoformat()+'.zip"' + response['Content-Disposition'] = 'attachment; filename="'+obj.slug+'-'+timezone.now().isoformat()+'.zip"' return response export.short_description = "Export JSON" @@ -228,7 +228,7 @@ def description_excerpt(self, obj): def phases(self, obj): phases = Phase.objects.filter(series=obj) return format_html(', '.join([f'{phase.name}' for phase in phases])) - + slug_link.short_description = "Slug" def dashboard(self, request, obj, parent_obj=None): @@ -249,7 +249,7 @@ def dashboard(self, request, obj, parent_obj=None): 'participant_count': len(exp.current_participants()), 'participants': exp.current_participants() } for exp in all_experiments] - + return render( request, 'collection-dashboard.html', @@ -265,8 +265,8 @@ def dashboard(self, request, obj, parent_obj=None): class PhaseAdmin(InlineActionsModelAdminMixin, admin.ModelAdmin): - list_display = ('name_link', 'related_series', 'order', 'dashboard', 'randomize', 'experiments') - fields = ['name', 'series', 'order', 'dashboard', 'randomize'] + list_display = ('name_link', 'related_series', 'index', 'dashboard', 'randomize', 'experiments') + fields = ['name', 'series', 'index', 'dashboard', 'randomize'] inlines = [GroupedExperimentInline] def name_link(self, obj): diff --git a/backend/experiment/migrations/0040_alter_phase_options_remove_phase_order_phase_index_and_more.py b/backend/experiment/migrations/0040_alter_phase_options_remove_phase_order_phase_index_and_more.py new file mode 100644 index 000000000..1ed4d43f2 --- /dev/null +++ b/backend/experiment/migrations/0040_alter_phase_options_remove_phase_order_phase_index_and_more.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.11 on 2024-07-02 08:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('experiment', '0039_auto_20240625_1055'), + ] + + operations = [ + migrations.AlterModelOptions( + name='phase', + options={'ordering': ['index']}, + ), + migrations.RemoveField( + model_name='phase', + name='order', + ), + migrations.AddField( + model_name='phase', + name='index', + field=models.IntegerField(default=0, help_text='Index of the phase in the series. Lower numbers come first.'), + ), + migrations.AlterField( + model_name='phase', + name='randomize', + field=models.BooleanField(default=False, help_text='Randomize the order of the experiments in this phase.'), + ), + ] diff --git a/backend/experiment/models.py b/backend/experiment/models.py index e7495a107..7cdaf7427 100644 --- a/backend/experiment/models.py +++ b/backend/experiment/models.py @@ -72,7 +72,7 @@ class Phase(models.Model): name = models.CharField(max_length=64, blank=True, default='') series = models.ForeignKey(ExperimentCollection, on_delete=models.CASCADE, related_name='phases') - order = models.IntegerField(default=0, help_text='Order of the phase in the series. Lower numbers come first.') + index = models.IntegerField(default=0, help_text='Index of the phase in the series. Lower numbers come first.') dashboard = models.BooleanField(default=False) randomize = models.BooleanField( default=False, help_text='Randomize the order of the experiments in this phase.') @@ -86,7 +86,7 @@ def __str__(self): return f'{compound_name}' class Meta: - ordering = ['order'] + ordering = ['index'] class GroupedExperiment(models.Model): diff --git a/backend/experiment/tests/test_admin_experiment.py b/backend/experiment/tests/test_admin_experiment.py index 1b638050a..53f1f0228 100644 --- a/backend/experiment/tests/test_admin_experiment.py +++ b/backend/experiment/tests/test_admin_experiment.py @@ -114,7 +114,7 @@ def setUp(self): self.admin = ExperimentAdmin(model=Experiment, admin_site=AdminSite ) - + def test_admin_export(self): response = self.admin.export(request, self.experiment) zip_buffer = BytesIO(response.content) @@ -225,7 +225,7 @@ def setUp(self): def test_related_series_with_series(self): series = ExperimentCollection.objects.create(name='Test Series') phase = Phase.objects.create( - name='Test Group', order=1, randomize=False, series=series, dashboard=True) + name='Test Group', index=1, randomize=False, series=series, dashboard=True) related_series = self.admin.related_series(phase) expected_url = reverse( "admin:experiment_experimentcollection_change", args=[series.pk]) @@ -235,14 +235,14 @@ def test_related_series_with_series(self): def test_experiments_with_no_experiments(self): series = ExperimentCollection.objects.create(name='Test Series') phase = Phase.objects.create( - name='Test Group', order=1, randomize=False, dashboard=True, series=series) + name='Test Group', index=1, randomize=False, dashboard=True, series=series) experiments = self.admin.experiments(phase) self.assertEqual(experiments, "No experiments") def test_experiments_with_experiments(self): series = ExperimentCollection.objects.create(name='Test Series') phase = Phase.objects.create( - name='Test Group', order=1, randomize=False, dashboard=True, series=series) + name='Test Group', index=1, randomize=False, dashboard=True, series=series) experiment1 = Experiment.objects.create(name='Experiment 1', slug='experiment-1') experiment2 = Experiment.objects.create(name='Experiment 2', slug='experiment-2') grouped_experiment1 = GroupedExperiment.objects.create(phase=phase, experiment=experiment1) diff --git a/backend/experiment/tests/test_views.py b/backend/experiment/tests/test_views.py index 9073e9fb7..1712d304c 100644 --- a/backend/experiment/tests/test_views.py +++ b/backend/experiment/tests/test_views.py @@ -33,7 +33,7 @@ def setUpTestData(cls): introductory_phase = Phase.objects.create( name='introduction', series=collection, - order=1 + index=1 ) cls.experiment1 = Experiment.objects.create( name='experiment1', slug='experiment1') @@ -44,7 +44,7 @@ def setUpTestData(cls): intermediate_phase = Phase.objects.create( name='intermediate', series=collection, - order=2 + index=2 ) cls.experiment2 = Experiment.objects.create( name='experiment2', slug='experiment2', theme_config=theme_config) @@ -61,7 +61,7 @@ def setUpTestData(cls): final_phase = Phase.objects.create( name='final', series=collection, - order=3 + index=3 ) cls.experiment4 = Experiment.objects.create( name='experiment4', slug='experiment4') diff --git a/backend/experiment/views.py b/backend/experiment/views.py index 45df7c954..5e9828152 100644 --- a/backend/experiment/views.py +++ b/backend/experiment/views.py @@ -106,7 +106,7 @@ def get_experiment_collection( request.session[COLLECTION_KEY] = slug participant = get_participant(request) phases = list(Phase.objects.filter( - series=collection.id).order_by('order')) + series=collection.id).order_by('index')) try: current_phase = phases[phase_index] serialized_phase = serialize_phase(