from django conf import settings from dja site import from price forms

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django.conf import settings
from dja.site import *
from price.forms import SearchGoodsForm
from price.models import Good, Search, Firm
@render_to('price/index.html')
def index(request):
searches = Search.objects.all()[:settings.LAST_SEARCHES_COUNT]
firms = Firm.objects.all().select_related()
return {'searches': searches,
'firms': firms,
}
@render_to('price/search.html')
@paged('goods', settings.SEARCH_PAGE_SIZE)
def search(request, query=None):
paged_qs = Good.objects.all().order_by('price')
form = build_form(SearchGoodsForm, request, use_get=True, query=query)
if form.is_valid():
paged_qs = form.filter(paged_qs)
count = form.filter(paged_qs).count()
if not 'page' in request.GET or request.GET['page'] == '1':
if form.query_display() and count:
Search.objects.create(query=form.query_display())
return {'form': form,
'query': form.query_display(),
'paged_qs': paged_qs}