Skip to content

Commit

Permalink
Merge branch 'master' into 2019/jerinisready/issue_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jerinisready authored Aug 10, 2019
2 parents ee313c8 + a54277a commit 6651659
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: gunicorn floodrelief.wsgi --timeout 600
web: gunicorn floodrelief.wsgi --timeout 600
worker: python redis_worker.py
4 changes: 0 additions & 4 deletions floodrelief/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ def get_list(text):
'propagate': True,
'level':'DEBUG',
},
'MYAPP': {
'handlers': ['file'],
'level': 'DEBUG',
},
}
}

Expand Down
23 changes: 23 additions & 0 deletions mainapp/migrations/0096_auto_20190810_1159.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.1.2 on 2019-08-10 06:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mainapp', '0095_hospital'),
]

operations = [
migrations.AddField(
model_name='hospital',
name='district',
field=models.CharField(blank=True, choices=[('alp', 'Alappuzha - ആലപ്പുഴ'), ('ekm', 'Ernakulam - എറണാകുളം'), ('idk', 'Idukki - ഇടുക്കി'), ('knr', 'Kannur - കണ്ണൂർ'), ('ksr', 'Kasaragod - കാസർഗോഡ്'), ('kol', 'Kollam - കൊല്ലം'), ('ktm', 'Kottayam - കോട്ടയം'), ('koz', 'Kozhikode - കോഴിക്കോട്'), ('mpm', 'Malappuram - മലപ്പുറം'), ('pkd', 'Palakkad - പാലക്കാട്'), ('ptm', 'Pathanamthitta - പത്തനംതിട്ട'), ('tvm', 'Thiruvananthapuram - തിരുവനന്തപുരം'), ('tcr', 'Thrissur - തൃശ്ശൂർ'), ('wnd', 'Wayanad - വയനാട്')], max_length=15, null=True, verbose_name='District - ജില്ല'),
),
migrations.AlterField(
model_name='hospital',
name='designation',
field=models.CharField(max_length=250, verbose_name='Officer name'),
),
]
9 changes: 8 additions & 1 deletion mainapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def summarise(self):
if(self.needkit_util):
out += "\nKit Requirements :\n {}".format(self.detailkit_util)
if(self.needrescue):
out += "\nRescue Action :\n {}".format(self.detailrescue)
out += "\nRescue Action :\n {}".format(self.detailrescue)
if(len(self.needothers.strip()) != 0):
out += "\nOther Needs :\n {}".format(self.needothers)
return out
Expand Down Expand Up @@ -728,6 +728,13 @@ def __str__(self):


class Hospital(models.Model):
district = models.CharField(
max_length = 15,
choices = districts,
verbose_name="District - ജില്ല",
null=True,
blank=True
)
name = models.CharField(max_length=200)
officer = models.CharField(max_length=100)
designation = models.CharField(max_length=250, verbose_name="Officer name")
Expand Down
41 changes: 20 additions & 21 deletions mainapp/templates/mainapp/hospitals.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,28 @@ <h4>{{ message }}</h4>
{% endfor %}
</tbody>
</table>
{% if is_paginated %}

{% if filter.qs.paginator.num_pages > 1 %}
<div class="pagination" >
<span class="step-links">
{% if filter.qs.has_previous %}
<a href="?page=1&name__icontains={{ request.GET.name__icontains }}&district={{ request.GET.district }}">&laquo; first</a>
<a href="?page={{filter.qs.previous_page_number}}&name__icontains={{ request.GET.name__icontains }}&district={{ request.GET.district }}">previous</a>
{% endif %}
<div class="pagination" >
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1&name__icontains={{ request.GET.name__icontains }}&designation__icontains={{ request.GET.designation__icontains}}&district={{ request.GET.district }}">&laquo; first</a>
<a href="?page={{filter.qs.previous_page_number}}&name__icontains={{ request.GET.name__icontains }}&designation__icontains={{ request.GET.designation__icontains}}&district={{ request.GET.district }}">previous</a>
{% endif %}

{% for i in filter.qs.paginator.page_range %}
{% if filter.qs.number == i %}
<a class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></a>
{% else %}
<a href="?page={{i}}&name__icontains={{ request.GET.name__icontains }}&district={{ request.GET.district }}">{{ i }}</a>
{% endif %}
{% endfor %}
{% for i in page_obj.paginator.page_range %}
{% if page_obj.number == i %}
<a class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></a>
{% elif i > page_obj.min_page and i < page_obj.max_page or i|divisibleby:data.lim_page %}
<a href="?page={{i}}&name__icontains={{ request.GET.name__icontains }}&designation__icontains={{ request.GET.designation__icontains}}&district={{ request.GET.district }}">{{ i }}</a>
{% endif %}
{% endfor %}

