Exemplo n.º 1
0
    def process_sat2(self):
        params = web.input(sat_subject=[], sat_subject_score=[])
        subjects = params.sat_subject
        scores = params.sat_subject_score
        score_pairs = dict(itertools.izip(subjects, scores))

        for known in SatSubjectScore.all().filter('uid =', self.key):
            # Update existing scores
            if known.subject in subjects:
                new_score = score_pairs[known.subject]
                known.score = int(new_score)
                try:
                    known.put()
                except TransactionFailedError:
                    # Ideally handle the error
                    pass

                subjects.remove(known.subject)
                del score_pairs[known.subject]

            # Delete a removed score
            else:
                known.delete()

        # Insert new scores
        for subject, score in score_pairs.iteritems():
            subject_score = SatSubjectScore(
                uid=self.key, subject=subject, score=score
            )
            try:
                subject_score.put()
            except TransactionFailedError:
                # Ideally handle the error
                pass
Exemplo n.º 2
0
 def GET(self):
     p = Profile.get_by_key_name(self.key) or {}
     s = SatScore.get_by_key_name(self.key) or {}
     sat2s = SatSubjectScore.all().filter('uid =', self.key)
     return super(self.__class__, self).GET({
         'profile' : p,
         'sat' : s,
         'sat2s' : sat2s,
         'groups' : SatSubjectScore._subject_categories,
         'subjects' : SatSubjectScore._subjects
     })