|
| 1 | + |
| 2 | +__author__ = "Individual contributors (see AUTHORS file)" |
| 3 | +__date__ = "$DATE$" |
| 4 | +__rev__ = "$REV$" |
| 5 | +__license__ = "AGPL v.3" |
| 6 | +__copyright__ = """ |
| 7 | +This file is part of the ESP Web Site |
| 8 | +Copyright (c) 2012 by the individual contributors |
| 9 | + (see AUTHORS file) |
| 10 | +The ESP Web Site is free software; you can redistribute it and/or |
| 11 | +modify it under the terms of the GNU Affero General Public License |
| 12 | +as published by the Free Software Foundation; either version 3 |
| 13 | +of the License, or (at your option) any later version. |
| 14 | +This program is distributed in the hope that it will be useful, |
| 15 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +GNU Affero General Public License for more details. |
| 18 | +You should have received a copy of the GNU Affero General Public |
| 19 | +License along with this program; if not, write to the Free Software |
| 20 | +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | +Contact information: |
| 22 | +MIT Educational Studies Program |
| 23 | + 84 Massachusetts Ave W20-467, Cambridge, MA 02139 |
| 24 | + Phone: 617-253-4882 |
| 25 | + |
| 26 | +Learning Unlimited, Inc. |
| 27 | + 527 Franklin St, Cambridge, MA 02139 |
| 28 | + Phone: 617-379-0178 |
| 29 | + |
| 30 | +""" |
| 31 | + |
| 32 | +from esp.middleware.threadlocalrequest import get_current_request |
| 33 | +from esp.program.modules.base import ProgramModuleObj, main_call, needs_student, meets_cap |
| 34 | +from esp.program.modules.handlers.programprintables import ProgramPrintables |
| 35 | +from esp.program.models import StudentRegistration |
| 36 | +from esp.tagdict.models import Tag |
| 37 | +from esp.users.models import Record |
| 38 | +from esp.utils.latex import render_to_latex |
| 39 | + |
| 40 | +from datetime import datetime |
| 41 | + |
| 42 | +class StudentCertModule(ProgramModuleObj): |
| 43 | + doc = """Allows students to download a completion certificate |
| 44 | + for the program once the program has ended.""" |
| 45 | + |
| 46 | + @classmethod |
| 47 | + def module_properties(cls): |
| 48 | + return { |
| 49 | + "link_title": "Print Completion Certificate", |
| 50 | + "admin_title": "Student Certificate Module", |
| 51 | + "module_type": "learn", |
| 52 | + "required": False, |
| 53 | + "seq": 999999, |
| 54 | + "choosable": 0, |
| 55 | + } |
| 56 | + |
| 57 | + @main_call |
| 58 | + @needs_student |
| 59 | + @meets_cap |
| 60 | + def certificate(self, request, tl, one, two, module, extra, prog): |
| 61 | + if not self.isStep(): |
| 62 | + return self.goToCore(tl) |
| 63 | + |
| 64 | + user = request.user |
| 65 | + |
| 66 | + if extra: |
| 67 | + file_type = extra.strip() |
| 68 | + else: |
| 69 | + file_type = 'pdf' |
| 70 | + |
| 71 | + attended = Tag.getProgramTag('student_certificate', prog) == 'class_attendance' |
| 72 | + if attended: |
| 73 | + verbs = ['Attended'] |
| 74 | + else: |
| 75 | + verbs = ['Enrolled'] |
| 76 | + |
| 77 | + context = {'user': user, 'prog': prog, |
| 78 | + 'schedule': ProgramPrintables.getTranscript(prog, user, 'latex', verbs, valid_only = (not attended)), |
| 79 | + 'descriptions': ProgramPrintables.getTranscript(prog, user, 'latex_desc', verbs, valid_only = (not attended))} |
| 80 | + |
| 81 | + return render_to_latex('program/modules/programprintables/completion_certificate.tex', context, file_type) |
| 82 | + |
| 83 | + def isStep(self): |
| 84 | + if hasattr(self, 'user'): |
| 85 | + user = self.user |
| 86 | + else: |
| 87 | + request = get_current_request() |
| 88 | + user = request.user |
| 89 | + cert_tag = Tag.getProgramTag('student_certificate', self.program) |
| 90 | + slots = self.program.getTimeSlots() |
| 91 | + if slots and datetime.now() > max(slots).end: |
| 92 | + if cert_tag == 'all': |
| 93 | + return True |
| 94 | + elif cert_tag == 'program_attendance': |
| 95 | + return Record.user_completed(user, "attended", self.program) |
| 96 | + elif cert_tag == 'class_attendance': |
| 97 | + return StudentRegistration.objects.filter(user = user, section__parent_class__parent_program=self.program, relationship__name = 'Attended').exists() |
| 98 | + return False |
| 99 | + |
| 100 | + class Meta: |
| 101 | + proxy = True |
| 102 | + app_label = 'modules' |
0 commit comments