예제 #1
0
def sign(request):
  form = GuestbookForm(request.POST)
  if form.is_valid():
    post = Post(message=form.clean_data['message'])
    if users.GetCurrentUser():
      post.author = users.GetCurrentUser()
  
    post.put()

  return HttpResponseRedirect('/')
예제 #2
0
def sign(request):
    form = GuestbookForm(request.POST)
    if form.is_valid():
        post = Post(message=form.clean_data['message'])
        if users.GetCurrentUser():
            post.author = users.GetCurrentUser()

        post.put()

    return HttpResponseRedirect('/')
예제 #3
0
def index(request):
    query = Post.gql('ORDER BY date DESC')
    form = GuestbookForm()
    return render_to_response('index.html', {
        'posts': query.fetch(20),
        'form': form
    })
예제 #4
0
def sign_guestbook():
    """
    The Flask app route for /guestbook/sign
    Allows a user to sign the guestbook.

    Returns
    -------
    html
        The HTML for the /guestbook/sign path depending upon the HTTP
        verb used.
    """
    if redis_available():
        gb_form = GuestbookForm()
        if request.method == "POST":
            # Handle guestbook signing.
            redis_conn = connect_to_redis()
            name = request.form['name']
            guest_num = redis_conn.rpush(guest_field, name)
            flash(
                f"Thanks for signing the guestbook, {name}! You are guest number {guest_num}."
            )
            return redirect(url_for('view_guestbook'))
        # Render the guestbook signing form.
        return render_template('form.html', form=gb_form, template="form-page")
    else:
        return handle_redis_err()
예제 #5
0
파일: views.py 프로젝트: gardarh/petit
def guestbook(request):
	instance = Guestbook(display=True,ip=request.META.get('HTTP_X_REAL_IP',request.META['REMOTE_ADDR']))
	guestbook_form = GuestbookForm(instance=instance)
	start_at = max(int(request.GET.get('start_at','0')),0)
	items_per_page = 20

	if request.method == "POST":
		guestbook_form = GuestbookForm(request.POST, instance=instance)
		if guestbook_form.is_valid():
			guestbook_form.save(request)
			messages.success(request, _("Guestbook entry added"))
			return HttpResponseRedirect('/guestbook/')


	context = {
			'guestbook_form': guestbook_form
			, 'entries': Guestbook.objects.filter(display=True).order_by('-date')[start_at:start_at+items_per_page]
			, 'display_next_page':len(Guestbook.objects.filter(display=True).order_by('-date')[start_at+items_per_page:]) > 0
			, 'display_last_page':start_at>0
			, 'next_startat':start_at+items_per_page
			, 'last_startat':max(start_at-items_per_page,0)
			}
	return HttpResponse(loader.get_template("guestbook.html").render(RequestContext(request,context)))
예제 #6
0
파일: views.py 프로젝트: chemt/vsad
def guestbook(request):
    added = False
	
    if request.method == 'POST': # If the form has been submitted...
        form = GuestbookForm(request.POST)
        if form.is_valid():
            form.save()
            data = form.cleaned_data
            message_text = u'Імя: %s \n Відгук: %s' % (data['name'], data['text'])
            send_mail(u'Новий відгук на сайті', message_text, '*****@*****.**',
                        REPORT_EMAILS, fail_silently=False)
            added = True
            form = GuestbookForm()

    else:
        form = GuestbookForm()

    entries = GuestBook.objects.all().order_by("-date")
    templates = {'form': form, 'entries': entries, 'added':added }
    c = RequestContext(request, templates)
    return render_to_response("guestbook.html", c)