예제 #1
0
def main_page(request):
    guestbook_name = request.GET.get('guestbook_name', DEFAULT_GUESTBOOK_NAME)

    # Ancestor Queries, as shown here, are strongly consistent with the High
    # Replication Datastore. Queries that span entity groups are eventually
    # consistent. If we omitted the ancestor from this query there would be
    # a slight chance that Greeting that had just been written would not
    # show up in a query.
    greetings_query = Greeting.query(
        ancestor=guestbook_key(guestbook_name)).order(-Greeting.date)
    greetings = greetings_query.fetch(10)

    # if users.get_current_user():
    #     url = users.create_logout_url(request.get_full_path())
    #     url_linktext = 'Logout'
    # else:
    #     url = users.create_login_url(request.get_full_path())
    #     url_linktext = 'Login'
    # url = users.create_login_url(request.get_full_path())
    url = ''
    url_linktext = 'Login'

    template_values = {
        'greetings': greetings,
        'guestbook_name': guestbook_name,
        'url': url,
        'url_linktext': url_linktext,
    }
    return render(request, 'guestbook/main_page.html', template_values)
예제 #2
0
def main_page(request):
    guestbook_name = request.GET.get('guestbook_name', DEFAULT_GUESTBOOK_NAME)
    
    # Ancestor Queries, as shown here, are strongly consistent with the High
    # Replication Datastore. Queries that span entity groups are eventually
    # consistent. If we omitted the ancestor from this query there would be
    # a slight chance that Greeting that had just been written would not
    # show up in a query.
    greetings_query = Greeting.query(ancestor=guestbook_key(guestbook_name)).order(-Greeting.date)
    greetings = greetings_query.fetch(10)

    if users.get_current_user():
        url = users.create_logout_url(request.get_full_path())
        url_linktext = 'Logout'
    else:
        url = users.create_login_url(request.get_full_path())
        url_linktext = 'Login'

    template_values = {
        'greetings': greetings,
        'guestbook_name': guestbook_name,
        'url': url,
        'url_linktext': url_linktext,
    }
    #return direct_to_template(request, 'guestbook/main_page.html', template_values)
    return render(request, 'guestbook/main_page.html', template_values)
예제 #3
0
	def testFilterByUser(self):
		anonymous_user = users.User(email="*****@*****.**")
		test_user = users.User(email="*****@*****.**")
		Greeting(content = "Testing", parent = guestbook_key(DEFAULT_GUESTBOOK_NAME), author = anonymous_user).put()
		Greeting(content = "Testing2", parent = guestbook_key(DEFAULT_GUESTBOOK_NAME), author = test_user).put()
		greetings_query = Greeting.query(ancestor=guestbook_key(DEFAULT_GUESTBOOK_NAME)).filter(ndb.GenericProperty('author') == anonymous_user)
		results = greetings_query.fetch(2)
		self.assertEqual(1, len(results))
		self.assertEqual(anonymous_user, results[0].author)
예제 #4
0
 def get_context_data(self, **kwargs):
     guestbook_name = self.request.GET.get('guestbook_name',
                                           DEFAULT_GUESTBOOK_NAME)
     greetings_query = Greeting.query(
         ancestor=guestbook_key(guestbook_name)).order(-Greeting.date)
     greetings = greetings_query.fetch(10)
     if users.get_current_user():
         url = users.create_logout_url(self.request.get_full_path())
         url_linktext = 'Logout'
     else:
         url = users.create_login_url(self.request.get_full_path())
         url_linktext = 'Login'
     context = super(IndexView, self).get_context_data(**kwargs)
     context['guestbook_name'] = guestbook_name
     context['greetings_query'] = greetings_query
     context['greetings'] = greetings
     context['url'] = url
     context['url_linktext'] = url_linktext
     return context
예제 #5
0
    def get(self):
        guestbook_name = self.request.get('guestbook_name',
                                            DEFAULT_GUESTBOOK_NAME)
        greetings_query = Greeting.query(
            ancestor=guestbook_key(guestbook_name)).order(-Greeting.date)
        greetings = greetings_query.fetch(10)

        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        template_values = {
            'greetings': greetings,
            'guestbook_name': urllib.quote_plus(guestbook_name),
            'url': url,
            'url_linktext': url_linktext,
        }

        template = settings.JINJA_ENVIRONMENT.get_template('guestbook/index.html')
        self.response.write(template.render(template_values))
예제 #6
0
	def testInsertEntity(self):
		Greeting(content = "Testing", parent = guestbook_key(DEFAULT_GUESTBOOK_NAME)).put()
		greetings_query = Greeting.query(ancestor=guestbook_key(DEFAULT_GUESTBOOK_NAME))
		self.assertEqual(1, len(greetings_query.fetch(2)))
예제 #7
0
 def get_queryset(self):
     guestbook_name = self.get_guestbook_name()
     return Greeting.query(ancestor=guestbook_key(guestbook_name)).order(
         -Greeting.date).fetch(5)