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):
annotations = AnnotationSerializer(many=True, read_only=True)
attrs = serializers.SerializerMethodField('attrs_as_dict')
#image_url = serializers.Field(source='image.url')
image_thumb = serializers.Field(source='thumb_url')
# image_thumb = serializers.SerializerMethodField('get_image_thumb')
#image_thumb = serializers.Field(source='thumb_url')
#image_thumb = serializers.SerializerMethodField('get_image_thumb')
class Meta:
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):
cache_key = '_'.join((ANOBJ_THUMB_CACHE_BASE_KEY, str(obj.id)))
......
......@@ -27,7 +27,7 @@ function($){
// Default values for configuration parameters, will be overridden
// by the parameters found in the `adim_config`
var config = $.extend({
var config = $.extend(true, {
MODE_EDIT: 'edit',
MODE_REVIEW: 'review',
......@@ -37,7 +37,10 @@ function($){
// This object is used to expose some modules' functions
adim_global_varname: "ADIM",
annotable: null,
annotable: {
image: 'image/',
thumbnail: 'thumb/'
},
// The url of the image to be loaded
image_url: "",
......
......@@ -108,7 +108,7 @@ function ($, paper, Signal, Config, view) {
fd.append('file', thumbBlob);
return $.ajax({
type: 'POST',
url: '/u/',
url: Config.annotable.thumbnail,
data: fd,
processData: false,
contentType: false
......
......@@ -52,7 +52,9 @@ window.ADIM_CONFIG = {
id: {{ anobj.id }},
title: '{{ anobj.name|escapejs }}',
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: {},
......
......@@ -121,15 +121,15 @@
{# JS TEMPLATES #}
{#==========================================#}
{% block js_templates %}
{% url "adim.app:annotate-new" as annotate_url %}
{# -- AnObjMgr list-item view -- #}
<script type="text/template" id="aom-list-item">
<button class="close" title="Supprimer l'image">
<span class="glyphicon glyphicon-remove-circle"></span>
</button>
<a href="{% url "adim.app:annotate-new" %}<%= uuid %>/" title="Editer l'image">
{# <img src="<%= image_thumb %>" style="background-image: ">#}
<a href="{{ annotate_url }}<%= uuid %>/" title="Editer l'image">
<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>
</a>
</script>
......
......@@ -5,11 +5,27 @@ from django.conf.urls import url, patterns, include
urlpatterns = patterns('adim_app.views',
url(r'^$', 'home', name="home"),
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'^u/$', 'upload_thumb'),
# 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'^u/$', 'upload_thumb', name="upload-thumb"),
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/(?P<anobj_uuid>[0-9a-f]{32})/$', 'annotate', name="annotate"),
url(r'^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):
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
def send_anobj_thumb(request, anobj_uuid):
try:
......@@ -192,18 +200,18 @@ def _validate_uploaded_file(image_file):
@login_required
@require_POST
def upload_thumb(request):
anobj_id = None
try:
anobj_id = int(request.POST.get('aid'))
except TypeError:
return HttpResponseBadRequest()
def upload_anobj_thumb(request, anobj_uuid=None):
if anobj_uuid:
anobj = _get_anobj(request, anobj_uuid=anobj_uuid)
else:
try:
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_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_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