Skip to content

Commit dfe3065

Browse files
authored
Merge branch 'master' into Issue-181
2 parents 9e587bb + e852343 commit dfe3065

Some content is hidden

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

60 files changed

+1361
-16524
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
env/
2+
frontend/

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Temporary Items
3131
# Byte-compiled / optimized / DLL files
3232
__pycache__/
3333
*.py[cod]
34+
.mypy_cache/
3435

3536
# C extensions
3637
*.so
@@ -95,8 +96,9 @@ db.sqlite3
9596
/.cache
9697
/dist
9798

98-
# dependencies
99+
# Javascript
99100
frontend/node_modules/
101+
node_modules
100102
frontend/.pnp
101103
.pnp.js
102104

@@ -116,4 +118,4 @@ npm-debug.log*
116118
yarn-debug.log*
117119
yarn-error.log*
118120

119-
/notes.txt
121+
/notes.txt

Dockerfile

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
FROM python:3.7
1+
FROM python:3.7-slim
22

3-
RUN pip install pipenv
4-
COPY . /app
3+
ARG APP_USER=appuser
54

5+
COPY . /app
66
WORKDIR /app
7-
RUN pipenv install --system
7+
8+
RUN set -ex \
9+
&& groupadd -r ${APP_USER} && useradd --no-log-init -r -g ${APP_USER} ${APP_USER} \
10+
&& buildDeps=' \
11+
gcc \
12+
libbz2-dev \
13+
libc6-dev \
14+
libgdbm-dev \
15+
liblzma-dev \
16+
libncurses-dev \
17+
libreadline-dev \
18+
libsqlite3-dev \
19+
libssl-dev \
20+
libpcre3-dev \
21+
make \
22+
tcl-dev \
23+
tk-dev \
24+
wget \
25+
xz-utils \
26+
zlib1g-dev \
27+
' \
28+
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends \
29+
&& pip install pipenv && pip install uwsgi && pipenv install --system \
30+
&& apt-get purge -y --auto-remove $buildDeps
31+
32+
CMD ["uwsgi", "uwsgi.ini"]

Pipfile.lock

Lines changed: 108 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Currently, they are storing data from their programs in separate Excel spreadshe
88

99
This project would work to migrate all of the disparate data sources into one system, make a UI that allows Prevention Point to access all participant data in one system, and increase the ease with which program coordinators can evaluate and monitor activities.
1010

11-
## Before Contributing:
11+
## Before Contributing:
1212

