Skip to content

Commit 6ca0fe4

Browse files
committed
Update to Django 2.2
1 parent a24c9c8 commit 6ca0fe4

14 files changed

+79
-219
lines changed

Procfile

-1
This file was deleted.

grants/migrations/0001_initial.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Migration(migrations.Migration):
3535
migrations.AddField(
3636
model_name='answer',
3737
name='applicant',
38-
field=models.ForeignKey(to='grants.Applicant', to_field='id'),
38+
field=models.ForeignKey(to='grants.Applicant', to_field='id', on_delete=models.CASCADE),
3939
preserve_default=True,
4040
),
4141
migrations.CreateModel(
@@ -57,7 +57,7 @@ class Migration(migrations.Migration):
5757
migrations.AddField(
5858
model_name='applicant',
5959
name='program',
60-
field=models.ForeignKey(to='grants.Program', to_field='id'),
60+
field=models.ForeignKey(to='grants.Program', to_field='id', on_delete=models.CASCADE),
6161
preserve_default=True,
6262
),
6363
migrations.CreateModel(
@@ -67,7 +67,7 @@ class Migration(migrations.Migration):
6767
('type', models.CharField(max_length=50, choices=[(b'boolean', b'Yes/No'), (b'text', b'Text'), (b'integer', b'Integer value')])),
6868
('question', models.TextField()),
6969
('order', models.IntegerField(default=0)),
70-
('program', models.ForeignKey(to='grants.Program', to_field='id')),
70+
('program', models.ForeignKey(to='grants.Program', to_field='id', on_delete=models.CASCADE)),
7171
],
7272
options={
7373
},
@@ -76,7 +76,7 @@ class Migration(migrations.Migration):
7676
migrations.AddField(
7777
model_name='answer',
7878
name='question',
79-
field=models.ForeignKey(to='grants.Question', to_field='id'),
79+
field=models.ForeignKey(to='grants.Question', to_field='id', on_delete=models.CASCADE),
8080
preserve_default=True,
8181
),
8282
migrations.CreateModel(
@@ -85,7 +85,7 @@ class Migration(migrations.Migration):
8585
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
8686
('name', models.CharField(max_length=100)),
8787
('type', models.CharField(max_length=50, choices=[(b'money', b'Money'), (b'ticket', b'Ticket'), (b'place', b'Place'), (b'accomodation', b'Accomodation')])),
88-
('program', models.ForeignKey(to='grants.Program', to_field='id')),
88+
('program', models.ForeignKey(to='grants.Program', to_field='id', on_delete=models.CASCADE)),
8989
],
9090
options={
9191
},
@@ -97,7 +97,7 @@ class Migration(migrations.Migration):
9797
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
9898
('amount', models.IntegerField()),
9999
('source', models.TextField(null=True, blank=True)),
100-
('resource', models.ForeignKey(to='grants.Resource', to_field='id')),
100+
('resource', models.ForeignKey(to='grants.Resource', to_field='id', on_delete=models.CASCADE)),
101101
],
102102
options={
103103
},

grants/migrations/0005_auto_20140624_1719.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class Migration(migrations.Migration):
2020
('score', models.FloatField(null=True, blank=True)),
2121
('comment', models.TextField(null=True, blank=True)),
2222
('score_history', models.TextField(null=True, blank=True)),
23-
('applicant', models.ForeignKey(to='grants.Applicant')),
24-
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
23+
('applicant', models.ForeignKey(to='grants.Applicant', on_delete=models.CASCADE)),
24+
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
2525
],
2626
options={
2727
},

grants/migrations/0007_auto_20140625_0314.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Migration(migrations.Migration):
1616
fields=[
1717
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
1818
('amount', models.PositiveIntegerField()),
19-
('applicant', models.ForeignKey(to='grants.Applicant')),
20-
('resource', models.ForeignKey(to='grants.Resource')),
19+
('applicant', models.ForeignKey(to='grants.Applicant', on_delete=models.CASCADE)),
20+
('resource', models.ForeignKey(to='grants.Resource', on_delete=models.CASCADE)),
2121
],
2222
options={
2323
},

grants/migrations/0010_auto_20150320_1734.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,49 @@ class Migration(migrations.Migration):
2121
migrations.AlterField(
2222
model_name='allocation',
2323
name='applicant',
24-
field=models.ForeignKey(related_name='allocations', to='grants.Applicant'),
24+
field=models.ForeignKey(related_name='allocations', to='grants.Applicant', on_delete=models.CASCADE),
2525
preserve_default=True,
2626
),
2727
migrations.AlterField(
2828
model_name='allocation',
2929
name='resource',
30-
field=models.ForeignKey(related_name='allocations', to='grants.Resource'),
30+
field=models.ForeignKey(related_name='allocations', to='grants.Resource', on_delete=models.CASCADE),
3131
preserve_default=True,
3232
),
3333
migrations.AlterField(
3434
model_name='answer',
3535
name='applicant',
36-
field=models.ForeignKey(related_name='answers', to='grants.Applicant'),
36+
field=models.ForeignKey(related_name='answers', to='grants.Applicant', on_delete=models.CASCADE),
3737
preserve_default=True,
3838
),
3939
migrations.AlterField(
4040
model_name='answer',
4141
name='question',
42-
field=models.ForeignKey(related_name='answers', to='grants.Question'),
42+
field=models.ForeignKey(related_name='answers', to='grants.Question', on_delete=models.CASCADE),
4343
preserve_default=True,
4444
),
4545
migrations.AlterField(
4646
model_name='applicant',
4747
name='program',
48-
field=models.ForeignKey(related_name='applicants', to='grants.Program'),
48+
field=models.ForeignKey(related_name='applicants', to='grants.Program', on_delete=models.CASCADE),
4949
preserve_default=True,
5050
),
5151
migrations.AlterField(
5252
model_name='question',
5353
name='program',
54-
field=models.ForeignKey(related_name='questions', to='grants.Program'),
54+
field=models.ForeignKey(related_name='questions', to='grants.Program', on_delete=models.CASCADE),
5555
preserve_default=True,
5656
),
5757
migrations.AlterField(
5858
model_name='resource',
5959
name='program',
60-
field=models.ForeignKey(related_name='resources', to='grants.Program'),
60+
field=models.ForeignKey(related_name='resources', to='grants.Program', on_delete=models.CASCADE),
6161
preserve_default=True,
6262
),
6363
migrations.AlterField(
6464
model_name='score',
6565
name='applicant',
66-
field=models.ForeignKey(related_name='scores', to='grants.Applicant'),
66+
field=models.ForeignKey(related_name='scores', to='grants.Applicant', on_delete=models.CASCADE),
6767
preserve_default=True,
6868
),
6969
migrations.AlterField(
@@ -75,7 +75,7 @@ class Migration(migrations.Migration):
7575
migrations.AlterField(
7676
model_name='score',
7777
name='user',
78-
field=models.ForeignKey(related_name='scores', to=settings.AUTH_USER_MODEL),
78+
field=models.ForeignKey(related_name='scores', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE),
7979
preserve_default=True,
8080
),
8181
]

grants/models.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Resource(models.Model):
5656
("accomodation", "Accomodation"),
5757
]
5858

59-
program = models.ForeignKey(Program, related_name="resources")
59+
program = models.ForeignKey(Program, related_name="resources", on_delete=models.CASCADE)
6060
name = models.CharField(max_length=100)
6161
type = models.CharField(max_length=50, choices=TYPE_CHOICES)
6262
amount = models.PositiveIntegerField()
@@ -94,7 +94,7 @@ class Question(models.Model):
9494
("integer", "Integer value"),
9595
]
9696

97-
program = models.ForeignKey(Program, related_name="questions")
97+
program = models.ForeignKey(Program, related_name="questions", on_delete=models.CASCADE)
9898
type = models.CharField(max_length=50, choices=TYPE_CHOICES)
9999
question = models.TextField()
100100
required = models.BooleanField(default=False)
@@ -115,7 +115,7 @@ class Applicant(models.Model):
115115
Someone applying for a grant.
116116
"""
117117

118-
program = models.ForeignKey(Program, related_name="applicants")
118+
program = models.ForeignKey(Program, related_name="applicants", on_delete=models.CASCADE)
119119
name = models.TextField()
120120
email = models.EmailField()
121121

@@ -157,8 +157,8 @@ class Allocation(models.Model):
157157
An allocation of some Resources to an Applicant.
158158
"""
159159

