diff --git a/adim_project/adim/models/annotables.py b/adim_project/adim/models/annotables.py index 4f34b6c89662977f7bf08c6d9b10b1d53a0bdd8c..0a3aed63d006c118277ab84e6842fad901899416 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 131bcb8189f567361f815abb36776b92be578149..64307e32da971f8312d67af29f9be31df619e9cd 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) diff --git a/adim_project/adim/permissions.py b/adim_project/adim/permissions.py index eaba9f9ac89d04d3323d9701fc558359c8abbb1a..711d72d19c0c908663864ea212f36907fdb3f758 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 e61fee1e1f52c1f979e5ed13ac2ce5d3aa6c52aa..2dffcb43636c4d957845ba4487835286d71d7a77 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 0b941317185aa515e45b54b9b22ba523409655dd..7f1736a4bb5434b6f969f116ca5610acfe4c8fff 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 a4de9efc8203883851ca536e2e1fab3584e5b8ab..a9f60bac5167ec3af875f890593855968832cc29 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 6318c901e1a99fa2778ce4819e3c0c9b83589ff5..66df436e22a2335388570791cff7c3a235768f35 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 78578ef14819a6fe30ebfe616c6b89eb1e954970..06fcf3ffdae5e7861b8618e60c5fdc3d010a21f8 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 47d89f1eac3cef845c553172fcf3fbf990b03540..3d73881dfb58ef0bef07f2acfec9b38ebe91c643 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 7ddf06c2d02ae74a1720f656946a2e9580cdce03..7a883d0cc6e8a6fd65b5d75230c32ce56a2f39e7 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 b1f06a70c6a8250528f7064e24cfdff0b69fa59c..9035c1cce81d402793da84c38c973808355bfa3c 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 eec1b8f577a66801ff480124a3aaf318c068d7f1..2938feb2c77a7f2f942341551f8798b2cd2adc48 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 a8b04bcd4cf032c925122872c8e6149368444fbf..48ceeb108ef3d5b6d57280b8b8b1ced184f9e35a 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}) diff --git a/requirements/base.txt b/requirements/base.txt index 6a30d9a382fedf62fbee6e99d8c91dc1bfeed8b6..f9b4fbb548efec97cadf36b896d60acc2971adb7 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 e81110a2a1029fd76d541a084043addcd7839471..6ff191d4d5167a719cff6371fdbcdde7269fb102 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