def save(self, request, formsets=None):
contact = super(OlimpiadaForm, self).save(request, formsets)
- mail_subject = render_to_string('contact/olimpiada/student_mail_subject.html').strip()
for formset in formsets or []:
if formset.prefix == 'student':
for f in formset.forms:
email = f.cleaned_data.get('email', None)
try:
- confirmation = Confirmation.objects.get(email=email)
+ Confirmation.objects.get(email=email)
except Confirmation.DoesNotExist:
first_name = f.cleaned_data.get('first_name', None)
last_name = f.cleaned_data.get('last_name', None)
confirmation = Confirmation.create(
first_name=first_name, last_name=last_name, email=email, contact=contact)
- mail_body = render_to_string(
- 'contact/olimpiada/student_mail_body.html', {'confirmation': confirmation})
- try:
- validate_email(email)
- except ValidationError:
- pass
- else:
- send_mail(mail_subject, mail_body, 'olimpiada@nowoczesnapolska.org.pl', [email],
- fail_silently=True)
-
+ confirmation.send_mail()
return contact
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
+from wtem.models import Confirmation
from .middleware import get_current_request
from .models import Submission, Assignment, Attachment, exercises
return qs
def get_urls(self):
- urls = super(SubmissionAdmin, self).get_urls()
return patterns(
'',
url(r'^report/$', self.admin_site.admin_view(report_view), name='wtem_admin_report')
response['Content-Disposition'] = 'attachment; filename="wyniki.csv"'
return response
+
+class ConfirmationAdmin(admin.ModelAdmin):
+ list_display = ('email', 'first_name', 'last_name', 'confirmed')
+ readonly_fields = ('contact', 'readable_contact', 'key', 'confirmed')
+
+ def resend_mail(self, request, queryset):
+ for confirmation in queryset:
+ confirmation.send_mail()
+ resend_mail.short_description = "WyĆlij kod ponownie"
+
+ actions = [resend_mail]
+
admin.site.register(Submission, SubmissionAdmin)
admin.site.register(Assignment)
+admin.site.register(Confirmation, ConfirmationAdmin)
import os
import json
+from django.core.validators import validate_email
from django.db import models
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
+from django.core.mail import send_mail
from django.core.urlresolvers import reverse
+from django.template.loader import render_to_string
from django.utils.translation import ugettext as _
from jsonfield import JSONField
key = models.CharField(max_length=30)
confirmed = models.BooleanField(default=False)
+ class Meta:
+ ordering = ['email']
+
@classmethod
def create(cls, first_name, last_name, email, contact=None, key=None):
confirmation = cls(
def absolute_url(self):
return reverse('student_confirmation', args=(self.id, self.key))
+ def readable_contact(self):
+ return '%s <%s>' % (self.contact.body.get('przewodniczacy'), self.contact.contact)
+
+ def send_mail(self):
+ mail_subject = render_to_string('contact/olimpiada/student_mail_subject.html').strip()
+ mail_body = render_to_string(
+ 'contact/olimpiada/student_mail_body.html', {'confirmation': self})
+ try:
+ validate_email(self.email)
+ except ValidationError:
+ pass
+ else:
+ send_mail(mail_subject, mail_body, 'olimpiada@nowoczesnapolska.org.pl', [self.email],
+ fail_silently=True)
+
def exercise_checked_manually(exercise):
return (exercise['type'] in ('open', 'file_upload')) or 'open_part' in exercise