Ejemplo n.º 1
0
def send_answer_sheets(school, answer_sheet, cc_admin=False):
    rteachers = ResponsibleTeacher.objects.filter(school=school.id)
    if not rteachers:
        print("No responsible teacher for school!")
        return
    rteacher = rteachers.filter(is_primary=True)[0]
    #Header
    output_string = 'Dear %s, \n\n' \
                    'This email contains answer sheets for %s for the upcoming UCT Mathematics Competition. ' \
                    'Attached you will find a printer-friendly .pdf file that contains the answer sheets that ' \
                    'your students will write on. \n\n' \
                    'Regards,\n\n' \
                    'The UCT Mathematics Competition team'%(rteacher.firstname + " " + rteacher.surname, school.name)
    output_string += UMC_header("Answer Sheets")
    output_string += 'Answer sheets for %s\n%s\n' % (school.name,
                                                     UMC_datetime())
    recipient_list = [rteacher.email_school]
    if cc_admin:
        recipient_list.append(compadmin.admin_emailaddress())
    send_email(
        "(Do not reply) UCT Mathematics Competition %s Answer Sheets" %
        (school.name),
        output_string,
        'UCT Mathematics Competition <%s>' %
        (settings.DEFAULT_FROM_EMAIL),  #from
        [{
            "name": "%s" % (compadmin.get_answer_sheet_name(school)),
            "value": answer_sheet.getvalue(),
            "type": "application/pdf"
        }],
        recipient_list)

    arteacher = ResponsibleTeacher.objects.filter(school=school.id).filter(
        is_primary=False)[0]
    alt_output_string = 'Dear %s, \n\n' \
                    'This email contains answer sheets for %s for the upcoming UCT Mathematics Competition. ' \
                    'your students will write on. \n\n' \
                    'Regards,\n\n' \
                    'The UCT Mathematics Competition team'%(arteacher.firstname + " " + arteacher.surname, school.name)
    alt_output_string += UMC_header("Answer Sheets")
    alt_output_string += 'Answer sheets for %s\n%s\n' % (school.name,
                                                         UMC_datetime())
    recipient_list = [arteacher.email_school]
    if cc_admin:
        recipient_list.append(compadmin.admin_emailaddress())
    send_email(
        "(Do not reply) UCT Mathematics Competition %s Answer Sheets" %
        (school.name),
        alt_output_string,
        'UCT Mathematics Competition <%s>' %
        (settings.DEFAULT_FROM_EMAIL),  #from
        [{
            "name": "%s" % (compadmin.get_answer_sheet_name(school)),
            "value": answer_sheet.getvalue(),
            "type": "application/pdf"
        }],
        recipient_list)
Ejemplo n.º 2
0
def send_results(in_school, result, cc_admin=False):
    """ Formats student information for the particular user and sends it via. smtp"""
    rteacher = ResponsibleTeacher.objects.filter(school=in_school.id)[0]
    name = rteacher.firstname + " " + rteacher.surname
    #Header
    output_string = 'Dear %s, \n\n' \
                    'This email contains results for %s from the UCT Mathematics Competition. ' \
                    'Attached you will find a printer-friendly .pdf file that contains your school\'s ' \
                    'results. \n\n' \
                    'Regards,\n\n' \
                    'The UCT Mathematics Competition team'%(name, in_school.name)
    output_string += UMC_header("Results")
    output_string += 'Results letter for %s\nRequested by %s\n%s\n' % (
        in_school.name, name, UMC_datetime())

    recipient_list = [rteacher.email]
    if cc_admin:
        recipient_list.append(compadmin.admin_emailaddress())

    send_email(
        '(Do not reply) UCT Mathematics Competition %s Competition Results' %
        (in_school.name),  #Subject line
        output_string,  #Body
        'UCT Mathematics Competition <*****@*****.**>',  #from
        [{
            "name": '%s' % (compadmin.get_school_report_name(in_school)),
            "value": result.getvalue(),
            "type": "application/pdf"
        }],
        recipient_list)
