From 0373b22e78d94eabb21a0d715ecfae57e0ce647f Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 20 May 2022 11:28:20 +0100 Subject: [PATCH] . --- Dockerfile | 1 + rad/settings.py | 37 ++++++++++---------- rapids/migrations/0053_ciduseranswer_user.py | 21 +++++++++++ rapids/models.py | 36 +++++++------------ 4 files changed, 53 insertions(+), 42 deletions(-) create mode 100644 rapids/migrations/0053_ciduseranswer_user.py diff --git a/Dockerfile b/Dockerfile index 375d654e..a6bc18fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ ENV PYTHONUNBUFFERED 1 # python3 python3-dev gcc \ # gfortran musl-dev \ # libffi-dev openssl-dev +RUN apt-get update && apt-get -y install postgresql postgresql-contrib # install dependencies RUN pip install --upgrade pip diff --git a/rad/settings.py b/rad/settings.py index be6214cd..2ab39b77 100644 --- a/rad/settings.py +++ b/rad/settings.py @@ -69,7 +69,7 @@ INSTALLED_APPS = [ "dbbackup", "rest_framework", "tinymce", - 'django_unused_media', + "django_unused_media", ] MIDDLEWARE = [ @@ -112,12 +112,11 @@ WSGI_APPLICATION = "rad.wsgi.application" DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", - "NAME": "rad", - "USER": "django", - "PASSWORD": "f7bf31dc9bda1256ea827953480d1917", - # "HOST": "xkjq.uk", - "HOST": "161.35.163.87", - "PORT": "5432", + "NAME": os.environ.get("DB_NAME", "rad"), + "USER": os.environ.get("DB_USER", "django"), + "PASSWORD": os.environ.get("DB_PASSWORD", "f7bf31dc9bda1256ea827953480d1917"), + "HOST": os.environ.get("DB_HOST", "161.35.163.87"), + "PORT": os.environ.get("DB_PORT", "5432"), } } @@ -259,21 +258,23 @@ DEFAULT_AUTO_FIELD = "django.db.models.AutoField" EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" -#SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY') -SENDGRID_API_KEY = "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" +# SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY') +SENDGRID_API_KEY = ( + "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" +) -EMAIL_HOST = 'smtp.sendgrid.net' -EMAIL_HOST_USER = 'apikey' # this is exactly the value 'apikey' +EMAIL_HOST = "smtp.sendgrid.net" +EMAIL_HOST_USER = "apikey" # this is exactly the value 'apikey' EMAIL_HOST_PASSWORD = SENDGRID_API_KEY EMAIL_PORT = 587 EMAIL_USE_TLS = True -#EMAIL_HOST = "smtp.office365.com " -#EMAIL_HOST_USER = "Penra.courses@nhs.net" -#EMAIL_HOST_PASSWORD = '"got3<}%o"~\J",\Di3<' -#EMAIL_PORT = 587 -#EMAIL_USE_TLS = True -#EMAIL_USE_SSl = False -#DEFAULT_FROM_EMAIL = EMAIL_HOST_USER +# EMAIL_HOST = "smtp.office365.com " +# EMAIL_HOST_USER = "Penra.courses@nhs.net" +# EMAIL_HOST_PASSWORD = '"got3<}%o"~\J",\Di3<' +# EMAIL_PORT = 587 +# EMAIL_USE_TLS = True +# EMAIL_USE_SSl = False +# DEFAULT_FROM_EMAIL = EMAIL_HOST_USER try: from .settings_local import * diff --git a/rapids/migrations/0053_ciduseranswer_user.py b/rapids/migrations/0053_ciduseranswer_user.py new file mode 100644 index 00000000..8cf56bc7 --- /dev/null +++ b/rapids/migrations/0053_ciduseranswer_user.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.13 on 2022-05-18 18:30 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('rapids', '0052_rapidimage_filename'), + ] + + operations = [ + migrations.AddField( + model_name='ciduseranswer', + name='user', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/rapids/models.py b/rapids/models.py index 04e35d82..01db6b0f 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -708,6 +708,11 @@ class CidUserAnswer(models.Model): help_text="Candidate ID (limitied by BigIntegerField size)", ) + user = models.ForeignKey( + settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True + ) + + # Each user answer is associated with a particular exam exam = models.ForeignKey( Exam, related_name="cid_user_answers", on_delete=models.CASCADE, null=True @@ -724,12 +729,17 @@ class CidUserAnswer(models.Model): ) def __str__(self): + + name = self.cid + if self.user is not None: + name = self.user.username + try: exam = self.exam except (Exam.DoesNotExist, KeyError) as e: exam = "None" return "{}/{}/{}: {}".format( - exam, self.cid, self.question.get_primary_answer(), self.answer + exam, name, self.question.get_primary_answer(), self.answer ) def save(self, *args, **kwargs): @@ -815,26 +825,4 @@ class CidUserAnswer(models.Model): elif marked_ans.status == Answer.MarkOptions.INCORRECT: mark = 0 - return mark - - if ( - q.answers.filter( - answer_compare__iexact=ans, status=Answer.MarkOptions.CORRECT - ).first() - is not None - ): - mark = 1 - elif ( - q.answers.filter( - answer_compare__iexact=ans, status=Answer.MarkOptions.HALF_MARK - ).first() - is not None - ): - mark = 0.5 - elif q.answers.filter( - answer_compare__iexact=ans, status=Answer.MarkOptions.INCORRECT - ).first(): - mark = 0 - else: - mark = "unmarked" - return mark + return mark \ No newline at end of file