diff --git a/apps/fsm/migrations/0224_rename_lock_after_answer_multichoiceproblem_disable_after_answer.py b/apps/fsm/migrations/0224_rename_lock_after_answer_multichoiceproblem_disable_after_answer.py new file mode 100644 index 00000000..a244a2ff --- /dev/null +++ b/apps/fsm/migrations/0224_rename_lock_after_answer_multichoiceproblem_disable_after_answer.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.3 on 2024-11-06 03:41 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('fsm', '0223_fsm_participant_limit'), + ] + + operations = [ + migrations.RenameField( + model_name='multichoiceproblem', + old_name='lock_after_answer', + new_name='disable_after_answer', + ), + ] diff --git a/apps/fsm/models/question_widgets.py b/apps/fsm/models/question_widgets.py index 46e2b5ef..0cf32323 100644 --- a/apps/fsm/models/question_widgets.py +++ b/apps/fsm/models/question_widgets.py @@ -59,7 +59,7 @@ class MultiChoiceProblem(Problem): validators=[MinValueValidator(0)], default=1) max_selections = models.IntegerField( validators=[MinValueValidator(0)], default=1) - lock_after_answer = models.BooleanField(default=False) + disable_after_answer = models.BooleanField(default=False) randomize_choices = models.BooleanField( default=False, help_text="If enabled, the choices will be presented in random order" @@ -99,23 +99,6 @@ class Choice(models.Model): text = models.TextField() is_correct = models.BooleanField(default=False) - # default is True - def is_enabled(self, *args, **kwargs): - from apps.fsm.utils import AnswerSheetFacade - player = kwargs.get('player') - if not player: - return False - - answer_sheet = player.answer_sheet - facade = AnswerSheetFacade(answer_sheet) - - question = self.problem - if question.lock_after_answer: - if facade.check_expected_choice(self.id): - return False - - return True - def __str__(self): return self.text diff --git a/apps/widgets/serializers/question_widgets/question_widget_serializers.py b/apps/widgets/serializers/question_widgets/question_widget_serializers.py index cd9904ce..2c237eee 100644 --- a/apps/widgets/serializers/question_widgets/question_widget_serializers.py +++ b/apps/widgets/serializers/question_widgets/question_widget_serializers.py @@ -79,22 +79,7 @@ class Meta(QuestionWidgetSerializer.Meta): model = MultiChoiceProblem fields = QuestionWidgetSerializer.Meta.fields + \ ['min_selections', 'max_selections', - 'lock_after_answer', 'randomize_choices', 'choices'] - - def to_representation(self, instance): - representation = super().to_representation(instance) - request = self.context.get('request') - fsm_id = request.headers.get("FSM") - user = request.user - player = get_active_player(fsm_id, user.id) - choices_representation = [] - for choice in instance.choices.all(): - choices_representation.append({ - **ChoiceSerializer(choice).data, - 'enabled': choice.is_enabled(user=user, player=player), - }) - representation['choices'] = choices_representation - return representation + 'disable_after_answer', 'randomize_choices', 'choices'] def create(self, validated_data): choices_data = validated_data.pop('choices')