Exemplo n.º 1
0
    def get(self):
        # Launch a separate task to create emails for each team, to make sure
        # we can scale memory and cpu time easily.
        teams = Team.get()
        programs_by_id = {p.uid: p for p in Program.get()}
        for team in teams:
            if programs_by_id[team.program_id].send_cycle_email:
                taskqueue.add(
                    url='/task/{}/cycle_emails'.format(team.uid),
                    queue_name='default',
                )

        team_ids = [t.uid for t in teams]
        logging.info(team_ids)
        self.response.write(json.dumps({'team_ids': team_ids}))
Exemplo n.º 2
0
    def release_and_notify(self, week):
        # Update all reports for a given week and set preview = False, _and_
        # create notifications for all related users.

        # Capture which reports are previews before we release them. We'll base
        # the notifications on this list to make sure we're not notifying about
        # any reports that aren't previews.
        reports_to_release = Report.get_previews(week)

        # This is the "release" part.
        num_reports_released = Report.release_previews(week)

        # Now we have to load a bunch of data from the related teams,
        # classrooms, and users in order to create notifications.
        if len(reports_to_release) != num_reports_released:
            logging.error(
                "Report.get_previews() ({}) and Report.release_previews() "
                "({}) didn't hit the same number of rows.".format(
                    len(reports_to_release), num_reports_released))

        team_ids = {r.team_id for r in reports_to_release}
        classroom_ids = {
            r.classroom_id
            for r in reports_to_release if r.classroom_id
        }

        # Load all related teams and classrooms as a batch.
        teams = Team.get_by_id(team_ids)
        classrooms = Classroom.get_by_id(classroom_ids)

        t_index = {t.uid: t for t in teams}
        c_index = {c.uid: c for c in classrooms}
        p_index = {p.uid: p for p in Program.get()}
        notes = []
        for r in reports_to_release:
            team = t_index.get(r.team_id)
            program = p_index.get(team.program_id)
            classroom = c_index.get(r.classroom_id, None)
            result = self.notify_for_single_report(program, team, classroom)
            # result might be a list or None
            if result:
                notes += result

        Notification.put_multi(notes)

        return num_reports_released
Exemplo n.º 3
0
    def index(self, program=None):
        program = util.session("current_program", identity.current.user.programID, program)
        if identity.in_group("global_admin") and int(program) == 0:
            userlist = User.select()
            program = identity.current.user.programID
        elif int(program) == 0:
            program = identity.current.user.programID
            userlist = User.selectBy(programID=program)
        else:
            userlist = User.selectBy(programID=program)
        programlist = Program.select()

        return dict(
            program=Program.get(program),
            programlist=programlist,
            curProg=self.curProg,
            userlist=userlist,
            shaded=util.shaded,
        )
Exemplo n.º 4
0
 def get(self):
     self.write(Program.get(active=True, order='name'))