Gitlab CSE Unil

Commit 0ca32140 authored by Julien Furrer's avatar Julien Furrer
Browse files

Changed url schema for images and thumbnails

Image and thumbnail URLs are now seen as
"sub pages" of the annotable 

image     .../<anobj_uuid>/image/
thumbnail .../<anobj_uuid>/thumb/
parent ba5d2d18
...@@ -31,12 +31,12 @@ class AnObjSerializer(serializers.ModelSerializer): ...@@ -31,12 +31,12 @@ class AnObjSerializer(serializers.ModelSerializer):
annotations = AnnotationSerializer(many=True, read_only=True) annotations = AnnotationSerializer(many=True, read_only=True)
attrs = serializers.SerializerMethodField('attrs_as_dict') attrs = serializers.SerializerMethodField('attrs_as_dict')
#image_url = serializers.Field(source='image.url') #image_url = serializers.Field(source='image.url')
image_thumb = serializers.Field(source='thumb_url') #image_thumb = serializers.Field(source='thumb_url')
# image_thumb = serializers.SerializerMethodField('get_image_thumb') #image_thumb = serializers.SerializerMethodField('get_image_thumb')
class Meta: class Meta:
model = AnObj model = AnObj
fields = ('id', 'uuid', 'name', 'owner', 'ao_type', 'image_thumb', 'annotations') fields = ('id', 'uuid', 'name', 'owner', 'ao_type', 'annotations')
def get_image_thumb(self, obj): def get_image_thumb(self, obj):
cache_key = '_'.join((ANOBJ_THUMB_CACHE_BASE_KEY, str(obj.id))) cache_key = '_'.join((ANOBJ_THUMB_CACHE_BASE_KEY, str(obj.id)))
......
...@@ -27,7 +27,7 @@ function($){ ...@@ -27,7 +27,7 @@ function($){
// Default values for configuration parameters, will be overridden // Default values for configuration parameters, will be overridden
// by the parameters found in the `adim_config` // by the parameters found in the `adim_config`
var config = $.extend({ var config = $.extend(true, {
MODE_EDIT: 'edit', MODE_EDIT: 'edit',
MODE_REVIEW: 'review', MODE_REVIEW: 'review',
...@@ -37,7 +37,10 @@ function($){ ...@@ -37,7 +37,10 @@ function($){
// This object is used to expose some modules' functions // This object is used to expose some modules' functions
adim_global_varname: "ADIM", adim_global_varname: "ADIM",
annotable: null, annotable: {
image: 'image/',
thumbnail: 'thumb/'
},
// The url of the image to be loaded // The url of the image to be loaded
image_url: "", image_url: "",
......
...@@ -108,7 +108,7 @@ function ($, paper, Signal, Config, view) { ...@@ -108,7 +108,7 @@ function ($, paper, Signal, Config, view) {
fd.append('file', thumbBlob); fd.append('file', thumbBlob);
return $.ajax({ return $.ajax({
type: 'POST', type: 'POST',
url: '/u/', url: Config.annotable.thumbnail,
data: fd, data: fd,
processData: false, processData: false,
contentType: false contentType: false
......
...@@ -52,7 +52,9 @@ window.ADIM_CONFIG = { ...@@ -52,7 +52,9 @@ window.ADIM_CONFIG = {
id: {{ anobj.id }}, id: {{ anobj.id }},
title: '{{ anobj.name|escapejs }}', title: '{{ anobj.name|escapejs }}',
slug: '{{ anobj.name|slugify }}', slug: '{{ anobj.name|slugify }}',
image: '{% url "adim.app:ao_image" anobj_uuid=anobj.uuid %}' image: 'image/',
thumbnail: 'thumb/'
{# image: '{% url "adim.app:ao_image" anobj_uuid=anobj.uuid %}'#}
}, },
users: {}, users: {},
......
...@@ -121,15 +121,15 @@ ...@@ -121,15 +121,15 @@
{# JS TEMPLATES #} {# JS TEMPLATES #}
{#==========================================#} {#==========================================#}
{% block js_templates %} {% block js_templates %}
{% url "adim.app:annotate-new" as annotate_url %}
{# -- AnObjMgr list-item view -- #} {# -- AnObjMgr list-item view -- #}
<script type="text/template" id="aom-list-item"> <script type="text/template" id="aom-list-item">
<button class="close" title="Supprimer l'image"> <button class="close" title="Supprimer l'image">
<span class="glyphicon glyphicon-remove-circle"></span> <span class="glyphicon glyphicon-remove-circle"></span>
</button> </button>
<a href="{% url "adim.app:annotate-new" %}<%= uuid %>/" title="Editer l'image"> <a href="{{ annotate_url }}<%= uuid %>/" title="Editer l'image">
{# <img src="<%= image_thumb %>" style="background-image: ">#}
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
style="background-image: url(<%= image_thumb %>);"> style="background-image: url({{ annotate_url }}<%= uuid %>/thumb/);">
<span class="name"><%= name %></span> <span class="name"><%= name %></span>
</a> </a>
</script> </script>
......
...@@ -5,11 +5,27 @@ from django.conf.urls import url, patterns, include ...@@ -5,11 +5,27 @@ from django.conf.urls import url, patterns, include
urlpatterns = patterns('adim_app.views', urlpatterns = patterns('adim_app.views',
url(r'^$', 'home', name="home"), url(r'^$', 'home', name="home"),
url(r'^i/(?P<anobj_uuid>[0-9a-f]{32})/$', 'send_anobj_img', name='ao_image'), # url(r'^i/(?P<anobj_uuid>[0-9a-f]{32})/$', 'send_anobj_img', name='ao_image'),
url(r'^t/(?P<anobj_uuid>[0-9a-f]{32})/$', 'send_anobj_thumb', name="ao_thumb"), # url(r'^t/(?P<anobj_uuid>[0-9a-f]{32})/$', 'send_anobj_thumb', name="ao_thumb"),
url(r'^u/$', 'upload_thumb'), # url(r'^u/$', 'upload_thumb', name="upload-thumb"),
url(r'^new/$', 'upload_file', name='upload_file'), url(r'^new/$', 'upload_file', name='upload_file'),
url(r'^annotate/$', 'annotate_new', name="annotate-new"),
# url(r'^annotate/(?P<anobj_id>\d+|_)/$', 'annotate', name="annotate"), url(r'^annotate/',
url(r'^annotate/(?P<anobj_uuid>[0-9a-f]{32})/$', 'annotate', name="annotate"), include(patterns('adim_app.views',
url(r'^$', 'annotate_new', name="annotate-new"),
url(r'^(?P<anobj_uuid>[0-9a-f]{32})/',
include(patterns('adim_app.views',
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"
),
# url(r'^annotate/$', 'annotate_new', name="annotate-new"),
# url(r'^annotate/(?P<anobj_uuid>[0-9a-f]{32})/$', 'annotate', name="annotate"),
# url(r'^annotate/(?P<anobj_uuid>[0-9a-f]{32})/u/$', 'upload_thumb',),
) )
...@@ -76,6 +76,14 @@ def send_anobj_img(request, anobj_uuid): ...@@ -76,6 +76,14 @@ def send_anobj_img(request, anobj_uuid):
return HttpResponseForbidden('Sorry, you cannot access this file') return HttpResponseForbidden('Sorry, you cannot access this file')
@login_required
def anobj_thumb(request, anobj_uuid):
if request.method == 'GET':
return send_anobj_thumb(request, anobj_uuid=anobj_uuid)
elif request.method == 'POST':
return upload_anobj_thumb(request, anobj_uuid=anobj_uuid)
@login_required @login_required
def send_anobj_thumb(request, anobj_uuid): def send_anobj_thumb(request, anobj_uuid):
try: try:
...@@ -192,18 +200,18 @@ def _validate_uploaded_file(image_file): ...@@ -192,18 +200,18 @@ def _validate_uploaded_file(image_file):
@login_required @login_required
@require_POST @require_POST
def upload_thumb(request): def upload_anobj_thumb(request, anobj_uuid=None):
anobj_id = None if anobj_uuid:
try: anobj = _get_anobj(request, anobj_uuid=anobj_uuid)
anobj_id = int(request.POST.get('aid')) else:
except TypeError: try:
return HttpResponseBadRequest() anobj_id = int(request.POST.get('aid'))
anobj = _get_anobj(request, anobj_id=anobj_id)
except TypeError:
return HttpResponseBadRequest()
# anobj = AnObj.objects.get(pk=anobj_id)
anobj = _get_anobj(request, anobj_id=anobj_id)
thumb_name = os.path.splitext(anobj.image.name)[0] + '__.png' thumb_name = os.path.splitext(anobj.image.name)[0] + '__.png'
thumb_path = os.path.join(settings.MEDIA_ROOT, thumb_name) thumb_path = os.path.join(settings.MEDIA_ROOT, thumb_name)
# thumb_url = os.path.join(settings.MEDIA_URL, thumb_name)
thumb_url = reverse('adim.app:ao_thumb', kwargs={'anobj_uuid': anobj.uuid}) thumb_url = reverse('adim.app:ao_thumb', kwargs={'anobj_uuid': anobj.uuid})
thumb_file = request.FILES['file'] thumb_file = request.FILES['file']
......
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