Skip to content
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

New Emailing Settings #362

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ class UserChangeForm(forms.ModelForm):
# overriding modelfields to ensure required fields are provided
first_name = forms.CharField(max_length = 30, required=True)
last_name = forms.CharField(max_length = 30, required=True)
attestation_emails = forms.BooleanField(help_text="recive Email for each task attestation.", required=False)
upload_confirm_emails = forms.BooleanField(help_text="recive submission Email for each upload.", required=False)
#email = forms.EmailField(required=True)

class Meta:
model = User
fields = ("first_name", "last_name")
fields = ("first_name", "last_name", "attestation_emails", "upload_confirm_emails")


class AdminUserCreationForm(UserBaseCreationForm):
Expand Down
4 changes: 4 additions & 0 deletions src/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class User(BasicUser):
activation_key=models.CharField(_('activation key'), max_length=40, editable=False)
user_text=models.CharField(null=True, blank=True, max_length=500, help_text = _("Custom text which will be shown to this student."))
accepted_disclaimer=models.BooleanField(default=False, help_text="Whether the user accepted the disclaimer.")
#'attestationEmails' to check whether the user wishes to receive an email notification for each attestation.
attestationEmails = models.BooleanField(default=True, help_text="recive confirmation Email for each task has been attested.")
#'uploadConfirmEmails' to check whether the user wishes to receive an email notification for each upload they make.
uploadConfirmEmails = models.BooleanField(default=False, help_text="recive confirmation Email for each file has been uploaded.")

# Use UserManager to get the create_user method, etc.
objects = UserManager()
Expand Down
16 changes: 16 additions & 0 deletions src/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ def change(request):
form = UserChangeForm(request.POST, instance=request.user)
if form.is_valid():
form.save()
#to get the value of the 'attestation_emails' checkbox.
attestation_emails = request.POST.get('attestation_emails')
#to change the values of the value of the checkbox to 'True' or 'False'
is_checked = bool(attestation_emails)
if is_checked:
attestation_emails = 'True'
else:
attestation_emails = 'False'
#to get the value of the 'upload_confirm_emails' checkbox.
upload_confirm_emails = request.POST.get('upload_confirm_emails')
#to change the values of the value of the checkbox to 'True' or 'False'
is_checked = bool(upload_confirm_emails)
if is_checked:
upload_confirm_emails = 'True'
else:
upload_confirm_emails = 'False'
return HttpResponseRedirect(reverse('task_list'))
else:
form = UserChangeForm(instance=request.user)
Expand Down
4 changes: 3 additions & 1 deletion src/attestation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def publish(self, request, by):
+ ([get_settings().attestation_reply_to] if get_settings().attestation_reply_to else [])
headers = {'Reply-To': ', '.join(reply_to)} if reply_to else None
email = EmailMessage(subject, body, None, (email,), headers = headers)
email.send()
#to check if the user has selected the checkbox on the 'Change Account' page to confirm their willingness to receive attestation emails ('True' by default)
if User.attestationEmails:
email.send()

def withdraw(self, request, by):
self.published = False
Expand Down
3 changes: 2 additions & 1 deletion src/solutions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def solution_list(request, task_id, user_id=None):
message.send() # any PY2-PY3 problem in here ?

else: #we are sending unsigned email
if solution.author.email:
#one of the checks is: if the user has selected the checkbox on the 'Change Account' page to confirm their willingness to receive an email fo each file upload ('False' by default)
if solution.author.email and User.uploadConfirmEmails:
send_mail(_("%s submission confirmation") % settings.SITE_NAME, t.render(c), None, [solution.author.email])

return HttpResponseRedirect(reverse('solution_detail', args=[solution.id]))
Expand Down