Ejemplo n.º 3
0
def profile(request):
    # auth(request)
    school_blurb = 'Welcome. This profile is currently '
    try:
        #Attempt to find user's chosen school
        assigned_school = School.objects.get(assigned_to=request.user)
        school_blurb += 'associated with ' + unicode(
            assigned_school.name
        ) + ' and has sole access and responsibility for its UCT Mathematics Competition entry forms. Please navigate to \'Entry Form\' on the side-bar to review or edit your entry.'
    except exceptions.ObjectDoesNotExist:
        # No school is associated with this user! Redirect to the select_schools page
        school_blurb += 'not associated with any school. Navigate to \'Entry Form\' to select your school.'

    admin_contact = compadmin.admin_emailaddress()

    if compadmin.isOpen():
        closingdate_blurb = 'Please note that online entries for this year\'s UCT Mathematics Competition strictly close on ' + compadmin.closingDate(
        ) + '.'
    elif not request.user.is_staff:
        closingdate_blurb = 'School submissions for this year\'s UCT Mathematics Competition are closed. If you have previously submitted an entry, please navigate to \'Entry form\' if you wish to view your entry.'
    else:
        closingdate_blurb = 'Online entries are closed but you may still create and modify entries because you have admin rights.'
    return render_to_response(
        'profile.html', {
            'school_blurb': school_blurb,
            'closingdate_blurb': closingdate_blurb,
            'admin_contact': admin_contact
        })
Ejemplo n.º 4
0
def school_select(request):
    error = " "
    invalid_request = False
    inv_req_message = ''
    school_assignment = ''

    if not (compadmin.isOpen() or request.user.is_staff):
        return HttpResponseRedirect('/accounts/profile')

    if request.method == 'POST':  # If the form has been submitted...
        try:
            #Attempt to find user's chosen school
            assigned_school = School.objects.get(assigned_to=request.user)
            inv_req_message = 'This profile is already bound to ' + assigned_school.name + '. Please proceed with student registration for the UCT Mathematics Competition by selecting "Entry form." If you have selected the incorrect school, please contact ' + compadmin.admin_emailaddress(
            ) + '.'
            invalid_request = True
        except exceptions.ObjectDoesNotExist:
            # No school is associated with this user! Continue
            form = (request.POST)  # A form bound to the POST data
            school_selected = School.objects.get(
                pk=int(form.getlist('school', '')[0]))
            school_assignment = School.objects.get(
                name=school_selected).assigned_to

            if school_assignment == None:  #An unassigned school is assigned to user.
                #TODO: Add a "Please be sure" message just telling them what they're doing.
                #schoolAssmtUpdate = School.objects.get(id = school_assignment)
                school_selected.assigned_to = request.user
                school_selected.save()
                #School.objects.set(name=school_selected).assign_to(request.user)
                return HttpResponseRedirect('../students/newstudents.html')

            elif school_assignment == request.user:  #This should not happen
                return HttpResponseRedirect('../students/newstudents.html')
            else:
                invalid_request = True
                inv_req_message = 'This school has already been assigned to another user. If you believe this to be an error, please contact ' + compadmin.admin_emailaddress(
                ) + '.'

    schoolOptions = School.objects.all()
    c = {
        'schools': schoolOptions,
        'invalid_request': invalid_request,
        'inv_req_message': inv_req_message,
        'user': request.user,
        'error': error,
        'ierror': error,
        'admin_emailaddress': compadmin.admin_emailaddress()
    }
    c.update(csrf(request))
    return render_to_response('school_select.html',
                              c,
                              context_instance=RequestContext(request))
def send_confirmation(request, in_school='UNDEFINED', cc_admin=False):
    """ Formats student information for the particular user and sends it via. smtp"""

    if request.user.first_name not in [
            '', None
    ] and request.user.last_name not in ['', None]:
        name = request.user.first_name + " " + request.user.last_name
    else:
        name = request.user.username
    student_list = SchoolStudent.objects.filter(school=in_school)
    invigilator_list = Invigilator.objects.filter(school=in_school)
    rteacher = ResponsibleTeacher.objects.filter(school=in_school)[0]

    #Header
    output_string = 'Dear %s, \n\n' \
                    'This email confirms your entry for %s to the UCT Mathematics Competition. ' \
                    'Attached you will find a printer-friendly .pdf file that contains a record of your school\'s ' \
                    'entry. Below is a text-based summary of that same information.\n\n' \
                    'Regards,\n\n' \
                    'The UCT Mathematics Competition team'%(name, in_school)
    output_string += UMC_header()
    output_string += 'Confirmation letter for %s\nRequested by %s\n%s\n' % (
        in_school, name, UMC_datetime())

    output_string += print_responsibleTeacher(rteacher)
    output_string += print_invigilators(invigilator_list)
    output_string += print_students(student_list)
    ### Debugging - output to file ###
    #temp_output = open('confirmation.txt', 'w')
    #temp_output.write(temp_output)
    #temp_output.close()

    recipient_list = [request.user.email]
    if cc_admin:
        recipient_list.append(compadmin.admin_emailaddress())

    email = EmailMessage(
        '(Do not reply) UCT Mathematics Competition %s Entry Confirmation' %
        (in_school),  #Subject line
        output_string,  #Body
        'UCT Mathematics Competition <*****@*****.**>',  #from
        recipient_list,
    )
    result = views.printer_entry_result(request)
    email.attach('%s_confirmation.pdf' % (unicode(in_school)),
                 result.getvalue(),
                 mimetype='application/pdf')
    email.send()
