Example #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()
Example #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()
Example #3
0
    def map(self, student):
        self.log.append('########## Student %s ##########' % student.key().name())
        report = PartReport.on(student, course=self.course, part=self.part,
                force_re_run=self.re_run, put=self.really)

        completion = report.completion()
        self.log.append(' Passed? %s.' % str(completion))

        badge_version = choose_badge_version(report.slug, completion)

        if badge_version:
            badge = Badge.get_by_key_name(badge_version)
            if not badge:
                self.log.append(' There is no badge with key_name %s (so I cannot issue a badge)' % badge_version)

            self.num_issued += 1
            if self.really and badge:
                b = Badge.issue(badge, student, put=False) # need to include evidence URL here somehow
                b.evidence = self.host_url + '/badges/evidence?id=%d' % report.key().id()
                b.put()
                self.log.append(' Issued badge, name=%s, assertion id=%d' % (
                    badge_version, b.key().id()))
                return ([b], [])
            else:
                self.log.append(' WOULD issue badge.')
        else:
            self.log.append('Not issuing because at least one of: %s' % (', '.join(report.incomplete_reasons)))

            ##TODO: this is not comprehensive: they could still have .expertise or .leader versions.
            #if self.really and badge:
                #Badge.ensure_not_issued(badge, student)
        return ([], [])
Example #4
0
    def map(self, student):
        self.log.append('--------------- Student %s' % student.key().name())

        report = ExpertBadgeReport.on(student, self.course,
                force_re_run=self.force_re_run, put=self.really)

        completion = report.completion()
        self.log.append(' Passed? %s.' % str(completion))

        badge_version = choose_expert_badge_version(completion)

        if badge_version:
            badge = Badge.get_by_key_name(badge_version)
            if not badge:
                self.log.append('no such badge! %s' % badge_version)
            self.num_issued += 1
            if self.really and badge:
                b = Badge.issue(badge, student, put=False) # need to include evidence URL here somehow
                b.evidence = self.host_url + '/badges/expert_evidence?id=%d' % report.key().id()
                b.put()
                self.log.append(' Issued badge, name=%s, assertion id=%d' % (
                    badge.key().name(), b.key().id()))
                return ([b], [])
            else:
                self.log.append(' WOULD issue badge %s' % badge_version)
        else:
            self.log.append('Incomplete, we are missing: %s' % (', '.join(report.incomplete_reasons())))
        
        return ([], [])
Example #5
0
    def post(self):
        if not users.is_current_user_admin():
            self.abort(403)
        if not XsrfTokenManager.is_xsrf_token_valid(self.request.POST.get('xsrf_token', ''), 'post'):
            self.abort(403, 'XSRF token failed.')
        form = self.Form(self.request.POST)
        if not form.validate():
            self.response.write('<br>'.join(form.errors))
            return

        student = Student.get_by_key_name(form.email.data)
        report = PartReport.on(student, course=self.get_course(),
                part=form.part.data,
                force_re_run=form.re_run.data,
                put=form.really_save.data)


        badge_version = choose_badge_version(part_config[form.part.data]['slug'], report.completion())
        if badge_version:
            badge = Badge.get_by_key_name(badge_version)
            if not badge:
                self.response.write(' There is no badge with key_name %s (so I cannot issue a badge)' % badge_version)
            if form.really_save.data and badge:
                b = Badge.issue(badge, student, put=False)
                b.evidence = self.request.host_url + '/badges/evidence?id=%d' % report.key().id()
                b.put()
                self.response.write('Issued badge %s!' % badge_version)
            else:
                self.response.write('Would have issued badge %s!' % badge_version)
        else:
            self.response.write('Not issuing because at least one of: %s' % (', '.join(report.incomplete_reasons)))