From 447213fa0c0edae0e15e29c2b4aeecc070d41ee5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= <trabarni@gmail.com>
Date: Fri, 26 Jan 2018 02:09:23 +0100
Subject: [PATCH] Upgrade to Django 2.0.1 & small improvments, fixes & update
 dependencies

---
 requirements/base.in                          |  5 ++--
 requirements/development.in                   |  3 +-
 requirements/development.txt                  | 27 ++++++++++++-----
 requirements/production.in                    |  2 ++
 requirements/production.txt                   | 25 ++++++++++++++++
 .../migrations/0005_auto_20180126_0135.py     | 20 +++++++++++++
 src/homework/models.py                        | 18 ++++++------
 src/homework/permissions.py                   | 18 ++----------
 .../migrations/0003_auto_20180126_0135.py     | 29 +++++++++++++++++++
 src/news/models.py                            |  5 ++--
 src/news/permissions.py                       |  6 +---
 src/news/serializers.py                       |  2 +-
 src/news/urls.py                              |  3 +-
 src/stats/urls.py                             |  1 -
 14 files changed, 119 insertions(+), 45 deletions(-)
 create mode 100644 requirements/production.in
 create mode 100644 requirements/production.txt
 create mode 100644 src/homework/migrations/0005_auto_20180126_0135.py
 create mode 100644 src/news/migrations/0003_auto_20180126_0135.py

diff --git a/requirements/base.in b/requirements/base.in
index 442a003..d38f35b 100644
--- a/requirements/base.in
+++ b/requirements/base.in
@@ -1,3 +1,4 @@
-Django==1.11.5
-djangorestframework==3.6.4
+Django==2.0.1
+djangorestframework==3.7.7
 django-social-authsch==0.1
+django-solo==1.1.3
diff --git a/requirements/development.in b/requirements/development.in
index a947995..d80fc62 100644
--- a/requirements/development.in
+++ b/requirements/development.in
@@ -1,4 +1,5 @@
 -r base.in
 flake8==3.4.1
 pip-tools==1.9.0
-django-extensions==1.9.1
+django-extensions==1.9.9
+python-language-server==0.13.0
diff --git a/requirements/development.txt b/requirements/development.txt
index 68babd8..2806f07 100644
--- a/requirements/development.txt
+++ b/requirements/development.txt
@@ -7,25 +7,38 @@
 certifi==2017.7.27.1      # via requests
 chardet==3.0.4            # via requests
 click==6.7                # via pip-tools
+configparser==3.5.0       # via python-language-server
 defusedxml==0.5.0         # via python3-openid, social-auth-core
-django-extensions==1.9.1
+django-extensions==1.9.9
 django-social-authsch==0.1
-django==1.11.5
-djangorestframework==3.6.4
+django-solo==1.1.3
+django==2.0.1
+djangorestframework==3.7.7
 first==2.0.1              # via pip-tools
 flake8==3.4.1
+future==0.16.0            # via python-language-server
 idna==2.6                 # via requests
-mccabe==0.6.1             # via flake8
+jedi==0.11.1              # via python-language-server
+json-rpc==1.10.8          # via python-language-server
+mccabe==0.6.1             # via flake8, python-language-server
 oauthlib==2.0.6           # via requests-oauthlib, social-auth-core
+parso==0.1.1              # via jedi
 pip-tools==1.9.0
-pycodestyle==2.3.1        # via flake8
-pyflakes==1.5.0           # via flake8
+pluggy==0.6.0             # via python-language-server
+pycodestyle==2.3.1        # via flake8, python-language-server
+pydocstyle==2.1.1         # via python-language-server
+pyflakes==1.5.0           # via flake8, python-language-server
 pyjwt==1.5.3              # via social-auth-core
+python-language-server==0.13.0
 python3-openid==3.1.0     # via social-auth-core
 pytz==2017.2              # via django
 requests-oauthlib==0.8.0  # via social-auth-core
 requests==2.18.4          # via requests-oauthlib, social-auth-core
-six==1.10.0               # via django-extensions, pip-tools, social-auth-app-django, social-auth-core
+rope==0.10.7              # via python-language-server
+six==1.10.0               # via django-extensions, pip-tools, pydocstyle, social-auth-app-django, social-auth-core
+snowballstemmer==1.2.1    # via pydocstyle
 social-auth-app-django==2.0.0  # via django-social-authsch
 social-auth-core==1.5.0   # via django-social-authsch, social-auth-app-django
+typing==3.6.4             # via django-extensions
 urllib3==1.22             # via requests
