Пример #1
0
def ajax_select_city(request):
    if request.method == 'POST':
        form = SelectCityForm(request.POST)
        if form.is_valid():
            city = form.cleaned_data['city']
            return _json_response([{"":_('Hall of event')}] + [dict([[hall.id,hall.name]]) for hall in city.halls.all()])
    return _json_response([{"":_('Hall of event')}])
Пример #2
0
def select_event(request, template='localsite/select_event.html'):
    events = Event.objects.none()
    form_city = None
    form_event = None
    if request.method == 'POST':
        form_city = SelectCityForm(request.POST)
        if form_city.is_valid():
            city = form_city.cleaned_data['city']
            form_event = SelectEventForm(request.POST)
            form_event.fields['hall'].queryset = city.halls.all()
            if form_event.is_valid():
                hall = form_event.cleaned_data['hall']
                category = form_event.cleaned_data['category']
                min_price = form_event.cleaned_data['min_price']
                max_price = form_event.cleaned_data['max_price']
                min_date = form_event.cleaned_data['min_date']
                max_date = form_event.cleaned_data['max_date']
                events = Event.objects.active().filter(
                        min_price and Q(min_price__gte=min_price) | Q(max_price__gte=min_price) or Q(),
                        max_price and Q(max_price__lte=max_price) | Q(min_price__lte=max_price) or Q(),
                        min_date and Q(min_date__gte=min_date) | Q(max_date__gte=min_date) or Q(),
                        max_date and Q(max_date__lte=max_date) | Q(min_date__lte=max_date) or Q(),
                        hall and Q(hallscheme__hall=hall) or city and Q(hallscheme__hall__city=city) or Q(),
                        category and Q(product__category=category) or Q(),
                        )
     

    if not form_city:
        form_city = SelectCityForm()
    if not form_event:
        form_event = SelectEventForm()
    ctx = RequestContext(request, {
        'events': events,
        'form_city': form_city,
        'form_event': form_event,
    })
    return render_to_response(template, context_instance=ctx)