Skip to content

Commit

Permalink
Migrate to Django2, drop Python2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Nov 6, 2018
1 parent f438256 commit 0adce5c
Show file tree
Hide file tree
Showing 70 changed files with 382 additions and 291 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ language: python
cache: pip

python:
- 2.7
- 3.4
- 3.5
- 3.6
- 3.7

addons:
mariadb: '10.1'
Expand Down
21 changes: 21 additions & 0 deletions daiquiri/archive/migrations/0005_django2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.1.3 on 2018-11-05 16:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('daiquiri_archive', '0004_python3'),
]

operations = [
migrations.AlterModelOptions(
name='archivejob',
options={'ordering': ('start_time',), 'verbose_name': 'ArchiveJob', 'verbose_name_plural': 'ArchiveJobs'},
),
migrations.AlterModelOptions(
name='collection',
options={'ordering': ('name',), 'verbose_name': 'Collection', 'verbose_name_plural': 'Collections'},
),
]
9 changes: 1 addition & 8 deletions daiquiri/archive/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging
import os
import six
import uuid

from django.conf import settings
from django.contrib.auth.models import Group
from django.db import models
from django.http.request import QueryDict
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from rest_framework.exceptions import ValidationError
Expand All @@ -25,7 +23,6 @@
logger = logging.getLogger(__name__)


@python_2_unicode_compatible
class Collection(models.Model):

objects = AccessLevelManager()
Expand All @@ -51,8 +48,6 @@ class Meta:
verbose_name = _('Collection')
verbose_name_plural = _('Collections')

permissions = (('view_collection', 'Can view Collection'),)

def __str__(self):
return self.name

Expand All @@ -76,8 +71,6 @@ class Meta:
verbose_name = _('ArchiveJob')
verbose_name_plural = _('ArchiveJobs')

permissions = (('view_archivejob', 'Can view ArchiveJob'),)


@property
def file_path(self):
Expand Down Expand Up @@ -139,7 +132,7 @@ def process(self):
})

# get the index of the path column in the row
path_index = six.next((i for i, column in enumerate(settings.ARCHIVE_COLUMNS) if column['name'] == 'path'))
path_index = next((i for i, column in enumerate(settings.ARCHIVE_COLUMNS) if column['name'] == 'path'))

for row in rows:
# append the file to the list of files only if it exists on the filesystem
Expand Down
2 changes: 0 additions & 2 deletions daiquiri/archive/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, unicode_literals

import logging
import os
import zipfile
Expand Down
2 changes: 1 addition & 1 deletion daiquiri/archive/tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.test import TestCase

from test_generator.viewsets import TestViewsetMixin, TestListViewsetMixin
Expand Down
7 changes: 4 additions & 3 deletions daiquiri/archive/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.conf.urls import url, include
from django.urls import include, path

from rest_framework import routers

from .views import ArchiveView
from .viewsets import RowViewSet, ColumnViewSet, FileViewSet, ArchiveViewSet

app_name = 'archive'

router = routers.DefaultRouter()
router.register(r'rows', RowViewSet, base_name='row')
Expand All @@ -13,8 +14,8 @@
router.register(r'archives', ArchiveViewSet, base_name='archive')

urlpatterns = [
url(r'^$', ArchiveView.as_view(), name='archive'),
path('', ArchiveView.as_view(), name='archive'),

# rest api
url(r'^api/', include(router.urls)),
path('api/', include(router.urls)),
]
2 changes: 1 addition & 1 deletion daiquiri/archive/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def create(self, request):

except ArchiveJob.DoesNotExist:
archive_job = ArchiveJob(
owner=(None if self.request.user.is_anonymous() else self.request.user),
owner=(None if self.request.user.is_anonymous else self.request.user),
client_ip=get_client_ip(self.request),
data=request.data
)
Expand Down
2 changes: 1 addition & 1 deletion daiquiri/auth/adapter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from django.conf import settings
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.http import HttpResponseRedirect

