Skip to content

Commit

Permalink
Added Count of Registrations in each section over home page.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jerinisready committed Aug 10, 2019
1 parent 7aeaeba commit 0343611
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 70 deletions.
63 changes: 58 additions & 5 deletions mainapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
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
from django.core.cache.utils import make_template_fragment_key
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 - ആലപ്പുഴ'),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -301,14 +323,18 @@ 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(
max_length = 15,
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'
Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 - പേര്")
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -686,4 +736,7 @@ class Hospital(models.Model):

def __str__(self):
return self.name + ' - ' + self.designation


@classmethod
def count(cls):
return cls._default_manager.count()
31 changes: 28 additions & 3 deletions mainapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
83 changes: 48 additions & 35 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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{
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
5 changes: 4 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@
{% block javascript %}
{% endblock %}

<!-- This site was developed under IEEE by
<!--
This site was developed under IEEE by
Biswas - https://biswaz.github.io/
and
Shameel Kadannamanna - https://shameelsadaka.github.io/
-->


Expand Down
Loading

0 comments on commit 0343611

Please sign in to comment.