From 9672d53fa066951c4bfee2f846de0510e0c7922a Mon Sep 17 00:00:00 2001 From: Marion Chardon Date: Mon, 12 Mar 2018 17:25:32 +0100 Subject: [PATCH 1/3] deprecated db parameters --- adim_project/adim/models/annotables.py | 8 ++++---- adim_project/adim/models/annotations.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/adim_project/adim/models/annotables.py b/adim_project/adim/models/annotables.py index 4f34b6c..0a3aed6 100644 --- a/adim_project/adim/models/annotables.py +++ b/adim_project/adim/models/annotables.py @@ -102,7 +102,7 @@ class AnObj(models.Model): uuid = models.CharField(max_length=32, unique=True, blank=True) name = models.CharField(max_length=125) - owner = models.ForeignKey(User, verbose_name=_("owner"), related_name='anobjs') + owner = models.ForeignKey(User, verbose_name=_("owner"), related_name='anobjs', on_delete=models.CASCADE) owners = models.ManyToManyField(User, verbose_name=_("owners"), related_name='owned_anobjs', blank=True) locked = models.BooleanField(verbose_name=_("locked"), default=False) @@ -245,8 +245,8 @@ PUBLISHING_MODES = ( class AnObjMembership(models.Model): - anobj = models.ForeignKey(AnObj) - user = models.ForeignKey(User) + anobj = models.ForeignKey(AnObj, on_delete=models.CASCADE) + user = models.ForeignKey(User, on_delete=models.CASCADE) publish_mode = models.IntegerField(choices=PUBLISHING_MODES, default=0) class Meta: @@ -255,7 +255,7 @@ class AnObjMembership(models.Model): class EnvParam(models.Model): - anobj = models.OneToOneField(AnObj) + anobj = models.OneToOneField(AnObj, on_delete=models.CASCADE) # ----- Categories Set category_set_name = models.CharField(max_length=64, blank=True) diff --git a/adim_project/adim/models/annotations.py b/adim_project/adim/models/annotations.py index 131bcb8..64307e3 100644 --- a/adim_project/adim/models/annotations.py +++ b/adim_project/adim/models/annotations.py @@ -11,8 +11,8 @@ class Annotation(models.Model): """ # TODO: add description for model Annotation - owner = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("owner")) - annotable = models.ForeignKey(AnObj, verbose_name=_("annotable"), related_name='annotations') + owner = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("owner"), on_delete=models.CASCADE) + annotable = models.ForeignKey(AnObj, verbose_name=_("annotable"), related_name='annotations', on_delete=models.CASCADE) item = models.TextField(verbose_name=_("Paper.js item")) order = models.IntegerField(verbose_name=_("order"), default=0) -- GitLab From 2fdbac07e97de17d82b443f99fda6dfe3ed3b772 Mon Sep 17 00:00:00 2001 From: Marion Chardon Date: Mon, 19 Mar 2018 13:06:13 +0100 Subject: [PATCH 2/3] maj sur django 1.11 --- adim_project/adim/permissions.py | 2 +- adim_project/adim_app/urls.py | 21 ++++++++------- adim_project/adim_app/views.py | 10 +++---- adim_project/adim_env/cimaf/urls.py | 2 ++ .../adim_project/apache/generate_config.py | 1 - adim_project/adim_project/settings/base.py | 27 +++++++++---------- adim_project/adim_project/settings/local.py | 2 +- adim_project/adim_project/settings/staging.py | 2 +- adim_project/adim_project/urls.py | 16 +++++------ adim_project/adim_ttp/authentication.py | 3 +-- adim_project/adim_ttp/views.py | 5 ++-- 11 files changed, 44 insertions(+), 47 deletions(-) diff --git a/adim_project/adim/permissions.py b/adim_project/adim/permissions.py index eaba9f9..711d72d 100644 --- a/adim_project/adim/permissions.py +++ b/adim_project/adim/permissions.py @@ -53,7 +53,7 @@ class PermissionClass(object): def check_permission(self, request, anobj): user = request.user # Anonymous users have no permissions - if user.is_anonymous(): + if user.is_anonymous: raise PermissionDenied() # Owner can always access diff --git a/adim_project/adim_app/urls.py b/adim_project/adim_app/urls.py index e61fee1..2dffcb4 100644 --- a/adim_project/adim_app/urls.py +++ b/adim_project/adim_app/urls.py @@ -3,24 +3,25 @@ from __future__ import unicode_literals from django.conf.urls import url, include -from .views import home, upload_file, annotate_new, annotate, send_anobj_img, anobj_thumb, upload_anobj_thumb, \ - suggest_users, essai +from . import views + +app_name='adim_app' urlpatterns = [ - url(r'^$', home, name="home"), - url(r'^new/$', upload_file, name='upload_file'), + url(r'^$', views.home, name='home'), + url(r'^new/$', views.upload_file, name='upload_file'), url(r'^annotate/', include([ - url(r'^$', annotate_new, name="annotate-new"), + url(r'^$', views.annotate_new, name="annotate-new"), url(r'^(?P[0-9a-f]{6,32})/', include([ - url(r'^$', annotate, name="annotate"), - url(r'^image/$', send_anobj_img, name='ao_image'), - url(r'^thumb/$', anobj_thumb, name="ao_thumb"), - url(r'^u/$', upload_anobj_thumb) + url(r'^$', views.annotate, name="annotate"), + url(r'^image/$', views.send_anobj_img, name='ao_image'), + url(r'^thumb/$', views.anobj_thumb, name="ao_thumb"), + url(r'^u/$', views.upload_anobj_thumb) ])), ]), name="annotate_base" ), - url(r'^s/u/$', suggest_users, name='suggest-users'), + url(r'^s/u/$', views.suggest_users, name='suggest-users'), ] diff --git a/adim_project/adim_app/views.py b/adim_project/adim_app/views.py index 0b94131..7f1736a 100644 --- a/adim_project/adim_app/views.py +++ b/adim_project/adim_app/views.py @@ -40,10 +40,10 @@ def home(request): :param request: :return: """ - context = {} - if request.user.is_anonymous(): - context['next'] = request.GET.get('next', "") - return render(request, "adim/home.html", context) + next = request.GET.get('next', "") + if request.user.is_anonymous: + return render(request, "adim/home.html", {'next': next}) + return render(request, "adim/home.html", {}) def handle_404(request): @@ -162,7 +162,7 @@ def annotate(request, anobj_uuid=None): # ----- Login check. Not using decorator so we can delegate to Trusted Third Party if needed permission = get_permission_class(anobj.sharing_mode) - if request.user.is_anonymous(): + if request.user.is_anonymous: if permission and permission.ttp: check_url = settings.ATTP.get(permission.ttp_id, {}).get('CHECK_URL') return HttpResponseRedirect(check_url.format(uuid=anobj.uuid)) diff --git a/adim_project/adim_env/cimaf/urls.py b/adim_project/adim_env/cimaf/urls.py index a4de9ef..a9f60ba 100644 --- a/adim_project/adim_env/cimaf/urls.py +++ b/adim_project/adim_env/cimaf/urls.py @@ -5,6 +5,8 @@ from django.conf.urls import url, include from .views import analysis +app_name='adim_env' + urlpatterns = [ url( r'^analysis/(?P[0-9a-f]{32})/', diff --git a/adim_project/adim_project/apache/generate_config.py b/adim_project/adim_project/apache/generate_config.py index 6318c90..66df436 100755 --- a/adim_project/adim_project/apache/generate_config.py +++ b/adim_project/adim_project/apache/generate_config.py @@ -11,7 +11,6 @@ import django from django.conf import settings from django.template import Context from django.template.loader import get_template -from django.utils import timezone __TARGETS = ('local', 'production', 'staging') diff --git a/adim_project/adim_project/settings/base.py b/adim_project/adim_project/settings/base.py index 78578ef..06fcf3f 100644 --- a/adim_project/adim_project/settings/base.py +++ b/adim_project/adim_project/settings/base.py @@ -37,8 +37,7 @@ except ImportError: DEBUG = False ALLOWED_HOSTS = [] ADMINS = ( - ("Julien Furrer", 'julien.furrer@unil.ch'), - ("Marion Chardon", 'marion.chardon@unil.ch'), + ("Admin Riset", 'riset-admin@unil.ch') ) MANAGERS = ADMINS @@ -65,19 +64,19 @@ TEMPLATES = [{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': (normpath(join(SITE_ROOT, 'templates')), ), 'OPTIONS': { - 'debug': False, + 'debug': DEBUG, 'loaders': ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader' ), 'context_processors': [ 'django.contrib.auth.context_processors.auth', - 'django.core.context_processors.debug', - 'django.core.context_processors.i18n', - 'django.core.context_processors.media', - 'django.core.context_processors.static', - 'django.core.context_processors.request', - 'django.core.context_processors.tz', + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.media', + 'django.template.context_processors.static', + 'django.template.context_processors.request', + 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'adim_utils.context_processors.default', ], @@ -86,11 +85,11 @@ TEMPLATES = [{ }] # backward compatibility -TEMPLATE_DIRS = TEMPLATES[0]['DIRS'] -TEMPLATE_CONTEXT_PROCESSORS = TEMPLATES[0]['OPTIONS']['context_processors'] -TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] -TEMPLATE_LOADERS = TEMPLATES[0]['OPTIONS']['loaders'] -TEMPLATE_STRING_IF_INVALID = TEMPLATES[0]['OPTIONS']['string_if_invalid'] +#TEMPLATE_DIRS = TEMPLATES[0]['DIRS'] +#TEMPLATE_CONTEXT_PROCESSORS = TEMPLATES[0]['OPTIONS']['context_processors'] +#TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] +#TEMPLATE_LOADERS = TEMPLATES[0]['OPTIONS']['loaders'] +#TEMPLATE_STRING_IF_INVALID = TEMPLATES[0]['OPTIONS']['string_if_invalid'] # ..... MEDIA AND STATICS PATHS diff --git a/adim_project/adim_project/settings/local.py b/adim_project/adim_project/settings/local.py index 47d89f1..3d73881 100644 --- a/adim_project/adim_project/settings/local.py +++ b/adim_project/adim_project/settings/local.py @@ -4,7 +4,7 @@ Settings for local development from .base import * DEBUG = True -TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] = True +#TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] = True # update_urls('/adim-dev/', __name__) diff --git a/adim_project/adim_project/settings/staging.py b/adim_project/adim_project/settings/staging.py index 7ddf06c..7a883d0 100644 --- a/adim_project/adim_project/settings/staging.py +++ b/adim_project/adim_project/settings/staging.py @@ -4,7 +4,7 @@ Settings for staging server from .base import * DEBUG = True -TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] = True +#TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] = True update_urls('/adim-dev/', __name__) diff --git a/adim_project/adim_project/urls.py b/adim_project/adim_project/urls.py index b1f06a7..9035c1c 100644 --- a/adim_project/adim_project/urls.py +++ b/adim_project/adim_project/urls.py @@ -2,6 +2,8 @@ from django.conf.urls import include, url, static from django.conf import settings from django.contrib import admin +from django.contrib.auth import views + admin.site.site_header = "ADIM - Site d'administration" admin.site.site_title = "ADIM" admin.site.index_title = "Administration" @@ -9,23 +11,19 @@ admin.site.site_url = None admin.autodiscover() urlpatterns = [ - # Examples: - # url(r'^$', 'adim_project.views.home', name='home'), - # url(r'^blog/', include('blog.urls')), # url(r'^admin/', include(admin.site.urls)), - url(r'^s-412-5/admin/', include(admin.site.urls)), - # url(r'^admin/', include('django_trap.urls', namespace='django_trap')), + url(r'^s-412-5/admin/', admin.site.urls), url(r'^shibauth/', include('shibauth.urls')), - url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': "adim/home.html"}), - url(r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login', name="logout"), + url(r'^accounts/login/$', views.login, {'template_name': "adim/home.html"}, name='django.contrib.auth.views.login'), + url(r'^accounts/logout/$', views.logout, name='logout'), url(r'^api/', include('adim.urls')), url(r'^attp/', include('adim_ttp.urls')), - url(r'^cimaf/', include('adim_env.cimaf.urls', namespace='adim.env.cimaf', app_name='adim_env')), - url(r'^', include('adim_app.urls', namespace='adim.app', app_name='adim_app')), + url(r'^cimaf/', include('adim_env.cimaf.urls', namespace='adim.env.cimaf')), + url(r'^', include('adim_app.urls', namespace="adim.app")) ] handler404 = 'adim_app.views.handle_404' diff --git a/adim_project/adim_ttp/authentication.py b/adim_project/adim_ttp/authentication.py index eec1b8f..2938feb 100644 --- a/adim_project/adim_ttp/authentication.py +++ b/adim_project/adim_ttp/authentication.py @@ -3,7 +3,6 @@ from django.contrib.auth.models import User from django.db import IntegrityError from rest_framework.authentication import BaseAuthentication -from rest_framework.exceptions import AuthenticationFailed from .utils import get_request_attp @@ -116,7 +115,7 @@ def login_attp_user(request, attp_message, persist=True): return user = get_or_create_user(attp_user) - if request.user.is_anonymous() or request.user != user: + if request.user.is_anonymous or request.user != user: if persist: user.backend = 'django.contrib.auth.backends.ModelBackend' auth_login(request, user) diff --git a/adim_project/adim_ttp/views.py b/adim_project/adim_ttp/views.py index a8b04bc..48ceeb1 100644 --- a/adim_project/adim_ttp/views.py +++ b/adim_project/adim_ttp/views.py @@ -1,6 +1,5 @@ -from django.core.exceptions import PermissionDenied from django.views.decorators.clickjacking import xframe_options_exempt -from django.http.response import HttpResponseRedirect, HttpResponse, HttpResponseForbidden, Http404 +from django.http.response import HttpResponseRedirect, Http404 from django.core.urlresolvers import reverse from django.shortcuts import get_object_or_404, render from adim.models.annotables import AnObj @@ -20,7 +19,7 @@ def login(request): :param attp_hash: :return: """ - if request.user.is_anonymous(): + if request.user.is_anonymous: raise Http404() token, _ = Token.objects.get_or_create(user=request.user) return render(request, "adim_ttp/logged.html", context={'token': token}) -- GitLab From 6a7451232896156c006bfb8b861dbb78942364ef Mon Sep 17 00:00:00 2001 From: Marion Chardon Date: Mon, 19 Mar 2018 13:22:58 +0100 Subject: [PATCH 3/3] maj requirement django 1.11 --- requirements/base.txt | 19 +++++++++---------- requirements/dev.txt | 8 ++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 6a30d9a..f9b4fbb 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,13 +1,12 @@ -Django==1.8.18 -django-autoslug==1.7.2 -django-jsonfield==0.9.13 -django-sendfile==0.3.11 -django-split-settings==0.1.1 -djangorestframework==3.1.1 -drf-nested-routers==0.9.0 +Django==1.11.11 +django-autoslug==1.9.3 django-eav==0.9.4.post1 +django-jsonfield==1.0.1 +django-sendfile==0.3.11 +djangorestframework==3.7.7 +drf-nested-routers==0.90.2 MySQL-python -Pillow==2.7.0 -python-ldap==2.4.19 -python-memcached==1.53 +Pillow==5.0.0 +python-ldap==3.0.0 +python-memcached==1.59 django-cors-headers \ No newline at end of file diff --git a/requirements/dev.txt b/requirements/dev.txt index e81110a..6ff191d 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,5 +1,5 @@ -r base.txt -django-guardian==1.2.0 -Pygments==2.0.2 -Werkzeug==0.10.4 -django-extensions==1.5.2 +django-guardian==1.4.9 +Pygments==2.2.0 +Werkzeug==0.14.1 +django-extensions==2.0.6 -- GitLab