Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new stats for DMO #746

Merged
merged 2 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mainapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
path('map/' , views.mapview , name="mapview"),
path('dmodash/' , views.dmodash , name="DMODash"),
path('dmoinfo/' , views.dmoinfo , name="DMOInfo" ),
path('dmocsv/' , views.dmocsv , name="DMOCSV" ),
path('error/' , views.error , name="errorview" ),
path('login/', auth_views.LoginView.as_view(template_name='mainapp/login.html'),name='user_login'),
path('logout/', views.logout_view, name='user_logout'),
Expand Down
37 changes: 36 additions & 1 deletion mainapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.http import Http404
from mainapp.admin import create_csv_response
import csv

class CustomForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -284,6 +285,26 @@ def mapview(request):
def dmodash(request):
return render(request , "dmodash.html")


def dmocsv(request):
if("district" not in request.GET.keys()):return HttpResponseRedirect("/")
dist = request.GET.get("district")
header_row = [i.name for i in RescueCamp._meta.get_fields() ][1:] # There is a person field in the begining , to remove that
body_rows = []
csv_name = "{}-data".format(dist)
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="{}.csv"'.format(csv_name)
writer = csv.writer(response)
writer.writerow(header_row)
for camp in RescueCamp.objects.all().filter(district = dist):
row = [
getattr(camp , key) for key in header_row
]
writer.writerow(row)


return response

def dmoinfo(request):
if("district" not in request.GET.keys()):return HttpResponseRedirect("/")
dist = request.GET.get("district")
Expand All @@ -292,7 +313,21 @@ def dmoinfo(request):
volcount = Volunteer.objects.all().filter(district = dist).count()
conserve = Contributor.objects.all().filter(status = "ful" , district = dist).count()
contotal = Contributor.objects.all().filter(district = dist).count()
return render(request ,"dmoinfo.html",{"reqserve" : reqserve , "reqtotal" : reqtotal , "volcount" : volcount , "conserve" : conserve , "contotal" : contotal })

camps = RescueCamp.objects.all().filter(district = dist)

total_people = 0 ;total_male = 0 ; total_female = 0 ; total_infant = 0 ; total_medical = 0

for i in camps:

total_people += i.total_people
total_male += i.total_males
total_female += i.total_females
total_infant += i.total_infants
if(i.medical_req.strip() != ""):total_medical+=1

return render(request ,"dmoinfo.html",{"district" : dist , "reqserve" : reqserve , "reqtotal" : reqtotal , "volcount" : volcount , "conserve" : conserve , "contotal" : contotal ,
"total_camps" : camps.count() ,"total_people" : total_people , "total_male" : total_male , "total_female" : total_female , "total_infant" : total_infant , "total_medical" : total_medical })

def error(request):
error_text = request.GET.get('error_text')
Expand Down
29 changes: 27 additions & 2 deletions templates/dmoinfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<div class="container text-center">
<h1 class="main-logo">kerala<span style="font-weight: normal;">rescue DMO Portal</span></h1>
<p style="margin-bottom:20px;">
<i>Stats for your District </i><br/>
<p style="margin-top:60px; margin-bottom: 30px">
<i style="font-size: 40px ;"> Request Stats for your District </i><br/>
</p>

<div class="row">
Expand All @@ -28,8 +28,33 @@ <h1 class="main-logo">kerala<span style="font-weight: normal;">rescue DMO Porta

</div>

<br>
<br>
<i style="font-size: 40px ;" > Camp Stats for your District </i> <a href="/dmocsv?district={{district}}" > Download as csv</a>

<div class="container" style="font-size: 30px ; padding-top: 30px">


Total Camps
{{total_camps}}
<br>
Total People
{{total_people}}
<br>
Total Male
{{total_male}}
<br>
Total Female
{{total_female}}
<br>
Total Infants
{{total_infant}}
<br>
Camps with Med Requirements
{{total_medical}}

</div>
</div>
</div>

{% endblock %}