160-
applicant = models.ForeignKey(Applicant, related_name="allocations")
161-
resource = models.ForeignKey(Resource, related_name="allocations")
160+
applicant = models.ForeignKey(Applicant, related_name="allocations", on_delete=models.CASCADE)
161+
resource = models.ForeignKey(Resource, related_name="allocations", on_delete=models.CASCADE)
162162
amount = models.PositiveIntegerField()
163163

164164
class Meta:
@@ -172,8 +172,8 @@ class Answer(models.Model):
172172
An applicant's answer to a question.
173173
"""
174174

175-
applicant = models.ForeignKey(Applicant, related_name="answers")
176-
question = models.ForeignKey(Question, related_name="answers")
175+
applicant = models.ForeignKey(Applicant, related_name="answers", on_delete=models.CASCADE)
176+
question = models.ForeignKey(Question, related_name="answers", on_delete=models.CASCADE)
177177
answer = models.TextField()
178178

179179
class Meta:
@@ -187,8 +187,8 @@ class Score(models.Model):
187187
A score and optional comment on an applicant by a user.
188188
"""
189189

190-
applicant = models.ForeignKey(Applicant, related_name="scores")
191-
user = models.ForeignKey("users.User", related_name="scores")
190+
applicant = models.ForeignKey(Applicant, related_name="scores", on_delete=models.CASCADE)
191+
user = models.ForeignKey("users.User", related_name="scores", on_delete=models.CASCADE)
192192
score = models.FloatField(blank=True, null=True, help_text="From 1 (terrible) to 5 (excellent)")
193193
comment = models.TextField(blank=True, null=True, help_text="Seen only by other voters, not by the applicant")
194194
score_history = models.TextField(blank=True, null=True)

grorg/heroku_settings.py

-16
This file was deleted.

grorg/settings.py

+26-12
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,22 @@
2020

2121
ALLOWED_HOSTS = []
2222

23-
TEMPLATE_DIRS = (
24-
os.path.join(BASE_DIR, "templates"),
25-
)
23+
24+
TEMPLATES = [
25+
{
26+
"BACKEND": "django.template.backends.django.DjangoTemplates",
27+
"DIRS": [os.path.join(BASE_DIR, "templates")],
28+
"APP_DIRS": True,
29+
"OPTIONS": {
30+
"context_processors": [
31+
"django.template.context_processors.debug",
32+
"django.template.context_processors.request",
33+
"django.contrib.auth.context_processors.auth",
34+
"django.contrib.messages.context_processors.messages",
35+
]
36+
},
37+
}
38+
]
2639

2740
LOGIN_REDIRECT_URL = "/"
2841

@@ -39,22 +52,23 @@
3952
'grants',
4053
)
4154

