# HG changeset patch # User durandn # Date 1466771216 -7200 # Node ID 31d4f0e8672342cc7531cc37c0d9de20033ef68a # Parent 1ede957a686842ce17e842c538f613e77f46fd9d added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid diff -r 1ede957a6868 -r 31d4f0e86723 src/iconolab/forms/annotations.py --- 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 diff -r 1ede957a6868 -r 31d4f0e86723 src/iconolab/models.py --- 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, diff -r 1ede957a6868 -r 31d4f0e86723 src/iconolab/templates/iconolab/change_annotation.html --- 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 @@ + id="id_{{ form.title.name }}" value="{% if form.title.value %}{{ form.title.value}}{% endif %}">
+ id="id_{{ form.description.name }}" >{% if form.description.value %}{{ form.description.value}}{% endif %}
diff -r 1ede957a6868 -r 31d4f0e86723 src/iconolab/templates/iconolab/detail_annotation.html --- 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 %} - Revoir l'image + Revoir l'image
diff -r 1ede957a6868 -r 31d4f0e86723 src/iconolab/templates/iconolab/detail_image.html --- 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 %} -

detail_image for {{image_ref}} in the collection {{collection_name}}

-Create Annotation +
+
+ Créer une nouvelle annotation + + {% thumbnail image.media "x800" crop="center" as im %} + + {% endthumbnail %} +
+
+ +{% include "partials/image_annotations_list.html" with annotation_list=image.annotations.all %} {% endblock %} \ No newline at end of file diff -r 1ede957a6868 -r 31d4f0e86723 src/iconolab/templates/partials/image_annotations_list.html --- 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 @@
{% endthumbnail %}
- Voir -

Créer par {{ annotation.author }}

+ Voir +

Créee par {{ annotation.author }}

Révisée par {{ annotation.current_revision.author }} le {{ annotation.current_revision.created|date:'d-m-Y' }}

diff -r 1ede957a6868 -r 31d4f0e86723 src/iconolab/views.py --- 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):