Beispiel #1
0
    def finish(self):
        leader_badge_slugs = ('expert.leader', 'expert.expertise.leader')
        leader_badges = dict((k, Badge.get_by_key_name(k)) for k in leader_badge_slugs)

        for group_id, (emails, count) in self.best_by_group.iteritems():
            self.log.append('Considering group %s, best score is %d' % (
                str(group_id), count))
            if count < 1:
                self.log.append('... Best score is too low, skipping.')
                continue
            for email in emails:
                report = ExpertBadgeReport.on(
                        db.Key.from_path(Student.kind(), email),
                        course=self.course,
                        force_re_run=self.re_run)
                base_badge_version = choose_expert_badge_version(report.completion())
                if not base_badge_version:
                    raise AssertionError('They should have passed, wat?')
                leader_badge_slug = base_badge_version + '.leader'
                if self.really:
                    leader_badge = leader_badges[leader_badge_slug]
                    b = Badge.issue(leader_badge,
                            db.Key.from_path(Student.kind(), email), put=False)
                    b.evidence = self.host_url + '/badges/expert_evidence?id=%d' % report.key().id()
                    b.put()
                    self.log.append('... ISSUED %s to %s, id=%d' % (
                        leader_badge_slug, email, b.key().id()))
                else:
                    self.log.append('... WOULD ISSUE %s to %s' % (
                        leader_badge_slug, email))
        self._batch_write()
Beispiel #2
0
    def finish(self):
        if self.really:
            leader_badges = dict((key, Badge.get_by_key_name(key)) for key in self.leader_badge_keys)

        for group_id, (emails, count) in self.best_by_group.iteritems():
            self.log.append('Considering group %s, best score is %d' % (
                str(group_id), count))
            if count < 1:
                self.log.append('... Best score is too low, skipping.')
                continue
            if self.really:
                for email in emails:
                    report = PartReport.on(
                            db.Key.from_path(Student.kind(), email),
                            course=self.course, part=self.part,
                            force_re_run=self.re_run)
                    base_badge_version = choose_badge_version(report.slug, report.completion())
                    leader_badge_version = combine_badge_slug_parts(base_badge_version, 'leader')
                    leader_badge = leader_badges[leader_badge_version]
                    assert leader_badge, "Should be a badge called %s" % leader_badge_version

                    b = Badge.issue(leader_badge,
                            db.Key.from_path(Student.kind(), email), put=False)
                    b.evidence = self.host_url + '/badges/evidence?id=%d' % report.key().id()
                    b.put()
                    self.log.append('... ISSUED leader badge %s to %s, id=%d' % (
                        leader_badge_version, email, b.key().id()))
            else:
                self.log.append('... WOULD ISSUE leader badge to %s' % ' '.join(emails))
        self._batch_write()