From 0dfc33e3dd8ddfaead254932ef55c419fc03e527 Mon Sep 17 00:00:00 2001 From: "Jishnu.k" Date: Fri, 17 Aug 2018 15:18:39 +0530 Subject: [PATCH 1/2] NGO/Company registrations --- mainapp/admin.py | 34 +++++++++++++++++-- mainapp/migrations/0034_ngo.py | 29 ++++++++++++++++ mainapp/migrations/0035_auto_20180817_1339.py | 18 ++++++++++ mainapp/migrations/0036_auto_20180817_1500.py | 28 +++++++++++++++ mainapp/models.py | 25 ++++++++++++++ mainapp/templates/mainapp/ngo_form.html | 23 +++++++++++++ mainapp/urls.py | 1 + mainapp/views.py | 9 ++++- templates/home.html | 7 ++++ 9 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 mainapp/migrations/0034_ngo.py create mode 100644 mainapp/migrations/0035_auto_20180817_1339.py create mode 100644 mainapp/migrations/0036_auto_20180817_1500.py create mode 100644 mainapp/templates/mainapp/ngo_form.html diff --git a/mainapp/admin.py b/mainapp/admin.py index a42b129f1..361b583be 100644 --- a/mainapp/admin.py +++ b/mainapp/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Request, Volunteer, Contributor, DistrictNeed, DistrictCollection, DistrictManager ,vol_categories, RescueCamp, Person +from .models import Request, Volunteer, Contributor, DistrictNeed, DistrictCollection, DistrictManager ,vol_categories, RescueCamp, Person, NGO import csv from django.http import HttpResponse @@ -72,6 +72,34 @@ def download_csv(self, request, queryset): return response +class NGOAdmin(admin.ModelAdmin): + actions = ['download_csv'] + readonly_fields = ('joined',) + list_display = ('name', 'phone', 'organisation', 'joined') + list_filter = ('district', 'joined',) + def download_csv(self, request, queryset): + options = vol_categories + mapper = {} + for i in vol_categories: + mapper[i[0]] = i[1] + f = open('vol.csv', 'w') + writer = csv.writer(f) + l = [] + for i in (NGO._meta.get_fields()): + l.append(i.name) + writer.writerow(l) + data = NGO.objects.all().values_list() + for s in data: + s = list(s) + s[6] = mapper[s[6]] + writer.writerow(s) + f.close() + f = open('vol.csv', 'r') + response = HttpResponse(f, content_type='text/csv') + response['Content-Disposition'] = 'attachment; filename=NGO.csv' + return response + + class ContributorAdmin(admin.ModelAdmin): actions = ['download_csv'] list_filter = ('district', 'status',) @@ -95,10 +123,12 @@ def download_csv(self, request, queryset): class RescueCampAdmin(admin.ModelAdmin): list_display = ('district', 'name', 'location') + admin.site.register(Request, RequestAdmin) admin.site.register(Volunteer, VolunteerAdmin) admin.site.register(Contributor, ContributorAdmin) admin.site.register(DistrictNeed) admin.site.register(DistrictCollection) admin.site.register(DistrictManager) -admin.site.register(RescueCamp,RescueCampAdmin) \ No newline at end of file +admin.site.register(RescueCamp,RescueCampAdmin) +admin.site.register(NGO, NGOAdmin) diff --git a/mainapp/migrations/0034_ngo.py b/mainapp/migrations/0034_ngo.py new file mode 100644 index 000000000..1961d1c38 --- /dev/null +++ b/mainapp/migrations/0034_ngo.py @@ -0,0 +1,29 @@ +# Generated by Django 2.1 on 2018-08-17 07:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mainapp', '0033_auto_20180817_1003'), + ] + + operations = [ + migrations.CreateModel( + name='NGO', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('district', models.CharField(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)), + ('organisation', models.CharField(max_length=250, verbose_name='Name of Organization (സംഘടന)')), + ('organisation_type', models.CharField(max_length=250, verbose_name='Type of Organization (സംഘടന)')), + ('name', models.CharField(max_length=100, verbose_name='Contact Person')), + ('phone', models.CharField(max_length=10)), + ('description', models.TextField(verbose_name='About Organisation')), + ('area', models.CharField(max_length=500, verbose_name='Area of volunteering')), + ('location', models.CharField(max_length=500, verbose_name='Preferred Location to Volunteer')), + ('is_spoc', models.BooleanField(default=False, verbose_name='Is point of contact')), + ('joined', models.DateTimeField(auto_now_add=True)), + ], + ), + ] diff --git a/mainapp/migrations/0035_auto_20180817_1339.py b/mainapp/migrations/0035_auto_20180817_1339.py new file mode 100644 index 000000000..e23dcbc63 --- /dev/null +++ b/mainapp/migrations/0035_auto_20180817_1339.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1 on 2018-08-17 08:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mainapp', '0034_ngo'), + ] + + operations = [ + migrations.AlterField( + model_name='ngo', + name='area', + field=models.TextField(verbose_name='Area of volunteering'), + ), + ] diff --git a/mainapp/migrations/0036_auto_20180817_1500.py b/mainapp/migrations/0036_auto_20180817_1500.py new file mode 100644 index 000000000..9f7c5dcc2 --- /dev/null +++ b/mainapp/migrations/0036_auto_20180817_1500.py @@ -0,0 +1,28 @@ +# Generated by Django 2.1 on 2018-08-17 09:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mainapp', '0035_auto_20180817_1339'), + ] + + operations = [ + migrations.AddField( + model_name='ngo', + name='organisation_address', + field=models.TextField(default='', verbose_name='Address of Organization'), + ), + migrations.AlterField( + model_name='ngo', + name='organisation', + field=models.CharField(max_length=250, verbose_name='Name of Organization (സംഘടനയുടെ പേര്)'), + ), + migrations.AlterField( + model_name='ngo', + name='organisation_type', + field=models.CharField(max_length=250, verbose_name='Type of Organization'), + ), + ] diff --git a/mainapp/models.py b/mainapp/models.py index 9865c377d..7b849eb3b 100644 --- a/mainapp/models.py +++ b/mainapp/models.py @@ -131,6 +131,31 @@ def __str__(self): return self.name +class NGO(models.Model): + district = models.CharField( + max_length = 15, + choices = districts, + ) + organisation = models.CharField(max_length=250, verbose_name="Name of Organization (സംഘടനയുടെ പേര്)") + organisation_type = models.CharField(max_length=250, verbose_name="Type of Organization") + organisation_address = models.TextField(default='', verbose_name="Address of Organization") + name = models.CharField(max_length=100, verbose_name="Contact Person") + phone = models.CharField(max_length=10) + description = models.TextField(verbose_name="About Organisation") + area = models.TextField( + verbose_name = "Area of volunteering" + ) + location = models.CharField( + max_length=500, + verbose_name="Preferred Location to Volunteer" + ) + is_spoc = models.BooleanField(default=False, verbose_name="Is point of contact") + joined = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return self.name + + class Contributor(models.Model): district = models.CharField( max_length = 15, diff --git a/mainapp/templates/mainapp/ngo_form.html b/mainapp/templates/mainapp/ngo_form.html new file mode 100644 index 000000000..cdbc8ab08 --- /dev/null +++ b/mainapp/templates/mainapp/ngo_form.html @@ -0,0 +1,23 @@ +{% extends 'base.html' %} +{% load bootstrap3 %} + +{% block content %} +

