From 034361124f5c02cab2fda68dacc9519412281f98 Mon Sep 17 00:00:00 2001 From: JK Date: Sat, 10 Aug 2019 12:47:58 +0530 Subject: [PATCH] Added Count of Registrations in each section over home page. COMMIT ensures there is no breaking in design or working of the application. CHANGES ======= Added badges to cards which shows count of active items in that section. Date: Sat Aug 10 12:47:58 2019 +0530 On branch 2019/jerinisready/issue_fix Changes to be committed: modified: mainapp/models.py modified: mainapp/views.py modified: static/css/style.css modified: templates/base.html modified: templates/home.html --- mainapp/models.py | 63 ++++++++++++++++++++++++--- mainapp/views.py | 31 +++++++++++-- static/css/style.css | 83 ++++++++++++++++++++--------------- templates/base.html | 5 ++- templates/home.html | 84 +++++++++++++++++++++++++----------- templates/ngo_volunteer.html | 3 ++ 6 files changed, 199 insertions(+), 70 deletions(-) diff --git a/mainapp/models.py b/mainapp/models.py index 759e6eedb..da016306f 100644 --- a/mainapp/models.py +++ b/mainapp/models.py @@ -8,6 +8,7 @@ from django.db import models from django.core.validators import RegexValidator from django.contrib.auth.models import User +from django.db.models import Q from django.urls import reverse from django.core.exceptions import ValidationError from django.db.models.signals import post_save @@ -15,7 +16,7 @@ from django.core.cache import cache from django.dispatch import receiver from django.utils import timezone - +from django.utils.functional import cached_property districts = ( ('alp','Alappuzha - ആലപ്പുഴ'), @@ -189,6 +190,15 @@ def __str__(self): def is_old(self): return self.dateadded < (timezone.now() - timezone.timedelta(days=2)) + @classmethod + def request_for_rescue(cls): + return cls._default_manager.filter(needrescue=True).count() + + @classmethod + def request_for_resource(cls): + flt = Q(needwater=True) | Q(needfood=True) | Q(needcloth=True) | Q(needcloth=True) | Q(needmed=True) | Q(needtoilet=True) | Q(needkit_util=True) + return cls._default_manager.filter(flt).distinct('id').count() + class Volunteer(models.Model): district = models.CharField( @@ -220,6 +230,10 @@ class Meta: def __str__(self): return self.name + @classmethod + def count(cls): + return cls._default_manager.count() + class NGO(models.Model): district = models.CharField( @@ -251,6 +265,10 @@ class Meta: def __str__(self): return self.name + @classmethod + def count(cls): + return cls._default_manager.count() + class Contributor(models.Model): district = models.CharField( @@ -283,6 +301,10 @@ class Meta: def __str__(self): return self.name + ' ' + self.get_district_display() + @classmethod + def count(cls): + return cls._default_manager.count() + class DistrictManager(models.Model): district = models.CharField( @@ -301,6 +323,10 @@ class Meta: def __str__(self): return self.name + ' ' + self.get_district_display() + @classmethod + def count(cls): + return cls._default_manager.count() + class DistrictNeed(models.Model): district = models.CharField( @@ -308,7 +334,7 @@ class DistrictNeed(models.Model): choices = districts, ) needs = models.TextField(verbose_name="Items required") - cnandpts = models.TextField(verbose_name="Contacts and collection points") #contacts and collection points + cnandpts = models.TextField(verbose_name="Contacts and collection points") #contacts and collection points class Meta: verbose_name = 'District: Need' @@ -317,6 +343,10 @@ class Meta: def __str__(self): return self.get_district_display() + @classmethod + def count(cls): + return cls._default_manager.count() + class DistrictCollection(models.Model): district = models.CharField( @@ -394,10 +424,13 @@ def district_name(self): 'wnd':'Wayanad - വയനാട്', }.get(self.district, 'Unknown') - def __str__(self): return self.name + @classmethod + def count(cls): + return cls._default_manager.filter(status="active").count() + @receiver(post_save, sender=RescueCamp) def expire_people_filter_form(sender, **kwargs): @@ -445,10 +478,14 @@ class Meta: verbose_name = 'Private Relief: Camp' verbose_name_plural = "Private Relief: Camps" - def __str__(self): return self.name + @classmethod + def count(cls): + return cls._default_manager.filter(status="active").count() + + class Person(models.Model): name = models.CharField(max_length=51,blank=False,null=False,verbose_name="Name - പേര്") @@ -533,6 +570,10 @@ def save(self, *args, **kwargs): if(Person.objects.filter(unique_identifier = self.unique_identifier).count() == 0 ): super(Person, self).save(*args, **kwargs) + @classmethod + def count(cls): + return cls._default_manager.count() + def upload_to(instance, filename): @@ -562,6 +603,11 @@ def __str__(self): return self.description[:100] + @classmethod + def count(cls): + return cls._default_manager.count() + + class DataCollection(models.Model): created_at = models.DateTimeField(auto_now_add=True) document_name = models.CharField( @@ -641,6 +687,10 @@ def __str__(self): def get_absolute_url(self): return reverse('collection_centers_list') + @classmethod + def count(cls): + return cls._default_manager.count() + class CsvBulkUpload(models.Model): name = models.CharField(max_length=20) @@ -686,4 +736,7 @@ class Hospital(models.Model): def __str__(self): return self.name + ' - ' + self.designation - \ No newline at end of file + + @classmethod + def count(cls): + return cls._default_manager.count() diff --git a/mainapp/views.py b/mainapp/views.py index 227ef4187..c52cce8f9 100644 --- a/mainapp/views.py +++ b/mainapp/views.py @@ -202,10 +202,33 @@ class RegisterContributor(CreateView): class HomePageView(TemplateView): template_name = "home.html" + def get_context_data(self, **kwargs): + cxt = super(HomePageView, self).get_context_data(**kwargs) + cxt['request_for_rescue_count'] = Request.request_for_rescue() + cxt['request_for_resource_count'] = Request.request_for_resource() + cxt['relief_camps_count'] = RescueCamp.count() + cxt['announcement_count'] = Announcements.count() + cxt['to_contribute_count'] = Contributor.count() + cxt['district_needs_count'] = DistrictNeed.count() + cxt['volunteer_and_ngo_company_count'] = Volunteer.count() + NGO.count() + cxt['contact_info'] = DistrictManager.count() + cxt['registered_requests_count'] = "-" # todo + + cxt['hospital_count'] = Hospital.count() + cxt['private_relief_and_collection_centers_count'] = PrivateRescueCamp.count() + CollectionCenter.count() + + return cxt + class NgoVolunteerView(TemplateView): template_name = "ngo_volunteer.html" + def get_context_data(self, **kwargs): + cxt = super(NgoVolunteerView, self).get_context_data(**kwargs) + cxt['registered_volunteers_count'] = 0 + cxt['registered_ngo_count'] = 0 + return cxt + class MapView(TemplateView): template_name = "mapview.html" @@ -259,7 +282,8 @@ def __init__(self, *args, **kwargs): def relief_camps(request): - return render(request,"mainapp/relief_camps.html") + context = {'count': RescueCamp.count(), } + return render(request,"mainapp/relief_camps.html", context=context) def missing_persons(request): @@ -272,7 +296,7 @@ def relief_camps_list(request): paginator = Paginator(relief_camps,50) page = request.GET.get('page') data = paginator.get_page(page) - return render(request, 'mainapp/relief_camps_list.html', {'filter': filter, 'data': data}) + return render(request, 'mainapp/relief_camps_list.html', {'filter': filter, 'data': data, 'count': paginator.count}) class RequestFilter(django_filters.FilterSet): class Meta: @@ -831,13 +855,14 @@ def dispatch(self, request, *args, **kwargs): class ConsentSuccess(TemplateView): template_name = "mainapp/volunteer_consent_success.html" + def camp_requirements_list(request): filter = CampRequirementsFilter(request.GET, queryset=RescueCamp.objects.all()) camp_data = filter.qs.order_by('name') paginator = Paginator(camp_data, 50) page = request.GET.get('page') data = paginator.get_page(page) - return render(request, "mainapp/camp_requirements_list.html", {'filter': filter , 'data' : data}) + return render(request, "mainapp/camp_requirements_list.html", {'filter': filter , 'data': data}) class RequestUpdateView(CreateView): diff --git a/static/css/style.css b/static/css/style.css index fceed6a5d..7bbaa501f 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -83,6 +83,9 @@ form{ width:96%; margin: 20px auto; max-width: 600px; + border: 2px solid #fff; + padding: 14px; + border-radius: 10px; } footer{ margin: 40px 0; @@ -183,7 +186,7 @@ tr:hover td{ .pagination a:hover:not(.active) {background-color: #ddd;} table thead tr th { - border-top: 2px solid #ddd !important; + border-top: 2px solid #ddd !important; } .container{ @@ -203,13 +206,13 @@ table thead tr th { font-size: 12px; color:#777777; } - .priority-index b{ - display: inline-block; - width:14px; - height: 4px; - border-radius: 2px; - margin: 0 2px 2.5px 10px; - } +.priority-index b{ + display: inline-block; + width:14px; + height: 4px; + border-radius: 2px; + margin: 0 2px 2.5px 10px; +} .card{ display: block; background: #FFFFFF; @@ -229,18 +232,18 @@ table thead tr th { font-size: 14px; margin-bottom:6px; } - .card-link{ - margin: 12px 5px; - } +.card-link{ + margin: 12px 5px; +} .card-time{ float: left; color: #888888; font-size: 12px; padding:2px 8px; } - .card-time .glyphicon{ - font-size: 80%; - } +.card-time .glyphicon{ + font-size: 80%; +} .card-priority{ float: left; color: #FFFFFF; @@ -264,33 +267,33 @@ table thead tr th { /* Card Priority Variation */ .card.priority-very-important{ - border-top:5px solid #e05959; - border-left: none; - margin-bottom: 40px; - box-shadow:0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12); - } - .card.priority-very-important .card-text{ - font-size: 16px; - } - .card.priority-very-important .card-priority{ - font-size: 14px; - padding: 4px 12px; - background-color:#e05959; - -webkit-animation: 1s pinned-message-priority infinite; - animation: 1s pinned-message-priority infinite; - } - .card.priority-very-important .card-time{ - float: right - } + border-top:5px solid #e05959; + border-left: none; + margin-bottom: 40px; + box-shadow:0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12); +} +.card.priority-very-important .card-text{ + font-size: 16px; +} +.card.priority-very-important .card-priority{ + font-size: 14px; + padding: 4px 12px; + background-color:#e05959; + -webkit-animation: 1s pinned-message-priority infinite; + animation: 1s pinned-message-priority infinite; +} +.card.priority-very-important .card-time{ + float: right +} .card.priority-high{border-color:#ef7831;} - .card.priority-high .card-priority{background-color:#ef7831;} +.card.priority-high .card-priority{background-color:#ef7831;} .card.priority-medium{border-color:#ffc107;} - .card.priority-medium .card-priority{background-color:#ffc107;} +.card.priority-medium .card-priority{background-color:#ffc107;} .card.priority-low{border-color:#286090;} - .card.priority-low .card-priority{background-color:#286090;} +.card.priority-low .card-priority{background-color:#286090;} /* Safari 4.0 - 8.0 */ @-webkit-keyframes pinned-message-priority { @@ -318,3 +321,13 @@ table thead tr th { margin-right: auto; max-width: 1170px; } + +.badge { + margin-top:10px; + padding: 5px 7px; +} +.badge.badge-info { + color: #fff; + background-color: #9e9e9e; + border-color: #1b6d85; +} diff --git a/templates/base.html b/templates/base.html index f15477ef6..01079a951 100644 --- a/templates/base.html +++ b/templates/base.html @@ -102,10 +102,13 @@ {% block javascript %} {% endblock %} - diff --git a/templates/home.html b/templates/home.html index 07faba038..8740d1823 100644 --- a/templates/home.html +++ b/templates/home.html @@ -3,34 +3,40 @@ {% block content %} {% load bootstrap3 %} - + + +

Keralarescue

An initiative by Govt. of Kerala, Kerala State IT Mission and IEEE Kerala Section
- For effective collaboration and communications between authorities, volunteers and public

+ For effective collaboration and communications between authorities, volunteers and public
ദുരിതാശ്വാസ പ്രവർത്തനങ്ങളും രക്ഷാ ദൗത്യങ്ങളും ഏകോപിപ്പിക്കാൻ
- - Donate to Chief Minister's Fund Online -

- - {% bootstrap_icon "bell" %} - + + Donate to Chief Minister's Fund Online +

+ + {% bootstrap_icon "bell" %} + Request
for rescue
രക്ഷാപ്രവർത്തനം അഭ്യർത്ഥിക്കാൻ
-
- {% bootstrap_icon "grain" %} - + Registered: {{ request_for_rescue_count}} + + + {% bootstrap_icon "grain" %} + Request
for resources
സഹായം അഭ്യർത്ഥിക്കാൻ
-
+ Registered: {{ request_for_resource_count}} + + {% bootstrap_icon "phone" %} @@ -86,13 +98,15 @@

Keralarescue

INFO
ഞങ്ങളുമായി ബന്ധപ്പെടാൻ + Registered: {{contact_info}}
- {% bootstrap_icon "list" %} - + {% bootstrap_icon "list" %} + Registered Requests
ഇതു വരെ ആവശ്യപ്പെട്ടവ
+ Registered: {{registered_requests_count}}
{% bootstrap_icon "plus" %} @@ -100,6 +114,7 @@

Keralarescue

ആശുപത്രികൾ + Registered: {{hospital_count}}
{% bootstrap_icon "briefcase" %} @@ -107,16 +122,33 @@

Keralarescue

Collection Centers
സ്വകാര്യ റിലീഫ് ആൻഡ് കളക്ഷൻ സെന്ററുകൾ + Registered: {{private_relief_and_collection_centers_count}}

- For emergency support, call the District control room at 1077 or the State control room at 1070.
+ For emergency support, call the District control room at 1077 or the State control room at 1070.
Volunteers may contact District Project Managers for support related to volunteering and contributions

സഹായത്തിനായി സന്നദ്ധ സേവകർ തയ്യാറാണ്.
സഹായം ആവശ്യമെങ്കിൽ വിളിക്കുക: ജില്ലാ കൺട്രോൾ റൂം: 1077 , സംസ്ഥാന കൺട്രോൾ റൂം: 1070

-
-

- Our Collaboration Platform (Slack) Join -

+
+

+ Our Collaboration Platform (Slack) Join +

{% endblock %} +{% block javascript %} + +{% endblock %} \ No newline at end of file diff --git a/templates/ngo_volunteer.html b/templates/ngo_volunteer.html index 65fa3594d..f760e2fee 100644 --- a/templates/ngo_volunteer.html +++ b/templates/ngo_volunteer.html @@ -33,6 +33,8 @@

keralarescue

Volunteers + Registered: {{ registered_volunteers_count }} + {% bootstrap_icon "list-alt" %} @@ -47,6 +49,7 @@

keralarescue

NGO's/Company's + Registered: {{ registered_ngo_count }}

Contact Control Room or Disaster Management Cell or District Administration for any support.