Gitlab CSE Unil

Commit 3f47cd5b authored by Julien Furrer's avatar Julien Furrer
Browse files

compat django 1.8 et drf 3.1

parent 6e7c7970
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('adim', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='anobj',
name='ao_type',
),
migrations.AlterField(
model_name='anobj',
name='members',
field=models.ManyToManyField(related_name='shared_anobjs', verbose_name='members', to=settings.AUTH_USER_MODEL, through='adim.AnObjMembership', blank=True),
),
migrations.AlterField(
model_name='aoschema',
name='ao_types',
field=models.ManyToManyField(to='adim.AOType', blank=True),
),
]
...@@ -85,7 +85,7 @@ def get_image_path(instance, filename): ...@@ -85,7 +85,7 @@ def get_image_path(instance, filename):
) )
class AnObj(BaseEntity): class AnObj(models.Model):
""" """
Annotable Object Annotable Object
""" """
...@@ -107,9 +107,9 @@ class AnObj(BaseEntity): ...@@ -107,9 +107,9 @@ class AnObj(BaseEntity):
_thumb_url = models.CharField(max_length=512, blank=True, null=True) _thumb_url = models.CharField(max_length=512, blank=True, null=True)
# ----- eav attributes # ----- eav attributes
ao_type = models.ForeignKey(AOType, verbose_name="type", blank=True, null=True) # ao_type = models.ForeignKey(AOType, verbose_name="type", blank=True, null=True)
attrs = generic.GenericRelation(AOAttribute, object_id_field='entity_id', # attrs = generic.GenericRelation(AOAttribute, object_id_field='entity_id',
content_type_field='entity_type') # content_type_field='entity_type')
class Meta: class Meta:
app_label = "adim" app_label = "adim"
...@@ -117,9 +117,8 @@ class AnObj(BaseEntity): ...@@ -117,9 +117,8 @@ class AnObj(BaseEntity):
ordering = ["-id"] ordering = ["-id"]
def __unicode__(self): def __unicode__(self):
return u"{} ({})".format( return u"{}".format(
self.name, self.name
self.ao_type and self.ao_type.name or "default"
) )
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
...@@ -189,13 +188,13 @@ class AnObj(BaseEntity): ...@@ -189,13 +188,13 @@ class AnObj(BaseEntity):
def thumb_url(self, url): def thumb_url(self, url):
self._thumb_url = url self._thumb_url = url
@classmethod # @classmethod
def get_schemata_for_model(cls): # def get_schemata_for_model(cls):
return AOSchema.objects.all() # return AOSchema.objects.all()
#
def get_schemata_for_instance(self, qs): # def get_schemata_for_instance(self, qs):
qs = qs.filter(models.Q(ao_types__isnull=True) | models.Q(ao_types=self.ao_type)) # qs = qs.filter(models.Q(ao_types__isnull=True) | models.Q(ao_types=self.ao_type))
return qs # return qs
def clear_thumbnails(qs=None): def clear_thumbnails(qs=None):
......
# coding=utf-8 # coding=utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings from django.conf import settings
from django.db.models import get_model from django.contrib.auth import get_user_model
from rest_framework import serializers from rest_framework import serializers
from rest_framework.fields import Field from rest_framework.fields import Field
from adim.models import AnObj, Annotation from adim.models import AnObj, Annotation
...@@ -12,14 +12,14 @@ from django.core.cache import cache ...@@ -12,14 +12,14 @@ from django.core.cache import cache
ANOBJ_THUMB_CACHE_BASE_KEY = 'anobj_thumb_url' ANOBJ_THUMB_CACHE_BASE_KEY = 'anobj_thumb_url'
from rest_framework.pagination import PaginationSerializer #from rest_framework.pagination import PaginationSerializer
class UserSerializer(serializers.ModelSerializer): class UserSerializer(serializers.ModelSerializer):
# full_name = serializers.Field(source='get_full_name') # full_name = serializers.Field(source='get_full_name')
class Meta: class Meta:
model = get_model(*settings.AUTH_USER_MODEL.split('.')) model = get_user_model()
fields = ('id', 'username', 'email') fields = ('id', 'username', 'email')
...@@ -30,21 +30,21 @@ class AnnotationSerializer(serializers.ModelSerializer): ...@@ -30,21 +30,21 @@ class AnnotationSerializer(serializers.ModelSerializer):
read_only_fields = ("id",) read_only_fields = ("id",)
class OwnerOnlyField(serializers.WritableField): # class OwnerOnlyField(serializers.WritableField):
""" # """
A field that display it's value to the owner only # A field that display it's value to the owner only
""" # """
#
def field_to_native(self, obj, field_name): # def field_to_native(self, obj, field_name):
if self.context['request'].user == obj.owner: # if self.context['request'].user == obj.owner:
return super(OwnerOnlyField, self).field_to_native(obj, field_name) # return super(OwnerOnlyField, self).field_to_native(obj, field_name)
else: # else:
return "" # return ""
class BaseAnObjSerializer(serializers.ModelSerializer): class BaseAnObjSerializer(serializers.ModelSerializer):
owner_name = serializers.Field(source='owner.username') owner_name = serializers.ReadOnlyField(source='owner.username')
annotations = serializers.SerializerMethodField('get_annotations') annotations = serializers.SerializerMethodField()
# members = serializers.SerializerMethodField('get_members') # members = serializers.SerializerMethodField('get_members')
# members = UserSerializer(many=True, read_only=True) # members = UserSerializer(many=True, read_only=True)
# sharing_opts = OwnerOnlyField(source='sharing_opts', required=False) # sharing_opts = OwnerOnlyField(source='sharing_opts', required=False)
...@@ -57,7 +57,7 @@ class BaseAnObjSerializer(serializers.ModelSerializer): ...@@ -57,7 +57,7 @@ class BaseAnObjSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = AnObj model = AnObj
fields = ('id', 'uuid', 'name', 'owner', 'owner_name', 'ao_type', 'annotations', 'sharing_mode', 'locked') fields = ('id', 'uuid', 'name', 'owner', 'owner_name', 'annotations', 'sharing_mode', 'locked')
def get_annotations(self, anobj): def get_annotations(self, anobj):
request = self.context.get('request') request = self.context.get('request')
...@@ -99,7 +99,7 @@ class BaseAnObjSerializer(serializers.ModelSerializer): ...@@ -99,7 +99,7 @@ class BaseAnObjSerializer(serializers.ModelSerializer):
class AnObjSerializer(BaseAnObjSerializer): class AnObjSerializer(BaseAnObjSerializer):
members = UserSerializer(many=True, required=False, allow_add_remove=True) # read_only=True) members = UserSerializer(many=True, required=False) # , allow_add_remove=True) # read_only=True)
class Meta: class Meta:
model = AnObj model = AnObj
......
...@@ -14,9 +14,9 @@ from adim.views import AnObjViewSet, SharedAnObjViewSet, AnnotationViewSet, Shar ...@@ -14,9 +14,9 @@ from adim.views import AnObjViewSet, SharedAnObjViewSet, AnnotationViewSet, Shar
d_router = DefaultRouter() d_router = DefaultRouter()
router = routers.SimpleRouter() router = routers.SimpleRouter()
router.register(r'anobjs', AnObjViewSet) router.register(r'anobjs', AnObjViewSet, base_name='anobjs')
router.register(r'shared/anobjs', SharedAnObjViewSet, base_name='shared-anobj') router.register(r'shared/anobjs', SharedAnObjViewSet, base_name='shared-anobjs')
router.register(r'annotations', AnnotationViewSet) router.register(r'annotations', AnnotationViewSet, base_name='annotations')
router.register(r'users', UserViewSet, base_name='users') router.register(r'users', UserViewSet, base_name='users')
annot_router = routers.NestedSimpleRouter(router, r'anobjs', lookup='anobjs') annot_router = routers.NestedSimpleRouter(router, r'anobjs', lookup='anobjs')
......
...@@ -45,8 +45,8 @@ window.ADIM_CONFIG = { ...@@ -45,8 +45,8 @@ window.ADIM_CONFIG = {
api: { api: {
baseUrl: "{% url "api-root" %}", baseUrl: "{% url "api-root" %}",
annotables: "{% if anobj.owner == user %}{% url "anobj-list" %}{% else %}{% url "shared-anobj-list" %}{% endif %}", annotables: "{% if anobj.owner == user %}{% url "anobjs-list" %}{% else %}{% url "shared-anobjs-list" %}{% endif %}",
annotations: "{% url "annotation-list" %}" annotations: "{% url "annotations-list" %}"
}, },
annotable: { annotable: {
......
...@@ -23,8 +23,8 @@ window.ADIM_CONFIG = { ...@@ -23,8 +23,8 @@ window.ADIM_CONFIG = {
api: { api: {
baseUrl: "{% url "api-root" %}", baseUrl: "{% url "api-root" %}",
annotables: "{% url "anobj-list" %}", annotables: "{% url "anobjs-list" %}",
shared_anobj: "{% url "shared-anobj-list" %}" shared_anobj: "{% url "shared-anobjs-list" %}"
}, },
user: { user: {
......
# coding=utf-8 # coding=utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url, patterns, 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 .views import home, upload_file, annotate_new, annotate, send_anobj_img, anobj_thumb, upload_anobj_thumb, \
suggest_users suggest_users
...@@ -10,17 +10,15 @@ urlpatterns = [ ...@@ -10,17 +10,15 @@ urlpatterns = [
url(r'^$', home, name="home"), url(r'^$', home, name="home"),
url(r'^new/$', upload_file, name='upload_file'), url(r'^new/$', upload_file, name='upload_file'),
url(r'^annotate/', url(r'^annotate/',
include(patterns('', include([
url(r'^$', annotate_new, name="annotate-new"), url(r'^$', annotate_new, name="annotate-new"),
url(r'^(?P<anobj_uuid>[0-9a-f]{6,32})/', url(r'^(?P<anobj_uuid>[0-9a-f]{6,32})/', include([
include(patterns('', url(r'^$', annotate, name="annotate"),
url(r'^$', annotate, name="annotate"), url(r'^image/$', send_anobj_img, name='ao_image'),
url(r'^image/$', send_anobj_img, name='ao_image'), url(r'^thumb/$', anobj_thumb, name="ao_thumb"),
url(r'^thumb/$', anobj_thumb, name="ao_thumb"), url(r'^u/$', upload_anobj_thumb)
url(r'^u/$', upload_anobj_thumb), ])),
)) ]),
),
)),
name="annotate_base" name="annotate_base"
), ),
......
...@@ -3,7 +3,7 @@ AUTHENTICATION_BACKENDS = ( ...@@ -3,7 +3,7 @@ AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', 'django.contrib.auth.backends.ModelBackend',
) )
LOGIN_REDIRECT_URL = "adim.app:annotate_new" LOGIN_REDIRECT_URL = "adim.app:annotate-new"
LOGIN_URL = "adim.app:home" LOGIN_URL = "adim.app:home"
SHIBAUTH_ATTR_PATTERN = r'.*' SHIBAUTH_ATTR_PATTERN = r'.*'
......
...@@ -6,6 +6,7 @@ TEMPLATE_DEBUG = False ...@@ -6,6 +6,7 @@ TEMPLATE_DEBUG = False
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.sites',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
......
from django.conf.urls import patterns, include, url, static 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
admin.autodiscover() admin.autodiscover()
urlpatterns = patterns('', urlpatterns = [
# Examples: # Examples:
# url(r'^$', 'adim_project.views.home', name='home'), # url(r'^$', 'adim_project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')), # url(r'^blog/', include('blog.urls')),
...@@ -17,7 +17,7 @@ urlpatterns = patterns('', ...@@ -17,7 +17,7 @@ urlpatterns = patterns('',
url(r'^api/', include('adim.urls')), url(r'^api/', include('adim.urls')),
url(r'^', include('adim_app.urls', namespace='adim.app', app_name='adim_app')), url(r'^', include('adim_app.urls', namespace='adim.app', app_name='adim_app')),
) ]
handler404 = 'adim_app.views.handle_404' handler404 = 'adim_app.views.handle_404'
handler400 = 'adim_app.views.handle_404' handler400 = 'adim_app.views.handle_404'
......
Supports Markdown
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