how to make next/previous buttons to toggle between gql query results - django

Say I have a website that has 100 products. Then this is filtered down to 5 sections containing 20 products each. If you were in one of the sections that contained 20 products (e.g. toys), what would be the optimal method to display only 5 toys per page. At the bottom of the list would be next/previous buttons to show the next/previous set of 5 toys.
A better analogy would be google search. There are millions of results but only ~10 are shown at a given time.
So right now I'm using google app engine (python) and django templates. One way I thought of to remedy this problem would be making all the query results go into a div which could then be modified through javascript to give a similar effect. However, if someone were to click their browser's back button, they wouldn't go where they originally came from.
Thanks in advance. Any help would be useful...I don't know what this technique is called so google hasn't been really useful :(
Edit: based on responses, I found my question was solved here: How to use cursor() for pagination?

Look into query cursors. Thay are made to be serialized and sent to client, to be used in creating "next" and "previous" paging requests.
NOTE: don't use offset on queries. This can be VERY expensive, as it actually fetches (and charges) all entities up to offset+limit position, but returns to application only limit results.

I'm not sure that putting all the results as hidden content in the HTML and manipulating it using JS is a very good idea if you might have a large result set (think about what happened if Google used this approach). There's also the back functionality issue that you've mentioned.
So, as for querying a wanted "results page" each time, I think the Google's GQL Reference might help you, take a look specifically at the LIMIT clause, it can help you create the paging mechanism you're looking for by supplying it with the number of items-per-page you want as "count" and the numbers of items-previously-viewed as "offset" (0 at first call).
As for displaying, I think that the Google Images / Facebook News Feed approach might also be interesting to think about (loading on scroll instead of paging), but that's a matter of your personal choice :)
Hope this helps, good luck!
EDIT: After reading Peter's answer, I found it much more efficient to use cursors for pagination, a good reference is given in his answer.

Related

how implement an efficient visits counter per page?

how implement an efficient visits counter per page? I've marketplace platform, but not a visits counter per product page, then, this is my question.
what's is the better algorithm for implement this?
I not think that this alghoritm is the better "update product set product.visits = (product.visits + 1) where ..."
then, how?
I'm accept sugestions
Google Analytics?
third party solutions?
Alghoritm?
thanks everyone
Was developed in Django
"Visits counters" can really hammer a page because a page can be accessed so many times (per second). Also, they tend to over-state the desired result for the same basic reason. (Your database load sails through the rafters ...)
I've had the most success using post-processing of the server access logs. (Of course there are plenty of existing tools.) You'll find that you want to filter this raw data to pick out what's the most "business meaningful" result for your particular case.

Facebook Graph Pagination loses query on future pages

Let's say I want to search for McDonalds in a certain location using Facebook's graph API, like so. Now, since I know that Facebook won't always give me back all the results I want on the first page, or even the number of results I asked for, I follow the pagination link. This is the one I was given. Now, this second page loses the query string, and returns a bunch of results near the search location, but having nothing at all to do with McDonalds (e.g. Tufenkian Artisan Carpets Chicago). How can I tell when I have no more applicable results, if the pagination drops my original query entirely?
It looks like removing the limit parameter causes pagination to correctly have the query on future pages: see the same search without the limit parameter.

Performance issue when typing into search input when retrieving objects from store

I have a search field, which lets the user search books (filters records, which are retrieved with ember-data).
I have found that any access the store from the results computed property within my component (see jsbin) makes the typing into the search field very slow (noticeable on my PC, and terrible on smartphone).
Here is a screenshot of the Timeline pane when typing a search query. The displayed part show that every keypress causes A LOT of layout (the search field seems to rerendered on every keypress). I also provide the exported timeline which you can load into your dev tools as explained here
I have tried to recreate the issue in a jsfiddle, but it seems to work just fine. The difference might be that in the jsbin I am using fixtures, while in my app I retrieve data from a real API.
I don't understand what is causing this behavior. It may be hard to come to any conclusion from the data I can provide, but does anyone have any ideas? Has anyone experienced similar performance issues?
Update 2014-03-01
I should note that the performance hit only happens if the results computed property contains a call to the store. If I replace it with any other thing (like just returning [], or some random async method -- like $.get) it not display this performance hit.
Additionally, I should make it clear (in case you didn't read the code), that the results computed property is not called on every keypress, but only when the search is submitted.
This is not a Ember/Ember-data bug, but apparently a Google Chrome bug.
I have created a new question regarding the issue here

How can I prevent automatic form submission by bots?

I am running ColdFusion MX, so I don't have the possibility of using the built-in cfimage Captcha functionality in my application, before form submitting.
But the problem is without captcha the bots submit the forms.
What will be best way to prevent automatic submitting?
Captchas don't have to be images!
Try one of the following solutions:
Most bots don't understand CSS. Create two submit buttons, the first with a value that will be rejected by the server, the second with a value that will be accepted by the server. Hide the first one using CSS.
Ask the user to answer a simple math problem. This will require you to create the math problem and store the expected solution somewhere (like the user's session), then compare the user's submitted answer with the stored answer. For extra protection, you can create simple addition, subtraction and multiplication questions. Avoid division, remainders are a pain for some users.
Bots read the names of form elements, and tend to ignore text labels. Try creating a checkbox named "optout" (like a newsletter), checked by default. Next to the checkbox, ask the user to uncheck the checkbox if they are a human. The opposite technique also works (unchecked checkbox that you ask the user to check).
All of these solutions can be done without third party code or API calls.
That being said, reCAPTCHA is pretty good and easy to integrate into almost any environment.
Take a look at cfformprotect - it will work with CFMX 6 and all later engines.
It aims to be fully accessible - and invisible to most users - with an assortment of methods to stop bots and spammers.
Also you might want to look at a CF wrapper for reCaptcha, which is compatible with CFMX 7.
A technique I used with a different technology was to use image buttons. Your POST handler gets the x,y co-ordinates where the images were clicked. I found the bots (which are just generating post requests) were passing 0,0 and by dropping those requests on the floor I brought the spam posts down to less than the real ones. Sorry that I don't know how to do that in CF but I hope the technique is useful to you.
Its always a good idea to do data validation on the server side before processing no matter which solution you use.
This post may help: http://www.bennadel.com/blog/405-Fully-Accessible-Spam-Form-Submission-Blocking-Using-ColdFusion-And-X-HTML-Version-III-.htm
How about using calculation method? Just like 8 + 5 = ?
OR
how about using ColdFusion.Ajax.submitForm?

Nested Cells TCPDF

Im using TCPDF for the first time and am laying out some data using cells, the problem is because i am using multiple cells to layout what is essentially one item when the page breaks the items will split up rather than breaking all together.
Is there any way where you can nest cells / multicells in TCPDF??
Thanks
Found a good blog post that explains how to do this incase anyone finds this post later on - calulates the page dimensions to allow you to work out if you need to add a new page or not
http://www.onemoretake.com/2009/03/27/revisited-tcpdf-variable-height-table-rows-with-multicell/
The simplest way is to use HTML tables as on default examples, otherwise you can build custom low-level tables with Cell() or Multicell() as on the example n. 11. Check the official http://www.tcpdf.org website and forums for further information.