Django
1
Вклад в тег
from collections import defaultdict
from haystack.forms import FacetedSearchForm
class FacetedNotEmptySearchForm(FacetedSearchForm):
def no_query_found(self):
return self.searchqueryset.all()
@property
def selected_multi_facets(self):
selected_multi_facets = defaultdict(list)
for facet_kv in self.selected_facets:
if ":" not in facet_kv:
continue
field_name, value = facet_kv.split(':', 1)
selected_multi_facets[field_name].append(value)
return selected_multi_facets
def search(self):
sqs = super(FacetedSearchForm, self).search()
for field, values in self.selected_multi_facets.items():
if not values:
continue
clean_values = ['"%s"' % sqs.query.clean(val) for val in values]
sqs = sqs.narrow(u'%s:(%s)' % (field, " OR ".join(clean_values)))
return sqs
upstream test_project_server {
server 127.0.0.1:8001 fail_timeout=0;
}
server {
listen 80;
client_max_body_size 4G;
server_name test.site.ru;
access_log /home/test_project/log/nginx_access.log;
keepalive_timeout 5;
root /var/www/project/public;
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www/project;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://test_project_server;
break;
}
}
}