Ejemplo n.º 1
0
def send_mail_to_submission_owner(current_site_name, assignment, review,
                                  submitter):
    subject = _(u'Your assignment "%(nugget)s" has been reviewed') % {
        'nugget': assignment.kq.title
    }
    template = 'peerreview/email_review_submission.txt'
    review_criteria = []
    for item in review['criteria']:
        try:
            criterion = EvaluationCriterion.objects.get(pk=item[0]).title
        except:
            criterion = _(u'Undefined')

        review_criteria.append((criterion, item[1]))

    context = {
        'user': submitter,
        'date': review['created'].strftime('%d/%m/%Y'),
        'nugget': assignment.kq,
        'review_criteria': review_criteria,
        'comment': review['comment'],
        'site': current_site_name
    }

    to = [submitter.email]

    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 2
0
def course_add(request):
    allow_public = False
    try:
        allow_public = settings.ALLOW_PUBLIC_COURSE_CREATION
    except AttributeError:
        pass

    if not allow_public and not request.user.is_staff:
        return HttpResponseForbidden(_("Only administrators can create courses"))

    if request.method == "POST":
        if "course_owner" in request.POST:
            email_or_id = request.POST["course_owner"]
            try:
                validate_email(email_or_id)
                # is an email
                try:
                    owner = User.objects.get(email=email_or_id)
                except (User.DoesNotExist):
                    messages.error(request, _("That user doesn't exists, the owner must be an user of the platform"))
                    return HttpResponseRedirect(reverse("course_add"))
            except ValidationError:
                # is name plus id
                owner_id = name_and_id_regex.search(email_or_id)
                if owner_id is None:
                    messages.error(request, _("The owner must be a name plus ID or an email"))
                    return HttpResponseRedirect(reverse("course_add"))
                try:
                    owner_id = owner_id.groups()[0]
                    owner = User.objects.get(id=owner_id)
                except (User.DoesNotExist):
                    messages.error(request, _("That user doesn't exists, the owner must be an user of the platform"))
                    return HttpResponseRedirect(reverse("course_add"))
        else:
            owner = request.user

        name = request.POST["course_name"]
        if name == u"":
            messages.error(request, _("The name can't be an empty string"))
            return HttpResponseRedirect(reverse("course_add"))

        course = Course(name=name, owner=owner, description=_("To fill"))
        unique_slugify(course, name)
        course.save()

        CourseTeacher.objects.create(course=course, teacher=owner)

        if not allow_public:
            subject = _('Your course "%s" has been created') % name
            template = "courses/email_new_course.txt"
            context = {"user": owner.get_full_name(), "course": name, "site": get_current_site(request).name}
            to = [owner.email]
            send_mail_wrapper(subject, template, context, to)

        messages.success(request, _("The course was successfully created"))
        return HttpResponseRedirect(reverse("teacheradmin_info", args=[course.slug]))

    return render_to_response("courses/add.html", {}, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def send_removed_notification(request, email, course):
    subject = _(u'You have been removed as teacher from "%s"') % course.name
    template = 'teacheradmin/email_remove_teacher.txt'
    context = {
        'course': course.name,
        'host': request.user.get_full_name() or request.user.username,
        'site': get_current_site(request).name
    }
    to = [email]
    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 4
0
def send_removed_notification(request, email, course):
    subject = _(u'You have been removed as teacher from "%s"') % course.name
    template = 'teacheradmin/email_remove_teacher.txt'
    context = {
        'course': course.name,
        'host': request.user.get_full_name() or request.user.username,
        'site': get_current_site(request).name
    }
    to = [email]
    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 5
0
def send_cancellation_email(reservation):
    subject = _('Your reservation has been cancelled')
    template = 'assets/email_reservation_cancelled.txt'
    context = {
        'user': reservation.user.get_full_name(),
        'asset': reservation.asset.name,
        'kq': reservation.reserved_from.kq,
        'site': Site.objects.get_current().name
    }
    to = [reservation.user.email]
    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 6
0
def send_invitation(request, invitation):
    subject = _(u'You have been invited to be a teacher in "%s"') % invitation.course.name
    template = 'teacheradmin/email_invitation_teacher.txt'
    context = {
        'host': invitation.host.get_full_name() or invitation.host.username,
        'course': invitation.course.name,
        'register': reverse('register'),
        'site': get_current_site(request).name
    }
    to = [invitation.email]
    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 7
0
def send_cancellation_email(reservation):
    subject = _('Your reservation has been cancelled')
    template = 'assets/email_reservation_cancelled.txt'
    context = {
        'user': reservation.user.get_full_name(),
        'asset': reservation.asset.name,
        'kq': reservation.reserved_from.kq,
        'site': Site.objects.get_current().name
    }
    to = [reservation.user.email]
    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 8
0
def send_student_invitation_registered(request, email, course):
    subject = _(u'You have been invited to be a student in "%s"') % course.name
    template = 'teacheradmin/email_invitation_student.txt'
    context = {
        'course': course.name,
        'host': request.user.get_full_name() or request.user.username,
        'course_url': "https://%s%s" % (request.get_host(), reverse('course_overview', args=[course.slug])),
        'site': get_current_site(request).name
    }
    to = [email]
    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 9
0
def send_invitation_not_registered(request, invitation):
    subject = _(u'You have been invited to be a teacher in "%s"') % invitation.course.name
    template = 'teacheradmin/email_invitation_teacher_not_registered.txt'
    context = {
        'host': invitation.host.get_full_name() or invitation.host.username,
        'course': invitation.course.name,
        'course_url': "https://%s%s" % (request.get_host(), reverse('course_overview', args=[invitation.course.slug])),
        'site': get_current_site(request).name
    }
    to = [invitation.email]
    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 10
0
def send_invitation(request, invitation):
    subject = _(u'You have been invited to be a teacher in "%s"') % invitation.course.name
    template = "teacheradmin/email_invitation_teacher.txt"
    context = {
        "host": invitation.host.get_full_name() or invitation.host.username,
        "course": invitation.course.name,
        "register": settings.REGISTRY_URL,
        "site": get_current_site(request).name,
    }
    to = [invitation.email]
    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 11
0
def send_invitation(request, invitation):
    subject = _(u'You have been invited to be a teacher in "%s"'
                ) % invitation.course.name
    template = 'teacheradmin/email_invitation_teacher.txt'
    context = {
        'host': invitation.host.get_full_name() or invitation.host.username,
        'course': invitation.course.name,
        'register': settings.REGISTRY_URL,
        'site': get_current_site(request).name
    }
    to = [invitation.email]
    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 12
0
def send_mail_to_submission_owner(current_site_name, assignment, review, submitter):
    subject = _(u'Your assignment "%(nugget)s" has been reviewed') % {'nugget': assignment.kq.title}
    template = 'peerreview/email_review_submission.txt'
    review_criteria = []
    for item in review['criteria']:
        try:
            criterion = EvaluationCriterion.objects.get(pk=item[0]).title
        except:
            criterion = _(u'Undefined')

        review_criteria.append((criterion, item[1]))

    context = {
        'user': submitter,
        'date': review['created'].strftime('%d/%m/%Y'),
        'nugget': assignment.kq.title,
        'review_criteria': review_criteria,
        'comment': review['comment'],
        'site': current_site_name
    }
    to = [submitter.email]

    send_mail_wrapper(subject, template, context, to)
Ejemplo n.º 13
0
def course_add(request):

    """
    Create new courses. By default courses are created by platform admins unless
    ALLOW_PUBLIC_COURSE_CREATION is set to True.

    The view validates the email of the course_owner field and the course_name
    unless a regular user is creating the course, in which case the course_owner
    is directly taken from the current user.

    After that the course name is slugified and the CourseTeacher and Course are
    saved, and the user is returned to the TeacherAdmin module.

    .. versionadded:: 0.1
    """
    allow_public = False
    try:
        allow_public = settings.ALLOW_PUBLIC_COURSE_CREATION
    except AttributeError:
        pass

    if not allow_public and not request.user.is_staff:
        return HttpResponseForbidden(_("Only administrators can create courses"))

    if request.method == 'POST':
        if 'course_owner' in request.POST:
            email_or_id = request.POST['course_owner']
            try:
                validate_email(email_or_id)
                # is an email
                try:
                    owner = User.objects.get(email=email_or_id)
                except (User.DoesNotExist):
                    messages.error(request, _('That user doesn\'t exists, the owner must be an user of the platform'))
                    return HttpResponseRedirect(reverse('course_add'))
            except ValidationError:
                # is name plus id
                owner_id = name_and_id_regex.search(email_or_id)
                if owner_id is None:
                    messages.error(request, _('The owner must be a name plus ID or an email'))
                    return HttpResponseRedirect(reverse('course_add'))
                try:
                    owner_id = owner_id.groups()[0]
                    owner = User.objects.get(id=owner_id)
                except (User.DoesNotExist):
                    messages.error(request, _('That user doesn\'t exists, the owner must be an user of the platform'))
                    return HttpResponseRedirect(reverse('course_add'))
        else:
            owner = request.user

        name = request.POST['course_name']
        if (name == u''):
            messages.error(request, _('The name can\'t be an empty string'))
            return HttpResponseRedirect(reverse('course_add'))

        course = Course(name=name, owner=owner, description=_('To fill'))
        course.slug = slugify(course)
        course.save()

        CourseTeacher.objects.create(course=course, teacher=owner)

        if not allow_public:
            subject = _('Your course "%s" has been created') % name
            template = 'courses/email_new_course.txt'
            context = {
                'user': owner.get_full_name(),
                'course': name,
                'site': get_current_site(request).name
            }
            to = [owner.email]
            send_mail_wrapper(subject, template, context, to)

        messages.success(request, _('The course was successfully created'))
        return HttpResponseRedirect(reverse('teacheradmin_info',
                                            args=[course.slug]))

    return render_to_response('courses/add.html', {},
                              context_instance=RequestContext(request))
Ejemplo n.º 14
0
def course_add(request):
    """
    Create new courses. By default courses are created by platform admins unless
    ALLOW_PUBLIC_COURSE_CREATION is set to True.

    The view validates the email of the course_owner field and the course_name
    unless a regular user is creating the course, in which case the course_owner
    is directly taken from the current user.

    After that the course name is slugified and the CourseTeacher and Course are
    saved, and the user is returned to the TeacherAdmin module.

    .. versionadded:: 0.1
    """
    allow_public = False
    try:
        allow_public = settings.ALLOW_PUBLIC_COURSE_CREATION
    except AttributeError:
        pass

    if not allow_public and not request.user.is_staff:
        return HttpResponseForbidden(
            _("Only administrators can create courses"))

    if request.method == 'POST':
        if 'course_owner' in request.POST:
            email_or_id = request.POST['course_owner']
            try:
                validate_email(email_or_id)
                # is an email
                try:
                    owner = User.objects.get(email=email_or_id)
                except (User.DoesNotExist):
                    messages.error(
                        request,
                        _('That user doesn\'t exists, the owner must be an user of the platform'
                          ))
                    return HttpResponseRedirect(reverse('course_add'))
            except ValidationError:
                # is name plus id
                owner_id = name_and_id_regex.search(email_or_id)
                if owner_id is None:
                    messages.error(
                        request,
                        _('The owner must be a name plus ID or an email'))
                    return HttpResponseRedirect(reverse('course_add'))
                try:
                    owner_id = owner_id.groups()[0]
                    owner = User.objects.get(id=owner_id)
                except (User.DoesNotExist):
                    messages.error(
                        request,
                        _('That user doesn\'t exists, the owner must be an user of the platform'
                          ))
                    return HttpResponseRedirect(reverse('course_add'))
        else:
            owner = request.user

        name = request.POST['course_name']
        if (name == u''):
            messages.error(request, _('The name can\'t be an empty string'))
            return HttpResponseRedirect(reverse('course_add'))

        course = Course(name=name, owner=owner, description=_('To fill'))
        unique_slugify(course, name)
        course.save()

        CourseTeacher.objects.create(course=course, teacher=owner)

        if not allow_public:
            subject = _('Your course "%s" has been created') % name
            template = 'courses/email_new_course.txt'
            context = {
                'user': owner.get_full_name(),
                'course': name,
                'site': get_current_site(request).name
            }
            to = [owner.email]
            send_mail_wrapper(subject, template, context, to)

        messages.success(request, _('The course was successfully created'))
        return HttpResponseRedirect(
            reverse('teacheradmin_info', args=[course.slug]))

    return render_to_response('courses/add.html', {},
                              context_instance=RequestContext(request))