Gitlab CSE Unil
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
M. Chardon
ADIM
Commits
3f47cd5b
Commit
3f47cd5b
authored
Apr 20, 2015
by
Julien Furrer
Browse files
compat django 1.8 et drf 3.1
parent
6e7c7970
Changes
10
Hide whitespace changes
Inline
Side-by-side
adim/migrations/0002_auto_20150417_1302.py
0 → 100644
View file @
3f47cd5b
# -*- 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
),
),
]
adim/models/annotables.py
View file @
3f47cd5b
...
...
@@ -85,7 +85,7 @@ def get_image_path(instance, filename):
)
class
AnObj
(
BaseEntity
):
class
AnObj
(
models
.
Model
):
"""
Annotable Object
"""
...
...
@@ -107,9 +107,9 @@ class AnObj(BaseEntity):
_thumb_url
=
models
.
CharField
(
max_length
=
512
,
blank
=
True
,
null
=
True
)
# ----- eav attributes
ao_type
=
models
.
ForeignKey
(
AOType
,
verbose_name
=
"type"
,
blank
=
True
,
null
=
True
)
attrs
=
generic
.
GenericRelation
(
AOAttribute
,
object_id_field
=
'entity_id'
,
content_type_field
=
'entity_type'
)
#
ao_type = models.ForeignKey(AOType, verbose_name="type", blank=True, null=True)
#
attrs = generic.GenericRelation(AOAttribute, object_id_field='entity_id',
#
content_type_field='entity_type')
class
Meta
:
app_label
=
"adim"
...
...
@@ -117,9 +117,8 @@ class AnObj(BaseEntity):
ordering
=
[
"-id"
]
def
__unicode__
(
self
):
return
u
"{} ({})"
.
format
(
self
.
name
,
self
.
ao_type
and
self
.
ao_type
.
name
or
"default"
return
u
"{}"
.
format
(
self
.
name
)
def
save
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -189,13 +188,13 @@ class AnObj(BaseEntity):
def
thumb_url
(
self
,
url
):
self
.
_thumb_url
=
url
@
classmethod
def
get_schemata_for_model
(
cls
):
return
AOSchema
.
objects
.
all
()
def
get_schemata_for_instance
(
self
,
qs
):
qs
=
qs
.
filter
(
models
.
Q
(
ao_types__isnull
=
True
)
|
models
.
Q
(
ao_types
=
self
.
ao_type
))
return
qs
#
@classmethod
#
def get_schemata_for_model(cls):
#
return AOSchema.objects.all()
#
#
def get_schemata_for_instance(self, qs):
#
qs = qs.filter(models.Q(ao_types__isnull=True) | models.Q(ao_types=self.ao_type))
#
return qs
def
clear_thumbnails
(
qs
=
None
):
...
...
adim/serializers.py
View file @
3f47cd5b
# coding=utf-8
from
__future__
import
unicode_literals
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.fields
import
Field
from
adim.models
import
AnObj
,
Annotation
...
...
@@ -12,14 +12,14 @@ from django.core.cache import cache
ANOBJ_THUMB_CACHE_BASE_KEY
=
'anobj_thumb_url'
from
rest_framework.pagination
import
PaginationSerializer
#
from rest_framework.pagination import PaginationSerializer
class
UserSerializer
(
serializers
.
ModelSerializer
):
# full_name = serializers.Field(source='get_full_name')
class
Meta
:
model
=
get_model
(
*
settings
.
AUTH_USER_MODEL
.
split
(
'.'
)
)
model
=
get_
user_
model
()
fields
=
(
'id'
,
'username'
,
'email'
)
...
...
@@ -30,21 +30,21 @@ class AnnotationSerializer(serializers.ModelSerializer):
read_only_fields
=
(
"id"
,)
class
OwnerOnlyField
(
serializers
.
WritableField
):
"""
A field that display it's value to the owner only
"""
def
field_to_native
(
self
,
obj
,
field_name
):
if
self
.
context
[
'request'
].
user
==
obj
.
owner
:
return
super
(
OwnerOnlyField
,
self
).
field_to_native
(
obj
,
field_name
)
else
:
return
""
#
class OwnerOnlyField(serializers.WritableField):
#
"""
#
A field that display it's value to the owner only
#
"""
#
#
def field_to_native(self, obj, field_name):
#
if self.context['request'].user == obj.owner:
#
return super(OwnerOnlyField, self).field_to_native(obj, field_name)
#
else:
#
return ""
class
BaseAnObjSerializer
(
serializers
.
ModelSerializer
):
owner_name
=
serializers
.
Field
(
source
=
'owner.username'
)
annotations
=
serializers
.
SerializerMethodField
(
'get_annotations'
)
owner_name
=
serializers
.
ReadOnly
Field
(
source
=
'owner.username'
)
annotations
=
serializers
.
SerializerMethodField
()
# members = serializers.SerializerMethodField('get_members')
# members = UserSerializer(many=True, read_only=True)
# sharing_opts = OwnerOnlyField(source='sharing_opts', required=False)
...
...
@@ -57,7 +57,7 @@ class BaseAnObjSerializer(serializers.ModelSerializer):
class
Meta
:
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
):
request
=
self
.
context
.
get
(
'request'
)
...
...
@@ -99,7 +99,7 @@ class BaseAnObjSerializer(serializers.ModelSerializer):
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
:
model
=
AnObj
...
...
adim/urls.py
View file @
3f47cd5b
...
...
@@ -14,9 +14,9 @@ from adim.views import AnObjViewSet, SharedAnObjViewSet, AnnotationViewSet, Shar
d_router
=
DefaultRouter
()
router
=
routers
.
SimpleRouter
()
router
.
register
(
r
'anobjs'
,
AnObjViewSet
)
router
.
register
(
r
'shared/anobjs'
,
SharedAnObjViewSet
,
base_name
=
'shared-anobj'
)
router
.
register
(
r
'annotations'
,
AnnotationViewSet
)
router
.
register
(
r
'anobjs'
,
AnObjViewSet
,
base_name
=
'anobjs'
)
router
.
register
(
r
'shared/anobjs'
,
SharedAnObjViewSet
,
base_name
=
'shared-anobj
s
'
)
router
.
register
(
r
'annotations'
,
AnnotationViewSet
,
base_name
=
'annotations'
)
router
.
register
(
r
'users'
,
UserViewSet
,
base_name
=
'users'
)
annot_router
=
routers
.
NestedSimpleRouter
(
router
,
r
'anobjs'
,
lookup
=
'anobjs'
)
...
...
adim_app/templates/adim_app/annotation.html
View file @
3f47cd5b
...
...
@@ -45,8 +45,8 @@ window.ADIM_CONFIG = {
api
:
{
baseUrl
:
"
{% url
"
api
-
root
"
%}
"
,
annotables
:
"
{% if anobj.owner == user %}{% url
"
anobj
-
list
"
%}{% else %}{% url
"
shared
-
anobj
-
list
"
%}{% endif %}
"
,
annotations
:
"
{% url
"
annotation
-
list
"
%}
"
annotables
:
"
{% if anobj.owner == user %}{% url
"
anobj
s
-
list
"
%}{% else %}{% url
"
shared
-
anobj
s
-
list
"
%}{% endif %}
"
,
annotations
:
"
{% url
"
annotation
s
-
list
"
%}
"
},
annotable
:
{
...
...
adim_app/templates/adim_app/annotation_new.html
View file @
3f47cd5b
...
...
@@ -23,8 +23,8 @@ window.ADIM_CONFIG = {
api
:
{
baseUrl
:
"
{% url
"
api
-
root
"
%}
"
,
annotables
:
"
{% url
"
anobj
-
list
"
%}
"
,
shared_anobj
:
"
{% url
"
shared
-
anobj
-
list
"
%}
"
annotables
:
"
{% url
"
anobj
s
-
list
"
%}
"
,
shared_anobj
:
"
{% url
"
shared
-
anobj
s
-
list
"
%}
"
},
user
:
{
...
...
adim_app/urls.py
View file @
3f47cd5b
# coding=utf-8
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
,
\
suggest_users
...
...
@@ -10,17 +10,15 @@ urlpatterns = [
url
(
r
'^$'
,
home
,
name
=
"home"
),
url
(
r
'^new/$'
,
upload_file
,
name
=
'upload_file'
),
url
(
r
'^annotate/'
,
include
(
patterns
(
''
,
include
(
[
url
(
r
'^$'
,
annotate_new
,
name
=
"annotate-new"
),
url
(
r
'^(?P<anobj_uuid>[0-9a-f]{6,32})/'
,
include
(
patterns
(
''
,
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
'^(?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
)
])),
]),
name
=
"annotate_base"
),
...
...
adim_project/settings/components/auth.py
View file @
3f47cd5b
...
...
@@ -3,7 +3,7 @@ AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend'
,
)
LOGIN_REDIRECT_URL
=
"adim.app:annotate
_
new"
LOGIN_REDIRECT_URL
=
"adim.app:annotate
-
new"
LOGIN_URL
=
"adim.app:home"
SHIBAUTH_ATTR_PATTERN
=
r
'.*'
...
...
adim_project/settings/components/base.py
View file @
3f47cd5b
...
...
@@ -6,6 +6,7 @@ TEMPLATE_DEBUG = False
ALLOWED_HOSTS
=
[]
INSTALLED_APPS
=
(
'django.contrib.sites'
,
'django.contrib.admin'
,
'django.contrib.auth'
,
'django.contrib.contenttypes'
,
...
...
adim_project/urls.py
View file @
3f47cd5b
from
django.conf.urls
import
patterns
,
include
,
url
,
static
from
django.conf.urls
import
include
,
url
,
static
from
django.conf
import
settings
from
django.contrib
import
admin
admin
.
autodiscover
()
urlpatterns
=
patterns
(
''
,
urlpatterns
=
[
# Examples:
# url(r'^$', 'adim_project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
...
...
@@ -17,7 +17,7 @@ urlpatterns = patterns('',
url
(
r
'^api/'
,
include
(
'adim.urls'
)),
url
(
r
'^'
,
include
(
'adim_app.urls'
,
namespace
=
'adim.app'
,
app_name
=
'adim_app'
)),
)
]
handler404
=
'adim_app.views.handle_404'
handler400
=
'adim_app.views.handle_404'
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment