Skip to content

Commit

Permalink
Upgrade to Django 2 (#42)
Browse files Browse the repository at this point in the history
* Upgrade to Django==2.0.13

* Add missing ON DELETE CASCADE to old migrations

* Upgrade to Django==2.2.17

Hoping to solve string type problem, in case related to python 3.9

* Replace auth_views.login/logout with auth_views.LoginView/LogoutView

* %s/MIDDLEWARE_CLASSES/MIDDLEWARE

* Update to default Django 2.2 middleware

* Resolve TypeError by removing byte qualifier in M2M fields in migrations

Was getting this error when trying to run migrations, the stack trace
pointing at M2M fields:
TypeError: attribute name must be string, not 'bytes'

* Drop parens from user.is_authenticated

* Change Login/LogoutView to Login/LogoutView.as_view()

* Nest login.html in registration dir

* Upgrade to 2.2.26

* Upgrade to sorl-thumbnail==12.4.1

Note: thumbnail.0001_initial migration was not in my django_migrataion
table, so after this upgrade I was prompted to apply the migration, which
then errored out because the thumbnail_kvstore table already exists.

Probably related to the issue here:
jazzband/sorl-thumbnail#458

To fix, I just manually added a row to django_migrations to indicate
that this migration was already applied.

* Upgrade to sorl-thumbnail==12.5.0

This fixes the bug on the UploadedImage admin (due to sorl thumbnail
widget compatibility)

* Upgrade all the way to sorl-thumbnail==12.7.0

* Upgrade to django-taggit==2.0.0

* Restore cors middleware (and upgrade package)
  • Loading branch information
katur authored Jan 21, 2022
1 parent e5961aa commit 0f3c310
Show file tree
Hide file tree
Showing 27 changed files with 59 additions and 38 deletions.
9 changes: 5 additions & 4 deletions birds/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down Expand Up @@ -39,7 +40,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='MinnesotaSpecies',
fields=[
('species', models.OneToOneField(primary_key=True, serialize=False, to='birds.Species')),
('species', models.OneToOneField(primary_key=True, serialize=False, to='birds.Species', on_delete=django.db.models.deletion.CASCADE)),
('include_in_book', models.NullBooleanField(default=None)),
('mou_status', models.CharField(max_length=50, verbose_name=b'MOU status', blank=True)),
('mou_breeding_status', models.NullBooleanField(default=None, verbose_name=b'MOU breeding status')),
Expand Down Expand Up @@ -80,19 +81,19 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='taxonomicgroup',
name='level',
field=models.ForeignKey(to='birds.TaxonomicLevel'),
field=models.ForeignKey(to='birds.TaxonomicLevel', on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='taxonomicgroup',
name='parent',
field=models.ForeignKey(blank=True, to='birds.TaxonomicGroup', null=True),
field=models.ForeignKey(blank=True, to='birds.TaxonomicGroup', null=True, on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='species',
name='parent',
field=models.ForeignKey(to='birds.TaxonomicGroup'),
field=models.ForeignKey(to='birds.TaxonomicGroup', on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
]
2 changes: 1 addition & 1 deletion birds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def bird(request, slug):

if actual_creation.is_public:
public_creations.append(actual_creation)
elif request.user.is_authenticated():
elif request.user.is_authenticated:
private_creations.append(actual_creation)
else:
continue
Expand Down
5 changes: 3 additions & 2 deletions creations/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -25,7 +26,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Book',
fields=[
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation')),
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation', on_delete=django.db.models.deletion.CASCADE)),
('purchase_url', models.CharField(max_length=500, blank=True)),
('photo', models.ImageField(null=True, upload_to=b'books', blank=True)),
('publisher', models.CharField(max_length=100, blank=True)),
Expand All @@ -42,7 +43,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='RadioProgram',
fields=[
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation')),
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation', on_delete=django.db.models.deletion.CASCADE)),
('original_air_date', models.DateField(null=True, blank=True)),
('file', models.FileField(null=True, upload_to=b'radio', blank=True)),
('supplemental_content_url', models.CharField(max_length=500, blank=True)),
Expand Down
5 changes: 3 additions & 2 deletions creations/migrations/0005_article_blogpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Article',
fields=[
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation')),
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation', on_delete=django.db.models.deletion.CASCADE)),
('published_by', models.CharField(max_length=100, blank=True)),
('date_published', models.DateField(null=True, blank=True)),
('url', models.URLField(blank=True)),
Expand All @@ -28,7 +29,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='BlogPost',
fields=[
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation')),
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation', on_delete=django.db.models.deletion.CASCADE)),
('url', models.URLField(blank=True)),
],
options={
Expand Down
3 changes: 2 additions & 1 deletion creations/migrations/0006_auto_20140912_2327.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Research',
fields=[
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation')),
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation', on_delete=django.db.models.deletion.CASCADE)),
('date', models.DateField(null=True, blank=True)),
('url', models.URLField(blank=True)),
('file', models.FileField(null=True, upload_to=b'research', blank=True)),
Expand Down
3 changes: 2 additions & 1 deletion creations/migrations/0009_research_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='research',
name='category',
field=models.ForeignKey(default=1, to='creations.ResearchCategory'),
field=models.ForeignKey(default=1, to='creations.ResearchCategory', on_delete=django.db.models.deletion.CASCADE),
preserve_default=False,
),
]
3 changes: 2 additions & 1 deletion creations/migrations/0015_webpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='WebPage',
fields=[
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation')),
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation', on_delete=django.db.models.deletion.CASCADE)),
('slug', models.SlugField(max_length=255, editable=False)),
('content', models.TextField(blank=True)),
],
Expand Down
3 changes: 2 additions & 1 deletion creations/migrations/0017_externalproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ExternalProject',
fields=[
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation')),
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation', on_delete=django.db.models.deletion.CASCADE)),
('url', models.URLField(blank=True)),
],
options={
Expand Down
3 changes: 2 additions & 1 deletion creations/migrations/0018_researchcategory_parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='researchcategory',
name='parent',
field=models.ForeignKey(blank=True, to='creations.ResearchCategory', null=True),
field=models.ForeignKey(blank=True, to='creations.ResearchCategory', null=True, on_delete=django.db.models.deletion.CASCADE),
preserve_default=True,
),
]
3 changes: 2 additions & 1 deletion creations/migrations/0020_abafieldguideimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ABAFieldGuideImage',
fields=[
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation')),
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation', on_delete=django.db.models.deletion.CASCADE)),
('filepath', models.CharField(max_length=500, blank=True)),
],
options={
Expand Down
3 changes: 2 additions & 1 deletion creations/migrations/0024_auto_20150726_1324.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,7 +15,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='SpeakingProgram',
fields=[
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation')),
('creation_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='creations.Creation', on_delete=django.db.models.deletion.CASCADE)),
],
options={
'ordering': ['-title'],
Expand Down
3 changes: 2 additions & 1 deletion creations/migrations/0027_speakingpresentationfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -19,7 +20,7 @@ class Migration(migrations.Migration):
('date', models.DateField(null=True, blank=True)),
('description', models.TextField(help_text=b'Use Markdown syntax for italics, bullets, etc. See <a href="http://www.darkcoding.net/software/markdown-quick-reference">a quick reference</a>, <a href="http://www.markdowntutorial.com/">a tutorial</a>, or practice <a href="http://dillinger.io/">here</a>. ', blank=True)),
('file', models.FileField(null=True, upload_to=b'presentations', blank=True)),
('program', models.ForeignKey(to='creations.SpeakingProgram')),
('program', models.ForeignKey(to='creations.SpeakingProgram', on_delete=django.db.models.deletion.CASCADE)),
],
),
]
3 changes: 2 additions & 1 deletion creations/migrations/0028_auto_20151017_1636.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -19,7 +20,7 @@ class Migration(migrations.Migration):
('date', models.DateField(null=True, blank=True)),
('description', models.TextField(help_text=b'Use Markdown syntax for italics, bullets, etc. See <a href="http://www.darkcoding.net/software/markdown-quick-reference">a quick reference</a>, <a href="http://www.markdowntutorial.com/">a tutorial</a>, or practice <a href="http://dillinger.io/">here</a>. ', blank=True)),
('file', models.FileField(null=True, upload_to=b'presentations', blank=True)),
('program', models.ForeignKey(to='creations.SpeakingProgram')),
('program', models.ForeignKey(to='creations.SpeakingProgram', on_delete=django.db.models.deletion.CASCADE)),
],
),
migrations.RemoveField(
Expand Down
3 changes: 2 additions & 1 deletion creations/migrations/0030_auto_20151017_1819.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -19,7 +20,7 @@ class Migration(migrations.Migration):
('date', models.DateField(null=True, blank=True)),
('description', models.TextField(help_text=b'Use Markdown syntax for italics, bullets, etc. See <a href="http://www.darkcoding.net/software/markdown-quick-reference">a quick reference</a>, <a href="http://www.markdowntutorial.com/">a tutorial</a>, or practice <a href="http://dillinger.io/">here</a>. ', blank=True)),
('file', models.FileField(null=True, upload_to=b'speaking', blank=True)),
('program', models.ForeignKey(to='creations.SpeakingProgram')),
('program', models.ForeignKey(to='creations.SpeakingProgram', on_delete=django.db.models.deletion.CASCADE)),
],
options={
'ordering': ['date'],
Expand Down
3 changes: 2 additions & 1 deletion creations/migrations/0032_book_cover_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -15,6 +16,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='book',
name='cover_photo',
field=models.ForeignKey(blank=True, to='website.UploadedImage', null=True),
field=models.ForeignKey(blank=True, to='website.UploadedImage', null=True, on_delete=django.db.models.deletion.CASCADE),
),
]
3 changes: 2 additions & 1 deletion creations/migrations/0034_radioprogramairdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -16,7 +17,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('date', models.DateField()),
('program', models.ForeignKey(to='creations.RadioProgram')),
('program', models.ForeignKey(to='creations.RadioProgram', on_delete=django.db.models.deletion.CASCADE)),
],
options={
'ordering': ['date'],
Expand Down
3 changes: 2 additions & 1 deletion creations/migrations/0036_radioprogram_original_air_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -14,6 +15,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='radioprogram',
name='original_air_date',
field=models.OneToOneField(null=True, blank=True, to='creations.RadioProgramAirDate'),
field=models.OneToOneField(null=True, blank=True, to='creations.RadioProgramAirDate', on_delete=django.db.models.deletion.CASCADE),
),
]
3 changes: 2 additions & 1 deletion creations/migrations/0045_auto_20151101_1411.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -16,7 +17,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('date', models.DateField()),
('program', models.ForeignKey(to='creations.RadioProgram')),
('program', models.ForeignKey(to='creations.RadioProgram', on_delete=django.db.models.deletion.CASCADE)),
],
options={
'ordering': ['-date'],
Expand Down
4 changes: 2 additions & 2 deletions creations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def miscellany(request):
"""
Render the landing page for miscellaneous projects.
"""
if request.user.is_authenticated():
if request.user.is_authenticated:
webpages = WebPage.objects.all()
else:
webpages = WebPage.objects.filter(is_public=True)
Expand Down Expand Up @@ -234,7 +234,7 @@ def research_category(request, id):
def research_item(request, id):
research_item = get_object_or_404(Research, id=id)

if not research_item.is_public and not request.user.is_authenticated():
if not research_item.is_public and not request.user.is_authenticated:
raise Http404

context = {
Expand Down
3 changes: 2 additions & 1 deletion forthebirds/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
'waystohelp',
]

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down
6 changes: 3 additions & 3 deletions forthebirds/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

urlpatterns += [
url(r'^admin/', admin.site.urls),
url(r'^login/$', auth_views.login, {'template_name': 'login.html'},
name='login_url'),
url(r'^logout/$', auth_views.logout, name='logout_url'),
url(r'^login/$', auth_views.LoginView.as_view(),
{'template_name': 'login.html'}, name='login_url'),
url(r'^logout/$', auth_views.LogoutView.as_view(), name='logout_url'),

url(r'^', include('website.urls')),
url(r'^(?P<path>bird\/Species\/.+)$', try_old_website),
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
certifi==2019.3.9
chardet==3.0.4
charset-normalizer==2.0.10
Django==1.11.29
django-cors-headers==1.1.0
Django==2.2.26
django-cors-headers==3.10.1
django-jquery==1.9.1
django-taggit==1.1.0
django-taggit==2.0.0
flickrapi==2.4.0
idna==2.8
Markdown==3.3.3
Expand All @@ -18,5 +18,5 @@ requests==2.27.1
requests-oauthlib==1.2.0
requests-toolbelt==0.9.1
six==1.12.0
sorl-thumbnail==12.3
sorl-thumbnail==12.7.0
urllib3==1.26.5
Loading

0 comments on commit 0f3c310

Please sign in to comment.