{% if filter.qs.has_next %}
<a href="?page={{ filter.qs.next_page_number }}&name__icontains={{ request.GET.name__icontains }}&district={{ request.GET.district }}">next</a>
<a href="?page={{ filter.qs.paginator.num_pages }}&name__icontains={{ request.GET.name__icontains }}&district={{ request.GET.district }}">last &raquo;</a>
{% endif %}
</span>
</div>
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}&name__icontains={{ request.GET.name__icontains }}&designation__icontains={{ request.GET.designation__icontains}}&district={{ request.GET.district }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}&name__icontains={{ request.GET.name__icontains }}&designation__icontains={{ request.GET.designation__icontains}}&district={{ request.GET.district }}">last &raquo;</a>
{% endif %}
</span>
</div>
{% endif %}

{% endblock %}
50 changes: 49 additions & 1 deletion mainapp/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.test import TestCase, Client
from django.urls import reverse

from mainapp.models import Request, Volunteer, Contributor, NGO, DistrictNeed, RescueCamp
from mainapp.models import Request, Volunteer, Contributor, NGO, DistrictNeed, RescueCamp, Hospital


class TemplateViewTests(TestCase):
Expand Down Expand Up @@ -492,3 +492,51 @@ def test_limit_query(self):
'meta']['description'], 'select * from mainapp_rescuecamp where id > offset order by id limit 300')
self.assertEqual(response.json()['meta']['last_record_id'], 500)
# RescueCamp.objects.all().delete()



class HospitalsDataTest(TestCase):
def setUp(self):
self.url = '/hospitals/'

def test_empty_query(self):
client = Client()
response = client.get(self.url)
self.assertTemplateUsed(response, 'mainapp/hospitals.html')
self.assertIn('select name="district"', str(
response.context['filter'].form))

def test_query_params(self):
client = Client()
bulk_entries = []
for i in range(110):
bulk_entries.append(Hospital(**{
'name': 'adoor public hospital -' + str(i),
'district': 'ptm',
'officer': 'doc-' + str(i),
'designation': 'CDI',
'landline': '91029122' + str(i),
'mobile': '99012931' + str(i),
'email': 'someone+' + str(i) + '@random.org'
}))
_ = Hospital.objects.bulk_create(bulk_entries)

# Default List
response = client.get(self.url)
self.assertTemplateUsed(response, 'mainapp/hospitals.html')
self.assertEqual(len(response.context['object_list']), 50)

# Empty List
response = client.get(self.url, {'district':'tcr'})
self.assertTemplateUsed(response, 'mainapp/hospitals.html')
self.assertEqual(len(response.context['object_list']), 0)

# Filtered List
response = client.get(self.url, {'district': 'ptm'})
self.assertTemplateUsed(response, 'mainapp/hospitals.html')
self.assertEqual(len(response.context['object_list']), 50)

# Paginated List
response = client.get(self.url, {'page': 3})
self.assertTemplateUsed(response, 'mainapp/hospitals.html')
self.assertEqual(len(response.context['object_list']), 10)
4 changes: 3 additions & 1 deletion mainapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@
path('consent_success/', views.ConsentSuccess.as_view(), name='consent_success'),
url(r'c/(?P<pk>\d+)/(?P<ts>\d+)/$', views.VolunteerConsent.as_view(), name='volunteer_consent'),
url('missing_and_finding_persons/', views.ReportFindPerson.as_view(), name='report_find_person'),
url('hospitals/', views.HospitalView.as_view(), name='hospitals')
url('hospitals/', views.HospitalView.as_view(), name='hospitals'),
url('announcements/api', views.announcement_api, name='announcements_api'),

]
23 changes: 18 additions & 5 deletions mainapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from collections import OrderedDict



class CustomForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(CustomForm, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -977,8 +978,9 @@ class Meta:
fields = OrderedDict()
fields['name'] = ['icontains']
fields['designation'] = ['icontains']
fields['district'] = ['exact']



# def __init__(self, *args, **kwargs):
# super(HospitalViewFitler, self).__init__(*args, **kwargs)
# if self.data == {}:
Expand All @@ -988,19 +990,23 @@ class Meta:
class HospitalForm(forms.ModelForm):
class Meta:
model = Hospital
fields = ['name', 'designation']
fields = ['name', 'designation', 'district']

class HospitalView(ListView):
model = Hospital
success_url = '/hospitals/'
paginate_by = 50
template_name = 'mainapp/hospitals.html'
queryset = Hospital.objects.order_by('-id')

def get_context_data(self, **kwargs):
filtered_list = HospitalViewFitler(
self.request.GET, queryset=self.get_queryset())
kwargs['object_list'] = filtered_list.qs
context = super().get_context_data(**kwargs)
context['filter'] = HospitalViewFitler(
self.request.GET, queryset=Hospital.objects.all()
)
filtered_list._qs = context['object_list']

context['filter'] = filtered_list
return context

class CollectionCenterListView(ListView):
Expand Down Expand Up @@ -1044,3 +1050,10 @@ class CollectionCenterView(CreateView):
model = CollectionCenter
form_class = CollectionCenterForm
success_url = '/collection_centers/'


def announcement_api(request):
objects = Announcements.objects
data = list(objects.values())
return JsonResponse({"announcements" : data})

0 comments on commit 6651659

Please sign in to comment.