コード例 #1
0
    def post(self):
        logging.info('newAchievement posted')

        # Get the current Cheever's profile so we can update their numContribs
        cheever_key = ndb.Key('Cheever', self.user.email())
        cheever = cheever_key.get()

        # Create new achievement with auto - generated key
        achievement = Achievement()

        achievement.populate(
            title=self.request.get('title'),
            description=self.request.get('description'),
            category=self.request.get('category'),
            score=int(self.request.get('score')),
            contributor=cheever.username,
            verified=False
        )

        cheever.numContribs += 1

        # Commit our updates to the datastore
        @ndb.transactional(xg=True)
        def commit():
            achievement.put()
            cheever.put()

        commit()

        self.redirect('/profile')