From 904080f95fe3b8d739fa0a45aa3788fc1e9d0587 Mon Sep 17 00:00:00 2001 From: Amelia He Date: Mon, 3 Jun 2019 17:07:23 -0700 Subject: [PATCH 01/13] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cece88d2e..13d950e2a 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ include_package_data=True, install_requires=[ 'django == 1.11.20', - 'djangorestframework == 3.6.2', + 'djangorestframework == 3.9.1', 'pillow', 'requests', 'jsonfield', From 1b17fb5b315539b8f7521e7b71437f664deb8076 Mon Sep 17 00:00:00 2001 From: Amelia He Date: Tue, 4 Jun 2019 12:13:19 -0700 Subject: [PATCH 02/13] updated to django 2.2 --- dispatch/admin/urls.py | 10 +++++----- dispatch/api/mixins.py | 4 ++-- dispatch/api/urls.py | 6 +++--- dispatch/default_settings.py | 2 +- dispatch/modules/actions/models.py | 4 ++-- dispatch/modules/content/models.py | 26 ++++++++++++------------- dispatch/modules/podcasts/models.py | 8 ++++---- dispatch/modules/podcasts/urls.py | 4 ++-- dispatch/tests/helpers.py | 2 +- dispatch/tests/test_admin.py | 2 +- dispatch/tests/test_api_articles.py | 2 +- dispatch/tests/test_api_auth.py | 2 +- dispatch/tests/test_api_files.py | 2 +- dispatch/tests/test_api_imagegallery.py | 2 +- dispatch/tests/test_api_images.py | 4 ++-- dispatch/tests/test_api_invites.py | 2 +- dispatch/tests/test_api_pages.py | 2 +- dispatch/tests/test_api_persons.py | 2 +- dispatch/tests/test_api_polls.py | 2 +- dispatch/tests/test_api_sections.py | 2 +- dispatch/tests/test_api_subsections.py | 2 +- dispatch/tests/test_api_tags.py | 2 +- dispatch/tests/test_api_topics.py | 2 +- dispatch/tests/test_api_users.py | 2 +- dispatch/tests/test_api_videos.py | 2 +- dispatch/tests/test_api_zones.py | 2 +- dispatch/tests/test_embeds.py | 2 +- dispatch/tests/urls.py | 6 +++--- setup.py | 4 ++-- 29 files changed, 57 insertions(+), 57 deletions(-) diff --git a/dispatch/admin/urls.py b/dispatch/admin/urls.py index aece9b571..c023167c9 100644 --- a/dispatch/admin/urls.py +++ b/dispatch/admin/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url +from django.urls import re_path from django.contrib.auth import views as auth_views from django.conf import settings from django.shortcuts import render_to_response @@ -16,9 +16,9 @@ def admin(request): return render_to_response('manager/index.html', context) urlpatterns = [ - url(r'signup/(?P[0-9a-f-]+)/', views.signup, name='dispatch-signup'), - url(r'reset/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})', + re_path(r'signup/(?P[0-9a-f-]+)/', views.signup, name='dispatch-signup'), + re_path(r'reset/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})', auth_views.password_reset_confirm, name='password_reset_confirm'), - url(r'reset/done', auth_views.password_reset_complete, name='password_reset_complete'), - url(r'.*', admin, name='dispatch-admin') + re_path(r'reset/done', auth_views.password_reset_complete, name='password_reset_complete'), + re_path(r'.*', admin, name='dispatch-admin') ] diff --git a/dispatch/api/mixins.py b/dispatch/api/mixins.py index 203d6c98a..d30b80b15 100644 --- a/dispatch/api/mixins.py +++ b/dispatch/api/mixins.py @@ -31,7 +31,7 @@ class DispatchPublishableMixin(object): def get_publishable_queryset(self): # Only show unpublished articles to authenticated users - if self.request.user.is_authenticated(): + if self.request.user.is_authenticated: queryset = self.model.objects.all() version = self.request.query_params.get('version', None) @@ -93,7 +93,7 @@ def __init__(self, *args, **kwargs): def is_authenticated(self): return (self.context.get('request') and - self.context.get('request').user.is_authenticated()) + self.context.get('request').user.is_authenticated) def hide_authenticated_fields(self): """Hides authenticated_fields if request context is missing or diff --git a/dispatch/api/urls.py b/dispatch/api/urls.py index 59e28c19b..beac3cec6 100644 --- a/dispatch/api/urls.py +++ b/dispatch/api/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url +from django.urls import re_path from rest_framework import routers from rest_framework.urlpatterns import format_suffix_patterns @@ -35,6 +35,6 @@ urlpatterns = format_suffix_patterns([ # Dashboard routes - url(r'^dashboard/recent', dashboard_recent_articles, name='dashboard_recent_articles'), - url(r'^dashboard/actions', dashboard_user_actions, name='dashboard_user_actions') + re_path(r'^dashboard/recent', dashboard_recent_articles, name='dashboard_recent_articles'), + re_path(r'^dashboard/actions', dashboard_user_actions, name='dashboard_user_actions') ]) + router.urls diff --git a/dispatch/default_settings.py b/dispatch/default_settings.py index f0bb8f5a5..cfa240e8d 100644 --- a/dispatch/default_settings.py +++ b/dispatch/default_settings.py @@ -74,7 +74,7 @@ 'DATETIME_INPUT_FORMATS': ['iso-8601'] } -MIDDLEWARE_CLASSES = [ +MIDDLEWARE = [ 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', diff --git a/dispatch/modules/actions/models.py b/dispatch/modules/actions/models.py index 1f0b3875a..1a17da50d 100644 --- a/dispatch/modules/actions/models.py +++ b/dispatch/modules/actions/models.py @@ -1,9 +1,9 @@ -from django.db.models import Model, ForeignKey, CharField, DateTimeField, PositiveIntegerField +from django.db.models import Model, ForeignKey, CharField, DateTimeField, PositiveIntegerField, CASCADE from dispatch.modules.auth.models import User class Action(Model): - user = ForeignKey(User) + user = ForeignKey(User, on_delete=CASCADE) action = CharField(max_length=50) object_type = CharField(max_length=50) object_id = PositiveIntegerField() diff --git a/dispatch/modules/content/models.py b/dispatch/modules/content/models.py index 3852b1691..aaaf842d3 100644 --- a/dispatch/modules/content/models.py +++ b/dispatch/modules/content/models.py @@ -57,7 +57,7 @@ class Section(Model): slug = SlugField(unique=True) class Author(Model): - person = ForeignKey(Person) + person = ForeignKey(Person, on_delete=SET_NULL) order = PositiveIntegerField() type = CharField(blank=True, default='author', max_length=100) @@ -321,13 +321,13 @@ class Meta: abstract = True class Article(Publishable, AuthorMixin): - parent = ForeignKey('Article', related_name='article_parent', blank=True, null=True) + parent = ForeignKey('Article', on_delete=CASCADE, related_name='article_parent', blank=True, null=True) headline = CharField(max_length=255) - section = ForeignKey('Section') - subsection = ForeignKey('Subsection', related_name='article_subsection', blank=True, null=True) + section = ForeignKey('Section', on_delete=SET_NULL) + subsection = ForeignKey('Subsection', on_delete=SET_NULL,related_name='article_subsection', blank=True, null=True) authors = ManyToManyField('Author', related_name='article_authors') - topic = ForeignKey('Topic', null=True) + topic = ForeignKey('Topic', on_delete=SET_NULL, null=True) tags = ManyToManyField('Tag') is_breaking = BooleanField(default=False) @@ -414,7 +414,7 @@ class Subsection(Model, AuthorMixin): slug = SlugField(unique=True) description = TextField(null=True, blank=True) authors = ManyToManyField('Author', related_name='subsection_authors') - section = ForeignKey('Section') + section = ForeignKey('Section', on_delete=SET_NULL) is_active = BooleanField(default=False) AuthorModel = Author @@ -434,8 +434,8 @@ def get_absolute_url(self): return "%s%s/" % (settings.BASE_URL, self.slug) class Page(Publishable): - parent = ForeignKey('Page', related_name='page_parent', blank=True, null=True) - parent_page = ForeignKey('Page', related_name='parent_page_fk', null=True) + parent = ForeignKey('Page', on_delete=SET_NULL, related_name='page_parent', blank=True, null=True) + parent_page = ForeignKey('Page', on_delete=SET_NULL, related_name='parent_page_fk', null=True) title = CharField(max_length=255) class Meta: @@ -600,8 +600,8 @@ def save_tags(self, tag_ids): pass class VideoAttachment(Model): - article = ForeignKey(Article, blank=True, null=True, related_name='video_article') - page = ForeignKey(Page, blank=True, null=True, related_name='video_page') + article = ForeignKey(Article, on_delete=SET_NULL, blank=True, null=True, related_name='video_article') + page = ForeignKey(Page, on_delete=SET_NULL, blank=True, null=True, related_name='video_page') caption = TextField(blank=True, null=True) credit = TextField(blank=True, null=True) @@ -610,9 +610,9 @@ class VideoAttachment(Model): order = PositiveIntegerField(null=True) class ImageAttachment(Model): - article = ForeignKey(Article, blank=True, null=True, related_name='image_article') - page = ForeignKey(Page, blank=True, null=True, related_name='image_page') - gallery = ForeignKey('ImageGallery', blank=True, null=True) + article = ForeignKey(Article, on_delete=SET_NULL, blank=True, null=True, related_name='image_article') + page = ForeignKey(Page, on_delete=SET_NULL, blank=True, null=True, related_name='image_page') + gallery = ForeignKey('ImageGallery', on_delete=SET_NULL, blank=True, null=True) caption = TextField(blank=True, null=True) credit = TextField(blank=True, null=True) diff --git a/dispatch/modules/podcasts/models.py b/dispatch/modules/podcasts/models.py index 0d0e35cc9..735ee2405 100644 --- a/dispatch/modules/podcasts/models.py +++ b/dispatch/modules/podcasts/models.py @@ -8,7 +8,7 @@ from django.db.models import ( Model, DateTimeField, CharField, TextField, PositiveIntegerField, ImageField, FileField, BooleanField, UUIDField, ForeignKey, - SlugField, EmailField) + SlugField, EmailField, SET_NULL) from dispatch.modules.content.models import Image from dispatch.core.storage import generate_signed_url @@ -50,7 +50,7 @@ class Podcast(Model): owner_name = CharField(max_length=255) owner_email = EmailField(max_length=255) - image = ForeignKey(Image, null=True) + image = ForeignKey(Image, on_delete=SET_NULL, null=True) category = CharField( max_length=255, @@ -71,14 +71,14 @@ def __init__(self, *args, **kwargs): id = UUIDField(primary_key=True, default=uuid.uuid4) - podcast = ForeignKey(Podcast) + podcast = ForeignKey(Podcast, on_delete=SET_NULL) title = CharField(max_length=255) description = TextField() author = CharField(max_length=255) - image = ForeignKey(Image, null=True) + image = ForeignKey(Image, on_delete=SET_NULL, null=True) duration = PositiveIntegerField(null=True) type = CharField(max_length=255) diff --git a/dispatch/modules/podcasts/urls.py b/dispatch/modules/podcasts/urls.py index 8b9b15073..efae99977 100644 --- a/dispatch/modules/podcasts/urls.py +++ b/dispatch/modules/podcasts/urls.py @@ -1,6 +1,6 @@ -from django.conf.urls import url +from django.urls import re_path from dispatch.modules.podcasts.feeds import PodcastFeed urlpatterns = [ - url(r'^(?P[-\w]+)/', PodcastFeed(), name='podcast'), + re_path(r'^(?P[-\w]+)/', PodcastFeed(), name='podcast'), ] diff --git a/dispatch/tests/helpers.py b/dispatch/tests/helpers.py index 5253c5d7b..384f2a50c 100644 --- a/dispatch/tests/helpers.py +++ b/dispatch/tests/helpers.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status diff --git a/dispatch/tests/test_admin.py b/dispatch/tests/test_admin.py index 1f4da55ca..1a52d99fa 100644 --- a/dispatch/tests/test_admin.py +++ b/dispatch/tests/test_admin.py @@ -1,5 +1,5 @@ from django.test import TestCase -from django.core.urlresolvers import reverse +from django.urls import reverse class AdminTests(TestCase): def test_admin_index(self): diff --git a/dispatch/tests/test_api_articles.py b/dispatch/tests/test_api_articles.py index 9d0e67836..d7b6e9942 100644 --- a/dispatch/tests/test_api_articles.py +++ b/dispatch/tests/test_api_articles.py @@ -1,5 +1,5 @@ import datetime -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status diff --git a/dispatch/tests/test_api_auth.py b/dispatch/tests/test_api_auth.py index 60d6e1043..a838f95e2 100644 --- a/dispatch/tests/test_api_auth.py +++ b/dispatch/tests/test_api_auth.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from django.core.exceptions import ObjectDoesNotExist from rest_framework import status diff --git a/dispatch/tests/test_api_files.py b/dispatch/tests/test_api_files.py index 452249dc4..924a4c899 100644 --- a/dispatch/tests/test_api_files.py +++ b/dispatch/tests/test_api_files.py @@ -7,7 +7,7 @@ from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from dispatch.models import File from dispatch.tests.helpers import DispatchTestHelpers diff --git a/dispatch/tests/test_api_imagegallery.py b/dispatch/tests/test_api_imagegallery.py index dcc8334bb..4ed93749e 100644 --- a/dispatch/tests/test_api_imagegallery.py +++ b/dispatch/tests/test_api_imagegallery.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status diff --git a/dispatch/tests/test_api_images.py b/dispatch/tests/test_api_images.py index ddc47ab2b..a9f26b100 100644 --- a/dispatch/tests/test_api_images.py +++ b/dispatch/tests/test_api_images.py @@ -7,7 +7,7 @@ from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from dispatch.models import Image, Person, Tag @@ -75,7 +75,7 @@ def test_create_image_png(self): with open(self.get_input_file(image_file), 'rb') as test_image: response = self.client.post(url, { 'img': test_image }, format='multipart') - self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue(self.fileExists(response.data['url'])) # Assert that resized versions were created diff --git a/dispatch/tests/test_api_invites.py b/dispatch/tests/test_api_invites.py index 7f2cebf32..b3e457593 100644 --- a/dispatch/tests/test_api_invites.py +++ b/dispatch/tests/test_api_invites.py @@ -2,7 +2,7 @@ from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from django.conf import settings from django.contrib.auth import authenticate diff --git a/dispatch/tests/test_api_pages.py b/dispatch/tests/test_api_pages.py index 6c714bae2..123890bbf 100644 --- a/dispatch/tests/test_api_pages.py +++ b/dispatch/tests/test_api_pages.py @@ -1,6 +1,6 @@ from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from urllib import request from dispatch.tests.cases import DispatchAPITestCase, DispatchMediaTestMixin from dispatch.tests.helpers import DispatchTestHelpers diff --git a/dispatch/tests/test_api_persons.py b/dispatch/tests/test_api_persons.py index e8d6e557f..86abc23b5 100644 --- a/dispatch/tests/test_api_persons.py +++ b/dispatch/tests/test_api_persons.py @@ -1,7 +1,7 @@ from os.path import join from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from django.conf import settings from dispatch.tests.cases import DispatchAPITestCase, DispatchMediaTestMixin diff --git a/dispatch/tests/test_api_polls.py b/dispatch/tests/test_api_polls.py index 60a304fc9..d02dcfbd3 100644 --- a/dispatch/tests/test_api_polls.py +++ b/dispatch/tests/test_api_polls.py @@ -1,7 +1,7 @@ from collections import OrderedDict from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from dispatch.tests.cases import DispatchAPITestCase from dispatch.tests.helpers import DispatchTestHelpers diff --git a/dispatch/tests/test_api_sections.py b/dispatch/tests/test_api_sections.py index 36dca10dd..57229decc 100644 --- a/dispatch/tests/test_api_sections.py +++ b/dispatch/tests/test_api_sections.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status diff --git a/dispatch/tests/test_api_subsections.py b/dispatch/tests/test_api_subsections.py index 41d427540..e18bbf79a 100644 --- a/dispatch/tests/test_api_subsections.py +++ b/dispatch/tests/test_api_subsections.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status diff --git a/dispatch/tests/test_api_tags.py b/dispatch/tests/test_api_tags.py index 5d589167e..d80f15e90 100644 --- a/dispatch/tests/test_api_tags.py +++ b/dispatch/tests/test_api_tags.py @@ -1,6 +1,6 @@ from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from dispatch.tests.cases import DispatchAPITestCase from dispatch.tests.helpers import DispatchTestHelpers diff --git a/dispatch/tests/test_api_topics.py b/dispatch/tests/test_api_topics.py index 6f322d559..26090bae9 100644 --- a/dispatch/tests/test_api_topics.py +++ b/dispatch/tests/test_api_topics.py @@ -1,6 +1,6 @@ from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from dispatch.tests.cases import DispatchAPITestCase from dispatch.tests.helpers import DispatchTestHelpers diff --git a/dispatch/tests/test_api_users.py b/dispatch/tests/test_api_users.py index 90b8c552a..343b9f527 100644 --- a/dispatch/tests/test_api_users.py +++ b/dispatch/tests/test_api_users.py @@ -1,6 +1,6 @@ from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from django.conf import settings from django.contrib.auth import authenticate from rest_framework.authtoken.models import Token diff --git a/dispatch/tests/test_api_videos.py b/dispatch/tests/test_api_videos.py index c83782a29..5ff931754 100644 --- a/dispatch/tests/test_api_videos.py +++ b/dispatch/tests/test_api_videos.py @@ -1,6 +1,6 @@ from rest_framework import status -from django.core.urlresolvers import reverse +from django.urls import reverse from dispatch.tests.cases import DispatchAPITestCase from dispatch.tests.helpers import DispatchTestHelpers diff --git a/dispatch/tests/test_api_zones.py b/dispatch/tests/test_api_zones.py index ebdf187a1..0878f7ad3 100644 --- a/dispatch/tests/test_api_zones.py +++ b/dispatch/tests/test_api_zones.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from rest_framework import status diff --git a/dispatch/tests/test_embeds.py b/dispatch/tests/test_embeds.py index 5e973bf2a..1c72743b1 100644 --- a/dispatch/tests/test_embeds.py +++ b/dispatch/tests/test_embeds.py @@ -1,5 +1,5 @@ from django.template import loader -from django.core.urlresolvers import reverse +from django.urls import reverse from dispatch.modules.content.embeds import embeds, EmbedException, ListEmbed, HeaderEmbed, CodeEmbed from dispatch.models import ImageGallery diff --git a/dispatch/tests/urls.py b/dispatch/tests/urls.py index ecab7a843..1a010f8cc 100644 --- a/dispatch/tests/urls.py +++ b/dispatch/tests/urls.py @@ -1,8 +1,8 @@ -from django.conf.urls import include, url +from django.urls import include, re_path from dispatch.urls import admin_urls, api_urls urlpatterns = [ - url(r'^admin/', include(admin_urls)), - url(r'^api/', include(api_urls)), + re_path(r'^admin/', include(admin_urls)), + re_path(r'^api/', include(api_urls)), ] diff --git a/setup.py b/setup.py index 13d950e2a..820c173da 100644 --- a/setup.py +++ b/setup.py @@ -11,8 +11,8 @@ scripts=['dispatch/bin/dispatch-admin'], include_package_data=True, install_requires=[ - 'django == 1.11.20', - 'djangorestframework == 3.9.1', + 'django == 2.2', + 'djangorestframework == 3.6.2', 'pillow', 'requests', 'jsonfield', From fe9e64c8140564bb4e683ddecde9e5955278a96b Mon Sep 17 00:00:00 2001 From: Amelia He Date: Tue, 4 Jun 2019 14:26:51 -0700 Subject: [PATCH 03/13] Update test_api_images.py --- dispatch/tests/test_api_images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dispatch/tests/test_api_images.py b/dispatch/tests/test_api_images.py index a9f26b100..f6c3a69ce 100644 --- a/dispatch/tests/test_api_images.py +++ b/dispatch/tests/test_api_images.py @@ -75,7 +75,7 @@ def test_create_image_png(self): with open(self.get_input_file(image_file), 'rb') as test_image: response = self.client.post(url, { 'img': test_image }, format='multipart') - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertTrue(self.fileExists(response.data['url'])) # Assert that resized versions were created From 03ec8459e57ef184c90a9aed8cea73aec4731123 Mon Sep 17 00:00:00 2001 From: Amelia He Date: Tue, 4 Jun 2019 14:54:41 -0700 Subject: [PATCH 04/13] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 820c173da..0f02ad762 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ scripts=['dispatch/bin/dispatch-admin'], include_package_data=True, install_requires=[ - 'django == 2.2', + 'django == 2.0.13', 'djangorestframework == 3.6.2', 'pillow', 'requests', From 07f34703a6facc04f7dc6803c2513873e2de002f Mon Sep 17 00:00:00 2001 From: Amelia He Date: Tue, 4 Jun 2019 14:57:08 -0700 Subject: [PATCH 05/13] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0f02ad762..35bc3d714 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ include_package_data=True, install_requires=[ 'django == 2.0.13', - 'djangorestframework == 3.6.2', + 'djangorestframework >=3.9.1', 'pillow', 'requests', 'jsonfield', From f52116e5ce55bb6fe7fb480033e8672a9f861cac Mon Sep 17 00:00:00 2001 From: Amelia He Date: Tue, 4 Jun 2019 15:08:15 -0700 Subject: [PATCH 06/13] Changed conflicting conflict of cascade --- dispatch/modules/content/models.py | 10 +++++----- dispatch/modules/podcasts/models.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dispatch/modules/content/models.py b/dispatch/modules/content/models.py index aaaf842d3..e5655b9c3 100644 --- a/dispatch/modules/content/models.py +++ b/dispatch/modules/content/models.py @@ -14,7 +14,7 @@ from django.db.models import ( Model, DateTimeField, CharField, TextField, PositiveIntegerField, ImageField, FileField, BooleanField, NullBooleanField, UUIDField, - ForeignKey, ManyToManyField, SlugField, SET_NULL, CASCADE, F) + ForeignKey, ManyToManyField, SlugField, SET_NULL, CASCADE) from django.conf import settings from django.core.validators import MaxValueValidator from django.utils import timezone @@ -57,7 +57,7 @@ class Section(Model): slug = SlugField(unique=True) class Author(Model): - person = ForeignKey(Person, on_delete=SET_NULL) + person = ForeignKey(Person, on_delete=CASCADE) order = PositiveIntegerField() type = CharField(blank=True, default='author', max_length=100) @@ -321,10 +321,10 @@ class Meta: abstract = True class Article(Publishable, AuthorMixin): - parent = ForeignKey('Article', on_delete=CASCADE, related_name='article_parent', blank=True, null=True) + parent = ForeignKey('Article', on_delete=SET_NULL, related_name='article_parent', blank=True, null=True) headline = CharField(max_length=255) - section = ForeignKey('Section', on_delete=SET_NULL) + section = ForeignKey('Section', on_delete=CASCADE) subsection = ForeignKey('Subsection', on_delete=SET_NULL,related_name='article_subsection', blank=True, null=True) authors = ManyToManyField('Author', related_name='article_authors') topic = ForeignKey('Topic', on_delete=SET_NULL, null=True) @@ -414,7 +414,7 @@ class Subsection(Model, AuthorMixin): slug = SlugField(unique=True) description = TextField(null=True, blank=True) authors = ManyToManyField('Author', related_name='subsection_authors') - section = ForeignKey('Section', on_delete=SET_NULL) + section = ForeignKey('Section', on_delete=CASCADE) is_active = BooleanField(default=False) AuthorModel = Author diff --git a/dispatch/modules/podcasts/models.py b/dispatch/modules/podcasts/models.py index 735ee2405..cf18d6604 100644 --- a/dispatch/modules/podcasts/models.py +++ b/dispatch/modules/podcasts/models.py @@ -8,7 +8,7 @@ from django.db.models import ( Model, DateTimeField, CharField, TextField, PositiveIntegerField, ImageField, FileField, BooleanField, UUIDField, ForeignKey, - SlugField, EmailField, SET_NULL) + SlugField, EmailField, SET_NULL, CASCADE) from dispatch.modules.content.models import Image from dispatch.core.storage import generate_signed_url @@ -71,7 +71,7 @@ def __init__(self, *args, **kwargs): id = UUIDField(primary_key=True, default=uuid.uuid4) - podcast = ForeignKey(Podcast, on_delete=SET_NULL) + podcast = ForeignKey(Podcast, on_delete=CASCADE) title = CharField(max_length=255) description = TextField() From 3be55a005395ace97630174eba02d0c9dd4ff1ff Mon Sep 17 00:00:00 2001 From: Amelia He Date: Tue, 4 Jun 2019 15:15:13 -0700 Subject: [PATCH 07/13] Update models.py --- dispatch/modules/content/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dispatch/modules/content/models.py b/dispatch/modules/content/models.py index e5655b9c3..b110cb429 100644 --- a/dispatch/modules/content/models.py +++ b/dispatch/modules/content/models.py @@ -14,7 +14,7 @@ from django.db.models import ( Model, DateTimeField, CharField, TextField, PositiveIntegerField, ImageField, FileField, BooleanField, NullBooleanField, UUIDField, - ForeignKey, ManyToManyField, SlugField, SET_NULL, CASCADE) + ForeignKey, ManyToManyField, SlugField, SET_NULL, CASCADE, F) from django.conf import settings from django.core.validators import MaxValueValidator from django.utils import timezone From 43b04d4d6a9825c19a90eb124180fc7e51f3e571 Mon Sep 17 00:00:00 2001 From: Razvan Nesiu Date: Wed, 5 Jun 2019 16:19:50 -0700 Subject: [PATCH 08/13] Freeze djangorestframework to 3.7.7 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 35bc3d714..5747c7241 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ include_package_data=True, install_requires=[ 'django == 2.0.13', - 'djangorestframework >=3.9.1', + 'djangorestframework == 3.7.7', 'pillow', 'requests', 'jsonfield', From f0d4a7a2757b08b7035f979eba1cef062d6cff1c Mon Sep 17 00:00:00 2001 From: Amelia He Date: Wed, 5 Jun 2019 16:22:00 -0700 Subject: [PATCH 09/13] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 35bc3d714..a3aedb540 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ include_package_data=True, install_requires=[ 'django == 2.0.13', - 'djangorestframework >=3.9.1', + 'djangorestframework ==3.7.3', 'pillow', 'requests', 'jsonfield', From c8364777bf5a554aed37318799c67675a5eee233 Mon Sep 17 00:00:00 2001 From: Razvan Nesiu Date: Fri, 7 Jun 2019 16:40:46 -0700 Subject: [PATCH 10/13] Add support for Django 2.2.2 --- dispatch/admin/urls.py | 6 +++--- dispatch/api/serializers.py | 1 + dispatch/api/views.py | 3 +-- dispatch/templates/manager/index.html | 2 +- dispatch/tests/test_fields.py | 5 +++-- dispatch/theme/fields.py | 3 ++- setup.py | 4 ++-- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dispatch/admin/urls.py b/dispatch/admin/urls.py index c023167c9..473b8cd91 100644 --- a/dispatch/admin/urls.py +++ b/dispatch/admin/urls.py @@ -1,5 +1,5 @@ from django.urls import re_path -from django.contrib.auth import views as auth_views +from django.contrib.auth.views import PasswordResetConfirmView, PasswordResetCompleteView from django.conf import settings from django.shortcuts import render_to_response from dispatch.admin import views @@ -18,7 +18,7 @@ def admin(request): urlpatterns = [ re_path(r'signup/(?P[0-9a-f-]+)/', views.signup, name='dispatch-signup'), re_path(r'reset/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})', - auth_views.password_reset_confirm, name='password_reset_confirm'), - re_path(r'reset/done', auth_views.password_reset_complete, name='password_reset_complete'), + PasswordResetConfirmView, name='password_reset_confirm'), + re_path(r'reset/done', PasswordResetCompleteView, name='password_reset_complete'), re_path(r'.*', admin, name='dispatch-admin') ] diff --git a/dispatch/api/serializers.py b/dispatch/api/serializers.py index a8ab59926..dfb4015d1 100644 --- a/dispatch/api/serializers.py +++ b/dispatch/api/serializers.py @@ -1,6 +1,7 @@ from rest_framework import serializers from rest_framework.exceptions import ValidationError from rest_framework.validators import UniqueValidator +from django.core.validators import ProhibitNullCharactersValidator from django.conf import settings diff --git a/dispatch/api/views.py b/dispatch/api/views.py index 537cb97cc..41360c339 100644 --- a/dispatch/api/views.py +++ b/dispatch/api/views.py @@ -321,7 +321,6 @@ class VideoViewSet(DispatchModelViewSet): def get_queryset(self): queryset = Video.objects.order_by('-updated_at') - author = self.request.query_params.get('author', None) tags = self.request.query_params.getlist('tags', None) q = self.request.query_params.get('q', None) @@ -592,7 +591,7 @@ def create(self, request): email = request.data.get('email', None) password = request.data.get('password', None) - user = authenticate(username=email, password=password) + user = authenticate(request, username=email, password=password) if user is not None and user.is_active: (token, created) = Token.objects.get_or_create(user=user) diff --git a/dispatch/templates/manager/index.html b/dispatch/templates/manager/index.html index 02b3c10c7..51e8a6cbd 100644 --- a/dispatch/templates/manager/index.html +++ b/dispatch/templates/manager/index.html @@ -1,4 +1,4 @@ -{% load staticfiles %} +{% load static %} diff --git a/dispatch/tests/test_fields.py b/dispatch/tests/test_fields.py index b6dbf6d87..d76462c2f 100644 --- a/dispatch/tests/test_fields.py +++ b/dispatch/tests/test_fields.py @@ -7,6 +7,7 @@ ModelField, WidgetField, Field, DateTimeField, IntegerField, BoolField, SelectField ) +from django.db import NotSupportedError from dispatch.theme.widgets import Zone, Widget from dispatch.tests.cases import DispatchAPITestCase, DispatchMediaTestMixin from dispatch.tests.helpers import DispatchTestHelpers @@ -487,8 +488,8 @@ def test_not_implemented_validate_method(self): try: testfield.validate(data) - self.fail('Code should have failed with NotImplementedError') - except NotImplementedError: + self.fail('Code should have failed with NotSupportedError') + except NotSupportedError: pass def test_image_singular_data(self): diff --git a/dispatch/theme/fields.py b/dispatch/theme/fields.py index 8703a1999..158d10cdd 100644 --- a/dispatch/theme/fields.py +++ b/dispatch/theme/fields.py @@ -3,6 +3,7 @@ from django.db.models import Case, When from django.utils.dateparse import parse_datetime from django.core.exceptions import ObjectDoesNotExist +from django.db import NotSupportedError from dispatch.models import Article, Image, Poll, PodcastEpisode from dispatch.api.serializers import ( @@ -54,7 +55,7 @@ def __init__(self, label, many=False, required=False): def validate(self, data): """Validates the field data""" - raise NotImplementedError + raise NotSupportedError def to_json(self, data): """Returns JSON representation of field data""" diff --git a/setup.py b/setup.py index 5747c7241..601871c3a 100644 --- a/setup.py +++ b/setup.py @@ -11,8 +11,8 @@ scripts=['dispatch/bin/dispatch-admin'], include_package_data=True, install_requires=[ - 'django == 2.0.13', - 'djangorestframework == 3.7.7', + 'django == 2.2.2', + 'djangorestframework == 3.8.2', 'pillow', 'requests', 'jsonfield', From 61d014d09730f4368c3b1723094a8b0adff970c8 Mon Sep 17 00:00:00 2001 From: Razvan Nesiu Date: Fri, 7 Jun 2019 17:05:27 -0700 Subject: [PATCH 11/13] Add migration for SET_NULL, CA --- .../migrations/0025_upgrade_to_django2.py | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 dispatch/migrations/0025_upgrade_to_django2.py diff --git a/dispatch/migrations/0025_upgrade_to_django2.py b/dispatch/migrations/0025_upgrade_to_django2.py new file mode 100644 index 000000000..d8aef1014 --- /dev/null +++ b/dispatch/migrations/0025_upgrade_to_django2.py @@ -0,0 +1,149 @@ +# Generated by Django 2.2.2 on 2019-06-07 23:53 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('dispatch', '0024_video_meta_fields'), + ] + + operations = [ + migrations.AlterField( + model_name='article', + name='parent', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='article_parent', to='dispatch.Article'), + ), + migrations.AlterField( + model_name='article', + name='reading_time', + field=models.CharField(choices=[('anytime', 'Anytime'), ('morning', 'Morning'), ('midday', 'Midday'), ('evening', 'Evening')], default='anytime', max_length=100), + ), + migrations.AlterField( + model_name='article', + name='subsection', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='article_subsection', to='dispatch.Subsection'), + ), + migrations.AlterField( + model_name='article', + name='template', + field=models.CharField(default='default', max_length=255), + ), + migrations.AlterField( + model_name='article', + name='topic', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='dispatch.Topic'), + ), + migrations.AlterField( + model_name='author', + name='type', + field=models.CharField(blank=True, default='author', max_length=100), + ), + migrations.AlterField( + model_name='file', + name='file', + field=models.FileField(upload_to='files/%Y/%m'), + ), + migrations.AlterField( + model_name='image', + name='img', + field=models.ImageField(upload_to='images/%Y/%m'), + ), + migrations.AlterField( + model_name='imageattachment', + name='article', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='image_article', to='dispatch.Article'), + ), + migrations.AlterField( + model_name='imageattachment', + name='gallery', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='dispatch.ImageGallery'), + ), + migrations.AlterField( + model_name='imageattachment', + name='page', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='image_page', to='dispatch.Page'), + ), + migrations.AlterField( + model_name='integration', + name='settings', + field=models.TextField(default='{}'), + ), + migrations.AlterField( + model_name='invite', + name='permissions', + field=models.CharField(default='', max_length=255), + ), + migrations.AlterField( + model_name='issue', + name='file', + field=models.FileField(upload_to='issues/%Y/%m'), + ), + migrations.AlterField( + model_name='issue', + name='img', + field=models.ImageField(upload_to='images/%Y/%m'), + ), + migrations.AlterField( + model_name='page', + name='parent', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='page_parent', to='dispatch.Page'), + ), + migrations.AlterField( + model_name='page', + name='parent_page', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='parent_page_fk', to='dispatch.Page'), + ), + migrations.AlterField( + model_name='page', + name='template', + field=models.CharField(default='default', max_length=255), + ), + migrations.AlterField( + model_name='person', + name='image', + field=models.ImageField(null=True, upload_to='images'), + ), + migrations.AlterField( + model_name='podcast', + name='category', + field=models.CharField(choices=[('Arts', 'Arts'), ('Business', 'Business'), ('Comedy', 'Comedy'), ('Education', 'Education'), ('Games & Hobbies', 'Games & Hobbies'), ('Government & Organizations', 'Government & Organizations'), ('Health', 'Health'), ('Kids & Family', 'Kids & Family'), ('Music', 'Music'), ('News & Politics', 'News & Politics'), ('Religion & Spirituality', 'Religion & Spirituality'), ('Science & Medicine', 'Science & Medicine'), ('Society & Culture', 'Society & Culture'), ('Sports & Recreation', 'Sports & Recreation'), ('Technology', 'Technology'), ('TV & Film', 'TV & Film')], default='Arts', max_length=255), + ), + migrations.AlterField( + model_name='podcast', + name='explicit', + field=models.CharField(choices=[('No', 'No'), ('Yes', 'Yes'), ('Clean', 'Clean')], default='No', max_length=5), + ), + migrations.AlterField( + model_name='podcast', + name='image', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='dispatch.Image'), + ), + migrations.AlterField( + model_name='podcastepisode', + name='explicit', + field=models.CharField(choices=[('No', 'No'), ('Yes', 'Yes'), ('Clean', 'Clean')], default='No', max_length=5), + ), + migrations.AlterField( + model_name='podcastepisode', + name='file', + field=models.FileField(upload_to='podcasts/'), + ), + migrations.AlterField( + model_name='podcastepisode', + name='image', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='dispatch.Image'), + ), + migrations.AlterField( + model_name='videoattachment', + name='article', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='video_article', to='dispatch.Article'), + ), + migrations.AlterField( + model_name='videoattachment', + name='page', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='video_page', to='dispatch.Page'), + ), + ] From c639e9506d0425f77441cad59801fce1546e3939 Mon Sep 17 00:00:00 2001 From: Razvan Nesiu Date: Fri, 7 Jun 2019 17:24:11 -0700 Subject: [PATCH 12/13] Remove unused import --- dispatch/api/serializers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dispatch/api/serializers.py b/dispatch/api/serializers.py index dfb4015d1..a8ab59926 100644 --- a/dispatch/api/serializers.py +++ b/dispatch/api/serializers.py @@ -1,7 +1,6 @@ from rest_framework import serializers from rest_framework.exceptions import ValidationError from rest_framework.validators import UniqueValidator -from django.core.validators import ProhibitNullCharactersValidator from django.conf import settings From 099adfb7d775b5efec7d11bb35ef81c56b87ecd8 Mon Sep 17 00:00:00 2001 From: Razvan Nesiu Date: Thu, 20 Jun 2019 10:42:26 -0700 Subject: [PATCH 13/13] Fix migrations for django update to v2.2.2 --- .../{0024_video_meta_fields.py => 0022_video_meta_fields.py} | 2 +- .../{0025_upgrade_to_django2.py => 0023_upgrade_to_django2.py} | 2 +- ...blishable_constraints.py => 0024_publishable_constraints.py} | 2 +- ...aints_default.py => 0025_publishable_constraints_default.py} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename dispatch/migrations/{0024_video_meta_fields.py => 0022_video_meta_fields.py} (94%) rename dispatch/migrations/{0025_upgrade_to_django2.py => 0023_upgrade_to_django2.py} (99%) rename dispatch/migrations/{0022_publishable_constraints.py => 0024_publishable_constraints.py} (98%) rename dispatch/migrations/{0023_publishable_constraints_default.py => 0025_publishable_constraints_default.py} (96%) diff --git a/dispatch/migrations/0024_video_meta_fields.py b/dispatch/migrations/0022_video_meta_fields.py similarity index 94% rename from dispatch/migrations/0024_video_meta_fields.py rename to dispatch/migrations/0022_video_meta_fields.py index e7ab8553d..1a6dff5b4 100644 --- a/dispatch/migrations/0024_video_meta_fields.py +++ b/dispatch/migrations/0022_video_meta_fields.py @@ -9,7 +9,7 @@ class Migration(migrations.Migration): dependencies = [ - ('dispatch', '0023_publishable_constraints_default'), + ('dispatch', '0021_podcast_fields'), ] operations = [ diff --git a/dispatch/migrations/0025_upgrade_to_django2.py b/dispatch/migrations/0023_upgrade_to_django2.py similarity index 99% rename from dispatch/migrations/0025_upgrade_to_django2.py rename to dispatch/migrations/0023_upgrade_to_django2.py index d8aef1014..684437531 100644 --- a/dispatch/migrations/0025_upgrade_to_django2.py +++ b/dispatch/migrations/0023_upgrade_to_django2.py @@ -7,7 +7,7 @@ class Migration(migrations.Migration): dependencies = [ - ('dispatch', '0024_video_meta_fields'), + ('dispatch', '0022_video_meta_fields'), ] operations = [ diff --git a/dispatch/migrations/0022_publishable_constraints.py b/dispatch/migrations/0024_publishable_constraints.py similarity index 98% rename from dispatch/migrations/0022_publishable_constraints.py rename to dispatch/migrations/0024_publishable_constraints.py index bf0efc577..cb4faef03 100644 --- a/dispatch/migrations/0022_publishable_constraints.py +++ b/dispatch/migrations/0024_publishable_constraints.py @@ -56,7 +56,7 @@ def remove_duplicates(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('dispatch', '0021_podcast_fields'), + ('dispatch', '0023_upgrade_to_django2'), ] operations = [ diff --git a/dispatch/migrations/0023_publishable_constraints_default.py b/dispatch/migrations/0025_publishable_constraints_default.py similarity index 96% rename from dispatch/migrations/0023_publishable_constraints_default.py rename to dispatch/migrations/0025_publishable_constraints_default.py index 7f37f5b4e..c758ced5e 100644 --- a/dispatch/migrations/0023_publishable_constraints_default.py +++ b/dispatch/migrations/0025_publishable_constraints_default.py @@ -9,7 +9,7 @@ class Migration(migrations.Migration): dependencies = [ - ('dispatch', '0022_publishable_constraints'), + ('dispatch', '0024_publishable_constraints'), ] operations = [