Gitlab CSE Unil

Commit 83a89651 authored by M. Chardon's avatar M. Chardon
Browse files

Merge branch 'django' into 'javascript'

Django

See merge request !4
parents 438cb502 6a745123
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
......@@ -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<anobj_uuid>[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'),
]
......@@ -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))
......
......@@ -5,6 +5,8 @@ from django.conf.urls import url, include
from .views import analysis
app_name='adim_env'
urlpatterns = [
url(
r'^analysis/(?P<anobj_uuid>[0-9a-f]{32})/',
......
......@@ -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')
......
......@@ -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
......
......@@ -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__)
......
......@@ -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__)
......
......@@ -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'
......
......@@ -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)
......
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})
......
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
-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
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