def get(self): logging.info('ProfilePage class requested') #------------------------------------------------------------------- #Look for existing profile based on User's email cheever_key = ndb.Key('Cheever', self.user.email()) cheever = cheever_key.get() if not cheever: #Profile doesn't yet exist, create a new Cheever with default values newKey = ndb.Key("Cheever", self.user.email()) cheever = models.Cheever(key=newKey) #Add the cheever model to our template values for rendering self.template_values['cheever'] = cheever #-------------------------------------------------------------------- auth_http = profileauthdecorator.http() logging.info(auth_http) service = build('plus', 'v1', http=auth_http) people_resource = service.people() people_document = people_resource.get(userId='me').execute() self.template_values['imgUrl'] = people_document['image']['url'] template = jinja_environment.get_template('profile.template') self.response.out.write(template.render(self.template_values))
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() if not cheever: #Profile doesn't yet exist, create a new Cheever with default values cheever = models.Cheever(key=ndb.Key("Cheever",self.user.email())) #Create new achievement with auto-generated key achievement = models.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=True ) cheever.numContribs += 1 #Commit our updates to the datastore achievement.put() cheever.put() self.redirect('/profile')
def post(self): logging.info('ProfilePage posted') #Look for existing profile based on Users' email cheever_key = ndb.Key('Cheever', self.user.email()) cheever = cheever_key.get() if not cheever: #Profile doesn't yet exist, create a new Cheever with default values cheever = models.Cheever(key=ndb.Key("Cheever",self.user.email())) #Update the user controlled values cheever.username = self.request.get('username') cheever.notifyEmail = self.request.get('notifyEmail') cheever.bio = self.request.get('bio') #Commit our updates to the datastore cheever.put() self.redirect('/profile')