PEP8 cleanups, unused imports cleanups

This commit is contained in:
Roberto Rosario
2014-06-29 14:14:27 -04:00
parent 904ff92cf1
commit ecb6733cd4
53 changed files with 92 additions and 189 deletions
-2
View File
@@ -1,7 +1,5 @@
from __future__ import absolute_import
from django.utils.translation import ugettext_lazy as _
from navigation.api import register_sidebar_template, register_links
from .links import search, search_advanced, search_again
+12 -13
View File
@@ -1,9 +1,8 @@
from __future__ import absolute_import
import re
import types
import logging
import datetime
import logging
import re
from django.db.models import Q
from django.db.models.loading import get_model
@@ -37,7 +36,7 @@ class SearchModel(object):
def get_all_search_fields(self):
return self.search_fields.values()
def get_search_field(self, full_name):
return self.search_fields[full_name]
@@ -57,7 +56,7 @@ class SearchModel(object):
"""
search_field = SearchField(self, *args, **kwargs)
self.search_fields[search_field.get_full_name()] = search_field
def add_related_field(self, *args, **kwargs):
"""
Add a search field that will search content in a related field in
@@ -92,15 +91,15 @@ class SearchModel(object):
'field_name': [search_field.field],
'terms': self.normalize_query(query_string)
}
)
)
logger.debug('search_dict: %s' % search_dict)
return self.execute_search(search_dict, global_and_search=False)
def advanced_search(self, dictionary):
search_dict = {}
for key, value in dictionary.items():
logger.debug('key: %s' % key)
logger.debug('value: %s' % value)
@@ -118,7 +117,7 @@ class SearchModel(object):
'field_name': [search_field.field],
'terms': self.normalize_query(value)
}
)
)
logger.debug('search_dict: %s' % search_dict)
@@ -147,12 +146,12 @@ class SearchModel(object):
# Initialize per field result set
field_result_set = set()
# Get results per search field
for query in field_query_list:
logger.debug('query: %s' % query)
term_query_result_set = set(model.objects.filter(query).values_list(data['return_value'], flat=True))
# Convert the QuerySet to a Python set and perform the
# AND operation on the program and not as a query.
# This operation ANDs all the field term results
@@ -174,7 +173,7 @@ class SearchModel(object):
model_result_set &= field_result_set
else:
model_result_set |= field_result_set
logger.debug('model_result_set: %s' % model_result_set)
# Update the search result total count
@@ -192,7 +191,7 @@ class SearchModel(object):
for result in results:
if result not in flat_list:
flat_list.append(result)
logger.debug('model_list: %s' % model_list)
logger.debug('flat_list: %s' % flat_list)
+9 -13
View File
@@ -1,22 +1,18 @@
from __future__ import absolute_import
import urlparse
import logging
import urlparse
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from django.conf import settings
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.http import urlencode
from .conf.settings import SHOW_OBJECT_TYPE
from .conf.settings import LIMIT
from .classes import SearchModel
from .conf.settings import LIMIT, SHOW_OBJECT_TYPE
from .forms import SearchForm, AdvancedSearchForm
from .models import RecentSearch
from .classes import SearchModel
logger = logging.getLogger(__name__)
document_search = SearchModel.get('documents.Document')
@@ -44,22 +40,22 @@ def results(request, extra_context=None):
# Advanced search
logger.debug('advanced search')
model_list, flat_list, shown_result_count, result_count, elapsed_time = document_search.advanced_search(request.GET)
if shown_result_count != result_count:
title = _(u'results, (showing only %(shown_result_count)s out of %(result_count)s)') % {
'shown_result_count': shown_result_count,
'result_count': result_count}
else:
title = _(u'results')
# Update the context with the search results
context.update({
'found_entries': model_list,
'object_list': flat_list,
'title': title,
'time_delta': elapsed_time,
})
})
RecentSearch.objects.add_query_for_user(request.user, request.GET, result_count)