from allauth.account.adapter import DefaultAccountAdapter
Expand Down
17 changes: 17 additions & 0 deletions daiquiri/auth/migrations/0012_django2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.1.3 on 2018-11-05 16:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('daiquiri_auth', '0011_meta'),
]

operations = [
migrations.AlterModelOptions(
name='profile',
options={'ordering': ('user__last_name', 'user__last_name', 'user__username'), 'verbose_name': 'Profile', 'verbose_name_plural': 'Profiles'},
),
]
9 changes: 2 additions & 7 deletions daiquiri/auth/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from __future__ import unicode_literals

import logging

from django.contrib.auth.models import User
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from jsonfield import JSONField
Expand All @@ -21,10 +18,10 @@
logger = logging.getLogger(__name__)


@python_2_unicode_compatible
class Profile(models.Model):

user = models.OneToOneField(User)
user = models.OneToOneField(User, on_delete=models.CASCADE)

is_pending = models.BooleanField(
default=False,
help_text='Designates whether the user waiting on confirmation by a manager.')
Expand All @@ -45,8 +42,6 @@ class Meta:
verbose_name = _('Profile')
verbose_name_plural = _('Profiles')

permissions = (('view_profile', 'Can view Profile'),)

def __str__(self):
return self.user.username

Expand Down
2 changes: 1 addition & 1 deletion daiquiri/auth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def update(self, obj, validated_data):
# update the user for this profile seperately
obj.user.first_name = user['first_name']
obj.user.last_name = user['last_name']
obj.user.groups = user['groups']
obj.user.groups.set(user['groups'])
obj.user.save()

return super(ProfileSerializer, self).update(obj, validated_data)
Expand Down
2 changes: 1 addition & 1 deletion daiquiri/auth/tests/test_accounts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.test import TestCase

from ..models import Profile
Expand Down
20 changes: 10 additions & 10 deletions daiquiri/auth/urls_accounts.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from django.conf.urls import url, include
from django.urls import include, re_path
from django.views.generic import TemplateView

from .views import profile_update, profile_json, token, logout, password_change, password_set


urlpatterns = [
url(r'^profile/$', profile_update, name='account_profile'),
url(r'^profile.json/$', profile_json, name='account_profile_json'),
url(r'^token/$', token, name='account_token'),
url(r'^pending/$', TemplateView.as_view(template_name='account/account_pending.html'), name='account_pending'),
re_path(r'^profile/$', profile_update, name='account_profile'),
re_path(r'^profile.json/$', profile_json, name='account_profile_json'),
re_path(r'^token/$', token, name='account_token'),
re_path(r'^pending/$', TemplateView.as_view(template_name='account/account_pending.html'), name='account_pending'),

# override login by allauth to remove wordpress cookies
url(r"^logout/$", logout, name="account_logout"),
re_path(r"^logout/$", logout, name="account_logout"),

# include allauth patterns
url(r'^password/change/$', password_change, name='account_change_password'),
url(r'^password/change/done/$', TemplateView.as_view(template_name='account/password_change_done.html'), name='account_change_password_done'),
url(r'^password/set/$', password_set, name='account_password_set'),
url(r'^', include('allauth.urls')),
re_path(r'^password/change/$', password_change, name='account_change_password'),
re_path(r'^password/change/done/$', TemplateView.as_view(template_name='account/password_change_done.html'), name='account_change_password_done'),
re_path(r'^password/set/$', password_set, name='account_password_set'),
re_path(r'^', include('allauth.urls')),
]
9 changes: 6 additions & 3 deletions daiquiri/auth/urls_auth.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from django.conf.urls import url, include
from django.urls import include, path

from rest_framework import routers

from .views import UsersView
from .viewsets import ProfileViewSet, GroupViewSet


app_name = 'auth'

router = routers.DefaultRouter()
router.register(r'profiles', ProfileViewSet)
router.register(r'groups', GroupViewSet)

urlpatterns = [
# user management
url(r'^users/', UsersView.as_view(), name='users'),
path('users/', UsersView.as_view(), name='users'),

# rest api
url(r'^api/', include(router.urls)),
path('api/', include(router.urls)),
]
2 changes: 1 addition & 1 deletion daiquiri/auth/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.contrib.auth.models import User, Permission
from django.db.models import Q

