示例#1
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)
示例#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 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)
示例#4
0
 def form_valid(self, form, **kwargs):
     # how to get velue in the form
     guestbook_name = form.cleaned_data['guestbook_name']
     content = form.cleaned_data['content']
     greeting = Greeting(parent=guestbook_key(guestbook_name))
     if users.get_current_user():
         greeting.author = users.get_current_user()
     greeting.guestbook_name = guestbook_name
     greeting.content = content
     greeting.put()
     return super(SignView, self).form_valid(form, **kwargs)
示例#5
0
文件: views.py 项目: SJ12/Cricket
def sign_post(request):
    if request.method == 'POST':
        guestbook_name = request.POST.get('guestbook_name')
        greeting = Greeting(parent=guestbook_key(guestbook_name))
    
        if users.get_current_user():
            greeting.author = users.get_current_user()
    
        greeting.content = request.POST.get('content')
        greeting.put()
        return HttpResponseRedirect('/?' + urllib.urlencode({'guestbook_name': guestbook_name}))
    return HttpResponseRedirect('/')
示例#6
0
    def post(self):
        guestbook_name = self.request.get('guestbook_name',DEFAULT_GUESTBOOK_NAME)
        greeting = Greeting(parent=guestbook_key(guestbook_name))

        if users.get_current_user():
            greeting.author = users.get_current_user()

        greeting.content = self.request.get('content')
        greeting.put()

        query_params = {'guestbook_name': guestbook_name}
        self.redirect('/guestbook/?' + urllib.urlencode(query_params))
示例#7
0
def sign_post(request):
	if request.method == 'POST':
		guestbook_name = request.POST.get('guestbook_name')
		greeting = Greeting(parent=guestbook_key(guestbook_name))

		if users.get_current_user():
			greeting.author = users.get_current_user()

		greeting.content = request.POST.get('content')
		greeting.put()
		return HttpResponseRedirect('/?' + urllib.urlencode({'guestbook_name':guestbook_name}))
	return HttpResponseRedirect('/')
示例#8
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
示例#9
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))
示例#10
0
	def testGetEntityViaMemcache(self):
		entity_key = Greeting(content = "Testing", parent = guestbook_key(DEFAULT_GUESTBOOK_NAME)).put()
		retrieved_entity = GetEntityViaMemcache(entity_key)
		self.assertNotEqual(None, retrieved_entity)
		self.assertEqual("Testing", retrieved_entity.content)
示例#11
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)))
示例#12
0
 def get_queryset(self):
     guestbook_name = self.get_guestbook_name()
     return Greeting.query(ancestor=guestbook_key(guestbook_name)).order(
         -Greeting.date).fetch(5)