Skip to content

Commit

Permalink
Implement notificate for asynchronous feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
teemulehtinen committed Sep 13, 2016
1 parent 7b84832 commit a618fe2
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 15 deletions.
22 changes: 22 additions & 0 deletions course/migrations/0030_auto_20160912_1341.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('course', '0029_usertags'),
]

operations = [
migrations.AlterModelOptions(
name='usertag',
options={'ordering': ['course_instance', 'name']},
),
migrations.AlterModelOptions(
name='usertagging',
options={'ordering': ['tag']},
),
]
8 changes: 8 additions & 0 deletions exercise/async_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from lib.email_messages import email_course_error
from lib.helpers import extract_form_errors
from notification.models import Notification
from .forms import SubmissionCallbackForm


Expand Down Expand Up @@ -54,6 +55,13 @@ def _post_async_submission(request, exercise, submission, errors=None):
else:
submission.set_ready()
submission.save()

if form.cleaned_data["notificate"]:
for student in submission.submitters.all():
Notification.send(None, student, submission)
else:
Notification.remove(submission.submitters.all(), submission)

return {
"success": True,
"errors": []
Expand Down
1 change: 1 addition & 0 deletions exercise/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SubmissionCallbackForm(forms.Form):
points = forms.IntegerField(min_value=0)
max_points = forms.IntegerField(min_value=0, required=False)
feedback = forms.CharField(required=False)
notificate = forms.CharField(required=False)
grading_payload = forms.CharField(required=False)
error = forms.BooleanField(required=False)

Expand Down
16 changes: 8 additions & 8 deletions exercise/staff_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ def form_valid(self, form):
self.submission.set_ready()
self.submission.save()

sub = _('Feedback to {name}').format(name=self.exercise)
msg = _('<p>You have new personal feedback to exercise '
'<a href="{url}">{name}</a>.</p>{message}').format(
url=self.submission.get_absolute_url(),
name=self.exercise,
message=note,
)
#sub = _('Feedback to {name}').format(name=self.exercise)
#msg = _('<p>You have new personal feedback to exercise '
# '<a href="{url}">{name}</a>.</p>{message}').format(
# url=self.submission.get_absolute_url(),
# name=self.exercise,
# message=note,
#)
for student in self.submission.submitters.all():
Notification.send(self.profile, student, self.instance, sub, msg)
Notification.send(self.profile, student, self.submission)

messages.success(self.request, _("The review was saved successfully "
"and the submitters were notified."))
Expand Down
39 changes: 39 additions & 0 deletions notification/migrations/0002_auto_20160912_1341.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('exercise', '0022_auto_20160906_1401'),
('notification', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='notification',
name='submission',
field=models.ForeignKey(to='exercise.Submission', blank=True, null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='notification',
name='notification',
field=models.TextField(blank=True),
preserve_default=True,
),
migrations.AlterField(
model_name='notification',
name='sender',
field=models.ForeignKey(related_name='sent_notifications', to='userprofile.UserProfile', blank=True, null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='notification',
name='subject',
field=models.CharField(blank=True, max_length=255),
preserve_default=True,
),
]
23 changes: 16 additions & 7 deletions notification/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models

from course.models import CourseInstance
from exercise.models import Submission
from userprofile.models import UserProfile


Expand Down Expand Up @@ -57,23 +58,31 @@ class Notification(models.Model):
"""

@classmethod
def send(cls, sender, recipient, course_instance, subject, notification):
def send(cls, sender, recipient, submission):
notification = Notification(
notification=notification,
subject=subject,
sender=sender,
recipient=recipient,
course_instance=course_instance
course_instance=submission.exercise.course_instance,
submission=submission,
)
notification.save()

subject = models.CharField(max_length=255)
notification = models.TextField()
sender = models.ForeignKey(UserProfile, related_name="sent_notifications")
@classmethod
def remove(cls, recipients, submission):
Notification.objects.filter(
submission=submission,
recipient__in=recipients
).delete()

subject = models.CharField(max_length=255, blank=True)
notification = models.TextField(blank=True)
sender = models.ForeignKey(UserProfile, related_name="sent_notifications",
blank=True, null=True)
recipient = models.ForeignKey(UserProfile, related_name="received_notifications")
timestamp = models.DateTimeField(auto_now_add=True)
seen = models.BooleanField(default=False)
course_instance = models.ForeignKey(CourseInstance)
submission = models.ForeignKey(Submission, blank=True, null=True)

class Meta:
ordering = ['-timestamp']
Expand Down

0 comments on commit a618fe2

Please sign in to comment.