Skip to content

Commit

Permalink
Merge pull request #946 from ubyssey/django2.2
Browse files Browse the repository at this point in the history
Upgrade Django to 2.2 LTS
  • Loading branch information
razvannesiu authored Jun 20, 2019
2 parents f230005 + 099adfb commit 16664c1
Show file tree
Hide file tree
Showing 36 changed files with 357 additions and 64 deletions.
14 changes: 7 additions & 7 deletions dispatch/admin/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.urls import re_path
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
Expand All @@ -16,9 +16,9 @@ def admin(request):
return render_to_response('manager/index.html', context)

urlpatterns = [
url(r'signup/(?P<uuid>[0-9a-f-]+)/', views.signup, name='dispatch-signup'),
url(r'reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[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'signup/(?P<uuid>[0-9a-f-]+)/', views.signup, name='dispatch-signup'),
re_path(r'reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})',
PasswordResetConfirmView, name='password_reset_confirm'),
re_path(r'reset/done', PasswordResetCompleteView, name='password_reset_complete'),
re_path(r'.*', admin, name='dispatch-admin')
]
4 changes: 2 additions & 2 deletions dispatch/api/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions dispatch/api/urls.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions dispatch/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dispatch/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
149 changes: 149 additions & 0 deletions dispatch/migrations/0023_upgrade_to_django2.py
Original file line number Diff line number Diff line change
@@ -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', '0022_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 &amp; Hobbies', 'Games & Hobbies'), ('Government &amp; Organizations', 'Government & Organizations'), ('Health', 'Health'), ('Kids &amp; Family', 'Kids & Family'), ('Music', 'Music'), ('News &amp; Politics', 'News & Politics'), ('Religion &amp; Spirituality', 'Religion & Spirituality'), ('Science &amp; Medicine', 'Science & Medicine'), ('Society &amp; Culture', 'Society & Culture'), ('Sports &amp; Recreation', 'Sports & Recreation'), ('Technology', 'Technology'), ('TV &amp; 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'),
),
]
92 changes: 92 additions & 0 deletions dispatch/migrations/0024_publishable_constraints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-10-30 18:59

from django.db import migrations, models

from dispatch.models import Article, Page

def fix_latest_head(model, item):
latest = model.objects. \
filter(parent=item.parent). \
order_by('-id')[0]

model.objects. \
filter(parent=item.parent). \
update(head=None)

latest.head = True
latest.save(revision=False)

duplicates = model.objects. \
filter(slug=item.slug). \
exclude(parent=item.parent). \
delete()

def fix_latest_published(model, item):
latest_items = model.objects. \
filter(parent_id=item.parent_id, is_published=True). \
order_by('-id')

if not latest_items:
return

model.objects. \
filter(parent=item.parent). \
update(is_published=None)

latest = latest_items[0]
latest.is_published = True
latest.save(revision=False)

def fix_items(model):
seen = set()
for item in model.objects.order_by('-id'):
if item.slug in seen:
continue

fix_latest_head(model, item)
fix_latest_published(model, item)

seen.add(item.slug)

def remove_duplicates(apps, schema_editor):
fix_items(Article)
fix_items(Page)

class Migration(migrations.Migration):

dependencies = [
('dispatch', '0023_upgrade_to_django2'),
]

operations = [
migrations.AlterField(
model_name='article',
name='head',
field=models.NullBooleanField(db_index=True, default=False),
),
migrations.AlterField(
model_name='article',
name='is_published',
field=models.NullBooleanField(db_index=True, default=False),
),
migrations.AlterField(
model_name='page',
name='head',
field=models.NullBooleanField(db_index=True, default=False),
),
migrations.AlterField(
model_name='page',
name='is_published',
field=models.NullBooleanField(db_index=True, default=False),
),
migrations.RunPython(remove_duplicates),
migrations.AlterUniqueTogether(
name='article',
unique_together=set([('parent', 'slug', 'is_published'), ('slug', 'head'), ('parent', 'slug', 'head')]),
),
migrations.AlterUniqueTogether(
name='page',
unique_together=set([('parent', 'slug', 'is_published'), ('slug', 'head'), ('parent', 'slug', 'head')]),
),
]
51 changes: 51 additions & 0 deletions dispatch/migrations/0025_publishable_constraints_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2019-05-05 22:30
from __future__ import unicode_literals

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('dispatch', '0024_publishable_constraints'),
]

operations = [
migrations.AlterField(
model_name='article',
name='head',
field=models.NullBooleanField(db_index=True, default=None),
),
migrations.AlterField(
model_name='article',
name='is_active',
field=models.NullBooleanField(default=True),
),
migrations.AlterField(
model_name='article',
name='is_published',
field=models.NullBooleanField(db_index=True, default=None),
),
migrations.AlterField(
model_name='page',
name='head',
field=models.NullBooleanField(db_index=True, default=None),
),
migrations.AlterField(
model_name='page',
name='is_active',
field=models.NullBooleanField(default=True),
),
migrations.AlterField(
model_name='page',
name='is_published',
field=models.NullBooleanField(db_index=True, default=None),
),
migrations.AlterField(
model_name='topic',
name='slug',
field=models.SlugField(max_length=255, unique=True),
),
]
4 changes: 2 additions & 2 deletions dispatch/modules/actions/models.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Loading

0 comments on commit 16664c1

Please sign in to comment.