42-
MIDDLEWARE_CLASSES = (
43-
'whitenoise.middleware.WhiteNoiseMiddleware',
44-
'django.contrib.sessions.middleware.SessionMiddleware',
45-
'django.middleware.common.CommonMiddleware',
46-
'django.middleware.csrf.CsrfViewMiddleware',
47-
'django.contrib.auth.middleware.AuthenticationMiddleware',
48-
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
49-
'django.contrib.messages.middleware.MessageMiddleware',
50-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
55+
MIDDLEWARE = (
56+
"django.middleware.security.SecurityMiddleware",
57+
"whitenoise.middleware.WhiteNoiseMiddleware",
58+
"django.contrib.sessions.middleware.SessionMiddleware",
59+
"django.middleware.common.CommonMiddleware",
60+
"django.middleware.csrf.CsrfViewMiddleware",
61+
"django.contrib.auth.middleware.AuthenticationMiddleware",
62+
"django.contrib.messages.middleware.MessageMiddleware",
63+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5164
)
5265

5366
ROOT_URLCONF = 'grorg.urls'
5467

5568
WSGI_APPLICATION = 'grorg.wsgi.application'
5669

5770
AUTH_USER_MODEL = 'users.User'
71+
LOGOUT_REDIRECT_URL = '/'
5872

5973
# Database
6074
# https://docs.djangoproject.com/en/dev/ref/settings/#databases

grorg/urls.py

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
from django.conf.urls import include, url
2-
from django.contrib import admin
1+
from django.contrib import admin, auth
2+
from django.urls import path, re_path
33
from grants.views import program, bulk_load
4+
from users import views as users
45

56
urlpatterns = [
6-
url(r'^$', 'grants.views.program.index'),
7-
url(r'^login/$', 'users.views.login'),
8-
url(r'^logout/$', 'users.views.logout'),
9-
url(r'^register/$', 'users.views.register'),
10-
url(r'^join/$', 'users.views.join'),
11-
url(r'^admin/', include(admin.site.urls)),
12-
url(r'^(?P<program>[^/]+)/$', program.ProgramHome.as_view()),
13-
url(r'^(?P<program>[^/]+)/questions/$', program.ProgramQuestions.as_view()),
14-
url(r'^(?P<program>[^/]+)/questions/(?P<question_id>[^/]+)/$', program.ProgramQuestionEdit.as_view()),
15-
url(r'^(?P<program>[^/]+)/apply/$', program.ProgramApply.as_view()),
16-
url(r'^(?P<program>[^/]+)/apply/success/$', program.ProgramApplySuccess.as_view()),
17-
url(r'^(?P<program>[^/]+)/applicants/$', program.ProgramApplicants.as_view()),
18-
url(r'^(?P<program>[^/]+)/applicants/bulk/$', bulk_load.BulkLoadApplicants.as_view()),
19-
url(r'^(?P<program>[^/]+)/applicants/bulk_scores/$', bulk_load.BulkLoadScores.as_view()),
20-
url(r'^(?P<program>[^/]+)/applicants/random-unscored/$', program.RandomUnscoredApplicant.as_view()),
21-
url(r'^(?P<program>[^/]+)/applicants/(?P<applicant_id>[^/]+)/$', program.ProgramApplicantView.as_view()),
22-
url(r'^(?P<program>[^/]+)/applicants/(?P<applicant_id>[^/]+)/allocations/$', program.ApplicantAllocations.as_view()),
23-
url(r'^(?P<program>[^/]+)/resources/$', program.ProgramResources.as_view()),
24-
url(r'^(?P<program>[^/]+)/resources/(?P<resource_id>[^/]+)/$', program.ProgramResourceEdit.as_view()),
7+
path('', program.index),
8+
path("login/", auth.views.LoginView.as_view(template_name="login.html")),
9+
path("logout/", auth.views.LogoutView.as_view()),
10+
path('register/', users.register),
11+
path('join/', users.join),
12+
path('admin/', admin.site.urls),
13+
re_path(r'^(?P<program>[^/]+)/$', program.ProgramHome.as_view()),
14+
re_path(r'^(?P<program>[^/]+)/questions/$', program.ProgramQuestions.as_view()),
15+
re_path(r'^(?P<program>[^/]+)/questions/(?P<question_id>[^/]+)/$', program.ProgramQuestionEdit.as_view()),
16+
re_path(r'^(?P<program>[^/]+)/apply/$', program.ProgramApply.as_view()),
17+
re_path(r'^(?P<program>[^/]+)/apply/success/$', program.ProgramApplySuccess.as_view()),
18+
re_path(r'^(?P<program>[^/]+)/applicants/$', program.ProgramApplicants.as_view()),
19+
re_path(r'^(?P<program>[^/]+)/applicants/bulk/$', bulk_load.BulkLoadApplicants.as_view()),
20+
re_path(r'^(?P<program>[^/]+)/applicants/bulk_scores/$', bulk_load.BulkLoadScores.as_view()),
21+
re_path(r'^(?P<program>[^/]+)/applicants/random-unscored/$', program.RandomUnscoredApplicant.as_view()),
22+
re_path(r'^(?P<program>[^/]+)/applicants/(?P<applicant_id>[^/]+)/$', program.ProgramApplicantView.as_view()),
23+
re_path(r'^(?P<program>[^/]+)/applicants/(?P<applicant_id>[^/]+)/allocations/$', program.ApplicantAllocations.as_view()),
24+
re_path(r'^(?P<program>[^/]+)/resources/$', program.ProgramResources.as_view()),
25+
re_path(r'^(?P<program>[^/]+)/resources/(?P<resource_id>[^/]+)/$', program.ProgramResourceEdit.as_view()),
2526

2627
]

requirements.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
-r requirements/common.txt
2-
-r requirements/heroku.txt
1+
Django~=2.2.0
2+
whitenoise~=5.0.1
3+
urlman~=1.3

requirements/common.txt

-2
This file was deleted.

requirements/heroku.txt

-5
This file was deleted.

urlman/__init__.py

-1
This file was deleted.

0 commit comments

Comments
 (0)