-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Assessments app Initial model structure #2
base: features/assessments-app
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
HTK_ASSESSMENTS_ASSESSMENT_MODEL = 'htk.Assessment' | ||
HTK_ASSESSMENTS_QUESTION_MODEL = 'htk.Question' | ||
HTK_ASSESSMENTS_QUESTION_CHOICE_MODEL = 'htk.QuestionChoice' | ||
HTK_ASSESSMENTS_ANSWER_MODEL = 'htk.Answer' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Django Imports | ||
from django.db import models | ||
|
||
# HTK Imports | ||
from htk.apps.assessments.models.fk_fields import ( | ||
fk_question, | ||
fk_question_choice, | ||
) | ||
from htk.models.classes import HtkBaseModel | ||
from htk.models.fk_fields import fk_user | ||
|
||
|
||
DEFAULT_RELATED_NAME = 'answers' | ||
|
||
|
||
class Answer(HtkBaseModel): | ||
user = fk_user(DEFAULT_RELATED_NAME, required=True) | ||
question = fk_question(DEFAULT_RELATED_NAME, required=True) | ||
choice = fk_question_choice(DEFAULT_RELATED_NAME) | ||
|
||
class Meta: | ||
verbose_name = 'Assessment Question Answer' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# HTK Imports | ||
from htk.models.classes import HtkBaseModel | ||
|
||
|
||
class Assessment(HtkBaseModel): | ||
class Meta: | ||
verbose_name = 'Assessment' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Django Imports | ||
from django.db import models | ||
|
||
# HTK Imports | ||
from htk.models.fk_fields import build_kwargs | ||
from htk.utils import htk_setting | ||
|
||
|
||
def fk_assessment(related_name, required=False): | ||
field = models.ForeignKey( | ||
htk_setting('HTK_ASSESSMENTS_ASSESSMENT_MODEL'), | ||
related_name=related_name, | ||
**build_kwargs(required=required), | ||
) | ||
return field | ||
|
||
|
||
def fk_question(related_name, required=False): | ||
field = models.ForeignKey( | ||
htk_setting('HTK_ASSESSMENTS_QUESTION_MODEL'), | ||
related_name=related_name, | ||
**build_kwargs(required=required), | ||
) | ||
return field | ||
|
||
|
||
def fk_question_choice(related_name, required=False): | ||
field = models.ForeignKey( | ||
htk_setting('HTK_ASSESSMENTS_QUESTION_MODEL'), | ||
related_name=related_name, | ||
**build_kwargs(required=required), | ||
) | ||
return field |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Python Standard Library Imports | ||
import random | ||
|
||
# Django Imports | ||
from django.db import models | ||
|
||
# HTK Imports | ||
from htk.apps.assessments.models.fk_fields import fk_assessment | ||
from htk.models.classes import HtkBaseModel | ||
|
||
|
||
DEFAULT_RELATED_NAME = 'questions' | ||
|
||
|
||
class Question(HtkBaseModel): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking that there should be: Question Types:
|
||
assessment = fk_assessment(DEFAULT_RELATED_NAME, required=True) | ||
text = models.TextField(max_length=512) | ||
order = models.PositiveSmallIntegerField(default=0) | ||
should_shuffle_choices = models.BooleanField(default=False) | ||
has_correct_answer = models.BooleanField(default=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
|
||
class Meta: | ||
verbose_name = 'Assessment Question' | ||
|
||
## | ||
# Properties | ||
|
||
@property | ||
def choices_ordered(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
choices = self.choices.order_by('order') | ||
return choices | ||
|
||
@property | ||
def choices_shuffled(self): | ||
choices = self.choices.all() | ||
random.shuffle(choices) | ||
return choices | ||
|
||
@property | ||
def all_choices(self): | ||
choices = ( | ||
self.choices_shuffled | ||
if self.should_shuffle_choices | ||
else self.choices_ordered | ||
) | ||
return choices | ||
|
||
## | ||
# Helpers | ||
|
||
def is_answered_by_user(self, user, check_correction=False): | ||
answers = user.answers.filter(choice__question=self) | ||
if check_correction: | ||
answers = answers.filter(choice__is_correct=True) | ||
is_answered = answers.exists() | ||
return is_answered |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Django Imports | ||
from django.db import models | ||
|
||
# HTK Imports | ||
from htk.apps.assessments.models.fk_fields import fk_question | ||
from htk.models.classes import HtkBaseModel | ||
|
||
|
||
DEFAULT_RELATED_NAME = 'choices' | ||
|
||
|
||
class QuestionChoice(HtkBaseModel): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
question = fk_question(DEFAULT_RELATED_NAME, required=True) | ||
text = models.TextField(max_length=256) | ||
order = models.PositiveSmallIntegerField(default=0) | ||
is_correct = models.BooleanField(default=False) | ||
|
||
class Meta: | ||
verbose_name = 'Assessment Question Choice' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.