Skip to content

Commit 1dac871

Browse files
committed
2 parents b7aed38 + e69cf91 commit 1dac871

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1097
-135
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ __pycache__
55
.env
66
staticfiles/
77
mysite.log
8+
venv
89
.idea/*

Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3
2+
ENV PYTHONUNBUFFERED 1
3+
RUN apt-get update && apt-get install -y netcat
4+
RUN mkdir /code
5+
WORKDIR /code
6+
ADD requirements.txt /code/
7+
RUN pip install -r requirements.txt
8+
ADD . /code/
9+
ADD wait.sh /usr/local/bin/
10+
RUN chmod +x /usr/local/bin/wait.sh
11+
ENTRYPOINT ["/usr/local/bin/wait.sh"]

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@ The Website for coordinating the rehabilitation of the people affected in the 20
1010

1111
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
1212

13+
14+
### Using Docker
15+
16+
- Only pre-requisite is having docker and docker-compose installed
17+
- Execute `sh docker.sh` in this directory (if you do not have permissions on the `docker.sh`, do `chmod +x docker.sh`)
18+
- Server will start running at `localhost:8000`
19+
- `Ctrl+C` to stop
20+
21+
#### troubleshooting docker
22+
* Incompatible docker version
23+
24+
> ERROR: Version in "./docker-compose.yaml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
25+
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
26+
27+
28+
**Fix**
29+
30+
Update your docker toolkit
31+
32+
* Insufficient permissions
33+
> ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
34+
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
35+
36+
37+
**Fix**
38+
39+
Run it with sudo - `sudo sh docker.sh`
40+
41+
42+
## Running natively
1343
### Prerequisites
1444

1545
You will need to have following softwares in your system:

docker-compose.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3'
2+
3+
services:
4+
5+
db:
6+
image: postgres
7+
restart: always
8+
9+
redis:
10+
image: redis
11+
ports:
12+
- 6379:6379
13+
web:
14+
build: .
15+
restart: always
16+
environment:
17+
ALLOWED_HOSTS: localhost
18+
SECRET_KEY: abcd
19+
DEBUG: "True"
20+
SENTRY_DSN: ""
21+
B_DATABASE_URL: postgres://postgres:@db:5432/postgres
22+
REDIS_URL: redis://redis:6379
23+
WAIT_FOR: db:5432,redis:6379
24+
command: ./run_dev_server.sh
25+
volumes:
26+
- .:/code
27+
ports:
28+
- "8000:8000"
29+
depends_on:
30+
- db
31+
- redis
32+

docker.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
#!/bin/sh -
3+
docker-compose -p rescue-kerala up --build --abort-on-container-exit

mainapp/admin.py

+51-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.contrib import admin
44
from django.http import HttpResponse
55

6-
from .models import Request, Volunteer, Contributor, DistrictNeed, DistrictCollection, DistrictManager, vol_categories, RescueCamp, Person, NGO
6+
from .models import Request, Volunteer, Contributor, DistrictNeed, DistrictCollection, DistrictManager, vol_categories, RescueCamp, Person, NGO, Announcements
77

88

99
def create_csv_response(csv_name, header_row, body_rows):
@@ -54,9 +54,9 @@ def download_csv(self, request, queryset):
5454

5555

5656
class VolunteerAdmin(admin.ModelAdmin):
57-
actions = ['download_csv']
57+
actions = ['download_csv', 'mark_inactive', 'mark_active']
5858
readonly_fields = ('joined',)
59-
list_display = ('name', 'phone', 'organisation', 'joined')
59+
list_display = ('name', 'phone', 'organisation', 'joined', 'is_active')
6060
list_filter = ('district', 'joined',)
6161

6262
def download_csv(self, request, queryset):
@@ -72,6 +72,12 @@ def download_csv(self, request, queryset):
7272
response = create_csv_response('Volunteers', header_row, body_rows)
7373
return response
7474

75+
def mark_inactive(self, request, queryset):
76+
queryset.update(is_active=False)
77+
78+
def mark_active(self, request, queryset):
79+
queryset.update(is_active=True)
80+
7581

7682
class NGOAdmin(admin.ModelAdmin):
7783
actions = ['download_csv']
@@ -94,8 +100,9 @@ def download_csv(self, request, queryset):
94100

95101

96102
class ContributorAdmin(admin.ModelAdmin):
97-
actions = ['download_csv']
103+
actions = ['download_csv', 'mark_as_fullfulled', 'mark_as_new']
98104
list_filter = ('district', 'status',)
105+
list_display = ('district', 'name', 'phone', 'address', 'commodities', 'status')
99106

100107
def download_csv(self, request, queryset):
101108
header_row = [f.name for f in Contributor._meta.get_fields()]
@@ -104,16 +111,53 @@ def download_csv(self, request, queryset):
104111
response = create_csv_response('Contributors', header_row, body_rows)
105112
return response
106113

114+
def mark_as_fullfulled(self, request, queryset):
115+
queryset.update(status='ful')
116+
return
117+
118+
def mark_as_new(self, request, queryset):
119+
queryset.update(status='new')
120+
return
107121

108122
class RescueCampAdmin(admin.ModelAdmin):
109-
list_display = ('name','district','location')
123+
actions = ['download_csv']
124+
list_display = ('district', 'name', 'location', 'contacts', 'total_people',
125+
'total_males', 'total_females', 'total_infants', 'food_req',
126+
'clothing_req', 'sanitary_req', 'medical_req', 'other_req')
127+
128+
def download_csv(self, request, queryset):
129+
header_row = ('district', 'name', 'location', 'contacts', 'total_people',
130+
'total_males', 'total_females', 'total_infants', 'food_req',
131+
'clothing_req', 'sanitary_req', 'medical_req', 'other_req')
132+
body_rows = []
133+
rescue_camps = queryset.all()
134+
for rescue_camp in rescue_camps:
135+
row = [getattr(rescue_camp, field) for field in header_row]
136+
body_rows.append(row)
137+
138+
response = create_csv_response('RescueCamp', header_row, body_rows)
139+
return response
110140

111141
def get_form(self, request, obj=None, **kwargs):
112142
form = super(RescueCampAdmin, self).get_form(request, obj, **kwargs)
113143
form.base_fields['data_entry_user'].initial = request.user.id
114144
return form
115145

116146

147+
class PersonAdmin(admin.ModelAdmin):
148+
actions = ['download_csv']
149+
list_display = ('name', 'phone', 'age', 'gender', 'district', 'camped_at')
150+
151+
def download_csv(self, request, queryset):
152+
header_row = ('name', 'phone', 'age', 'sex', 'district_name', 'camped_at')
153+
body_rows = []
154+
persons = queryset.all()
155+
for person in persons:
156+
row = [getattr(person, field) for field in header_row]
157+
body_rows.append(row)
158+
159+
response = create_csv_response('People in relief camps', header_row, body_rows)
160+
return response
117161

118162
admin.site.register(Request, RequestAdmin)
119163
admin.site.register(Volunteer, VolunteerAdmin)
@@ -123,3 +167,5 @@ def get_form(self, request, obj=None, **kwargs):
123167
admin.site.register(DistrictManager)
124168
admin.site.register(RescueCamp, RescueCampAdmin)
125169
admin.site.register(NGO, NGOAdmin)
170+
admin.site.register(Announcements)
171+
admin.site.register(Person, PersonAdmin)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 2.1 on 2018-08-17 08:43
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainapp', '0032_auto_20180817_0444'),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name='Announcements',
15+
fields=[
16+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
17+
('dateadded', models.DateTimeField(auto_now_add=True)),
18+
('name', models.CharField(max_length=50)),
19+
('link', models.CharField(max_length=100)),
20+
('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, verbose_name='Districts - ജില്ല')),
21+
('category', models.IntegerField(choices=[(0, 'General'), (1, 'Food'), (2, 'Camps'), (3, 'Weather')], verbose_name='Type')),
22+
],
23+
),
24+
migrations.AlterModelOptions(
25+
name='rescuecamp',
26+
options={'verbose_name': 'Relief Camp'},
27+
),
28+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 2.1 on 2018-08-17 09:01
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainapp', '0033_auto_20180817_1413'),
10+
('mainapp', '0034_auto_20180817_1337'),
11+
]
12+
13+
operations = [
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 2.1 on 2018-08-17 17:46
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainapp', '0035_merge_20180817_1431'),
10+
('mainapp', '0037_merge_20180817_1911'),
11+
]
12+
13+
operations = [
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 2.1 on 2018-08-18 04:27
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainapp', '0039_auto_20180818_0328'),
10+
('mainapp', '0038_merge_20180817_2316'),
11+
]
12+
13+
operations = [
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 2.1 on 2018-08-18 08:40
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainapp', '0040_merge_20180818_0957'),
10+
('mainapp', '0042_auto_20180818_1329'),
11+
]
12+
13+
operations = [
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.1 on 2018-08-18 08:29
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainapp', '0042_auto_20180818_1329'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='volunteer',
15+
name='is_active',
16+
field=models.BooleanField(default=True),
17+
),
18+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 2.1 on 2018-08-18 09:18
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainapp', '0043_volunteer_is_active'),
10+
('mainapp', '0043_merge_20180818_1410'),
11+
]
12+
13+
operations = [
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Generated by Django 2.1 on 2018-08-18 12:57
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainapp', '0044_merge_20180818_1448'),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name='announcements',
15+
options={'verbose_name': 'Announcement: News', 'verbose_name_plural': 'Announcements: News'},
16+
),
17+
migrations.AlterModelOptions(
18+
name='contributor',
19+
options={'verbose_name': 'Contributor: Donation', 'verbose_name_plural': 'Contributors: Donations'},
20+
),
21+
migrations.AlterModelOptions(
22+
name='districtcollection',
23+
options={'verbose_name': 'District: Collection', 'verbose_name_plural': 'District: Collections'},
24+
),
25+
migrations.AlterModelOptions(
26+
name='districtmanager',
27+
options={'verbose_name': 'District: Manager', 'verbose_name_plural': 'District: Managers'},
28+
),
29+
migrations.AlterModelOptions(
30+
name='districtneed',
31+
options={'verbose_name': 'District: Need', 'verbose_name_plural': 'District: Needs'},
32+
),
33+
migrations.AlterModelOptions(
34+
name='ngo',
35+
options={'verbose_name': 'Volunteer: NGO', 'verbose_name_plural': 'Volunteers: NGOs'},
36+
),
37+
migrations.AlterModelOptions(
38+
name='person',
39+
options={'verbose_name': 'Relief: Refugee', 'verbose_name_plural': 'Relief: Refugees'},
40+
),
41+
migrations.AlterModelOptions(
42+
name='request',
43+
options={'verbose_name': 'Relief: Supply Requiement', 'verbose_name_plural': 'Relief: Supply Requirements'},
44+
),
45+
migrations.AlterModelOptions(
46+
name='rescuecamp',
47+
options={'verbose_name': 'Relief: Camp', 'verbose_name_plural': 'Relief: Camps'},
48+
),
49+
migrations.AlterModelOptions(
50+
name='volunteer',
51+
options={'verbose_name': 'Volunteer: Individual', 'verbose_name_plural': 'Volunteers: Individuals'},
52+
),
53+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.1 on 2018-08-18 13:48
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainapp', '0045_auto_20180818_1827'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='rescuecamp',
15+
name='total_people',
16+
field=models.IntegerField(blank=True, null=True, verbose_name='Total Number of People'),
17+
),
18+
]

0 commit comments

Comments
 (0)