+yapf==0.20.1              # via python-language-server
diff --git a/requirements/production.in b/requirements/production.in
new file mode 100644
index 0000000..00a73ee
--- /dev/null
+++ b/requirements/production.in
@@ -0,0 +1,2 @@
+-r base.in
+gunicorn==19.7.1
diff --git a/requirements/production.txt b/requirements/production.txt
new file mode 100644
index 0000000..31199b0
--- /dev/null
+++ b/requirements/production.txt
@@ -0,0 +1,25 @@
+#
+# This file is autogenerated by pip-compile
+# To update, run:
+#
+#    pip-compile --output-file production.txt production.in
+#
+certifi==2018.1.18        # via requests
+chardet==3.0.4            # via requests
+defusedxml==0.5.0         # via python3-openid, social-auth-core
+django-social-authsch==0.1
+django-solo==1.1.3
+django==2.0.1
+djangorestframework==3.7.7
+gunicorn==19.7.1
+idna==2.6                 # via requests
+oauthlib==2.0.6           # via requests-oauthlib, social-auth-core
+pyjwt==1.5.3              # via social-auth-core
+python3-openid==3.1.0     # via social-auth-core
+pytz==2017.3              # via django
+requests-oauthlib==0.8.0  # via social-auth-core
+requests==2.18.4          # via requests-oauthlib, social-auth-core
+six==1.11.0               # via social-auth-app-django, social-auth-core
+social-auth-app-django==2.1.0  # via django-social-authsch
+social-auth-core==1.6.0   # via django-social-authsch, social-auth-app-django
+urllib3==1.22             # via requests
diff --git a/src/homework/migrations/0005_auto_20180126_0135.py b/src/homework/migrations/0005_auto_20180126_0135.py
new file mode 100644
index 0000000..0155be9
--- /dev/null
+++ b/src/homework/migrations/0005_auto_20180126_0135.py
@@ -0,0 +1,20 @@
+# Generated by Django 2.0.1 on 2018-01-26 00:35
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('homework', '0004_auto_20180125_1817'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='task',
+            name='created_by',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL),
+        ),
+    ]
diff --git a/src/homework/models.py b/src/homework/models.py
index 87772df..5a8b202 100644
--- a/src/homework/models.py
+++ b/src/homework/models.py
@@ -21,11 +21,11 @@ def validate_deadline(date):
 #         raise ValidationError(_('Please keep filesize under' + __MAX_UPLOAD_SIZE))
 
 class Task(models.Model):
-    title = models.CharField(max_length=150, )
-    date = models.DateTimeField(auto_now_add=True, editable=False, )
-    deadline = models.DateTimeField(validators=[validate_deadline], )
+    title = models.CharField(max_length=150)
+    date = models.DateTimeField(auto_now_add=True, editable=False)
+    deadline = models.DateTimeField(validators=[validate_deadline])
     text = models.TextField()
