diff --git a/mainapp/urls.py b/mainapp/urls.py
index 42247f077..dbdf42fcd 100644
--- a/mainapp/urls.py
+++ b/mainapp/urls.py
@@ -62,4 +62,5 @@
path('consent_success/', views.ConsentSuccess.as_view(), name='consent_success'),
url(r'c/(?P\d+)/(?P\d+)/$', views.VolunteerConsent.as_view(), name='volunteer_consent'),
url('missing_and_finding_persons/', views.ReportFindPerson.as_view(), name='report_find_person'),
+ url(r'renewvolunteer/(?P\d+)/$', views.RenewVolunteerPage.as_view(), name='renewvolunteer'),
]
diff --git a/mainapp/views.py b/mainapp/views.py
index 0b76491b0..74225715a 100644
--- a/mainapp/views.py
+++ b/mainapp/views.py
@@ -86,6 +86,45 @@ class RegisterVolunteer(CreateView):
fields = ['name', 'district', 'phone', 'organisation', 'area', 'address']
success_url = '/reg_success/'
+
+class RenewVolunteerForm(forms.ModelForm):
+
+
+ class Meta:
+ model = Volunteer
+ help_texts = {
+ 'local_body': 'Indicate the local body name',
+ 'date_time': 'Indicate the dates that you are available for volunteering',
+ }
+ fields = ['district', 'name', 'local_body', 'phone', 'email', 'date_time', 'has_consented']
+
+ read_only = ('phone',)
+ widgets = {
+ 'name': forms.Textarea(attrs={'rows':1}),
+ 'phone': forms.Textarea(attrs={'rows':3, 'readonly':True}),
+ }
+
+class RenewVolunteerPage(CreateView):
+ model = Volunteer
+ # form_class = RenewVolunteerForm
+ fields = ['district', 'name', 'local_body', 'phone', 'email', 'date_time', 'has_consented']
+ # read_only = ('phone',)
+ template_name = "mainapp/renew_volunteer.html"
+ success_url = '/reg_success/'
+ volunteer_ph = ""
+
+ def dispatch(self, request, *args, **kwargs):
+ self.volunteer_ph = kwargs['volunteer_ph']
+ return super().dispatch(request, *args, **kwargs)
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super().get_context_data(**kwargs)
+ # data = get_object_or_404(self.model, pk=self.volunteer_ph)
+ context['current'] = get_object_or_404(self.model, pk=self.volunteer_ph)
+ return context
+
+
def volunteerdata(request):
filter = VolunteerFilter( request.GET, queryset=Volunteer.objects.all() )
req_data = filter.qs.order_by('-id')
diff --git a/renew_volunteer_sms.py b/renew_volunteer_sms.py
new file mode 100644
index 000000000..f2644d125
--- /dev/null
+++ b/renew_volunteer_sms.py
@@ -0,0 +1,68 @@
+# Dependencies - Requests, dateutil
+# Python 2.7.15
+
+# Expects a csv file's path containing volunteer details
+# Fill in the credentials in line 55, and run the script
+
+# Example usage:
+# python2 path/to/sms.py path/to/csvFile.csv
+
+import calendar
+import csv
+import datetime
+import sys
+import time
+
+import requests
+
+from dateutil import parser
+
+csvFile = sys.argv[1] #command line argument
+
+if __name__ == "__main__":
+
+ # csv file path not provided
+ if len(sys.argv) < 1:
+ sys.exit()
+
+ #stores failed sms
+ failed = open("Failed",'w')
+ fin = open(csvFile,'r')
+
+ # to avoid multiple sms to same mobile number
+ mark = {}
+
+ for fields in csv.reader(fin):
+
+ sendID = fields[0]
+ timestamp = fields[8]
+ mobile = fields[3]
+
+ if mobile in mark:
+ continue
+ mark[mobile]=1
+
+ if mobile.isdigit():
+ try:
+ # Converting timestamp to epoch
+ timestamp = parser.parse(timestamp)
+ timestamp = calendar.timegm(timestamp.utctimetuple())
+
+ # Preparing unique URL
+ url = 'http://keralarescue.in/c/' + sendID + "/" + str(timestamp)[-4:]
+ message = "If you would like to volunteer to do the damage assessment, please click this link " + url
+
+ payload = { 'username':'xxxxxxxx','password':'xxxxxxxx','message':message,'numbers':mobile}
+ response = requests.get('http://api.esms.kerala.gov.in/fastclient/SMSclient.php',params=payload)
+
+ except KeyboardInterrupt:
+
+ failed.write(mobile)
+ sys.exit()
+
+ except:
+
+ failed.write(mobile)
+
+ fin.close()
+ failed.close()
diff --git a/requirements.txt b/requirements.txt
index a5843f030..1bc511bf7 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -23,3 +23,5 @@ django-storages==1.6.6
python-dateutil
beautifulsoup4==4.6.3
ddtrace==0.12.1
+pympler==0.5
+django_debug_toolbar==1.9.1
From 7a00a610a22dc7cb522903d207a1f62534ef3a0e Mon Sep 17 00:00:00 2001
From: Jino Jossy
Date: Tue, 28 Aug 2018 13:01:37 +0530
Subject: [PATCH 3/8] added new view and url for fail scenario
---
mainapp/migrations/0093_auto_20180827_1657.py | 4 -
mainapp/migrations/0095_auto_20180828_1140.py | 19 ++
mainapp/migrations/0096_auto_20180828_1147.py | 18 ++
mainapp/models.py | 6 +-
mainapp/templates/mainapp/reg_fail.html | 9 +
.../templates/mainapp/renew_volunteer.html | 243 ++++++++++--------
mainapp/urls.py | 1 +
mainapp/views.py | 13 +-
8 files changed, 188 insertions(+), 125 deletions(-)
create mode 100644 mainapp/migrations/0095_auto_20180828_1140.py
create mode 100644 mainapp/migrations/0096_auto_20180828_1147.py
create mode 100644 mainapp/templates/mainapp/reg_fail.html
diff --git a/mainapp/migrations/0093_auto_20180827_1657.py b/mainapp/migrations/0093_auto_20180827_1657.py
index df5ddb12c..7b161455b 100644
--- a/mainapp/migrations/0093_auto_20180827_1657.py
+++ b/mainapp/migrations/0093_auto_20180827_1657.py
@@ -11,10 +11,6 @@ class Migration(migrations.Migration):
]
operations = [
- migrations.RemoveField(
- model_name='volunteer',
- name='id',
- ),
migrations.AlterField(
model_name='volunteer',
name='phone',
diff --git a/mainapp/migrations/0095_auto_20180828_1140.py b/mainapp/migrations/0095_auto_20180828_1140.py
new file mode 100644
index 000000000..3fb28ebe0
--- /dev/null
+++ b/mainapp/migrations/0095_auto_20180828_1140.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.1 on 2018-08-28 06:10
+
+import django.core.validators
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('mainapp', '0094_volunteer_email'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='volunteer',
+ name='phone',
+ field=models.CharField(max_length=14, validators=[django.core.validators.RegexValidator(code='invalid_mobile', message='Please Enter 10 digit mobile number or landline as 0', regex='^((\\+91|91|0)[\\- ]{0,1})?[456789]\\d{9}$')], verbose_name='Phone - ഫോണ്\u200d നമ്പര്\u200d'),
+ ),
+ ]
diff --git a/mainapp/migrations/0096_auto_20180828_1147.py b/mainapp/migrations/0096_auto_20180828_1147.py
new file mode 100644
index 000000000..1d0d41567
--- /dev/null
+++ b/mainapp/migrations/0096_auto_20180828_1147.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1 on 2018-08-28 06:17
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('mainapp', '0095_auto_20180828_1140'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='volunteer',
+ name='local_body',
+ field=models.TextField(default='', max_length=250),
+ ),
+ ]
diff --git a/mainapp/models.py b/mainapp/models.py
index 3d9b2d031..1778e557c 100644
--- a/mainapp/models.py
+++ b/mainapp/models.py
@@ -2,7 +2,6 @@
import uuid
from enum import Enum
import csv
-from datetime import datetime
import codecs
from django.db import models
@@ -196,12 +195,11 @@ class Volunteer(models.Model):
verbose_name="District - ജില്ല"
)
name = models.CharField(max_length=100, verbose_name="Name - പേര്")
-
phone_number_regex = RegexValidator(regex='^((\+91|91|0)[\- ]{0,1})?[456789]\d{9}$', message='Please Enter 10 digit mobile number or landline as 0', code='invalid_mobile')
- phone = models.CharField(max_length=14, verbose_name="Phone - ഫോണ് നമ്പര്", validators=[phone_number_regex], primary_key=True)
+ phone = models.CharField(max_length=14, verbose_name="Phone - ഫോണ് നമ്പര്", validators=[phone_number_regex])
email = models.EmailField(max_length=250, blank=True)
organisation = models.CharField(max_length=250, verbose_name="Organization (സംഘടന) / Institution")
- local_body = models.CharField(max_length=250, default= "")
+ local_body = models.TextField(max_length=250, default= "")
address = models.TextField(verbose_name="Address - വിലാസം")
area = models.CharField(
max_length = 15,
diff --git a/mainapp/templates/mainapp/reg_fail.html b/mainapp/templates/mainapp/reg_fail.html
new file mode 100644
index 000000000..b1a3a7be4
--- /dev/null
+++ b/mainapp/templates/mainapp/reg_fail.html
@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+{% load bootstrap3 %}
+
+{% block content %}
+
+Your request has been failed
+താങ്കളുടെ അഭ്യർത്ഥന പരാജയപ്പെട്ടു
+
+{% endblock %}
diff --git a/mainapp/templates/mainapp/renew_volunteer.html b/mainapp/templates/mainapp/renew_volunteer.html
index 6a0ab0dd3..42471c4a3 100644
--- a/mainapp/templates/mainapp/renew_volunteer.html
+++ b/mainapp/templates/mainapp/renew_volunteer.html
@@ -13,119 +13,138 @@
Renew as Volunteer
വൊളന്റീയര് പുതുക്കാൻ
- |