Gitlab CSE Unil

Commit 2fdbac07 authored by M. Chardon's avatar M. Chardon
Browse files

maj sur django 1.11

parent 9672d53f
...@@ -53,7 +53,7 @@ class PermissionClass(object): ...@@ -53,7 +53,7 @@ class PermissionClass(object):
def check_permission(self, request, anobj): def check_permission(self, request, anobj):
user = request.user user = request.user
# Anonymous users have no permissions # Anonymous users have no permissions
if user.is_anonymous(): if user.is_anonymous:
raise PermissionDenied() raise PermissionDenied()
# Owner can always access # Owner can always access
......
...@@ -3,24 +3,25 @@ from __future__ import unicode_literals ...@@ -3,24 +3,25 @@ from __future__ import unicode_literals
from django.conf.urls import url, include from django.conf.urls import url, include
from .views import home, upload_file, annotate_new, annotate, send_anobj_img, anobj_thumb, upload_anobj_thumb, \ from . import views
suggest_users, essai
app_name='adim_app'
urlpatterns = [ urlpatterns = [
url(r'^$', home, name="home"), url(r'^$', views.home, name='home'),
url(r'^new/$', upload_file, name='upload_file'), url(r'^new/$', views.upload_file, name='upload_file'),
url(r'^annotate/', url(r'^annotate/',
include([ include([
url(r'^$', annotate_new, name="annotate-new"), url(r'^$', views.annotate_new, name="annotate-new"),
url(r'^(?P<anobj_uuid>[0-9a-f]{6,32})/', include([ url(r'^(?P<anobj_uuid>[0-9a-f]{6,32})/', include([
url(r'^$', annotate, name="annotate"), url(r'^$', views.annotate, name="annotate"),
url(r'^image/$', send_anobj_img, name='ao_image'), url(r'^image/$', views.send_anobj_img, name='ao_image'),
url(r'^thumb/$', anobj_thumb, name="ao_thumb"), url(r'^thumb/$', views.anobj_thumb, name="ao_thumb"),
url(r'^u/$', upload_anobj_thumb) url(r'^u/$', views.upload_anobj_thumb)
])), ])),
]), ]),
name="annotate_base" name="annotate_base"
), ),
url(r'^s/u/$', suggest_users, name='suggest-users'), url(r'^s/u/$', views.suggest_users, name='suggest-users'),
] ]
...@@ -40,10 +40,10 @@ def home(request): ...@@ -40,10 +40,10 @@ def home(request):
:param request: :param request:
:return: :return:
""" """
context = {} next = request.GET.get('next', "")
if request.user.is_anonymous(): if request.user.is_anonymous:
context['next'] = request.GET.get('next', "") return render(request, "adim/home.html", {'next': next})
return render(request, "adim/home.html", context) return render(request, "adim/home.html", {})
def handle_404(request): def handle_404(request):
...@@ -162,7 +162,7 @@ def annotate(request, anobj_uuid=None): ...@@ -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 # ----- Login check. Not using decorator so we can delegate to Trusted Third Party if needed
permission = get_permission_class(anobj.sharing_mode) permission = get_permission_class(anobj.sharing_mode)
if request.user.is_anonymous(): if request.user.is_anonymous:
if permission and permission.ttp: if permission and permission.ttp:
check_url = settings.ATTP.get(permission.ttp_id, {}).get('CHECK_URL') check_url = settings.ATTP.get(permission.ttp_id, {}).get('CHECK_URL')
return HttpResponseRedirect(check_url.format(uuid=anobj.uuid)) return HttpResponseRedirect(check_url.format(uuid=anobj.uuid))
......
...@@ -5,6 +5,8 @@ from django.conf.urls import url, include ...@@ -5,6 +5,8 @@ from django.conf.urls import url, include
from .views import analysis from .views import analysis
app_name='adim_env'
urlpatterns = [ urlpatterns = [
url( url(
r'^analysis/(?P<anobj_uuid>[0-9a-f]{32})/', r'^analysis/(?P<anobj_uuid>[0-9a-f]{32})/',
......
...@@ -11,7 +11,6 @@ import django ...@@ -11,7 +11,6 @@ import django
from django.conf import settings from django.conf import settings
from django.template import Context from django.template import Context
from django.template.loader import get_template from django.template.loader import get_template
from django.utils import timezone
__TARGETS = ('local', 'production', 'staging') __TARGETS = ('local', 'production', 'staging')
......
...@@ -37,8 +37,7 @@ except ImportError: ...@@ -37,8 +37,7 @@ except ImportError:
DEBUG = False DEBUG = False
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
ADMINS = ( ADMINS = (
("Julien Furrer", 'julien.furrer@unil.ch'), ("Admin Riset", 'riset-admin@unil.ch')
("Marion Chardon", 'marion.chardon@unil.ch'),
) )
MANAGERS = ADMINS MANAGERS = ADMINS
...@@ -65,19 +64,19 @@ TEMPLATES = [{ ...@@ -65,19 +64,19 @@ TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': (normpath(join(SITE_ROOT, 'templates')), ), 'DIRS': (normpath(join(SITE_ROOT, 'templates')), ),
'OPTIONS': { 'OPTIONS': {
'debug': False, 'debug': DEBUG,
'loaders': ( 'loaders': (
'django.template.loaders.filesystem.Loader', 'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader' 'django.template.loaders.app_directories.Loader'
), ),
'context_processors': [ 'context_processors': [
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug', 'django.template.context_processors.debug',
'django.core.context_processors.i18n', 'django.template.context_processors.i18n',
'django.core.context_processors.media', 'django.template.context_processors.media',
'django.core.context_processors.static', 'django.template.context_processors.static',
'django.core.context_processors.request', 'django.template.context_processors.request',
'django.core.context_processors.tz', 'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
'adim_utils.context_processors.default', 'adim_utils.context_processors.default',
], ],
...@@ -86,11 +85,11 @@ TEMPLATES = [{ ...@@ -86,11 +85,11 @@ TEMPLATES = [{
}] }]
# backward compatibility # backward compatibility
TEMPLATE_DIRS = TEMPLATES[0]['DIRS'] #TEMPLATE_DIRS = TEMPLATES[0]['DIRS']
TEMPLATE_CONTEXT_PROCESSORS = TEMPLATES[0]['OPTIONS']['context_processors'] #TEMPLATE_CONTEXT_PROCESSORS = TEMPLATES[0]['OPTIONS']['context_processors']
TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] #TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug']
TEMPLATE_LOADERS = TEMPLATES[0]['OPTIONS']['loaders'] #TEMPLATE_LOADERS = TEMPLATES[0]['OPTIONS']['loaders']
TEMPLATE_STRING_IF_INVALID = TEMPLATES[0]['OPTIONS']['string_if_invalid'] #TEMPLATE_STRING_IF_INVALID = TEMPLATES[0]['OPTIONS']['string_if_invalid']
# ..... MEDIA AND STATICS PATHS # ..... MEDIA AND STATICS PATHS
......
...@@ -4,7 +4,7 @@ Settings for local development ...@@ -4,7 +4,7 @@ Settings for local development
from .base import * from .base import *
DEBUG = True DEBUG = True
TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] = True #TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] = True
# update_urls('/adim-dev/', __name__) # update_urls('/adim-dev/', __name__)
......
...@@ -4,7 +4,7 @@ Settings for staging server ...@@ -4,7 +4,7 @@ Settings for staging server
from .base import * from .base import *
DEBUG = True DEBUG = True
TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] = True #TEMPLATE_DEBUG = TEMPLATES[0]['OPTIONS']['debug'] = True
update_urls('/adim-dev/', __name__) update_urls('/adim-dev/', __name__)
......
...@@ -2,6 +2,8 @@ from django.conf.urls import include, url, static ...@@ -2,6 +2,8 @@ from django.conf.urls import include, url, static
from django.conf import settings from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.contrib.auth import views
admin.site.site_header = "ADIM - Site d'administration" admin.site.site_header = "ADIM - Site d'administration"
admin.site.site_title = "ADIM" admin.site.site_title = "ADIM"
admin.site.index_title = "Administration" admin.site.index_title = "Administration"
...@@ -9,23 +11,19 @@ admin.site.site_url = None ...@@ -9,23 +11,19 @@ admin.site.site_url = None
admin.autodiscover() admin.autodiscover()
urlpatterns = [ 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'^admin/', include(admin.site.urls)),
url(r'^s-412-5/admin/', include(admin.site.urls)), url(r'^s-412-5/admin/', admin.site.urls),
# url(r'^admin/', include('django_trap.urls', namespace='django_trap')),
url(r'^shibauth/', include('shibauth.urls')), url(r'^shibauth/', include('shibauth.urls')),
url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': "adim/home.html"}), url(r'^accounts/login/$', views.login, {'template_name': "adim/home.html"}, name='django.contrib.auth.views.login'),
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login', name="logout"), url(r'^accounts/logout/$', views.logout, name='logout'),
url(r'^api/', include('adim.urls')), url(r'^api/', include('adim.urls')),
url(r'^attp/', include('adim_ttp.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'^cimaf/', include('adim_env.cimaf.urls', namespace='adim.env.cimaf')),
url(r'^', include('adim_app.urls', namespace='adim.app', app_name='adim_app')), url(r'^', include('adim_app.urls', namespace="adim.app"))
] ]
handler404 = 'adim_app.views.handle_404' handler404 = 'adim_app.views.handle_404'
......
...@@ -3,7 +3,6 @@ from django.contrib.auth.models import User ...@@ -3,7 +3,6 @@ from django.contrib.auth.models import User
from django.db import IntegrityError from django.db import IntegrityError
from rest_framework.authentication import BaseAuthentication from rest_framework.authentication import BaseAuthentication
from rest_framework.exceptions import AuthenticationFailed
from .utils import get_request_attp from .utils import get_request_attp
...@@ -116,7 +115,7 @@ def login_attp_user(request, attp_message, persist=True): ...@@ -116,7 +115,7 @@ def login_attp_user(request, attp_message, persist=True):
return return
user = get_or_create_user(attp_user) 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: if persist:
user.backend = 'django.contrib.auth.backends.ModelBackend' user.backend = 'django.contrib.auth.backends.ModelBackend'
auth_login(request, user) auth_login(request, user)
......
from django.core.exceptions import PermissionDenied
from django.views.decorators.clickjacking import xframe_options_exempt 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.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from adim.models.annotables import AnObj from adim.models.annotables import AnObj
...@@ -20,7 +19,7 @@ def login(request): ...@@ -20,7 +19,7 @@ def login(request):
:param attp_hash: :param attp_hash:
:return: :return:
""" """
if request.user.is_anonymous(): if request.user.is_anonymous:
raise Http404() raise Http404()
token, _ = Token.objects.get_or_create(user=request.user) token, _ = Token.objects.get_or_create(user=request.user)
return render(request, "adim_ttp/logged.html", context={'token': token}) return render(request, "adim_ttp/logged.html", context={'token': token})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment