Beispiel #1
0
  def post(self):
    # Read in answers
    answer = json.dumps(self.request.POST.items())

    assessment_type = self.request.get('assessment_type')
    num_correct = self.request.get('num_correct')
    num_questions = self.request.get('num_questions')

    # Check for enrollment status
    student = self.getStudent()
    if student:
      logging.info(student.key().name() + ':' + answer)

      # Find student entity and save answers
      student = Student.get_by_key_name(student.key().name().encode('utf8'))

      # FIXME: Currently the demonstration course is hardcoded to have
      # three assessments: 'precourse', 'midcourse', and 'postcourse'.
      # If you would like to have different types of assessments or
      # different score weights/thresholds, edit the code below ...
      if assessment_type == 'precourse':
        score = self.request.get('score')
        student.precourse_answer = answer
        student.precourse_score = int(float(score))
      elif assessment_type == 'midcourse':
        score = self.request.get('score')
        student.midterm_answer = answer
        student.midterm_score = int(float(score))
      elif assessment_type == 'postcourse':
        score = self.request.get('score')
        student.final_answer = answer
        student.final_score = int(float(score))
        if not student.midterm_score:
          student.midterm_score = 0
        student.overall_score = int((0.35 * student.midterm_score) + (0.65 * student.final_score))
        self.templateValue['score'] = student.overall_score
        if student.overall_score >= 70:
          assessment_type = 'postcourse_pass'
        else:
          assessment_type = 'postcourse_fail'
      student.put()

      # Update student entity in memcache
      memcache.set(student.key().name(), student)

      # Set template values for nav-x bar
      navbar = {'course':True}
      self.templateValue['navbar'] = navbar

      # Set template values for user
      user = users.get_current_user()
      if user:
        self.templateValue['email'] = user.email()
        self.templateValue['logoutUrl'] = users.create_logout_url("/")

      # Render confirmation page
      self.templateValue['assessment'] = assessment_type
      self.render('test_confirmation.html')
    else:
      self.redirect('/register')
Beispiel #2
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)))
Beispiel #3
0
    def get(self):


        if not(Roles.is_course_admin(self.app_context)):
            self.redirect("preview")

        self.response.headers['Content-type'] = 'text/csv'
        self.response.headers['Content-disposition'] = 'attachment; filename=students.csv'


        course = self.get_course()

        assessments=[]

        for unit in course.get_units():
            if (unit.type=="A"):
                assessments.append(str(unit.unit_id))


        writer = UnicodeWriter(self.response.out)

        keys = Student.all(keys_only=True).run()

        rows=[]

        for key in keys:

            student=Student.get_by_key_name(key.name())

            rec={"email": key.name(), "name": student.name, "enrolled": unicode(student.is_enrolled), "dateEnrolled": unicode(student.enrolled_on) }

            if (student.scores):
                scores=json.loads(student.scores)

                for assessmentName, score in scores.iteritems():
                    rec[assessmentName]=str(score)


            rows.append(rec)

        headerRow = ["Email", "Name", "Is Enrolled", "Enrolled On"]

        for assessmentName in assessments:
            headerRow.append(course.find_unit_by_id(assessmentName).title)

        writer.writerow(headerRow)

        for row in rows:

            renderedRow=[row["email"],row["name"],row["enrolled"],row["dateEnrolled"]]

            for assessmentName in assessments:
                if (assessmentName in row):
                    renderedRow.append(row[assessmentName])
                else:
                    renderedRow.append("")

            writer.writerow(renderedRow)
Beispiel #4
0
 def getStudent(self):
     user = users.get_current_user()
     if user:
         student = memcache.get(user.email())
         if not student:
             student = Student.get_by_key_name(user.email())
             memcache.set(user.email(), student)
         return student
     else:
         self.redirect(users.create_login_url(self.request.uri))
Beispiel #5
0
 def getStudent(self):
     user = users.get_current_user()
     if user:
         student = memcache.get(user.email())
         if not student:
             student = Student.get_by_key_name(user.email())
             memcache.set(user.email(), student)
         return student
     else:
         self.redirect(users.create_login_url(self.request.uri))
Beispiel #6
0
    def get(self):
        user = users.get_current_user()
        if user:
            self.templateValue["email"] = user.email()
            self.templateValue["logoutUrl"] = users.create_logout_url("/")

        navbar = {"registration": True}
        self.templateValue["navbar"] = navbar
        # Check for existing registration -> redirect to course page
        student = Student.get_by_key_name(user.email())
        if student is None:
            self.render("register.html")
        else:
            self.redirect("/course")
Beispiel #7
0
    def get(self):
        user = users.get_current_user()
        if user:
            self.templateValue['email'] = user.email()
            self.templateValue['logoutUrl'] = users.create_logout_url('/')

        navbar = {'registration': True}
        self.templateValue['navbar'] = navbar
        # Check for existing registration -> redirect to course page
        student = Student.get_by_key_name(user.email())
        if student is None:
            self.render('register.html')
        else:
            self.redirect('/course')
Beispiel #8
0
  def get(self):
    user = users.get_current_user()
    if user:
      self.templateValue['email'] = user.email()
      self.templateValue['logoutUrl'] = users.create_logout_url('/')

    navbar = {'registration': True}
    self.templateValue['navbar'] = navbar
    # Check for existing registration -> redirect to course page
    student = Student.get_by_key_name(user.email())
    if student is None:
      self.render('register.html')
    else:
      self.redirect('/course')
    def update_assessment_transaction(self, key_name, assessment_type,
                                      new_answers, score):
        """Stores answer and updates user scores.

        Args:
            email: the student's email address.
            assessment_type: the title of the assessment.
            new_answers: the latest set of answers supplied by the student.
            score: the numerical assessment score.

        Returns:
            the student instance.
        """
        student = Student.get_by_key_name(key_name)
        if not student or not student.is_enrolled:
            raise Exception('Expected enrolled student with key_name "%s".',
                            key_name)

        course = self.get_course()

        # It may be that old Student entities don't have user_id set; fix it.
        if not student.user_id:
            student.user_id = self.get_user().user_id()

        answers = StudentAnswersEntity.get_by_key_name(student.user_id)
        if not answers:
            answers = StudentAnswersEntity(key_name=student.user_id)
        answers.updated_on = datetime.datetime.now()

        utils.set_answer(answers, assessment_type, new_answers)

        store_score(course, student, assessment_type, score)

        student.put()
        answers.put()

        # Also record the event, which is useful for tracking multiple
        # submissions and history.
        models.EventEntity.record(
            'submit-assessment', self.get_user(),
            transforms.dumps({
                'type': 'assessment-%s' % assessment_type,
                'values': new_answers,
                'location': 'AnswerHandler'
            }))

        return student
Beispiel #10
0
    def update_assessment_transaction(
        self, key_name, assessment_type, new_answers, score):
        """Stores answer and updates user scores.

        Args:
            email: the student's email address.
            assessment_type: the title of the assessment.
            new_answers: the latest set of answers supplied by the student.
            score: the numerical assessment score.

        Returns:
            the student instance.
        """
        student = Student.get_by_key_name(key_name)
        if not student or not student.is_enrolled:
            raise Exception(
                'Expected enrolled student with key_name "%s".', key_name)

        course = self.get_course()

        # It may be that old Student entities don't have user_id set; fix it.
        if not student.user_id:
            student.user_id = self.get_user().user_id()

        answers = StudentAnswersEntity.get_by_key_name(student.user_id)
        if not answers:
            answers = StudentAnswersEntity(key_name=student.user_id)
        answers.updated_on = datetime.datetime.now()

        utils.set_answer(answers, assessment_type, new_answers)

        store_score(course, student, assessment_type, score)

        student.put()
        answers.put()

        # Also record the event, which is useful for tracking multiple
        # submissions and history.
        models.EventEntity.record(
            'submit-assessment', self.get_user(), transforms.dumps({
                'type': 'assessment-%s' % assessment_type,
                'values': new_answers, 'location': 'AnswerHandler'}))

        return student