Expand Down
2 changes: 1 addition & 1 deletion daiquiri/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.urls import reverse
from daiquiri.core.utils import get_referer_path_info, get_next
from django.views.generic import TemplateView
from django.http import HttpResponseRedirect, JsonResponse
Expand Down
5 changes: 3 additions & 2 deletions daiquiri/conesearch/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.conf.urls import url
from django.urls import re_path

from .viewsets import ConeSearchView

app_name = 'conesearch'

urlpatterns = [
url(r'^api/(?P<resource>.+)/$', ConeSearchView.as_view(), name='search'),
re_path(r'^api/(?P<resource>.+)/$', ConeSearchView.as_view(), name='search'),
]
17 changes: 17 additions & 0 deletions daiquiri/contact/migrations/0005_django2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.1.3 on 2018-11-05 16:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('daiquiri_contact', '0004_meta'),
]

operations = [
migrations.AlterModelOptions(
name='contactmessage',
options={'ordering': ('-created', 'author'), 'verbose_name': 'Contact message', 'verbose_name_plural': 'Contact messages'},
),
]
6 changes: 0 additions & 6 deletions daiquiri/contact/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from __future__ import unicode_literals

from django.contrib.auth.models import User
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _


@python_2_unicode_compatible
class ContactMessage(models.Model):

STATUS_ACTIVE = 'ACTIVE'
Expand Down Expand Up @@ -34,8 +30,6 @@ class Meta:
verbose_name = _('Contact message')
verbose_name_plural = _('Contact messages')

permissions = (('view_contactmessage', 'Can view ContactMessage'),)

def __str__(self):
return "created=%s; email=%s; subject=%s; status=%s" % (self.created, self.email, self.subject, self.status)

Expand Down
11 changes: 7 additions & 4 deletions daiquiri/contact/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from django.conf.urls import url, include
from django.urls import include, path

from rest_framework import routers

from .views import contact, MessagesView
from .viewsets import ContactMessageViewSet, StatusViewSet


app_name = 'contact'

router = routers.DefaultRouter()
router.register(r'messages', ContactMessageViewSet, base_name='message')
router.register(r'status', StatusViewSet, base_name='status')

urlpatterns = [
url(r'^$', contact, name='contact'),
url(r'^messages/', MessagesView.as_view(), name='messages'),
path('', contact, name='contact'),
path('messages/', MessagesView.as_view(), name='messages'),

# rest api
url(r'^api/', include(router.urls)),
path('api/', include(router.urls)),
]
4 changes: 1 addition & 3 deletions daiquiri/core/adapter/database/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import six

from django.db import connections


Expand Down Expand Up @@ -122,7 +120,7 @@ def _process_filtering(self, sql, sql_args, search, filters, escaped_column_name
escaped_column_name = self.escape_identifier(column_name)

# check if the filter is a list or a string
if isinstance(column_filter, six.string_types):
if isinstance(column_filter, str):
filter_list = [column_filter]
elif isinstance(column_filter, list):
filter_list = column_filter
Expand Down
3 changes: 1 addition & 2 deletions daiquiri/core/adapter/download/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import csv
import six
import subprocess
import re

Expand Down Expand Up @@ -75,7 +74,7 @@ def generate_rows(self, prepend=None):
if insert_result:
line = insert_result.group(1)
reader = csv.reader([line], quotechar="'", skipinitialspace=True)
row = six.next(reader)
row = next(reader)

if prepend:
yield [(prepend[i] + cell if (i in prepend and cell != 'NULL') else cell) for i, cell in enumerate(row)]
Expand Down
3 changes: 2 additions & 1 deletion daiquiri/core/management/commands/rabbitcreate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from urllib.parse import urlparse

from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils.six.moves.urllib.parse import urlparse


class Command(BaseCommand):
Expand Down
Loading

0 comments on commit 0adce5c

Please sign in to comment.