-
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):