Ejemplo n.º 6
0
def send_grade_answer_sheets_to_organiser(pdf_attachment_filename):
    print("Emailing " + os.path.basename(pdf_attachment_filename) +
          " to organiser.")
    f = open(pdf_attachment_filename, "rb")
    output_string = """Dear admin,

This email contains part of the collection of answer sheets for all students, separated by grade. This is being sent because of the request to generate all answer sheets. 
    """
    send_email(
        "(Do not reply) " + os.path.basename(pdf_attachment_filename),
        output_string,
        'UCT Mathematics Competition <%s>' % (settings.DEFAULT_FROM_EMAIL),
        [{
            "name": os.path.basename(pdf_attachment_filename),
            "value": StringIO.StringIO(f.read()).getvalue(),
            "type": "application/pdf"
        }], [compadmin.admin_emailaddress()])
    f.close()
Ejemplo n.º 7
0
def profile(request):
    # auth(request)
    school_blurb = 'Welcome. This profile is currently '
    try:
        #Attempt to find user's chosen school
        assigned_school = School.objects.get(assigned_to=request.user)
        school_blurb += 'associated with ' + unicode(assigned_school.name) + ' and has sole access and responsibility for its UCT Mathematics Competition entry forms. Please navigate to \'Entry Form\' on the side-bar to review or edit your entry.'
    except exceptions.ObjectDoesNotExist:
        # No school is associated with this user! Redirect to the select_schools page
        school_blurb += 'not associated with any school. Navigate to \'Entry Form\' to select your school.'
    
    admin_contact = compadmin.admin_emailaddress()

    if compadmin.isOpen():
        closingdate_blurb='Please note that online entries for this year\'s UCT Mathematics Competition strictly close on ' + compadmin.closingDate() + '.'
    else:
        closingdate_blurb='School submissions for this year\'s UCT Mathematics Competition are closed. If you have previously submitted an entry, please navigate to \'Entry form\' if you wish to view your entry.'
        #return HttpResponseRedirect('../register/school_select/school_select.html')
    return render_to_response('profile.html',{'school_blurb':school_blurb,'closingdate_blurb':closingdate_blurb, 'admin_contact':admin_contact})
def send_confirmation(request, in_school='UNDEFINED',cc_admin=False):
    """ Formats student information for the particular user and sends it via. smtp"""

    if request.user.first_name not in ['', None] and request.user.last_name  not in ['', None]:
        name = request.user.first_name + " " + request.user.last_name
    else:
        name = request.user.username
    student_list = SchoolStudent.objects.filter(school = in_school)
    invigilator_list = Invigilator.objects.filter(school = in_school)
    rteacher = ResponsibleTeacher.objects.filter(school = in_school)[0]

    #Header
    output_string = 'Dear %s, \n\n' \
                    'This email confirms your entry for %s to the UCT Mathematics Competition. ' \
                    'Attached you will find a printer-friendly .pdf file that contains a record of your school\'s ' \
                    'entry. Below is a text-based summary of that same information.\n\n' \
                    'Regards,\n\n' \
                    'The UCT Mathematics Competition team'%(name, in_school)
    output_string += UMC_header()
    output_string += 'Confirmation letter for %s\nRequested by %s\n%s\n'%(in_school, name, UMC_datetime())

    output_string += print_responsibleTeacher(rteacher)
    output_string += print_invigilators(invigilator_list)
    output_string += print_students(student_list)
    ### Debugging - output to file ###
    #temp_output = open('confirmation.txt', 'w')
    #temp_output.write(temp_output)
    #temp_output.close()

    recipient_list = [request.user.email]
    if cc_admin:
        recipient_list.append(compadmin.admin_emailaddress())

    email = EmailMessage(
                        '(Do not reply) UCT Mathematics Competition %s Entry Confirmation'%(in_school),#Subject line
                        output_string, #Body
                        'UCT Mathematics Competition <*****@*****.**>',#from
                        recipient_list,
                        )
    result = views.printer_entry_result(request)
    email.attach('%s_confirmation.pdf'%(unicode(in_school)),result.getvalue(), mimetype='application/pdf')
    email.send()
