.
This commit is contained in:
+2
-6
@@ -157,7 +157,7 @@ class ExamBase(models.Model):
|
|||||||
|
|
||||||
def get_exam_stats(self, name=True):
|
def get_exam_stats(self, name=True):
|
||||||
if self.stats_candidates < int(4):
|
if self.stats_candidates < int(4):
|
||||||
return f"- Candidates: {self.stats_candidates} (too few to generate stats)"
|
return f"- Candidates: {int(self.stats_candidates)} (too few to generate stats)"
|
||||||
|
|
||||||
text = f"""- Candidates: {int(self.stats_candidates)}
|
text = f"""- Candidates: {int(self.stats_candidates)}
|
||||||
- Mean: {self.stats_mean:.2f} Median: {self.stats_median} Mode: {self.stats_mode} [Min: {self.stats_min} / Max: {self.stats_max}]
|
- Mean: {self.stats_mean:.2f} Median: {self.stats_median} Mode: {self.stats_mode} [Min: {self.stats_min} / Max: {self.stats_max}]
|
||||||
@@ -324,17 +324,13 @@ class ExamBase(models.Model):
|
|||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def email_user_results(self, user, resend=False, additional_emails=[]):
|
def email_user_results(self, user, resend=False, additional_emails=list):
|
||||||
print("email_user_reuslts:", user)
|
|
||||||
|
|
||||||
#if self.results_email_sent and not resend:
|
#if self.results_email_sent and not resend:
|
||||||
# return False, "Already sent."
|
# return False, "Already sent."
|
||||||
|
|
||||||
# Get a list of taken exams
|
# Get a list of taken exams
|
||||||
msg = self.generate_user_report(user)
|
msg = self.generate_user_report(user)
|
||||||
|
|
||||||
print(msg)
|
|
||||||
|
|
||||||
if not user.email:
|
if not user.email:
|
||||||
return False, "User has no email"
|
return False, "User has no email"
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ from django.http import HttpResponseRedirect, HttpResponse
|
|||||||
|
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
||||||
|
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.core.validators import validate_email
|
||||||
|
|
||||||
|
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
|
|
||||||
@@ -585,6 +588,15 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
|
|
||||||
|
additional_email = request.GET.get("additional_email", "")
|
||||||
|
|
||||||
|
# check addition email is valid
|
||||||
|
if additional_email:
|
||||||
|
try:
|
||||||
|
validate_email(additional_email)
|
||||||
|
except ValidationError:
|
||||||
|
return JsonResponse("Invalid additional email")
|
||||||
|
|
||||||
# We only need to send emails to those who have scores
|
# We only need to send emails to those who have scores
|
||||||
# (who should be in exam.user_scores)
|
# (who should be in exam.user_scores)
|
||||||
users = [i[2:] for i in exam.user_scores if i.startswith("u/")]
|
users = [i[2:] for i in exam.user_scores if i.startswith("u/")]
|
||||||
@@ -594,6 +606,9 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
email_results = {}
|
email_results = {}
|
||||||
for u in users:
|
for u in users:
|
||||||
user = User.objects.get(pk=u)
|
user = User.objects.get(pk=u)
|
||||||
|
if additional_email:
|
||||||
|
email_results[user.username] = exam.email_user_results(user, additional_emails=[additional_email])
|
||||||
|
else:
|
||||||
email_results[user.username] = exam.email_user_results(user)
|
email_results[user.username] = exam.email_user_results(user)
|
||||||
|
|
||||||
user_exam = exam.get_or_create_cid_user_exam(user_user=user)
|
user_exam = exam.get_or_create_cid_user_exam(user_user=user)
|
||||||
|
|||||||
@@ -104,7 +104,16 @@
|
|||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
$("#email-results-button").click((evt) => {
|
$("#email-results-button").click((evt) => {
|
||||||
if (confirm("This will email results, please make sure scores have been refreshed before continuing")) {
|
if (confirm("This will email results, please make sure scores have been refreshed before continuing")) {
|
||||||
window.location = "{% url 'rapids:exam_report_email' exam_id=exam.pk %}";
|
|
||||||
|
let additional_email = prompt("Please enter an additional email to send to (user and supervisor will automatically be used if available) if required");
|
||||||
|
|
||||||
|
let url = "{% url 'rapids:exam_report_email' exam_id=exam.pk %}";
|
||||||
|
|
||||||
|
if ( additional_email != null ) {
|
||||||
|
url = url + "?additional_email="+encodeURI(additional_email)
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location = url;
|
||||||
|
|
||||||
}
|
}
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user