13-
* Read through the [Wiki](https://github.com/CodeForPhilly/prevention-point/wiki).
13+
* Read through the [Wiki](https://github.com/CodeForPhilly/prevention-point/wiki).
1414
* Familiarize yourself with the agreed upon project [change management practices](https://github.com/CodeForPhilly/prevention-point/wiki/Change-Management-Practices).
1515

1616
## [Code of Conduct](https://codeforphilly.org/pages/code_of_conduct/)
@@ -78,6 +78,16 @@ $ docker volume prune
7878
- Run `yarn dev` and navigate to `localhost:1234`
7979
- Default username / password: admin / password123
8080

81+
For more information on the front-end please see the [front-end README](./frontend/readme)
82+
83+
## Scripts
84+
85+
This project implements the [Scripts To Rule Them All](https://github.com/github/scripts-to-rule-them-all) interface for developers:
86+
87+
* `script/server` — Brings a fully working environment up at [localhost:8080](http://localhost:8080)
88+
* `script/setup` — Run after `script/server` to initialize local database with seed data
89+
* `script/update` — Run after changing code or switching branches to refresh server
90+
8191
Other tools
8292
## Links
8393
[Wiki](https://github.com/CodeForPhilly/prevention-point/wiki)

core/management/commands/seed.py

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import random, pytz
1+
import random, pytz, datetime
22

33

44
from django.utils import timezone
@@ -20,6 +20,7 @@
2020
Visit,
2121
ProgramServiceMap,
2222
UrgencyLevel,
23+
ProgramAvailability
2324
)
2425
from core.permissions import CASE_MANAGER, FRONT_DESK, ADMIN
2526
from core.models.front_desk_event import FrontDeskEventType, FrontDeskEvent
@@ -90,17 +91,44 @@ def frequency(self):
9091
fake.add_provider(FrequencyProvider)
9192

9293

94+
class MonFriProvider(BaseProvider):
95+
__provider__ = "day of week"
96+
__lang__ = "en_US"
97+
98+
def mon_fri(self):
99+
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
100+
return random.choices(days)
101+
102+
103+
fake.add_provider(MonFriProvider)
104+
105+
106+
class AvailabilityWindowProvider(BaseProvider):
107+
"""For HRSC sign in. HRSC appointments are available Mon-Fri, 10a-4p"""
108+
__provider__ = "availability window"
109+
__lang__ = "en_US"
110+
111+
def availability_window(self, start_hour = 10, end_hour = 17):
112+
"""Returns a tuple (start_time, end_time)"""
113+
window_begin = random.randint(start_hour, end_hour - 2)
114+
end_hour = random.randint(window_begin + 1, end_hour)
115+
return datetime.time(hour=window_begin), datetime.time(hour=end_hour)
116+
117+
118+
fake.add_provider(AvailabilityWindowProvider)
119+
120+
93121
def run_seed(self):
94-
call_command("migrate")
95-
call_command("flush")
122+
call_command("migrate", interactive=False)
123+
call_command("flush", interactive=False)
96124
create_groups(output=False)
97125
create_users(output=False)
98126
add_users_to_groups(output=False)
99127
create_insurers(output=False)
100128
create_participants()
101129
create_programs(output=False)
102130
create_visits(output=False)
103-
131+
create_program_availability(output=False)
104132

105133
def create_users(output=True):
106134
for group in DEFAULT_GROUPS:
@@ -298,6 +326,36 @@ def create_event(visit, type):
298326
f.full_clean()
299327
f.save()
300328

329+
330+
def create_program_availability(output=True):
331+
"""create program availability"""
332+
programs = Program.objects.all()
333+
days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
334+
for program in programs:
335+
for day in days_of_week:
336+
if random.randint(0, 10) < 8:
337+
availability = ProgramAvailability()
338+
availability.program = program
339+
availability.day_of_week = day
340+
availability.start_time, availability.end_time = fake.availability_window(
341+
start_hour=8, end_hour=18)
342+
window_one_end = availability.end_time.hour
343+
availability.full_clean()
344+
availability.save()
345+
if window_one_end < 15:
346+
availability_two = ProgramAvailability()
347+
availability_two.program = program
348+
availability_two.day_of_week = day
349+
availability_two.start_time, availability_two.end_time = fake.availability_window(
350+
start_hour=window_one_end+1, end_hour=23)
351+
availability_two.full_clean()
352+
availability_two.save()
353+
354+
if output:
355+
for availability in ProgramAvailability.objects.all().order_by('program'):
356+
print(f"Created program availability: {availability.program.name} {availability.day_of_week} {availability.start_time} {availability.end_time}")
357+
358+
301359
def arrived(visit):
302360
"""After ARRIVED, can be either LEFT, SEEN, STEPPED_OUT or pending (still in ARRIVED status)"""
303361
create_event(visit, "ARRIVED")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 2.2.9 on 2020-02-16 19:13
2+
3+
import core.models.visit
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('core', '0002_auto_20191026_1355'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='program',
16+
name='is_frozen',
17+
field=models.BooleanField(default=False),
18+
),
19+
migrations.AlterField(
20+
model_name='visit',
21+
name='urgency',
22+
field=models.CharField(choices=[('_1', 1), ('_2', 2), ('_3', 3), ('_4', 4), ('_5', 5)], default=core.models.visit.UrgencyLevel(1), max_length=20),
23+
),
24+
]

core/models/program.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
class Program(models.Model):
55
name = models.CharField(max_length=100)
66
is_closed = models.BooleanField(default=False)
7+
is_frozen = models.BooleanField(default=False)

core/participants/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from core.models import Participant
22
from rest_framework import serializers
33

4-
class ParticipantSerializer(serializers.HyperlinkedModelSerializer):
4+
class ParticipantSerializer(serializers.ModelSerializer):
55
class Meta:
66
model = Participant
77

core/programs/serializer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class Meta:
99
"id",
1010
"name",
1111
"is_closed",
12+
"is_frozen",
1213
) # backwards nested relationship uses '_set'

0 commit comments

Comments
 (0)