+

NGO/Company Registration

+

+
+ {% csrf_token %} + {% bootstrap_form form %} + {% buttons %} + + {% endbuttons %} +
+ + +{% endblock %} diff --git a/mainapp/urls.py b/mainapp/urls.py index b50b23d77..b0ee8de91 100644 --- a/mainapp/urls.py +++ b/mainapp/urls.py @@ -7,6 +7,7 @@ path('request/', views.CreateRequest.as_view(), name='requestview'), # path('volunteer/', views.Maintenance.as_view(), name='registerview'), path('volunteer/', views.RegisterVolunteer.as_view(), name='registerview'), + path('NGO/', views.RegisterNGO.as_view(), name='ngoregisterview'), path('requests/', views.request_list, name='requestlistview'), path('contactus/', views.districtmanager_list, name='contactus'), path('reg_success/', views.RegSuccess.as_view(), name='reg_successview'), diff --git a/mainapp/views.py b/mainapp/views.py index b563e69e0..2fe956961 100644 --- a/mainapp/views.py +++ b/mainapp/views.py @@ -2,7 +2,7 @@ from django.shortcuts import render from django.views.generic.edit import CreateView from django.views.generic.base import TemplateView -from .models import Request, Volunteer, DistrictManager, Contributor, DistrictNeed, Person, RescueCamp +from .models import Request, Volunteer, DistrictManager, Contributor, DistrictNeed, Person, RescueCamp, NGO import django_filters from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.http import JsonResponse @@ -50,6 +50,13 @@ class RegisterVolunteer(CreateView): success_url = '/reg_success' +class RegisterNGO(CreateView): + model = NGO + fields = ['organisation', 'organisation_type','organisation_address', 'name', 'phone', 'description', 'area', + 'location'] + success_url = '/reg_success' + + class RegisterContributor(CreateView): model = Contributor fields = ['name', 'district', 'phone', 'address', 'commodities'] diff --git a/templates/home.html b/templates/home.html index ca0cdc11d..8a45aacaa 100644 --- a/templates/home.html +++ b/templates/home.html @@ -40,6 +40,13 @@

keralarescue

വൊളന്‍റീയര്‍ ആകാന്‍ + + {% bootstrap_icon "user" %} + + Register as
NGO/Company + വൊളന്‍റീയര്‍ ആകാന്‍ +
+