def post(self): user = users.get_current_user() guestbook_name = self.request.get('guestbook_name') greeting = Greeting(parent = guestbook_key(guestbook_name)) if user: self.response.out.write('<html><body>You wrote:<pre>') self.response.out.write(cgi.escape(self.request.get('content'))) self.response.out.write('</pre></body></html>') greeting.author = user greeting.content = self.request.get('content') greeting.put() self.redirect('/?' + urllib.urlencode({'guestbook_name':guestbook_name})) else: self.redirect(users.create_login_url(self.request.uri))
def AddGreeting(self,request): refresh = simplejson.loads(request.get("refresh")) if refresh: greeting = Greeting() greeting.user = request.get("id") greeting.content = request.get("msg") currentUser = users.GetCurrentUser() if currentUser: greeting.author = currentUser greeting.put() query = datastore.Query('Greeting').Order(('date',datastore.Query.DESCENDING)) #the parameter must be list. greetings = [] for greeting_ in query.Get(20): greeting_['key'] = str(greeting_.key()) #greeting_['author'] = greeting_['user'] if greeting_['author']: greeting_['email'] = greeting_['author'].email() greeting_['author'] = "\""+greeting_['email'].split('@')[0]+"\"" else: greeting_['author'] = greeting_['user'].split('@')[0] greeting_["date"] = greeting_["date"].strftime('%m/%d/%y') greetings+=[greeting_] return greetings