def post_save(self): if not Roles.is_course_admin(self.app_context): self.abort(403, 'You are not an admin :(') user = self.personalize_page_and_get_enrolled() student_email = self.request.GET.get('email', None) if not student_email: self.abort(404, 'email= parameter required') student = Student.get_enrolled_student_by_email(student_email) if not student: self.abort(404, Markup('Could not find a student with email "%s"') % student_email) badge_slug = custom_badge_name(student) badge = Badge.get_or_insert(badge_slug) badge_form = BadgeForm(self.request.POST, badge) comments_form = CommentsForm(self.request.POST) if not (badge_form.validate() and comments_form.validate()): self.render_edit(badge_form, comments_form) return comments_form.validate() reviewer = Student.get_by_email(comments_form.review_source.data) if not reviewer: comments_form.review_source.errors.append("Could not find a user with that e-mail address") self.render_edit(badge_form, comments_form) return page = WikiPage.get_page(student, unit=UNIT_NUMBER) if not page: self.abort(404, Markup('Could not find unit %d wikifolio for student "%s"') % (UNIT_NUMBER, student_email)) old_reviews = Annotation.reviews(whose=student, unit=UNIT_NUMBER).run() db.delete(old_reviews) Annotation.review(page, who=reviewer, text=comments_form.public_comments.data) if not Annotation.endorsements(what=page, who=user).count(limit=1): Annotation.endorse(page, who=user, optional_done=True) badge_form.populate_obj(badge) badge.put() report = PartReport.on(student, self.get_course(), 4, force_re_run=True, put=False) for rep in report.unit_reports: rep._run() rep.put() report.slug = badge_slug report.put() assertion = Badge.issue(badge, student, put=False) assertion.evidence = urljoin(self.request.host_url, '/badges/evidence?id=%d' % report.key().id()) assertion.put() self.response.write( Markup("Issued badge %s to %s, evidence %s") % ( badge.key().name(), student_email, assertion.evidence))
def get(self): """Handles GET requests.""" student = self.personalize_page_and_get_enrolled() if not student: return course = self.get_course() self.template_value['navbar'] = {'myprofile': True} self.template_value['student'] = student self.template_value['assertion_link'] = lambda a: self.request.host_url + modules.badges.util.url_for_key(a.key()) self.template_value['date_enrolled'] = student.enrolled_on.strftime( HUMAN_READABLE_DATE_FORMAT) self.template_value['score_list'] = course.get_all_scores(student) self.template_value['overall_score'] = course.get_overall_score(student) self.template_value['part_reports'] = [PartReport.on(student, course, p) for p in (1,2,3,4)] self.template_value['expert_report'] = ExpertBadgeReport.on(student, course) self.template_value['student_edit_xsrf_token'] = ( XsrfTokenManager.create_xsrf_token('student-edit')) self.render('student_profile.html')
def map(self, ass): d = {} for f in ['issuedOn', 'expires', 'revoked', 'evidence']: d[f] = getattr(ass, f) d['badge_name'] = ass.badge_name student = ass.recipient d['recipient'] = student.badge_name d['email'] = student.key().name() d['group_id'] = student.group_id d['id'] = ass.key().id() logging.warning('Considering %s issued to %s', d['badge_name'], d['email']) if not ass.badge_name.startswith('expert'): part_num = get_part_num_by_badge_name(ass.badge_name) report = PartReport.on(student, self.course, part_num) unit_reps = report.unit_reports for attr in ['endorsements', 'promotions', 'comments']: d[attr] = sum(getattr(u, attr) for u in unit_reps) self.add_row(d)
def post_save(self): if not Roles.is_course_admin(self.app_context): self.abort(403, 'You are not an admin :(') user = self.personalize_page_and_get_enrolled() student_email = self.request.GET.get('email', None) if not student_email: self.abort(404, 'email= parameter required') student = Student.get_enrolled_student_by_email(student_email) if not student: self.abort( 404, Markup('Could not find a student with email "%s"') % student_email) badge_slug = custom_badge_name(student) badge = Badge.get_or_insert(badge_slug) badge_form = BadgeForm(self.request.POST, badge) comments_form = CommentsForm(self.request.POST) if not (badge_form.validate() and comments_form.validate()): self.render_edit(badge_form, comments_form) return comments_form.validate() reviewer = Student.get_by_email(comments_form.review_source.data) if not reviewer: comments_form.review_source.errors.append( "Could not find a user with that e-mail address") self.render_edit(badge_form, comments_form) return page = WikiPage.get_page(student, unit=UNIT_NUMBER) if not page: self.abort( 404, Markup('Could not find unit %d wikifolio for student "%s"') % (UNIT_NUMBER, student_email)) old_reviews = Annotation.reviews(whose=student, unit=UNIT_NUMBER).run() db.delete(old_reviews) Annotation.review(page, who=reviewer, text=comments_form.public_comments.data) if not Annotation.endorsements(what=page, who=user).count(limit=1): Annotation.endorse(page, who=user, optional_done=True) badge_form.populate_obj(badge) badge.put() report = PartReport.on(student, self.get_course(), 4, force_re_run=True, put=False) for rep in report.unit_reports: rep._run() rep.put() report.slug = badge_slug report.put() assertion = Badge.issue(badge, student, put=False) assertion.evidence = urljoin( self.request.host_url, '/badges/evidence?id=%d' % report.key().id()) assertion.put() self.response.write( Markup("Issued badge %s to %s, evidence %s") % (badge.key().name(), student_email, assertion.evidence))