コード例 #1
0
    def handle(self, *args, **kwargs):
        self.setup(**kwargs)

        # Format: byAdvisor[advisor][slot]
        byAdvisor = {}

        for slot in self.slots:
            missingStudents = getUnassignedStudents([slot])

            for student in sorted(missingStudents, key=lambda s: (s.last_name, s.first_name, s.nickname)):
                advisor = student.advisor

                if not advisor in byAdvisor:
                    byAdvisor[advisor] = {}

                if not slot in byAdvisor[advisor]:
                    byAdvisor[advisor][slot] = {"students": []}

                byAdvisor[advisor][slot]["students"].append(student)

        for advisor in byAdvisor:
            allStudents = set()

            flattenedSlots = []
            for slot in sorted(byAdvisor[advisor].keys(), key=lambda s: s.date):
                students = byAdvisor[advisor][slot]["students"]
                allStudents |= set(students)
                flattenedSlots.append((slot, students))

            studentCount = len(allStudents)

            if studentCount:
                deadline = min(
                    [slot.editable_until for slot in byAdvisor[advisor].keys() if slot.editable_until]
                ) - timedelta(hours=1)

                template = get_template("enrichmentmanager/emails/unassigned_advisor.html")
                context = Context(
                    {
                        "slots": flattenedSlots,
                        "count": studentCount,
                        "advisor": advisor,
                        "deadline": deadline,
                        "base_url": settings.MAIL_BASE_URL,
                    }
                )
                body = template.render(context)

                self.sendMail(
                    mailFrom="Glenn Ames <*****@*****.**>",
                    mailTo=[advisor.email],
                    mailCC=["*****@*****.**", "*****@*****.**"],
                    replyTo=["*****@*****.**", "*****@*****.**", "*****@*****.**"],
                    subject="Unassigned Advisees for Enrichment",
                    bodyHTML=body,
                )
コード例 #2
0
 def handle(self, *args, **kwargs):
     self.setup(**kwargs)
     
     sendTo = map(str.strip, kwargs["send_to"])
     
     #Format: bySlot[slot][advisor]['students'] = [students]
     bySlot = {}
     allStudents = set()
     
     for slot in self.slots:
         if not slot in bySlot:
             bySlot[slot] = {}
             
         missingStudents = getUnassignedStudents([slot])
         
         for student in sorted(missingStudents, key=lambda s: (s.last_name, s.first_name, s.nickname)):
             advisor = student.advisor
             allStudents.add(student)
             
             if not advisor in bySlot[slot]:
                 bySlot[slot][advisor] = {'students': []}
             
             bySlot[slot][advisor]['students'].append(student)
     
     #(slot, [(advisor, [students])])
     flattenedData = []
     for slot in bySlot:
         out = []
         
         for advisor in sorted(bySlot[slot], key=lambda a: (a.last_name, a.first_name)):
             out.append((advisor, bySlot[slot][advisor]['students']))
         
         flattenedData.append((slot, out))
     
     template = get_template('enrichmentmanager/emails/unassigned_administrator.html')
     count = len(allStudents)
     
     context = Context({'slots': flattenedData, 'count': count, 'base_url': settings.MAIL_BASE_URL})
     body = template.render(context)
     
     if self.slots.count():
         self.sendMail(
             mailFrom='Technology <*****@*****.**>', 
             mailTo=sendTo,
             subject='Master List of Unassigned Advisees for Enrichment',
             replyTo=['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'],
             bodyHTML = body
             )