Exemplo n.º 1
0
def on_new_successful_delivery(sender, delivery, **kwargs):
    deadline = delivery.deadline
    assignment_group = deadline.assignment_group
    assignment = assignment_group.parentnode
    period = assignment.parentnode
    subject = period.parentnode
    user_list = [candidate.student \
            for candidate in assignment_group.candidates.all()]
    url = create_absolute_show_delivery_url(delivery)

    files = ''
    for fm in delivery.filemetas.all():
        files += ' - {0} ({1})\n'.format(fm.filename, filesizeformat(fm.size))

    email_subject = 'Receipt for delivery on {0}'.format(assignment.get_path())
    email_message = ('This is a receipt for your delivery.\n\n'
                     'Subject: {subject}\n'
                     'Period: {period}\n'
                     'Assignment: {assignment}\n'
                     'Deadline: {deadline}\n'
                     'Delivery number: {deliverynumer}\n'
                     'Time of delivery: {time_of_delivery}\n'
                     'Files:\n{files}\n\n'
                     'The delivery can be viewed at:\n'
                     '{url}'.format(subject = subject.long_name,
                                    period = period.long_name,
                                    assignment = assignment.long_name,
                                    deadline = deadline.deadline.isoformat(),
                                    deliverynumer = delivery.number,
                                    time_of_delivery = delivery.time_of_delivery.isoformat(),
                                    files = files,
                                    url = url))
    send_email(user_list, email_subject, email_message)
Exemplo n.º 2
0
def on_new_staticfeedback(sender, **kwargs):
    staticfeedback = kwargs['instance']
    delivery = staticfeedback.delivery
    deadline = delivery.deadline
    assignment_group = deadline.assignment_group
    assignment = assignment_group.parentnode
    period = assignment.parentnode
    subject = period.parentnode

    user_list = [candidate.student \
            for candidate in assignment_group.candidates.all()]

    url = create_absolute_show_delivery_url(delivery)
    email_subject = 'New feedback - {0}'.format(assignment.get_path())

    # Make sure the values that may contain non-ascii characters are utf-8
    unicode_kw = dict(subject = subject.long_name,
                      period = period.long_name,
                      assignment = assignment.long_name)
    for key, value in unicode_kw.iteritems():
        unicode_kw[key] = value.encode(CHARSET)

    email_message = ('One of your deliveries has new feedback.\n\n'
                     'Subject: {subject}\n'
                     'Period: {period}\n'
                     'Assignment: {assignment}\n'
                     'Deadline: {deadline}\n'
                     'Delivery number: {delivery}\n\n'
                     'The feedback can be viewed at:\n'
                     '{url}'.format(deadline = deadline.deadline.isoformat(),
                                    delivery = delivery.number,
                                    url = url,
                                    **unicode_kw))
    send_email(user_list, email_subject, email_message)
Exemplo n.º 3
0
def on_new_staticfeedback(sender, **kwargs):
    staticfeedback = kwargs['instance']
    delivery = staticfeedback.delivery
    deadline = delivery.deadline
    assignment_group = deadline.assignment_group
    assignment = assignment_group.parentnode
    period = assignment.parentnode
    subject = period.parentnode

    user_list = [candidate.student \
            for candidate in assignment_group.candidates.all()]


    urlpath = reverse('student-show-assignmentgroup', kwargs=dict(assignmentgroupid=assignment_group.id))
    url = '{domain}{prefix}{path}?deliveryid={deliveryid}'.format(domain = settings.DEVILRY_SCHEME_AND_DOMAIN,
                                                                  prefix = settings.DEVILRY_URLPATH_PREFIX,
                                                                  path = urlpath,
                                                                  deliveryid = delivery.id)
    email_subject = 'New feedback - {0}'.format(assignment.get_path())

    # Make sure the values that may contain non-ascii characters are utf-8
    unicode_kw = dict(subject = subject.long_name,
                      period = period.long_name,
                      assignment = assignment.long_name)
    for key, value in unicode_kw.iteritems():
        unicode_kw[key] = value.encode(CHARSET)

    email_message = ('One of your deliveries has new feedback.\n\n'
                     'Subject: {subject}\n'
                     'Period: {period}\n'
                     'Assignment: {assignment}\n'
                     'Deadline: {deadline}\n'
                     'Delivery number: {delivery}\n\n'
                     'The feedback can be viewed at:\n'
                     '{url}'.format(deadline = deadline.deadline.isoformat(),
                                    delivery = delivery.number,
                                    url = url,
                                    **unicode_kw))
    send_email(user_list, email_subject, email_message)
Exemplo n.º 4
0
def on_new_successful_delivery(sender, delivery, **kwargs):
    deadline = delivery.deadline
    assignment_group = deadline.assignment_group
    assignment = assignment_group.parentnode
    period = assignment.parentnode
    subject = period.parentnode
    user_list = [candidate.student \
            for candidate in assignment_group.candidates.all()]
    urlpath = reverse('student-show-assignmentgroup', kwargs=dict(assignmentgroupid=assignment_group.id))
    url = '{domain}{prefix}{path}?deliveryid={deliveryid}'.format(domain = settings.DEVILRY_SCHEME_AND_DOMAIN,
                                                                  prefix = settings.DEVILRY_URLPATH_PREFIX,
                                                                  path = urlpath,
                                                                  deliveryid = delivery.id)

    files = ''
    for fm in delivery.filemetas.all():
        files += ' - {0} ({1})\n'.format(fm.filename, filesizeformat(fm.size))

    email_subject = 'Receipt for delivery on {0}'.format(assignment.get_path())
    email_message = ('This is a receipt for your delivery.\n\n'
                     'Subject: {subject}\n'
                     'Period: {period}\n'
                     'Assignment: {assignment}\n'
                     'Deadline: {deadline}\n'
                     'Delivery number: {deliverynumer}\n'
                     'Time of delivery: {time_of_delivery}\n'
                     'Files:\n{files}\n\n'
                     'The delivery can be viewed at:\n'
                     '{url}'.format(subject = subject.long_name,
                                    period = period.long_name,
                                    assignment = assignment.long_name,
                                    deadline = deadline.deadline.isoformat(),
                                    deliverynumer = delivery.number,
                                    time_of_delivery = delivery.time_of_delivery.isoformat(),
                                    files = files,
                                    url = url))
    send_email(user_list, email_subject, email_message)
Exemplo n.º 5
0
    def get(self, request, username):
        if not request.user.is_superuser:
            return HttpResponseForbidden('Requires superuser')
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            return HttpResponseNotFound('ERROR: User "{username}" does not exist'.format(**vars()))

        if not request.user.email:
            return HttpResponseBadRequest('ERROR: YOU ({username}) have no email address'.format(username=request.user.username))
        if not user.email:
            return HttpResponseBadRequest('ERROR: User "{username}" has no email address'.format(**vars()))

        subject = 'Test email from Devilry.'
        body = emailbodytpl.format(username=request.user.username,
                                   frontpageurl=create_absolute_url(reverse('devilry_frontpage')),
                                   superuseremail=request.user.email)

        send_email([user], subject, body)
        return render(request, 'send_email_to_users/email_sending_debug.django.html',
                      {'email': user.email,
                       'subject': subject,
                       'body': body},
                      content_type="text/html")