Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
 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')
Ejemplo n.º 3
0
    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')
Ejemplo n.º 4
0
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 = 'An anonymous person'
    if users.get_current_user():
        user = users.get_current_user().nickname()
    return {'greeting': greeting.content, 'user': user}
Ejemplo n.º 5
0
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}
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    def test_loggedin_post_greeting(self):
        os.environ['USER_EMAIL'] = '[email protected]'
        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, '[email protected]',
            'author content should be \'[email protected]\'')
Ejemplo n.º 8
0
    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))
Ejemplo n.º 9
0
  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})