forked from hacktoolkit/django-htk
-
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
Open
goztrk
wants to merge
2
commits into
features/assessments-app
Choose a base branch
from
features/assessments-app-model-structure
base: features/assessments-app
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Assessments App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# HTK Imports | ||
from htk.apps.assessments.enums import QuestionType | ||
from htk.utils.enums import get_enum_choices | ||
|
||
|
||
def get_question_type_choices(include_hidden=True): | ||
choices = get_enum_choices(QuestionType, include_hidden=include_hidden) | ||
return choices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# HTK Imports | ||
from htk.utils.enums import HtkEnum | ||
|
||
|
||
class QuestionType(HtkEnum): | ||
UNSPECIFIED = 0 | ||
# Answer is a free text response | ||
BASIC = 1 | ||
# Multiple answer choices are presented, only one is correct | ||
MULTI_CHOICE = 2 | ||
# Multiple answer choices are presented, any number (0 or many) can be correct, | ||
# all correct responses must be selected | ||
MULTI_CHOICE_MULTI_ANSWER = 4 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Django Imports | ||
from django.db import models | ||
|
||
# HTK Imports | ||
from htk.apps.assessments.models.fk_fields import ( | ||
fk_assessment, | ||
fk_question, | ||
) | ||
from htk.models.classes import HtkBaseModel | ||
|
||
|
||
DEFAULT_RELATED_NAME = 'answer_key' | ||
DEFAULT_RELATED_NAME_PLURAL = 'answer_keys' | ||
|
||
|
||
class AssessmentQuestionAnswerKey(HtkBaseModel): | ||
assessment = fk_assessment(DEFAULT_RELATED_NAME_PLURAL, required=True) | ||
question = fk_question(DEFAULT_RELATED_NAME, required=True, one_to_one=True) | ||
|
||
class Meta: | ||
verbose_name = 'Assessment Question Answer Key' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# HTK Imports | ||
from htk.models.classes import HtkBaseModel | ||
|
||
|
||
class Assessment(HtkBaseModel): | ||
class Meta: | ||
verbose_name = 'Assessment' | ||
|
||
@property | ||
def max_score(self): | ||
return self.questions.count() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 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, one_to_one=False): | ||
method_name = 'OneToOneField' if one_to_one else 'ForeignKey' | ||
field_method = getattr(models, method_name) | ||
field = field_method( | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Python Standard Library Imports | ||
import random | ||
|
||
# Django Imports | ||
from django.db import models | ||
|
||
# HTK Imports | ||
from htk.apps.assessments.choices import get_question_type_choices | ||
from htk.apps.assessments.enums import QuestionType | ||
from htk.apps.assessments.models.fk_fields import fk_assessment | ||
from htk.models.classes import HtkBaseModel | ||
|
||
|
||
DEFAULT_RELATED_NAME = 'questions' | ||
|
||
|
||
class AssessmentQuestion(HtkBaseModel): | ||
assessment = fk_assessment(DEFAULT_RELATED_NAME, required=True) | ||
type = models.PositiveIntegerField( | ||
choices=get_question_type_choices(), default=QuestionType.UNSPECIFIED | ||
) | ||
text = models.TextField(max_length=512) | ||
order = models.PositiveSmallIntegerField(default=0) | ||
should_shuffle_choices = models.BooleanField(default=False) | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# HTK Imports | ||
from htk.apps.assessments.models.fk_fields import ( | ||
fk_assessment, | ||
fk_question, | ||
) | ||
from htk.models.classes import HtkBaseModel | ||
|
||
|
||
DEFAULT_RELATED_NAME = 'responses' | ||
|
||
|
||
class AssessmentResponse(HtkBaseModel): | ||
assessment = fk_assessment(DEFAULT_RELATED_NAME, required=True) | ||
question = fk_question(DEFAULT_RELATED_NAME, required=True) | ||
|
||
class Meta: | ||
verbose_name = 'Assessment Question Response' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.