def send_confirmation(request, in_school='UNDEFINED',cc_admin=False):#Not happy with having 'school' here
    """ Formats student information for the particular user and sends it via. smtp"""

    username = request.user #Current user
    student_list = SchoolStudent.objects.filter(school = in_school)
    invigilator_list = Invigilator.objects.filter(school = in_school)
    rteacher = ResponsibleTeacher.objects.filter(school = in_school)[0] ##TODO only one per school

    #Header
    output_string = 'Dear %s, \n\nThis email is in confirmation of your entry for %s to the UCT Mathematics Competition. Attached you will find a printer-friendly .pdf file that contains a record of your school\'s entry. Below is a text-based summary of that same information.\n\nRegards,\n\nThe UCT Mathematics Competition team'%(username, in_school)
    output_string += UMC_header()
    output_string += 'Confirmation letter for %s\nRequested by %s\n%s\n'%(in_school, username, UMC_datetime())

    #output_string += print_responsibleTeacher(rteacher) #In progress

    output_string += print_responsibleTeacher(rteacher)
    output_string += print_invigilators(invigilator_list)
    output_string += print_students(student_list)
    ### Debugging - output to file ###
    #temp_output = open('confirmation.txt', 'w')
    #temp_output.write(temp_output)
    #temp_output.close()

    recipient_list = [username.email]
    if cc_admin:
        recipient_list.append(compadmin.admin_emailaddress())

    email = EmailMessage(
                        'UCT Mathematics Competition %s Entry Confirmation'%(in_school),#Subject line
                        output_string, #Body
                        '*****@*****.**',#from
                        recipient_list,
                        )
    result = views.printer_entry_result(request)
    email.attach('%s_confirmation.pdf'%(unicode(in_school)),result.getvalue(), mimetype='application/pdf')
    email.send()
Ejemplo n.º 10
0
def school_select(request):
    error = " "
    invalid_request = False
    inv_req_message = ''
    school_assignment = ''

    if not compadmin.isOpen():
        return HttpResponseRedirect('/accounts/profile')

    if request.method == 'POST':  # If the form has been submitted...
        try:
        #Attempt to find user's chosen school
            assigned_school = School.objects.get(assigned_to=request.user)
            inv_req_message = 'This profile is already bound to ' + assigned_school.name + '. Please proceed with student registration for the UCT Mathematics Competition by selecting "Entry form." If you have selected the incorrect school, please contact ' + compadmin.admin_emailaddress() + '.'
            invalid_request=True
        except exceptions.ObjectDoesNotExist:
        # No school is associated with this user! Continue
            form = (request.POST) # A form bound to the POST data
            school_selected = School.objects.get(pk=int(form.getlist('school','')[0]))
            school_assignment = School.objects.get(name=school_selected).assigned_to
            
            if school_assignment == None: #An unassigned school is assigned to user.
                #TODO: Add a "Please be sure" message just telling them what they're doing.
                #schoolAssmtUpdate = School.objects.get(id = school_assignment)
                school_selected.assigned_to = request.user
                school_selected.save()
                #School.objects.set(name=school_selected).assign_to(request.user)
                return HttpResponseRedirect('../students/newstudents.html')

            elif school_assignment == request.user: #This should not happen
                return HttpResponseRedirect('../students/newstudents.html')
            else:
                invalid_request = True 
                inv_req_message = 'This school has already been assigned to another user. If you believe this to be an error, please contact ' + compadmin.admin_emailaddress() + '.'

    schoolOptions = School.objects.all()
    c = {'schools':schoolOptions, 'invalid_request' : invalid_request, 'inv_req_message' : inv_req_message, 'user':request.user,'error':error,'ierror':error, 'admin_emailaddress':compadmin.admin_emailaddress()} 
    c.update(csrf(request))
    return render_to_response('school_select.html', c, context_instance=RequestContext(request))