Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: redhat-beyond/Hotails
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 408ddb7c015231490b439d47facec45684744388
Choose a base ref
..
head repository: redhat-beyond/Hotails
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2dcf8d7b5754b85e225463600b2a5849ce926f25
Choose a head ref
Showing with 32 additions and 9 deletions.
  1. +15 −0 daycare/forms.py
  2. +7 −0 dogowner/templates/dogowner/dog_owner_homepage.html
  3. +10 −9 dogowner/views.py
15 changes: 15 additions & 0 deletions daycare/forms.py
Original file line number Diff line number Diff line change
@@ -6,10 +6,25 @@
class DayCareSearchForm(forms.Form):
min_price = DayCare.objects.all().aggregate(Min('price_per_day')).get('price_per_day__min')
max_price = DayCare.objects.all().aggregate(Max('price_per_day')).get('price_per_day__max')
start_date = forms.DateField(required=True, label=' Start date',
widget=forms.widgets.DateInput(attrs={'class': 'form-control', 'type': 'date'}))
end_date = forms.DateField(required=True, label=' End date',
widget=forms.widgets.DateInput(attrs={'class': 'form-control', 'type': 'date'}), )
area = forms.ChoiceField(required=False, label='Area',
choices=(Area.choices + [('', 'All'), ]), initial="")
city = forms.CharField(required=False, label='City')
name = forms.CharField(required=False, label='Day care name')
price_per_day = forms.ChoiceField(required=False, label='Max price',
choices=((str(x), x) for x in range(min_price, max_price + 11, 10)),
initial=str(max_price))

def clean(self):
cleaned_data = super().clean()
start_date = cleaned_data.get("start_date")
end_date = cleaned_data.get("end_date")

if start_date and end_date:
if end_date < start_date:
self._errors['end_date'] = self.error_class(["End date should be greater!"])

return cleaned_data
7 changes: 7 additions & 0 deletions dogowner/templates/dogowner/dog_owner_homepage.html
Original file line number Diff line number Diff line change
@@ -7,10 +7,17 @@
{% endblock %}

{% block content %}

<div class="row">
<form method='POST' action=''>{% csrf_token %}
<div class="col-4" id="searchBoxArea">
<span>Search for daycare:</span>
<div class="form-group">
{{ form.start_date|as_crispy_field }}
</div>
<div class="form-group">
{{ form.end_date|as_crispy_field }}
</div>
<div class="form-group">
{{ form.price_per_day|as_crispy_field }}
</div>
19 changes: 10 additions & 9 deletions dogowner/views.py
Original file line number Diff line number Diff line change
@@ -14,14 +14,15 @@ def dog_owner_home(request):
'form': form
}
if request.method == 'POST':
day_care_queryset = DayCare.objects.filter(area__startswith=form['area'].value(),
city__icontains=form['city'].value(),
name__icontains=form['name'].value(),
price_per_day__lte=form['price_per_day'].value())
context = {
'title': title,
'day_care_queryset': day_care_queryset,
'form': form
}
if form.is_valid():
day_care_queryset = DayCare.objects.filter(area__startswith=form['area'].value(),
city__icontains=form['city'].value(),
name__icontains=form['name'].value(),
price_per_day__lte=form['price_per_day'].value())
context = {
'title': title,
'day_care_queryset': day_care_queryset,
'form': form
}

return render(request, 'dogowner/dog_owner_homepage.html', context)