Ejemplo n.º 1
0
def email_csv(request, slug):
    cur_course = get_object_or_404(Course, slug=slug)
    page_name = "Invite Students"
    page_description = "Invite Students via CSV Upload"
    title = "Invite Students"

    addcode = cur_course.addCode
    recipients = []
    if 'recipients' in request.session:
        recipients = request.session['recipients']

    print("in email_csv: ",recipients, "request.method:", request.method)

    form = EmailRosterForm()
    if request.method == 'POST':
        form = EmailRosterForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data

            subject = data.get('subject')
            content = data.get('content')

            print("recipients in email_csv",recipients)
            send_email(recipients, request.user.email, subject, content)
            messages.add_message(request, messages.SUCCESS, "Email Sent!")

            return redirect('view_one_course', slug)

        else:
            print("Form not valid!")

    return render(request, 'courses/email_roster_with_csv.html', { 'count':len(recipients),
        'slug':slug, 'form':form, 'addcode':addcode, 'students':recipients,
        'page_name':page_name, 'page_description':page_description,'title':title
        })
Ejemplo n.º 2
0
def sendemail(request, slug):
    email = request.POST.get('email')
    emailObj = json.loads(email)
    subject = emailObj.get('subject')
    content = emailObj.get('content')
    receivers = emailObj.get('receivers')
    send_email(receivers, request.user.email, subject, content)
    return JsonResponse({"code": 0, "msg": "success", "course": slug})
Ejemplo n.º 3
0
def update_course(request, slug):
    """
    Post an update for a given course
    """
    course = get_object_or_404(Course.objects.prefetch_related('creator'),
                               slug=slug)
    page_name = "Update Course"
    page_description = "Update %s" % (course.name) or "Post a new update"
    title = "Update Course"

    if not request.user.profile.isGT:
        user_role = Enrollment.objects.filter(user=request.user,
                                              course=course).first().role
    else:
        user_role = 'GT'

    if user_role == "student":
        # redirect them to the /course directory with message
        messages.info(request, 'Only Professor can post a course update')
        return HttpResponseRedirect('/course')

    if request.method == 'POST':
        form = CourseUpdateForm(request.user.id, request.POST)
        if form.is_valid():
            new_update = CourseUpdate(course=course)
            new_update.course = course
            new_update.title = form.cleaned_data.get('title')
            new_update.content = form.cleaned_data.get('content')
            new_update.creator = request.user
            new_update.save()

            # Next 4 lines handle sending an email to class roster
            # grab list of students in the course
            students_in_course = course.students.all().filter()
            # TODO: course variables contains (slug: blah blah)
            subject = "{0} has posted an update to {1}".format(
                request.user, course)
            content = "{0}\n\n www.grepthink.com".format(new_update.content)
            send_email(students_in_course, "*****@*****.**", subject,
                       content)
            messages.add_message(request, messages.SUCCESS,
                                 "Posted and Email Sent!")

            return redirect(view_one_course, course.slug)
    else:
        form = CourseUpdateForm(request.user.id)

    return render(
        request, 'courses/update_course.html', {
            'form': form,
            'course': course,
            'page_name': page_name,
            'page_description': page_description,
            'title': title
        })
Ejemplo n.º 4
0
 def test_successful_emaillist(self):
     recipient_list = []
     recipient_list.append(self.recipient1.email)
     recipient_list.append(self.recipient2.email)
     response = send_email(recipient_list, "*****@*****.**",
                           "test_single_recipient", "email content")
     self.assertTrue(response.content.decode("utf-8") == 'Email Sent!')
Ejemplo n.º 5
0
def email_project(request, slug):
    project = get_object_or_404(Project, slug=slug)
    page_name = "Email Project"
    page_description = "Emailing members of Project: %s" % (project.title)
    title = "Email Project"

    students_in_project = project.get_members()

    count = len(students_in_project) or 0

    form = EmailRosterForm()
    if request.method == 'POST':
        # send the current user.id to filter out
        form = EmailRosterForm(request.POST, request.FILES)
        #if form is accepted
        if form.is_valid():
            #the courseID will be gotten from the form
            data = form.cleaned_data
            subject = data.get('subject')
            content = data.get('content')

            send_email(students_in_project, request.user.email, subject,
                       content)
            messages.add_message(request, messages.SUCCESS, "Email Sent!")

            return redirect('view_one_project', slug)
        else:
            # redirect to error
            print("EmailRosterForm not valid")

    return render(
        request, 'projects/email_project.html', {
            'slug': slug,
            'form': form,
            'count': count,
            'students': students_in_project,
            'project': project,
            'page_name': page_name,
            'page_description': page_description,
            'title': title
        })
Ejemplo n.º 6
0
def email_roster(request, slug):
    cur_course = get_object_or_404(Course, slug=slug)
    page_name = "Email Roster"
    page_description = "Emailing members of Course: %s" % (cur_course.name)
    title = "Email Student Roster"

    staff = cur_course.get_staff()
    staff_ids = [o.id for o in staff]
    students_in_course = list(cur_course.students.exclude(id__in=staff_ids))
    tas = cur_course.get_tas()
    count = len(students_in_course) or 0
    tasCount = len(tas) or 0
    total = count + tasCount
    addcode = cur_course.addCode

    form = EmailRosterForm()
    if request.method == 'POST':
        # send the current user.id to filter out
        form = EmailRosterForm(request.POST, request.FILES)
        # if form is accepted
        if form.is_valid():
            # the courseID will be gotten from the form
            data = form.cleaned_data
            subject = data.get('subject')
            content = data.get('content')

            response = send_email(students_in_course, request.user.email,
                                  subject, content)

            if isinstance(response, HttpResponse):
                messages.add_message(request, messages.INFO, response.content)

            return redirect('view_one_course', slug)

    return render(
        request, 'courses/email_roster.html', {
            'slug': slug,
            'form': form,
            'count': count,
            'students': students_in_course,
            'tas': tas,
            'tasCount': tasCount,
            'total': total,
            'addcode': addcode,
            'cur_course': cur_course,
            'page_name': page_name,
            'page_description': page_description,
            'title': title
        })
Ejemplo n.º 7
0
 def test_norecipients_found(self):
     empty_list = []
     response = send_email(empty_list, "*****@*****.**",
                           "test_norecipients_found", "email content")
     self.assertTrue(
         response.content.decode("utf-8") == 'No recipients were found.')
Ejemplo n.º 8
0
 def test_bad_request(self):
     response = send_email(724, "*****@*****.**", "test_bad_request",
                           "email content")
     self.assertTrue(response.content.decode("utf-8") == 'Bad Request')
Ejemplo n.º 9
0
 def test_single_recipient(self):
     response = send_email(self.recipient1, "*****@*****.**",
                           "test_single_recipient", "email content")
     self.assertTrue(response.content.decode("utf-8") == 'Email Sent!')