Skip to content

Commit

Permalink
fixed search cases for city bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharrao198 committed Feb 8, 2021
1 parent 0db4ced commit 608cc19
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion covidtracker/templates/covidtracker/city.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load static %}

{% block content %}
<div class="section-bg" style="padding:5%;" id="introduction">
<div class="section-bg" style="padding:8%;" id="introduction">
<!-- Default switch -->
<div class='text-right' style='font-family: "JetBrains Mono", monospace;'>
Switch to Dark Mode
Expand Down
64 changes: 31 additions & 33 deletions covidtracker/templates/covidtracker/district.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


{% block content %}
<div class="section-bg" style="padding:5%;" id="introduction">
<div class="section-bg" style="padding:8%;" id="introduction">
<!-- Default switch -->
<div class='text-right' style='font-family: "JetBrains Mono", monospace;'>
Switch to Dark Mode
Expand All @@ -13,41 +13,39 @@
</label>
</div>
<div class="container mt-2">
<h1 class="title-a text-center headingtext">COVID Cases</h1>
<h1 class="title-head text-center headingtext">COVID Cases</h1>
<hr class="titlehr" />
</div>


<h2 align ="center" style="color:red"> <b>COVID Cases Districtwise</b></h2>
<div class="container">
<div class="section-bg">
<table class="table table-bordered table-striped">
<thead class= "thead-dark">
<tr>
<th>Sr.No</th>
<th>State</th>
<th>Districts</th>
<th>Confirmed </th>
<th>Deaths</th>
<th>Recovered</th>
<th>Active</th>
</tr>
</thead>
<tbody>
{% for district in district_cases %}
</div>
<h2 align ="center" style="color:red"> <b>COVID Cases Districtwise</b></h2>
<div class="container">
<div class="section-bg">
<table class="table table-bordered table-striped">
<thead class= "thead-dark">
<tr>
<td>{{district.id}}</td>
<td>{{district.state_name}}</td>
<td>{{district.city_name}}</td>
<td>{{district.confirmed}}</td>
<td>{{district.Death}}</td>
<td>{{district.Recovered}}</td>
<td>{{district.Active}}</td>
<th>Sr.No</th>
<th>State</th>
<th>Districts</th>
<th>Confirmed </th>
<th>Deaths</th>
<th>Recovered</th>
<th>Active</th>
</tr>
{% endfor %}
</tbody>
</table>
</thead>
<tbody>
{% for district in district_cases %}
<tr>
<td>{{district.id}}</td>
<td>{{district.state_name}}</td>
<td>{{district.city_name}}</td>
<td>{{district.confirmed}}</td>
<td>{{district.Death}}</td>
<td>{{district.Recovered}}</td>
<td>{{district.Active}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
6 changes: 2 additions & 4 deletions covidtracker/templates/covidtracker/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load static %}

{% block content %}
<div class="section-bg" style="padding:5%;" id="introduction">
<div class="section-bg" style="padding:8%;" id="introduction">
<!-- Default switch -->
<div class='text-right' style='font-family: "JetBrains Mono", monospace;'>
Switch to Dark Mode
Expand All @@ -18,7 +18,7 @@
</div>

<!-- cards -->
<div class="card-group justify-content-center subtitle-a text-center" style='font-weight: 900;'>
<div class="card-deck justify-content-center subtitle-a text-center" style='font-weight: 900;'>
<div class="card card1 bg-danger border-danger mb-2" style="max-width: 15rem;">
<div class="card-header border-danger">Confirmed</div>
<div class="card-body">
Expand Down Expand Up @@ -46,10 +46,8 @@
<div class="card card4 bg-warning border-warning mb-2 " style="max-width: 15rem;">
<div class="card-header border-warning">Active</div>
<div class="card-body text-center">
<!-- <h5 class="card-title">Active</h5> -->
<p class="card-text">{{Active}}</p>
</div>
<!-- <div class="card-footer bg-transparent border-success">Footer</div> -->
</div>
</div>
<br>
Expand Down
2 changes: 1 addition & 1 deletion covidtracker/templates/covidtracker/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block content %}
<h1 align ="center"style="color: green" ><b> Cases in State - Table</b></h1>

<div class="section-bg" style="padding:5%;" id="introduction">
<div class="section-bg" style="padding:8%;" id="introduction">
<!-- Default switch -->
<div class='text-right' style='font-family: "JetBrains Mono", monospace;'>
Switch to Dark Mode
Expand Down
26 changes: 15 additions & 11 deletions covidtracker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,25 @@ def search(request):
state_query = request.GET["state"]
city_query = request.GET["city"]
# print(f"{state_query} - >> {city_query}")
city_cases = district_cases.objects.filter(
state_name=state_query, city_name=city_query
)
a = list(city_cases)
city_json = district_cases.objects.filter(
state_name=state_query, city_name=city_query
).first() # .first() conveerts object to instance)
if str(city_query) == "Unknown":
city_query = f"Unknown+{state_query}"
city_cases = district_cases.objects.filter(
state_name=state_query, city_name=city_query
)
else:
city_cases = district_cases.objects.filter(
state_name=state_query, city_name=city_query
)

# a = list(city_cases)
# city_json = district_cases.objects.filter(
# state_name=state_query, city_name=city_query
# ).first() # .first() convert object to instance)

# {'id': 983, 'city_name': 'Mandi', 'state_name': 'Himachal Pradesh', 'confirmed': 10096, 'Death': 124, 'Recovered': 9786, 'Active': 182}

city_json = model_to_dict(city_json)
# print(city_json)
# city_json = model_to_dict(city_json)
context_ = {
"query_results": city_cases,
"city_json": "city_json",
"title": "Result",
"search": "active",
}
Expand Down

0 comments on commit 608cc19

Please sign in to comment.