Пример #1
0
 def fieldDataOf(self, fieldNameStr):
     f = self._meta.get_field(fieldNameStr)
     attname = f.get_attname()
     data= {'name': fieldNameStr,
            'attname': attname, # could be different from fieldNameStr, e.g. courseTeacher_id
            'verbose_name': f.verbose_name,
            'help_text': f.help_text,
            'value': eval("self."+attname)}
     if fieldNameStr  == 'courseTeacher':
         data['value'] = prettyNameOfUser(self.courseTeacher) # avoids showing foreign key id
     elif fieldNameStr == 'testBeginTime':
         theDay = self.fieldDataOf('testDate')['value']
         perTimeStart = data['value']
         perId = Period.idOfPeriodStartTimeOnDay(perTimeStart, theDay)
         data['value'] = Period.TIME_VERBOSE_NAME_MAP[perId]
     return data
Пример #2
0
    def handle(self, *args, **options):
        bookings = Booking.objects.filter(Q(testDate__lt=cutoffDay) | Q(testCompleted=True) | Q(noShow=True))
        if bookings.count() == 0:
            return
        
        sortedBookings = bookings.extra(select={'lower_studentFirstName': 'lower(studentFirstName)',
                                                'lower_studentLastName': 'lower(studentLastName)'}).order_by('testDate', 'testBeginTime',
                                                                                                             'lower_studentFirstName',
                                                                                                             'lower_studentLastName')

        # full report for exam center
        fullReport = ""
        for booking in sortedBookings:
            fullReport += "- "
            fullReport += str(booking)
            fullReport += " (" + str(prettyNameOfUser(booking.courseTeacher)) + ")"
            fullReport += "\n\n"
        send_mail(ReportEmail.fullReportSubject, fullReport, ReportEmail.fromEmail,
                  ReportEmail.fullReportRecipientEmails, fail_silently=True)

        # individual reports to teachers
        courseTeachersPks = set(bookings.values_list('courseTeacher', flat=True))
        bookingsReported = []
        for pk in courseTeachersPks:
            try:
                courseTeacherEmail = User.objects.get(id__iexact=pk).email
                report = ""
                bookingsReportedToTeacher = [] # temp var to ensure email is sent out before deleting these bookings
                for booking in sortedBookings.filter(courseTeacher = pk):
                    report += "- "
                    report += str(booking)
                    report += "\n\n"
                    bookingsReportedToTeacher.append(booking)
                send_mail(ReportEmail.individualReportSubject, report, ReportEmail.fromEmail,
                          [courseTeacherEmail], fail_silently=False)
                bookingsReported += bookingsReportedToTeacher
            except:
                pass

        # when all done reporting, DELETE
        for booking in bookingsReported:
            try:
                booking.delete()
            except:
                pass
Пример #3
0
 def label_from_instance(self, usr):
     return prettyNameOfUser(usr)