Currently, the system I work on (python 2.7 / django 1.6 / dojo toolkit) has a textual search feature inside .pdf files. It's a heavy search and the return is total: it returns all the records that matched the search only when it finishes browsing all the records.
Exemple.:
views.py
def search_document(request):
"""check permission and logic to show the grid """
varis = {
'url2': request.app_root + 'mod/document',
'url': request.app_root + 'mod/search-document-json',
'query': query
}
return render_to_response('mod/search_document_grid.html', RequestContext(request, varis))
def search_document_json(request, query=''):
# Sort
# srt logic (no problem here)
# Pagination
# pagination logic (no problem here)
# Searching for docs in database
# query database logic (no problem here)
documents = Document.objects.filter(QQ).order_by(srt).iterator()
list_docs = []
for doc in documents:
if doc.file.endswith('.pdf'):
# PDFMiner stuff (no problem here)
p = re.compile(query, re.IGNORECASE)
m = p.search(text)
if m:
list_docs.append(doc)
qtr = len(list_docs)
varis = {'lista': lista[ini:fim]}
templ = get_template('mod/search_document.json')
resp = HttpResponse(templ.render(RequestContext(request, varis)), content_type="application/json")
resp['Content-Range'] = rg
return resp
urls.py
url(r'^search-document/$', search_document, name='search_document'),
url(r'^search-document-json/(?P<query>.*)$', search_document_json, name='search_document_json'),
search_document_grid.html
require([
"dojo/cookie",
"dojo/aspect",
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dojox/grid/EnhancedGrid",
"dojox/grid/enhanced/plugins/Cookie",
"dojo/data/ObjectStore",
"dojo/_base/xhr",
"dojo/query",
"dojo/domReady!"
], function(cookie, aspect, JsonRest, Memory, Cache, EnhancedGrid, Cookie, ObjectStore, xhr, query){
var myStore = Cache(JsonRest({target:"{{url}}/{{query|urlencode}}"}), Memory());
var dataStore = new ObjectStore({ objectStore: myStore });
var grid = new dojox.grid.EnhancedGrid({
{% block gridoptions %}
store: dataStore,
rowsPerPage: 100,
keepRows: 200,
structure: {
defaultCell: { cellClasses: "normal" },
cells: [
{% block cells %}
{ name: "Name", field: "name", width: "300px"},
{ name: "Code", field: "code", width: "100px"},
{ name: "Version", field: "version", width: "60px"},
{ name: "Date", field: "date_pub", width: "80px"},
{ name: "Description", field: "description", width: "400px"},
"100px"}
{% endblock cells %}
]
},
{% endblock %}
}, "grid_1");
grid.startup();
I would like to return to the grid as the records match. What should be the logic to be used? Tool? Ajax? Jquery? Websockets(*edit2)?!?
edit: At the moment I found a document that fits my query I want that the document go to the grid as the query still working
edit2: As I still don't get what to do I'm thinking about change the entire project. From the day I asked this I still searching and found the new version of Django (3.1) that supports async methods, websockets, etc. This is the correct way? Anyone can help?