.
This commit is contained in:
+2
-6
@@ -157,7 +157,7 @@ class ExamBase(models.Model):
|
||||
|
||||
def get_exam_stats(self, name=True):
|
||||
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)}
|
||||
- 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
|
||||
|
||||
def email_user_results(self, user, resend=False, additional_emails=[]):
|
||||
print("email_user_reuslts:", user)
|
||||
|
||||
def email_user_results(self, user, resend=False, additional_emails=list):
|
||||
#if self.results_email_sent and not resend:
|
||||
# return False, "Already sent."
|
||||
|
||||
# Get a list of taken exams
|
||||
msg = self.generate_user_report(user)
|
||||
|
||||
print(msg)
|
||||
|
||||
if not user.email:
|
||||
return False, "User has no email"
|
||||
|
||||
|
||||
+16
-1
@@ -20,6 +20,9 @@ from django.http import HttpResponseRedirect, HttpResponse
|
||||
|
||||
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
|
||||
|
||||
@@ -585,6 +588,15 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
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
|
||||
# (who should be in exam.user_scores)
|
||||
users = [i[2:] for i in exam.user_scores if i.startswith("u/")]
|
||||
@@ -594,7 +606,10 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
email_results = {}
|
||||
for u in users:
|
||||
user = User.objects.get(pk=u)
|
||||
email_results[user.username] = exam.email_user_results(user)
|
||||
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)
|
||||
|
||||
user_exam = exam.get_or_create_cid_user_exam(user_user=user)
|
||||
user_exam.results_emailed_status = json.dumps(email_results[user.username]) + f" {time}"
|
||||
|
||||
@@ -104,7 +104,16 @@
|
||||
$(document).ready(() => {
|
||||
$("#email-results-button").click((evt) => {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user