def _search(request, cleaned_data): search_strings = _filter_search_terms(request, cleaned_data["search"]) if len(search_strings) == 0: messages.error(request, "Error: no search term left, can't search.") return preferences = get_preferences() min_pause = preferences["min_pause"] ban_limit = preferences["ban_limit"] try: LogEntry.objects.request_limit(request, min_pause, ban_limit, app_label="search") except LogEntry.RequestTooFast: # min_pause is not observed, page_msg has been created -> don't search return search_lang_codes = cleaned_data["language"] search_results = Search(request).search(search_lang_codes, search_strings) hits_count = len(search_results.hits) duration = human_duration(search_results.duration) msg = "done in %s, %s hits for: %r" % (duration, hits_count, search_strings) LogEntry.objects.log_action( app_label="search", action="search done", message=msg, data={ "search_strings": search_strings, "duration": search_results.duration, "hits": hits_count, } ) return search_results
def _search(request, cleaned_data): search_strings = _filter_search_terms(request, cleaned_data["search"]) if len(search_strings) == 0: messages.error(request, "Error: no search term left, can't search.") return preferences = get_preferences() min_pause = preferences["min_pause"] ban_limit = preferences["ban_limit"] try: LogEntry.objects.request_limit(request, min_pause, ban_limit, app_label="search") except LogEntry.RequestTooFast: # min_pause is not observed, page_msg has been created -> don't search return search_lang_codes = cleaned_data["language"] search_results = Search(request, preferences).search(search_lang_codes, search_strings) hits_count = len(search_results.hits) duration = human_duration(search_results.duration) msg = "done in %s, %s hits for: %r" % (duration, hits_count, search_strings) LogEntry.objects.log_action( app_label="search", action="search done", message=msg, data={ "search_strings": search_strings, "duration": search_results.duration, "hits": hits_count, } ) return search_results
def process_response(self, request, response): """ calculate the statistic and replace it into the html page. """ # Put only the statistic into HTML pages if (response.status_code != 200 or not isinstance(response, HttpResponse) or "html" not in response["content-type"]): # No HTML Page -> do nothing return response try: start_time = self.start_time except AttributeError: # FIXME: process_request() was not called?!? return response context = { 'total_time' : human_duration(time.time() - start_time), 'overall_time' : human_duration(time.time() - start_overall), } if settings.DEBUG: # compute the db time for the queries just run, this information is # only available if the debug cursor used context["query_count"] = len(connection.queries) - self.old_queries stat_info = FMT_DEBUG % context else: # Used the template without queries stat_info = FMT % context # insert the page statistic response = replace_content(response, TAG, stat_info) if settings.DEBUG and settings.SQL_DEBUG: # Insert all SQL queries into html page context["queries"] = connection.queries context["type_count"] = dict(connection.queries.type_count) context["table_count"] = dict(connection.queries.table_count) sql_info = render_to_string("pylucid/sql_debug.html", context) response = replace_content(response, "</body>", sql_info) return response
def process_response(self, request, response): """ calculate the statistic and replace it into the html page. """ # Put only the statistic into HTML pages if (response.status_code != 200 or not isinstance(response, HttpResponse) or "html" not in response["content-type"]): # No HTML Page -> do nothing return response try: start_time = self.start_time except AttributeError: # FIXME: process_request() was not called?!? return response context = { 'total_time': human_duration(time.time() - start_time), 'overall_time': human_duration(time.time() - start_overall), } if settings.DEBUG: # compute the db time for the queries just run, this information is # only available if the debug cursor used context["query_count"] = len(connection.queries) - self.old_queries stat_info = FMT_DEBUG % context else: # Used the template without queries stat_info = FMT % context # insert the page statistic response = replace_content(response, TAG, stat_info) if settings.DEBUG and settings.SQL_DEBUG: # Insert all SQL queries into html page context["queries"] = connection.queries context["type_count"] = dict(connection.queries.type_count) context["table_count"] = dict(connection.queries.table_count) sql_info = render_to_string("pylucid/sql_debug.html", context) response = replace_content(response, "</body>", sql_info) return response