def result_sheet_pdf_view(request, id): current_semester = Semester.objects.get(is_current_semester=True) current_session = Session.objects.get(is_current_session=True) result = TakenCourse.objects.filter(course__pk=id) no_of_pass = TakenCourse.objects.filter(course__pk=id, comment="PASS").count() no_of_fail = TakenCourse.objects.filter(course__pk=id, comment="FAIL").count() fname = str(current_semester) + '_semester_' + str(current_session) + '_session_' + 'resultSheet.pdf' fname = fname.replace("/", "-") flocation = '/tmp/'+fname doc = SimpleDocTemplate(flocation, rightMargin=0, leftMargin=6.5 * cm, topMargin=0.3 * cm, bottomMargin=0) styles = getSampleStyleSheet() styles.add(ParagraphStyle( name="ParagraphTitle", fontSize=11, fontName="FreeSansBold")) Story = [Spacer(1,.2)] style = styles["Normal"] logo = MEDIA_ROOT + "/logo/android-chrome-144x144.png" print(logo) im = Image(logo, 1*inch, 1*inch) im.__setattr__("_offs_x", -280) im.__setattr__("_offs_y", -45) Story.append(im) style = getSampleStyleSheet() normal = style["Normal"] normal.alignment = TA_CENTER normal.fontName = "Helvetica" normal.fontSize = 12 normal.leading = 15 title = "<b> "+str(current_semester) + " Semester " + str(current_session) + " Result Sheet</b>" title = Paragraph(title.upper(), normal) Story.append(title) Story.append(Spacer(1,0.1*inch)) style = getSampleStyleSheet() normal = style["Normal"] normal.alignment = TA_CENTER normal.fontName = "Helvetica" normal.fontSize = 10 normal.leading = 15 title = "<b>Course lecturer: " + request.user.get_full_name() + "</b>" title = Paragraph(title.upper(), normal) Story.append(title) Story.append(Spacer(1,0.1*inch)) normal = style["Normal"] normal.alignment = TA_CENTER normal.fontName = "Helvetica" normal.fontSize = 10 normal.leading = 15 level = result.filter(course_id=id).first() title = "<b>Level: </b>" + str(level.course.level+"L") title = Paragraph(title.upper(), normal) Story.append(title) Story.append(Spacer(1,.6*inch)) elements = [] count = 0 header = [('S/N', 'ID NUMBER', 'CA', 'EXAM', 'GRADE', 'COMMENT')] table_header=Table(header,1*[1.2*inch], 1*[0.5*inch]) table_header.setStyle( TableStyle([ ('ALIGN',(-2,-2), (-2,-2),'CENTER'), ('TEXTCOLOR',(1,0),(1,0),colors.blue), ('TEXTCOLOR',(-1,0),(-1,0),colors.blue), ('ALIGN',(0,-1),(-1,-1),'CENTER'), ('VALIGN',(0,-1),(-1,-1),'MIDDLE'), ('TEXTCOLOR',(0,-1),(-1,-1),colors.blue), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ])) Story.append(table_header) for student in result: data = [(count+1, student.student.id_number.upper(), student.ca, student.exam, student.grade, student.comment)] color = colors.black if student.grade == 'F': color = colors.red count += 1 t=Table(data,1*[1.2*inch], 1*[0.5*inch]) t.setStyle( TableStyle([ ('ALIGN',(-2,-2), (-2,-2),'CENTER'), ('ALIGN',(1,0), (1,0),'CENTER'), ('ALIGN',(-1,0), (-1,0),'CENTER'), ('ALIGN',(-3,0), (-3,0),'CENTER'), ('ALIGN',(-4,0), (-4,0),'CENTER'), ('ALIGN',(-6,0), (-6,0),'CENTER'), ('TEXTCOLOR',(0,-1),(-1,-1),color), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ])) Story.append(t) Story.append(Spacer(1,1*inch)) style_right = ParagraphStyle(name='right', parent=styles['Normal'], alignment=TA_RIGHT) tbl_data = [ [Paragraph("<b>Date:</b>_______________________________________", styles["Normal"]), Paragraph("<b>No. of PASS:</b> " + str(no_of_pass), style_right)], [Paragraph("<b>Siganture / Stamp:</b> _____________________________", styles["Normal"]), Paragraph("<b>No. of FAIL: </b>" + str(no_of_fail), style_right)]] tbl = Table(tbl_data) Story.append(tbl) doc.build(Story) fs = FileSystemStorage("/tmp") with fs.open(fname) as pdf: response = HttpResponse(pdf, content_type='application/pdf') response['Content-Disposition'] = 'inline; filename='+fname+'' return response return response
def course_registration_form(request): current_semester = Semester.objects.get(is_current_semester=True) current_session = Session.objects.get(is_current_session=True) courses = TakenCourse.objects.filter(student__user__id=request.user.id) fname = request.user.username + '.pdf' fname = fname.replace("/", "-") flocation = '/tmp/'+fname doc = SimpleDocTemplate(flocation, rightMargin=15, leftMargin=15, topMargin=0, bottomMargin=0) styles = getSampleStyleSheet() Story = [Spacer(1,0.5)] Story.append(Spacer(1,0.4*inch)) style = styles["Normal"] style = getSampleStyleSheet() normal = style["Normal"] normal.alignment = TA_CENTER normal.fontName = "Helvetica" normal.fontSize = 12 normal.leading = 18 title = "<b>MODIBBO ADAMA UNIVERSITY OF TECHNOLOGY, YOLA</b>" title = Paragraph(title.upper(), normal) Story.append(title) style = getSampleStyleSheet() school = style["Normal"] school.alignment = TA_CENTER school.fontName = "Helvetica" school.fontSize = 10 school.leading = 18 school_title = "<b>SCHOOL OF MANAGEMENT AND INFORMATION TECHNOLOGY</b>" school_title = Paragraph(school_title.upper(), school) Story.append(school_title) style = getSampleStyleSheet() Story.append(Spacer(1,0.1*inch)) department = style["Normal"] department.alignment = TA_CENTER department.fontName = "Helvetica" department.fontSize = 9 department.leading = 18 department_title = "<b>DEPARTMENT OF INFORMATION MANAGEMENT TECHNOLOGY</b>" department_title = Paragraph(department_title, department) Story.append(department_title) Story.append(Spacer(1,.3*inch)) title = "<b><u>STUDENT REGISTRATION FORM</u></b>" title = Paragraph(title.upper(), normal) Story.append(title) student = Student.objects.get(user__pk=request.user.id) style_right = ParagraphStyle(name='right', parent=styles['Normal']) tbl_data = [ [Paragraph("<b>Registration Number : " + request.user.username.upper() + "</b>", styles["Normal"])], [Paragraph("<b>Name : " + request.user.get_full_name().upper() + "</b>", styles["Normal"])], [Paragraph("<b>Session : " + current_session.session.upper() + "</b>", styles["Normal"]), Paragraph("<b>Level: " + student.level + "</b>", styles["Normal"]) ]] tbl = Table(tbl_data) Story.append(tbl) Story.append(Spacer(1, 0.6*inch)) style = getSampleStyleSheet() semester = style["Normal"] semester.alignment = TA_LEFT semester.fontName = "Helvetica" semester.fontSize = 9 semester.leading = 18 semester_title = "<b>FIRST SEMESTER</b>" semester_title = Paragraph(semester_title, semester) Story.append(semester_title) elements = [] # FIRST SEMESTER count = 0 header = [('S/No', 'Course Code', 'Course Title', 'Unit', Paragraph('Name, Siganture of course lecturer & Date', style['Normal']))] table_header = Table(header,1*[1.4*inch], 1*[0.5*inch]) table_header.setStyle( TableStyle([ ('ALIGN',(-2,-2), (-2,-2),'CENTER'), ('VALIGN',(-2,-2), (-2,-2),'MIDDLE'), ('ALIGN',(1,0), (1,0),'CENTER'), ('VALIGN',(1,0), (1,0),'MIDDLE'), ('ALIGN',(0,0), (0,0),'CENTER'), ('VALIGN',(0,0), (0,0),'MIDDLE'), ('ALIGN',(-4,0), (-4,0),'LEFT'), ('VALIGN',(-4,0), (-4,0),'MIDDLE'), ('ALIGN',(-3,0), (-3,0),'LEFT'), ('VALIGN',(-3,0), (-3,0),'MIDDLE'), ('TEXTCOLOR',(0,-1),(-1,-1),colors.black), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ])) Story.append(table_header) first_semester_unit = 0 for course in courses: if course.course.semester == FIRST: first_semester_unit += int(course.course.courseUnit) data = [(count+1, course.course.courseCode.upper(), course.course.courseTitle, course.course.courseUnit, '')] color = colors.black count += 1 table_body=Table(data,1*[1.4*inch], 1*[0.3*inch]) table_body.setStyle( TableStyle([ ('ALIGN',(-2,-2), (-2,-2),'CENTER'), ('ALIGN',(1,0), (1,0),'CENTER'), ('ALIGN',(0,0), (0,0),'CENTER'), ('ALIGN',(-4,0), (-4,0),'LEFT'), ('TEXTCOLOR',(0,-1),(-1,-1),colors.black), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ])) Story.append(table_body) style = getSampleStyleSheet() semester = style["Normal"] semester.alignment = TA_LEFT semester.fontName = "Helvetica" semester.fontSize = 8 semester.leading = 18 semester_title = "<b>Total Units : " + str(first_semester_unit) + "</b>" semester_title = Paragraph(semester_title, semester) Story.append(semester_title) # FIRST SEMESTER ENDS HERE Story.append(Spacer(1, 0.6*inch)) style = getSampleStyleSheet() semester = style["Normal"] semester.alignment = TA_LEFT semester.fontName = "Helvetica" semester.fontSize = 9 semester.leading = 18 semester_title = "<b>SECOND SEMESTER</b>" semester_title = Paragraph(semester_title, semester) Story.append(semester_title) # SECOND SEMESTER count = 0 header = [('S/No', 'Course Code', 'Course Title', 'Unit', Paragraph('<b>Name, Siganture of course lecturer & Date</b>', style['Normal']))] table_header = Table(header,1*[1.4*inch], 1*[0.5*inch]) table_header.setStyle( TableStyle([ ('ALIGN',(-2,-2), (-2,-2),'CENTER'), ('VALIGN',(-2,-2), (-2,-2),'MIDDLE'), ('ALIGN',(1,0), (1,0),'CENTER'), ('VALIGN',(1,0), (1,0),'MIDDLE'), ('ALIGN',(0,0), (0,0),'CENTER'), ('VALIGN',(0,0), (0,0),'MIDDLE'), ('ALIGN',(-4,0), (-4,0),'LEFT'), ('VALIGN',(-4,0), (-4,0),'MIDDLE'), ('ALIGN',(-3,0), (-3,0),'LEFT'), ('VALIGN',(-3,0), (-3,0),'MIDDLE'), ('TEXTCOLOR',(0,-1),(-1,-1),colors.black), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ])) Story.append(table_header) second_semester_unit = 0 for course in courses: if course.course.semester == SECOND: second_semester_unit += int(course.course.courseUnit) data = [(count+1, course.course.courseCode.upper(), course.course.courseTitle, course.course.courseUnit, '')] color = colors.black count += 1 table_body=Table(data,1*[1.4*inch], 1*[0.3*inch]) table_body.setStyle( TableStyle([ ('ALIGN',(-2,-2), (-2,-2),'CENTER'), ('ALIGN',(1,0), (1,0),'CENTER'), ('ALIGN',(0,0), (0,0),'CENTER'), ('ALIGN',(-4,0), (-4,0),'LEFT'), ('TEXTCOLOR',(0,-1),(-1,-1),colors.black), ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ])) Story.append(table_body) style = getSampleStyleSheet() semester = style["Normal"] semester.alignment = TA_LEFT semester.fontName = "Helvetica" semester.fontSize = 8 semester.leading = 18 semester_title = "<b>Total Units : " + str(second_semester_unit) + "</b>" semester_title = Paragraph(semester_title, semester) Story.append(semester_title) Story.append(Spacer(1, 2)) style = getSampleStyleSheet() certification = style["Normal"] certification.alignment = TA_JUSTIFY certification.fontName = "Helvetica" certification.fontSize = 8 certification.leading = 18 student = Student.objects.get(user__pk=request.user.id) certification_text = "CERTIFICATION OF REGISTRATION: I certify that <b>" + str(request.user.get_full_name().upper()) + "</b>\ has been duly registered for the <b>" + student.level + " level </b> of study in the department\ of INFORMATION MANAGEMENT TECHNOLOGY and that the courses and units registered are as approved by the senate of the University" certification_text = Paragraph(certification_text, certification) Story.append(certification_text) # FIRST SEMESTER ENDS HERE logo = MEDIA_ROOT + "/logo/android-chrome-144x144.png" im = Image(logo, 1.5*inch, 1.5*inch) im.__setattr__("_offs_x", -228) im.__setattr__("_offs_y", 625) Story.append(im) picture = BASE_DIR + request.user.get_picture() im = Image(picture, 1.0*inch, 1.0*inch) im.__setattr__("_offs_x", 218) im.__setattr__("_offs_y", 625) Story.append(im) doc.build(Story) fs = FileSystemStorage("/tmp") with fs.open(fname) as pdf: response = HttpResponse(pdf, content_type='application/pdf') response['Content-Disposition'] = 'inline; filename='+fname+'' return response return response
def course_registration_form(request): current_semester = Semester.objects.get(is_current_semester=True) current_session = Session.objects.get(is_current_session=True) courses = TakenCourse.objects.filter(student__user__id=request.user.id) fname = request.user.username + '.pdf' fname = fname.replace("/", "-") flocation = '/tmp/' + fname doc = SimpleDocTemplate(flocation, rightMargin=15, leftMargin=15, topMargin=0, bottomMargin=0) styles = getSampleStyleSheet() Story = [Spacer(1, 0.5)] Story.append(Spacer(1, 0.4 * inch)) style = styles["Normal"] style = getSampleStyleSheet() normal = style["Normal"] normal.alignment = TA_CENTER normal.fontName = "Helvetica" normal.fontSize = 12 normal.leading = 18 title = "<b>ECOLE SUPERIEUR POLYTECHNIQUE</b>" title = Paragraph(title.upper(), normal) Story.append(title) style = getSampleStyleSheet() school = style["Normal"] school.alignment = TA_CENTER school.fontName = "Helvetica" school.fontSize = 10 school.leading = 18 school_title = "<b>EPITA</b>" school_title = Paragraph(school_title.upper(), school) Story.append(school_title) style = getSampleStyleSheet() Story.append(Spacer(1, 0.1 * inch)) department = style["Normal"] department.alignment = TA_CENTER department.fontName = "Helvetica" department.fontSize = 9 department.leading = 18 department_title = "<b>DÉPARTEMENT DES TECHNOLOGIES DE GESTION DE L'INFORMATION</b>" department_title = Paragraph(department_title, department) Story.append(department_title) Story.append(Spacer(1, .3 * inch)) title = "<b><u>FORMULAIRE D'INSCRIPTION ÉTUDIANT</u></b>" title = Paragraph(title.upper(), normal) Story.append(title) student = Student.objects.get(user__pk=request.user.id) style_right = ParagraphStyle(name='right', parent=styles['Normal']) tbl_data = [ [ Paragraph( "<b>Numéro d'enregistrement : " + request.user.username.upper() + "</b>", styles["Normal"]) ], [ Paragraph( "<b>Nom : " + request.user.get_full_name().upper() + "</b>", styles["Normal"]) ], [ Paragraph( "<b>Session : " + current_session.session.upper() + "</b>", styles["Normal"]), Paragraph("<b>Niveau: " + student.level + "</b>", styles["Normal"]) ] ] tbl = Table(tbl_data) Story.append(tbl) Story.append(Spacer(1, 0.6 * inch)) style = getSampleStyleSheet() semester = style["Normal"] semester.alignment = TA_LEFT semester.fontName = "Helvetica" semester.fontSize = 9 semester.leading = 18 semester_title = "<b>PREMIER SEMESTRE</b>" semester_title = Paragraph(semester_title, semester) Story.append(semester_title) elements = [] # FIRST SEMESTER count = 0 header = [('S/No', 'Course Code', 'Course Title', 'Unit', Paragraph('Name, Siganture of course lecturer & Date', style['Normal']))] table_header = Table(header, 1 * [1.4 * inch], 1 * [0.5 * inch]) table_header.setStyle( TableStyle([ ('ALIGN', (-2, -2), (-2, -2), 'CENTER'), ('VALIGN', (-2, -2), (-2, -2), 'MIDDLE'), ('ALIGN', (1, 0), (1, 0), 'CENTER'), ('VALIGN', (1, 0), (1, 0), 'MIDDLE'), ('ALIGN', (0, 0), (0, 0), 'CENTER'), ('VALIGN', (0, 0), (0, 0), 'MIDDLE'), ('ALIGN', (-4, 0), (-4, 0), 'LEFT'), ('VALIGN', (-4, 0), (-4, 0), 'MIDDLE'), ('ALIGN', (-3, 0), (-3, 0), 'LEFT'), ('VALIGN', (-3, 0), (-3, 0), 'MIDDLE'), ('TEXTCOLOR', (0, -1), (-1, -1), colors.black), ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black), ('BOX', (0, 0), (-1, -1), 0.25, colors.black), ])) Story.append(table_header) first_semester_unit = 0 for course in courses: if course.course.semester == FIRST: #first_semester_unit += int(course.course.courseUnit) first_semester_unit += int(course.course.id) data = [(count + 1, course.course.courseCode.upper(), course.course.courseTitle, course.course.courseUnit, '')] color = colors.black count += 1 table_body = Table(data, 1 * [1.4 * inch], 1 * [0.3 * inch]) table_body.setStyle( TableStyle([ ('ALIGN', (-2, -2), (-2, -2), 'CENTER'), ('ALIGN', (1, 0), (1, 0), 'CENTER'), ('ALIGN', (0, 0), (0, 0), 'CENTER'), ('ALIGN', (-4, 0), (-4, 0), 'LEFT'), ('TEXTCOLOR', (0, -1), (-1, -1), colors.black), ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black), ('BOX', (0, 0), (-1, -1), 0.25, colors.black), ])) Story.append(table_body) style = getSampleStyleSheet() semester = style["Normal"] semester.alignment = TA_LEFT semester.fontName = "Helvetica" semester.fontSize = 8 semester.leading = 18 semester_title = "<b>Total Units : " + str(first_semester_unit) + "</b>" semester_title = Paragraph(semester_title, semester) Story.append(semester_title) # FIRST SEMESTER ENDS HERE Story.append(Spacer(1, 0.6 * inch)) style = getSampleStyleSheet() semester = style["Normal"] semester.alignment = TA_LEFT semester.fontName = "Helvetica" semester.fontSize = 9 semester.leading = 18 semester_title = "<b>SECOND SEMESTER</b>" semester_title = Paragraph(semester_title, semester) Story.append(semester_title) # SECOND SEMESTER count = 0 header = [('S/No', 'Course Code', 'Course Title', 'Unit', Paragraph('<b>Name, Siganture of course lecturer & Date</b>', style['Normal']))] table_header = Table(header, 1 * [1.4 * inch], 1 * [0.5 * inch]) table_header.setStyle( TableStyle([ ('ALIGN', (-2, -2), (-2, -2), 'CENTER'), ('VALIGN', (-2, -2), (-2, -2), 'MIDDLE'), ('ALIGN', (1, 0), (1, 0), 'CENTER'), ('VALIGN', (1, 0), (1, 0), 'MIDDLE'), ('ALIGN', (0, 0), (0, 0), 'CENTER'), ('VALIGN', (0, 0), (0, 0), 'MIDDLE'), ('ALIGN', (-4, 0), (-4, 0), 'LEFT'), ('VALIGN', (-4, 0), (-4, 0), 'MIDDLE'), ('ALIGN', (-3, 0), (-3, 0), 'LEFT'), ('VALIGN', (-3, 0), (-3, 0), 'MIDDLE'), ('TEXTCOLOR', (0, -1), (-1, -1), colors.black), ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black), ('BOX', (0, 0), (-1, -1), 0.25, colors.black), ])) Story.append(table_header) second_semester_unit = 0 for course in courses: if course.course.semester == SECOND: #second_semester_unit += int(course.course.courseUnit) second_semester_unit += int(course.course.id) data = [(count + 1, course.course.courseCode.upper(), course.course.courseTitle, course.course.courseUnit, '')] color = colors.black count += 1 table_body = Table(data, 1 * [1.4 * inch], 1 * [0.3 * inch]) table_body.setStyle( TableStyle([ ('ALIGN', (-2, -2), (-2, -2), 'CENTER'), ('ALIGN', (1, 0), (1, 0), 'CENTER'), ('ALIGN', (0, 0), (0, 0), 'CENTER'), ('ALIGN', (-4, 0), (-4, 0), 'LEFT'), ('TEXTCOLOR', (0, -1), (-1, -1), colors.black), ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black), ('BOX', (0, 0), (-1, -1), 0.25, colors.black), ])) Story.append(table_body) style = getSampleStyleSheet() semester = style["Normal"] semester.alignment = TA_LEFT semester.fontName = "Helvetica" semester.fontSize = 8 semester.leading = 18 semester_title = "<b>Total Units : " + str(second_semester_unit) + "</b>" semester_title = Paragraph(semester_title, semester) Story.append(semester_title) Story.append(Spacer(1, 2)) style = getSampleStyleSheet() certification = style["Normal"] certification.alignment = TA_JUSTIFY certification.fontName = "Helvetica" certification.fontSize = 8 certification.leading = 18 student = Student.objects.get(user__pk=request.user.id) certification_text = "CERTIFICATION D'INSCRIPTION: Je certifie que <b>" + str( request.user.get_full_name().upper()) + "</b>\ a été dûment enregistré pour le <b>" + student.level + " niveau </b> d'études dans le département\ de TECHNOLOGIE DE LA GESTION DE L'INFORMATION et que les cours et les unités inscrits sont tels qu'approuvés par la direction de l'Université" certification_text = Paragraph(certification_text, certification) Story.append(certification_text) # FIRST SEMESTER ENDS HERE logo = MEDIA_ROOT + "/logo/epita.jpeg" im = Image(logo, 1.5 * inch, 1.5 * inch) im.__setattr__("_offs_x", -228) im.__setattr__("_offs_y", 625) Story.append(im) picture = BASE_DIR + request.user.get_picture() im = Image(picture, 1.0 * inch, 1.0 * inch) im.__setattr__("_offs_x", 218) im.__setattr__("_offs_y", 625) Story.append(im) doc.build(Story) fs = FileSystemStorage("/tmp") with fs.open(fname) as pdf: response = HttpResponse(pdf, content_type='application/pdf') response['Content-Disposition'] = 'inline; filename=' + fname + '' return response return response