def get(self, guestbook_name='stremor'): # SELECT * FROM is a given when used in Model context greetings = Greeting.gql("WHERE ANCESTOR IS :1 " "ORDER BY date DESC LIMIT 10", guestbook_key(guestbook_name)) user = users.get_current_user() user_nick = '' if user: url = users.create_logout_url(self.request.uri) url_linktext = 'Logout' user_nick = user.nickname() else: url = users.create_login_url(self.request.uri) url_linktext = 'Login' template_values = { 'guestbook_name': guestbook_name, 'greetings': greetings, 'user_nick': user_nick, 'url_linktext': url_linktext, 'url': url } template = jinja_environment.get_template('index.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(template.render(template_values))
def post(self): greeting = Greeting(parent=guestbook_key(DB_NAME)) user_name = self.request.get('name') user_email = self.request.get('email') greeting.author = Author(name=user_name, email=user_email) greeting.content = self.request.get('content') greeting.put() self.redirect('/greet')
def test_post_greeting(self): response = self.testapp.post('/sign', {'guestbook_name': 'test', 'content': 'hi'}) eq_(response.status, '302 Moved Temporarily') greetings = Greeting.gql("WHERE ANCESTOR IS :1 " "ORDER BY date DESC LIMIT 10", guestbook_key('test')) ok_(greetings.count() == 1, 'There should be 1 Greeting object')
def post_guest_view(request): greeting = Greeting(parent=guestbook_key()) if users.get_current_user(): greeting.author = users.get_current_user() greeting.content = request.params['content'] greeting.put() user = '******' if users.get_current_user(): user = users.get_current_user().nickname() return {'greeting': greeting.content, 'user': user}
def get_guest_view(request): greetings_query = Greeting.query(ancestor=guestbook_key()).order(-Greeting.date) greetings = greetings_query.fetch(10) if users.get_current_user(): url = users.create_logout_url(request.url) url_linktext = 'Logout' else: url = users.create_login_url(request.url) url_linktext = 'Login' return {'url_linktext':url_linktext, 'url': url, 'greetings':greetings}
def post(self): guestbook_name = self.request.get('guestbook_name') greeting = Greeting(parent=guestbook_key(guestbook_name)) if users.get_current_user(): greeting.author = users.get_current_user().nickname() greeting.content = self.request.get('content') greeting.put() # redirect to home page self.redirect('/%s' % guestbook_name)
def test_loggedin_post_greeting(self): os.environ['USER_EMAIL'] = '*****@*****.**' os.environ['USER_ID'] = '123' os.environ['AUTH_DOMAIN'] = 'testbed' self.testapp.post('/sign', {'guestbook_name': 'test', 'content': 'hi'}) greetings = Greeting.gql("WHERE ANCESTOR IS :1 " "ORDER BY date DESC LIMIT 10", guestbook_key('test')) greeting = greetings.fetch(1)[0] # latest eq_(greeting.content, 'hi', 'greeting content should be \'hi\'') eq_(greeting.author, '*****@*****.**', 'author content should be \'[email protected]\'')
def get(self): guestbook = self.request.get('guestbook') greetings = Greeting.gql("WHERE ANCESTOR IS :1 " "ORDER BY date DESC LIMIT 10", guestbook_key(guestbook)) # this ought to be a lot smarter d = [] for greeting in greetings.fetch(10): d.append({ 'content': greeting.content, 'author': greeting.author, 'datetime': datetime.strftime(greeting.date, DATE_FMT) }) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(d))
def get(self): query = Greeting.query(ancestor=guestbook_key(DB_NAME)).order(-Greeting.date) greetings_obj = query.fetch(10) greetings = [] for greeting in greetings_obj: if greeting.author and greeting.author.name: author = greeting.author.name elif greeting.author and greeting.author.email: author = greeting.author.email else: author = "Anonymous" greetings.append({ "author": author, "content": greeting.content, }) self.generate("greet.html", {"greetings": greetings})