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 ff0633062..0d0ee4917 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 %} +
+