Skip to content

Commit

Permalink
refactor: rename lock_after_answer to disable_after_answer
Browse files Browse the repository at this point in the history
  • Loading branch information
AmooHashem committed Nov 6, 2024
1 parent aefdd69 commit 4f37f86
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -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',
),
]
19 changes: 1 addition & 18 deletions apps/fsm/models/question_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 4f37f86

Please sign in to comment.