コード例 #1
0
ファイル: custom_badge.py プロジェクト: twiffy/eabooc
    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))
コード例 #2
0
ファイル: custom_badge.py プロジェクト: twiffy/eabooc
    def get_edit(self):
        if not Roles.is_course_admin(self.app_context):
            self.abort(403, 'You are not an admin :(')

        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 = Badge.get_or_insert(
                custom_badge_name(student))

        badge_form = BadgeForm(None, badge)
        review = Annotation.reviews(whose=student, unit=UNIT_NUMBER).get()
        comments_form = CommentsForm()
        if review:
            comments_form.public_comments.data = review.reason
            comments_form.review_source.data = review.who.key().name()
        self.render_edit(badge_form, comments_form)
コード例 #3
0
ファイル: custom_badge.py プロジェクト: twiffy/eabooc
    def get_edit(self):
        if not Roles.is_course_admin(self.app_context):
            self.abort(403, 'You are not an admin :(')

        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 = Badge.get_or_insert(custom_badge_name(student))

        badge_form = BadgeForm(None, badge)
        review = Annotation.reviews(whose=student, unit=UNIT_NUMBER).get()
        comments_form = CommentsForm()
        if review:
            comments_form.public_comments.data = review.reason
            comments_form.review_source.data = review.who.key().name()
        self.render_edit(badge_form, comments_form)
コード例 #4
0
ファイル: custom_badge.py プロジェクト: twiffy/eabooc
    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))