-    created_by = models.ForeignKey(User, )
+    created_by = models.ForeignKey(User, on_delete=models.DO_NOTHING)
     files = models.FileField(
         validators=[validators.FileExtensionValidator(
             'image/png',
@@ -48,11 +48,11 @@ class Task(models.Model):
 
 
 class Solution(models.Model):
-    task = models.ForeignKey(Task, related_name='task_solution', on_delete=models.CASCADE, )
+    task = models.ForeignKey(Task, related_name='task_solution', on_delete=models.CASCADE)
     # student = models.ForeignKey(account.models.Profile, related_name='student_solution',  on_delete=models.CASCADE)
-    date = models.DateTimeField(auto_now_add=True, editable=False, )
-    ready = models.BooleanField(default=False, )  # if(Soulution.date <= Task.deadline)
-    accepted = models.BooleanField(default=False, )
+    date = models.DateTimeField(auto_now_add=True, editable=False)
+    ready = models.BooleanField(default=False)  # if(Soulution.date <= Task.deadline)
+    accepted = models.BooleanField(default=False)
     files = models.FileField(
         validators=[validators.FileExtensionValidator(
             'image/png',
@@ -61,7 +61,7 @@ class Solution(models.Model):
         )],
         blank=True,
     )
-    created_by = models.ForeignKey(User, )
+    created_by = models.ForeignKey(User, on_delete=models.CASCADE)
     # files = myfields.RestrictedFileField(
     #     content_types=['image/png', 'image/jpeg', 'application/zip'],
     #     max_upload_size=MAX_UPLOAD_SIZE,
diff --git a/src/homework/permissions.py b/src/homework/permissions.py
index ef5e09c..8c1bc6a 100644
--- a/src/homework/permissions.py
+++ b/src/homework/permissions.py
@@ -8,11 +8,7 @@ class IsStaffOrReadOnly(BasePermission):
     """
 
     def has_permission(self, request, view):
-        return (
-            request.method in SAFE_METHODS or
-            request.user and
-            request.user.is_staff
-        )
+        return request.method in SAFE_METHODS or request.user and request.user.is_staff
 
 
 class IsAuthenticatedOrReadOnly(BasePermission):
@@ -21,11 +17,7 @@ class IsAuthenticatedOrReadOnly(BasePermission):
     """
 
     def has_permission(self, request, view):
-        return (
-            request.method in SAFE_METHODS or
-            request.user and
-            request.user.is_authenticated
-        )
+        return request.method in SAFE_METHODS or request.user and request.user.is_authenticated
 
 
 class IsStaffOrReadOnlyForAuthenticated(BasePermission):
@@ -34,8 +26,4 @@ class IsStaffOrReadOnlyForAuthenticated(BasePermission):
     The request is authenticated as a staff, or is a read-only request for authenticated.
     """
     def has_permission(self, request, view):
-        return (
-            request.user.is_staff or
-            request.method in SAFE_METHODS and
-            request.user.is_authenticated
-        )
+        return request.user.is_staff or request.method in SAFE_METHODS and request.user.is_authenticated
diff --git a/src/news/migrations/0003_auto_20180126_0135.py b/src/news/migrations/0003_auto_20180126_0135.py
new file mode 100644
index 0000000..744aef9
--- /dev/null
+++ b/src/news/migrations/0003_auto_20180126_0135.py
@@ -0,0 +1,29 @@
+# Generated by Django 2.0.1 on 2018-01-26 00:35
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('news', '0002_auto_20171220_1852'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='article',
+            old_name='date',
+            new_name='created_at',
+        ),
+        migrations.AddField(
+            model_name='article',
+            name='updated_at',
+            field=models.DateTimeField(auto_now=True),
+        ),
+        migrations.AlterField(
+            model_name='article',
+            name='author',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='author', to='account.Profile'),
+        ),
+    ]
diff --git a/src/news/models.py b/src/news/models.py
index b30275b..0714bf1 100644
--- a/src/news/models.py
+++ b/src/news/models.py
@@ -3,10 +3,11 @@ from account.models import Profile
 
 
 class Article(models.Model):
-    author = models.ForeignKey(Profile, related_name="author")
+    author = models.ForeignKey(Profile, related_name="author", on_delete=models.DO_NOTHING)
     title = models.CharField(null=False, max_length=200)
     text = models.TextField()
-    date = models.DateTimeField(auto_now_add=True)
+    created_at = models.DateTimeField(auto_now_add=True, editable=False)
+    updated_at = models.DateTimeField(auto_now=True, editable=False)
 
     def __str__(self):
         return self.title
diff --git a/src/news/permissions.py b/src/news/permissions.py
index af200e5..c8405be 100644
--- a/src/news/permissions.py
+++ b/src/news/permissions.py
@@ -3,9 +3,5 @@ from rest_framework.permissions import SAFE_METHODS
 
 
 class IsStaffOrReadOnlyForAuthenticated(BasePermission):
-
     def has_permission(self, request, view):
-        return (request.user.is_staff or
-                request.method in SAFE_METHODS and
-                request.user.is_authenticated
-                )
+        return request.user.is_staff or request.method in SAFE_METHODS and request.user.is_authenticated
diff --git a/src/news/serializers.py b/src/news/serializers.py
index ced9a8a..6da75f5 100644
--- a/src/news/serializers.py
+++ b/src/news/serializers.py
@@ -5,4 +5,4 @@ from rest_framework import serializers
 class ArticleListSerializer(serializers.ModelSerializer):
     class Meta:
         model = Article
-        fields = '__all__'
+        fields = serializers.ALL_FIELDS
diff --git a/src/news/urls.py b/src/news/urls.py
index b08ebdd..d71ed82 100644
--- a/src/news/urls.py
+++ b/src/news/urls.py
@@ -2,8 +2,7 @@ from rest_framework import routers
 from news import views
 
 
-router = routers.DefaultRouter(trailing_slash=False)
-
+router = routers.DefaultRouter()
 router.register(r'news', views.NewsViewSet)
 
 urlpatterns = router.urls
diff --git a/src/stats/urls.py b/src/stats/urls.py
index 7c03811..ef0f4e2 100644
--- a/src/stats/urls.py
+++ b/src/stats/urls.py
@@ -5,5 +5,4 @@ from . import views
 router = routers.DefaultRouter()
 router.register(r'events', views.KszkEventViewSet)
 
-# app_name = 'stats'
 urlpatterns = router.urls
-- 
GitLab