def search(request): if request.method == 'GET' and 'search_string' in request.GET and request.GET['search_string'].strip(): query_string = request.GET['search_string'] textNode_query = get_query(query_string, ['text', ]) textNodes = TextNode.objects.filter(textNode_query).order_by("-id") search_results = [] for node in textNodes: search_results.append({"path": node.getTextPath(), "snippet": node.text[:min(len(node.text), 140)]}) root = getRootNode() anchor_nodes = json.dumps({"Anchors": [getGraphInfoForNode(root)], "related_nodes": [], "connections": []}) Entry_query = get_query(query_string, ['content', ]) activities = [convertEntryToBlogPost(e) for e in Entry.objects.filter(Entry_query).order_by("-time")] return render_to_response("search_results.html", {"pagename": "Root", "this_url": "/", "authForm": AuthenticationForm(), "navigation": getNavigationData(request, root.id, root.getType()), "anchor_nodes": anchor_nodes, "selected_id": root.id, "search_string": query_string, "search_results": search_results, "activities": activities }, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/') # No search
def home(request): root = getRootNode() anchor_nodes = json.dumps({"Anchors": [getGraphInfoForNode(root)], "related_nodes" : [], "connections" : []}) return render_to_response("index.html", {"pagename":"Root", "this_url": "/", "authForm": AuthenticationForm(), "navigation" : getNavigationData(request, root.id, root.getType()), "anchor_nodes" : anchor_nodes, "selected_id" : root.id }, context_instance=RequestContext(request))