added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
--- a/src/iconolab/forms/annotations.py Fri Jun 24 12:39:13 2016 +0200
+++ b/src/iconolab/forms/annotations.py Fri Jun 24 14:26:56 2016 +0200
@@ -1,4 +1,4 @@
-from django.forms import ModelForm, TypedMultipleChoiceField, HiddenInput, MultipleHiddenInput
+from django.forms import ModelForm, TypedMultipleChoiceField, HiddenInput, CharField, MultipleHiddenInput
from iconolab.models import AnnotationRevision
import json
@@ -6,9 +6,11 @@
pass
class AnnotationRevisionForm(ModelForm):
+ tags = CharField()
+
class Meta:
model = AnnotationRevision
- fields = ('title', 'description', 'fragment',)
+ fields = ('title', 'description', 'fragment')
widgets = {
'fragment': HiddenInput(),
'tags': HiddenInput()
@@ -18,7 +20,7 @@
if self.instance:
tags_list = []
for tag_info in self.instance.tagginginfo_set.all():
- tags_list.push({
+ tags_list.append({
'tag_input': tag_info.tag.link,
'relevancy': tag_info.relevancy,
'accuracy': tag_info.accuracy
--- a/src/iconolab/models.py Fri Jun 24 12:39:13 2016 +0200
+++ b/src/iconolab/models.py Fri Jun 24 14:26:56 2016 +0200
@@ -136,7 +136,7 @@
# Call to create a new revision, possibly from a merge
@transaction.atomic
- def make_new_revision(self, author, title, description, fragment, tags):
+ def make_new_revision(self, author, title, description, fragment, tags_json):
if author == self.author:
# We're creating an automatically accepted revision
new_revision_state = AnnotationRevision.ACCEPTED
@@ -153,6 +153,7 @@
state=new_revision_state
)
new_revision.save()
+ new_revision.set_tags(tags_json)
if new_revision.state == AnnotationRevision.ACCEPTED:
self.current_revision = new_revision
self.save()
@@ -222,8 +223,8 @@
tag_obj = Tag.objects.create(
label = tag_string,
description = "",
- link = settings.BASE_URL+tag_string,
- collection = self.parent_annotation.image.item.collection
+ link = settings.BASE_URL+'/'+tag_string,
+ collection = self.annotation.image.item.collection
)
tag_info = TaggingInfo.objects.create(
tag=tag_obj,
--- a/src/iconolab/templates/iconolab/change_annotation.html Fri Jun 24 12:39:13 2016 +0200
+++ b/src/iconolab/templates/iconolab/change_annotation.html Fri Jun 24 14:26:56 2016 +0200
@@ -81,13 +81,13 @@
<label class="control-label" for="id_{{ form.title.name }}">{{ form.title.label }}</label>
<input type="text" class="form-control"
name="{{ form.title.name }}"
- id="id_{{ form.title.name }}" value="{{ form.title.value}}">
+ id="id_{{ form.title.name }}" value="{% if form.title.value %}{{ form.title.value}}{% endif %}">
</fieldset>
<fieldset class="form-group">
<label class="control-label" for="id_{{ form.description.name }}">{{ form.description.label }}</label>
<textarea class="form-control"
name="{{ form.description.name }}"
- id="id_{{ form.description.name }}" >{{ form.description.value}}</textarea>
+ id="id_{{ form.description.name }}" >{% if form.description.value %}{{ form.description.value}}{% endif %}</textarea>
</fieldset>
<fieldset class="form-group">
<label class="control-label" for="id_{{ form.tags.name }}">{{ form.tags.label }}</label>
--- a/src/iconolab/templates/iconolab/detail_annotation.html Fri Jun 24 12:39:13 2016 +0200
+++ b/src/iconolab/templates/iconolab/detail_annotation.html Fri Jun 24 14:26:56 2016 +0200
@@ -8,7 +8,7 @@
{% block content %}
- <a href="{% url 'image_detail' collection_name image_ref %}"><i class="fa fa-list"></i> Revoir l'image </a>
+ <a href="{% url 'image_detail' collection_name image_guid %}"><i class="fa fa-list"></i> Revoir l'image </a>
<div id="annotation-wrapper" class="row" style="border: 1px solid gray">
<div v-show="formView" class="col-md-12">
--- a/src/iconolab/templates/iconolab/detail_image.html Fri Jun 24 12:39:13 2016 +0200
+++ b/src/iconolab/templates/iconolab/detail_image.html Fri Jun 24 14:26:56 2016 +0200
@@ -7,7 +7,16 @@
{% load iconolab_tags %}
{% block content %}
-<p>detail_image for {{image_ref}} in the collection {{collection_name}}</p>
-<a href="{% url 'annotation_create' collection_name image_guid %}">Create Annotation</a>
+<div class="row">
+ <div class="col-md-6 col-md-offset-3">
+ <a class="btn btn-link" href="{% url 'annotation_create' collection_name image_guid %}"><i class="fa fa-plus"></i> Créer une nouvelle annotation</a>
+
+ {% thumbnail image.media "x800" crop="center" as im %}
+ <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
+ {% endthumbnail %}
+ </div>
+</div>
+
+{% include "partials/image_annotations_list.html" with annotation_list=image.annotations.all %}
{% endblock %}
\ No newline at end of file
--- a/src/iconolab/templates/partials/image_annotations_list.html Fri Jun 24 12:39:13 2016 +0200
+++ b/src/iconolab/templates/partials/image_annotations_list.html Fri Jun 24 14:26:56 2016 +0200
@@ -19,8 +19,8 @@
</div>
{% endthumbnail %}
<div class="fragment-infos">
- <a class="fa fa-eye" href="{% url 'annotation_edit' collection_name image_ref annotation.annotation_guid %}">Voir</a>
- <p class="small">Créer par <strong>{{ annotation.author }}</strong></strong><p>
+ <a class="fa fa-eye" href="{% url 'annotation_edit' collection_name image_guid annotation.annotation_guid %}">Voir</a>
+ <p class="small">Créee par <strong>{{ annotation.author }}</strong></strong><p>
<p class="small">Révisée par <strong>{{ annotation.current_revision.author }}</strong>
le {{ annotation.current_revision.created|date:'d-m-Y' }}
</p>
--- a/src/iconolab/views.py Fri Jun 24 12:39:13 2016 +0200
+++ b/src/iconolab/views.py Fri Jun 24 14:26:56 2016 +0200
@@ -6,11 +6,12 @@
from django.core.urlresolvers import reverse
from iconolab.models import Annotation, Collection, Image
from iconolab.forms.annotations import AnnotationRevisionForm
+import json
def make_tags_json(annotation_revision):
final_list = []
for tagging_info in annotation_revision.tagginginfo_set.all():
- final_list.push({
+ final_list.append({
"tag_label": tagging_info.tag.label,
"tag_link": tagging_info.tag.link,
"accuracy": tagging_info.accuracy,
@@ -33,22 +34,6 @@
class ShowImageView(View, ContextMixin):
- def get(self, request, *args, **kwargs):
- context = super(ShowImageView, self).get_context_data(**kwargs)
- context["collection_name"] = self.kwargs.get("collection_name", "")
- context["image_guid"] = self.kwargs.get("image_guid", "")
- return render(request, 'iconolab/detail_image.html', context);
-
-
-class ShowAnnotationView(View, ContextMixin):
-
- def get_context_data(self, **kwargs):
- context = super(ShowAnnotationView, self).get_context_data(**kwargs)
- context["collection_name"] = self.kwargs.get("collection_name", "")
- context["image_guid"] = self.kwargs.get("image_guid", "")
- context["annotation_guid"] = self.kwargs.get("annotation_guid", "")
- return context
-
def check_kwargs(self, kwargs):
try:
collection = Collection.objects.get(name=kwargs.get("collection_name", ""))
@@ -58,19 +43,16 @@
image = Image.objects.get(image_guid=kwargs.get("image_guid", ""))
except Image.DoesNotExist:
return RedirectView.as_view(url=reverse("404error"))
- try:
- annotation = Annotation.objects.get(annotation_guid=kwargs.get("annotation_guid", ""))
- except Annotation.DoesNotExist:
- return RedirectView.as_view(url=reverse("404error"))
- return collection, image, annotation
+ return collection, image
def get(self, request, *args, **kwargs):
- collection, image, annotation = self.check_kwargs(kwargs)
- self.check_kwargs(kwargs)
- context = self.get_context_data(**kwargs)
- context["annotation"] = annotation
- return render(request, 'iconolab/detail_annotation.html', context)
-
+ collection, image = self.check_kwargs(kwargs)
+ context = super(ShowImageView, self).get_context_data(**kwargs)
+ context["collection_name"] = self.kwargs.get("collection_name", "")
+ context["image_guid"] = self.kwargs.get("image_guid", "")
+ context["collection"] = collection
+ context["image"] = image
+ return render(request, 'iconolab/detail_image.html', context);
class CreateAnnotationView(View, ContextMixin):
@@ -109,9 +91,43 @@
title = annotation_form.cleaned_data["title"]
description = annotation_form.cleaned_data["description"]
fragment = annotation_form.cleaned_data["fragment"]
- new_annotation = Annotation.objects.create_annotation(author, image, title=title, description=description, fragment=fragment)
+ tags_json = annotation_form.cleaned_data["tags"]
+ new_annotation = Annotation.objects.create_annotation(author, image, title=title, description=description, fragment=fragment, tags_json=tags_json)
return RedirectView.as_view(url=reverse("annotation_detail", kwargs={'collection_name': collection_name, 'image_guid': image_guid, 'annotation_guid': new_annotation.annotation_guid}))(request)
+
+
+class ShowAnnotationView(View, ContextMixin):
+ def get_context_data(self, **kwargs):
+ context = super(ShowAnnotationView, self).get_context_data(**kwargs)
+ context["collection_name"] = self.kwargs.get("collection_name", "")
+ context["image_guid"] = self.kwargs.get("image_guid", "")
+ context["annotation_guid"] = self.kwargs.get("annotation_guid", "")
+ return context
+
+ def check_kwargs(self, kwargs):
+ try:
+ collection = Collection.objects.get(name=kwargs.get("collection_name", ""))
+ except Collection.DoesNotExist:
+ return RedirectView.as_view(url=reverse("404error"))
+ try:
+ image = Image.objects.get(image_guid=kwargs.get("image_guid", ""))
+ except Image.DoesNotExist:
+ return RedirectView.as_view(url=reverse("404error"))
+ try:
+ annotation = Annotation.objects.select_related("current_revision").get(annotation_guid=kwargs.get("annotation_guid", ""))
+ except Annotation.DoesNotExist:
+ return RedirectView.as_view(url=reverse("404error"))
+ return collection, image, annotation
+
+ def get(self, request, *args, **kwargs):
+ collection, image, annotation = self.check_kwargs(kwargs)
+ self.check_kwargs(kwargs)
+ context = self.get_context_data(**kwargs)
+ context["annotation"] = annotation
+ return render(request, 'iconolab/detail_annotation.html', context)
+
+
class EditAnnotationView(View, ContextMixin):
def get_context_data(self, **kwargs):
@@ -131,7 +147,7 @@
except Image.DoesNotExist:
return RedirectView.as_view(url=reverse("404error"))
try:
- annotation = Annotation.objects.get(annotation_guid=kwargs.get("annotation_guid", ""))
+ annotation = Annotation.objects.select_related("current_revision").get(annotation_guid=kwargs.get("annotation_guid", ""))
except Annotation.DoesNotExist:
return RedirectView.as_view(url=reverse("404error"))
return collection, image, annotation
@@ -157,11 +173,12 @@
revision_title = annotation_form.cleaned_data["title"]
revision_description = annotation_form.cleaned_data["description"]
revision_fragment = annotation_form.cleaned_data["fragment"]
- revision_tags_json = annotation_form.cleaned_data["tags_input"]
+ revision_tags_json = annotation_form.cleaned_data["tags"]
annotation.make_new_revision(revision_author, revision_title, revision_description, revision_fragment, revision_tags_json)
return RedirectView.as_view(url=reverse("annotation_detail", kwargs={'collection_name': collection_name, 'image_guid': image_guid, 'annotation_guid': annotation_guid}))(request)
-
-
+ print(annotation_form.errors)
+ return HttpResponse("wow")
+
class MergeProposalView(View):
def get(self, request, *args, **kwargs):