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()
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 ([], [])
def post_save_settings(self): user = self.personalize_page_and_get_enrolled() if not user: return form = self.SettingsForm(self.request.POST) try: report = ExpertBadgeReport.get_by_id(int(form.report_id.data)) except ValueError: report = None if not report: self.abort(404, "That evidence report was not found.") if not self.can_edit(user, report): self.abort(403, "You can't edit that user's report.") display_field_params = exam_display_choices( report.final_exam_score) form.exam_display.choices = display_field_params['choices'] form.exam_display.default = display_field_params['default'] if not form.validate(): self.redirect('/') return report.exam_display = form.exam_display.data report.put() EventEntity.record( 'set-evidence-settings', users.get_current_user(), transforms.dumps({ 'slug': report.slug, 'exam_display': report.exam_display, 'email': user.key().name() })) self.template_value['navbar'] = {} self.template_value['content'] = '''<div class="gcb-aside">OK, saved settings.<br> <a href="/student/home">Back to your account page...</a></div>''' self.render('bare.html')
def get_settings(self): user = self.personalize_page_and_get_enrolled() if not user: return try: report = ExpertBadgeReport.get_by_id(int(self.request.GET.get('id', -1))) except ValueError: report = None if not report: self.abort(404, "That evidence report was not found.") if not self.can_edit(user, report): self.abort(403) form = self.SettingsForm( report_id=report.key().id(), exam_display=report.exam_display) display_field_params = { 'choices': [('blank', '(Blank)')], 'default': 'blank' } display_field_params = exam_display_choices( report.final_exam_score) form.exam_display.choices = display_field_params['choices'] form.exam_display.default = display_field_params['default'] self.template_value['report'] = report self.template_value['form'] = form self.template_value['xsrf_token'] = XsrfTokenManager.create_xsrf_token('save_settings') self.template_value['navbar'] = {} self.template_value['badge_name'] = "Assessment Expert Badge" self.template_value['action_url'] = '/badges/expert_evidence?action=save_settings' self.render('wf_evidence_settings.html')
def get_view(self): try: report = ExpertBadgeReport.get_by_id(int(self.request.GET.get('id', -1))) except ValueError: report = None if not report: self.abort(404) all_assertions_q = BadgeAssertion.all() all_assertions_q.filter('recipient', report.student_key) all_assertions_q.filter('revoked', False) all_assertions = all_assertions_q.run(limit=10) if not report.exam_display: if report.final_exam_score: display_info = exam_display_choices(report.final_exam_score) report.exam_display = display_info['default'] else: report.exam_display = 'blank' self.template_value['report'] = report self.template_value['navbar'] = {} self.template_value['author'] = report.student # TODO: links to the other badges all_assertions = prefetch.prefetch_refprops( list(all_assertions), BadgeAssertion.badge) course_parts = {'practices': None, 'principles': None, 'policies': None} for ass in all_assertions: name_parts = ass.badge_name.split('.') if name_parts[0] in course_parts: if (not course_parts[name_parts[0]]) or (len(name_parts) > 1): course_parts[name_parts[0]] = ass self.template_value['part_assertions'] = course_parts self.render('wf_expert_evidence.html')