Skip to content

Commit

Permalink
Merge pull request raksha-life#347 from jiikrish/feature/NGO
Browse files Browse the repository at this point in the history
Feature/ngo
  • Loading branch information
biswaz authored Aug 17, 2018
2 parents 80f3dee + 14a3a98 commit b861e4c
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 4 deletions.
34 changes: 32 additions & 2 deletions mainapp/admin.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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',)
Expand All @@ -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)
admin.site.register(RescueCamp,RescueCampAdmin)
admin.site.register(NGO, NGOAdmin)
29 changes: 29 additions & 0 deletions mainapp/migrations/0034_ngo.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
18 changes: 18 additions & 0 deletions mainapp/migrations/0035_auto_20180817_1339.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
28 changes: 28 additions & 0 deletions mainapp/migrations/0036_auto_20180817_1500.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
25 changes: 25 additions & 0 deletions mainapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions mainapp/templates/mainapp/ngo_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends 'base.html' %}
{% load bootstrap3 %}

{% block content %}
<p class="text-center">
<h3 class="text-center">NGO/Company Registration</h3>
</p>
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% bootstrap_icon "star" %} Submit
</button>
{% endbuttons %}
</form>

<script>
window.onload = function() {
$("#id_phone").attr('type', 'number');
}
</script>
{% endblock %}
1 change: 1 addition & 0 deletions mainapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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'),
url(r'request_details/(?P<request_id>\d+)/$', views.request_details, name='requestdetailsview'),
path('contactus/', views.districtmanager_list, name='contactus'),
Expand Down
9 changes: 8 additions & 1 deletion mainapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down
9 changes: 8 additions & 1 deletion templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ <h1 class="main-logo">kerala<span style="font-weight: normal;">rescue</span></h1
<span class="ml small">വൊളന്‍റീയര്‍ ആകാന്‍</span>
</span>
</a>
<a href="/map/" class="home-button card" role="button">
<a href="/NGO" class="home-button card" role="button">
{% bootstrap_icon "list-alt" %}
<span class="text">
Register as<br/> NGO/Company
<span class="ml small">വൊളന്‍റീയര്‍ ആകാന്‍</span>
</span>
</a>
<a href="/map" class="home-button card" role="button">
{% bootstrap_icon "globe" %}
<span class="text">
Request Map<br/>
Expand Down

0 comments on commit b861e4c

Please sign in to comment.