# HG changeset patch # User durandn # Date 1467289497 -7200 # Node ID aec0f3381736cabc861aed266423bc32d50f17a4 # Parent 86608f92ebeddc13efbea71e28c2cceee15d7184 Added metacategories to comments + error handling on annotation forms diff -r 86608f92ebed -r aec0f3381736 src/iconolab/fixtures/dev_initial_data.json --- a/src/iconolab/fixtures/dev_initial_data.json Fri Jul 01 11:19:59 2016 +0200 +++ b/src/iconolab/fixtures/dev_initial_data.json Thu Jun 30 14:24:57 2016 +0200 @@ -68,8 +68,7 @@ "author": 1, "created": "2016-03-24 14:13:44.913765+01" } - }, - { + },{ "model": "iconolab.Annotation", "pk": 2, "fields": { @@ -79,8 +78,7 @@ "author": 1, "created": "2016-03-24 14:13:44.913765+01" } - }, - { + },{ "model": "iconolab.Annotation", "pk": 3, "fields": { @@ -90,8 +88,7 @@ "author": 1, "created": "2016-03-24 14:13:44.913765+01" } - }, - { + },{ "model": "iconolab.AnnotationStats", "pk": 1, "fields": { @@ -116,8 +113,7 @@ "state": 1, "created": "2016-03-25 14:13:44.913765+01" } - }, - { + },{ "model": "iconolab.AnnotationRevision", "pk": 2, "fields": { @@ -130,8 +126,7 @@ "state": 1, "created": "2016-03-25 14:13:44.913765+01" } - }, - { + },{ "model": "iconolab.AnnotationRevision", "pk": 3, "fields": { @@ -144,7 +139,19 @@ "state": 1, "created": "2016-03-25 14:13:44.913765+01" } + },{ + "model": "iconolab.MetaCategory", + "pk": 1, + "fields": { + "collection": 1, + "label": "Appel à contribution" + } + },{ + "model": "iconolab.MetaCategory", + "pk": 2, + "fields": { + "collection": 1, + "label": "Trouble" + } } - - ] \ No newline at end of file diff -r 86608f92ebed -r aec0f3381736 src/iconolab/forms/comments.py --- a/src/iconolab/forms/comments.py Fri Jul 01 11:19:59 2016 +0200 +++ b/src/iconolab/forms/comments.py Thu Jun 30 14:24:57 2016 +0200 @@ -1,6 +1,8 @@ from django import forms from django.utils.translation import ugettext_lazy as _ from django_comments_xtd.forms import XtdCommentForm +from django_comments_xtd.models import TmpXtdComment +from django_comments_xtd import get_model as get_comment_model from django.contrib.contenttypes.models import ContentType from django.conf import settings from django.utils.encoding import force_text @@ -8,7 +10,7 @@ from iconolab.models import MetaCategory class IconolabCommentForm(XtdCommentForm): - metacategories = forms.ModelMultipleChoiceField(queryset=MetaCategory.objects.all(), required=False) + metacategories = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple, queryset=MetaCategory.objects.all(), required=False) email = forms.EmailField(required=False) def __init__(self, *args, **kwargs): @@ -16,15 +18,7 @@ self.fields.pop('email') def get_comment_create_data(self): - return dict( - content_type=ContentType.objects.get_for_model(self.target_object), - object_pk=force_text(self.target_object._get_pk_val()), - user_name=self.cleaned_data["name"], - user_email='', - user_url=self.cleaned_data["url"], - comment=self.cleaned_data["comment"], - submit_date=timezone.now(), - site_id=settings.SITE_ID, - is_public=True, - is_removed=False, - ) \ No newline at end of file + self.cleaned_data['email'] = '' + data = super(IconolabCommentForm, self).get_comment_create_data() + data.update({'user_email': ''}) + return data \ No newline at end of file diff -r 86608f92ebed -r aec0f3381736 src/iconolab/models.py --- a/src/iconolab/models.py Fri Jul 01 11:19:59 2016 +0200 +++ b/src/iconolab/models.py Thu Jun 30 14:24:57 2016 +0200 @@ -213,12 +213,12 @@ tag_accuracy = tag_data.get("accuracy", 0) tag_relevancy = tag_data.get("relevancy", 0) - if tag_string.startswith("http://"): #check if url + if tag_string.startswith("http://") or tag_string.startswith("https://"): #check if url if Tag.objects.filter(link=tag_string).exists(): #check if tag already exists tag_obj = Tag.objects.get(link=tag_string) else: tag_obj = Tag.objects.create( - link = settings.BASE_URL+tag_string, + link = tag_string, ) else: tag_obj = Tag.objects.create( diff -r 86608f92ebed -r aec0f3381736 src/iconolab/templates/iconolab/change_annotation.html --- a/src/iconolab/templates/iconolab/change_annotation.html Fri Jul 01 11:19:59 2016 +0200 +++ b/src/iconolab/templates/iconolab/change_annotation.html Thu Jun 30 14:24:57 2016 +0200 @@ -75,26 +75,56 @@
- {% csrf_token %} -
+ {% if form.errors %} + + {% endif %} + {% csrf_token %} +
+ {% if form.title.errors %} + + {% endif %}
-
+
+ {% if form.description.errors %} + + {% endif %}
-
+
+ {% if form.comment.errors %} + + {% endif %} diff -r 86608f92ebed -r aec0f3381736 src/iconolab/templates/iconolab/detail_annotation.html --- a/src/iconolab/templates/iconolab/detail_annotation.html Fri Jul 01 11:19:59 2016 +0200 +++ b/src/iconolab/templates/iconolab/detail_annotation.html Thu Jun 30 14:24:57 2016 +0200 @@ -49,8 +49,11 @@

{{ comment.comment }}

{{ comment.submit_date }} -  {{ comment.name }} - {% if comment.revision %} -  Show revision{% endif %} {% if comment.allow_thread %} -  {% trans "Reply" %}{% endif %}
+ {% if comment.revision %}Voir révision{% endif %} + {% for metacategory in comment.metacategories.all %} + {{metacategory.label}} + {% endfor %} {% endfor %} @@ -82,6 +85,15 @@ name="{{ comment_form.comment.name }}" id="id_{{ comment_form.comment.name }}" >
+
+
+ {% for metacategory in comment_form.metacategories %} + + {% endfor %} +
+

diff -r 86608f92ebed -r aec0f3381736 src/iconolab/views.py --- a/src/iconolab/views.py Fri Jul 01 11:19:59 2016 +0200 +++ b/src/iconolab/views.py Thu Jun 30 14:24:57 2016 +0200 @@ -11,7 +11,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site from django.conf import settings -from iconolab.models import Annotation, AnnotationRevision, Collection, Image, IconolabComment +from iconolab.models import Annotation, AnnotationRevision, Collection, Image, IconolabComment, MetaCategory, MetaCategoryInfo from iconolab.forms.annotations import AnnotationRevisionForm import datetime import django_comments @@ -20,343 +20,357 @@ class GlobalHomepageView(View): - def get(self, request, *args, **kwargs): - # Handle homepage view here - return render(request, 'iconolab/home.html'); + def get(self, request, *args, **kwargs): + # Handle homepage view here + return render(request, 'iconolab/home.html'); class CollectionHomepageView(View, ContextMixin): - def get(self, request, *args, **kwargs): - context = super(CollectionHomepageView, self).get_context_data(**kwargs) - context["collection_name"] = self.kwargs.get("collection_name", "") - return render(request, 'iconolab/collection_home.html', context); + def get(self, request, *args, **kwargs): + context = super(CollectionHomepageView, self).get_context_data(**kwargs) + context['collection_name'] = self.kwargs.get('collection_name', '') + return render(request, 'iconolab/collection_home.html', context); class ShowImageView(View, ContextMixin): - - 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")) - return collection, image - - def get(self, request, *args, **kwargs): - 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); - + + 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')) + return collection, image + + def get(self, request, *args, **kwargs): + 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): - - def get_context_data(self, **kwargs): - context = super(CreateAnnotationView, self).get_context_data(**kwargs) - context["collection_name"] = self.kwargs.get("collection_name", "") - context["image_guid"] = self.kwargs.get("image_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")) - return collection, image - - def get(self, request, *args, **kwargs): - collection, image = self.check_kwargs(kwargs) - annotation_form = AnnotationRevisionForm() - context = self.get_context_data(**kwargs) - context["image"] = image - context["form"] = annotation_form - context["tags_data"] = "[]" - return render(request, 'iconolab/change_annotation.html', context) - - def post(self, request, *args, **kwargs): - collection, image = self.check_kwargs(kwargs) - collection_name = kwargs["collection_name"] - image_guid = kwargs["image_guid"] - annotation_form = AnnotationRevisionForm(request.POST) - if annotation_form.is_valid(): - author = request.user - title = annotation_form.cleaned_data["title"] - description = annotation_form.cleaned_data["description"] - fragment = annotation_form.cleaned_data["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) - revision_comment = annotation_form.cleaned_data["comment"] - IconolabComment.objects.create( - comment = revision_comment, - revision = new_annotation.current_revision, - content_type = ContentType.objects.get(app_label="iconolab", model="annotation"), - content_object = new_annotation, - site = Site.objects.get(id=settings.SITE_ID), - object_pk = new_annotation.id, - user = request.user, - user_name = request.user.username - ) - return RedirectView.as_view(url=reverse("annotation_detail", kwargs={'collection_name': collection_name, 'image_guid': image_guid, 'annotation_guid': new_annotation.annotation_guid}))(request) - print(annotation_form.errors) - return HttpResponse("error") - + + def get_context_data(self, **kwargs): + context = super(CreateAnnotationView, self).get_context_data(**kwargs) + context['collection_name'] = self.kwargs.get('collection_name', '') + context['image_guid'] = self.kwargs.get('image_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')) + return collection, image + + def get(self, request, *args, **kwargs): + collection, image = self.check_kwargs(kwargs) + annotation_form = AnnotationRevisionForm() + context = self.get_context_data(**kwargs) + context['image'] = image + context['form'] = annotation_form + context['tags_data'] = '[]' + return render(request, 'iconolab/change_annotation.html', context) + + def post(self, request, *args, **kwargs): + collection, image = self.check_kwargs(kwargs) + collection_name = kwargs['collection_name'] + image_guid = kwargs['image_guid'] + annotation_form = AnnotationRevisionForm(request.POST) + if annotation_form.is_valid(): + author = request.user + title = annotation_form.cleaned_data['title'] + description = annotation_form.cleaned_data['description'] + fragment = annotation_form.cleaned_data['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) + revision_comment = annotation_form.cleaned_data['comment'] + IconolabComment.objects.create( + comment = revision_comment, + revision = new_annotation.current_revision, + content_type = ContentType.objects.get(app_label='iconolab', model='annotation'), + content_object = new_annotation, + site = Site.objects.get(id=settings.SITE_ID), + object_pk = new_annotation.id, + user = request.user, + user_name = request.user.username + ) + return RedirectView.as_view(url=reverse('annotation_detail', kwargs={'collection_name': collection_name, 'image_guid': image_guid, 'annotation_guid': new_annotation.annotation_guid}))(request) + context = self.get_context_data(**kwargs) + context['image'] = image + context['form'] = annotation_form + context['tags_data'] = '[]' + render(request, 'iconolab/change_annotation.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", "")) - 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["collection"] = collection - context["image"] = image - context["annotation"] = annotation - context["tags_data"] = annotation.current_revision.get_tags_json() - return render(request, 'iconolab/detail_annotation.html', context) + + 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['collection'] = collection + context['image'] = image + context['annotation'] = annotation + context['tags_data'] = annotation.current_revision.get_tags_json() + return render(request, 'iconolab/detail_annotation.html', context) class EditAnnotationView(View, ContextMixin): - - def get_context_data(self, **kwargs): - context = super(EditAnnotationView, 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) - annotation_form = AnnotationRevisionForm(instance=annotation.current_revision) - context = self.get_context_data(**kwargs) - context["image"] = image - context["annotation"] = annotation - context["form"] = annotation_form - context["tags_data"] = annotation.current_revision.get_tags_json() - return render(request, 'iconolab/change_annotation.html', context) - - def post(self, request, *args, **kwargs): - collection, image, annotation = self.check_kwargs(kwargs) - collection_name = kwargs["collection_name"] - image_guid = kwargs["image_guid"] - annotation_guid = kwargs["annotation_guid"] - annotation_form = AnnotationRevisionForm(request.POST) - if annotation_form.is_valid(): - revision_author = request.user - 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"] - new_revision = annotation.make_new_revision(revision_author, revision_title, revision_description, revision_fragment, revision_tags_json) - revision_comment = annotation_form.cleaned_data["comment"] - comment = IconolabComment.objects.create( - comment = revision_comment, - revision = new_revision, - content_type = ContentType.objects.get(app_label="iconolab", model="annotation"), - content_object = annotation, - site = Site.objects.get(id=settings.SITE_ID), - object_pk = annotation.id, - user = request.user, - user_name = request.user.username - ) - print(comment.revision) - print(new_revision.creation_comment.first()) - 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 errors") + + def get_context_data(self, **kwargs): + context = super(EditAnnotationView, 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) + annotation_form = AnnotationRevisionForm(instance=annotation.current_revision) + context = self.get_context_data(**kwargs) + context['image'] = image + context['annotation'] = annotation + context['form'] = annotation_form + context['tags_data'] = annotation.current_revision.get_tags_json() + return render(request, 'iconolab/change_annotation.html', context) + + def post(self, request, *args, **kwargs): + collection, image, annotation = self.check_kwargs(kwargs) + collection_name = kwargs['collection_name'] + image_guid = kwargs['image_guid'] + annotation_guid = kwargs['annotation_guid'] + annotation_form = AnnotationRevisionForm(request.POST) + if annotation_form.is_valid(): + revision_author = request.user + 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'] + new_revision = annotation.make_new_revision(revision_author, revision_title, revision_description, revision_fragment, revision_tags_json) + revision_comment = annotation_form.cleaned_data['comment'] + comment = IconolabComment.objects.create( + comment = revision_comment, + revision = new_revision, + content_type = ContentType.objects.get(app_label='iconolab', model='annotation'), + content_object = annotation, + site = Site.objects.get(id=settings.SITE_ID), + object_pk = annotation.id, + user = request.user, + user_name = request.user.username + ) + return RedirectView.as_view(url=reverse('annotation_detail', kwargs={'collection_name': collection_name, 'image_guid': image_guid, 'annotation_guid': annotation_guid}))(request) + context = self.get_context_data(**kwargs) + context['image'] = image + context['form'] = annotation_form + context['annotation'] = annotation + context['tags_data'] = annotation.current_revision.get_tags_json() + return render(request, 'iconolab/change_annotation.html', context) class ShowRevisionView(View, ContextMixin): - - def get_context_data(self, **kwargs): - context = super(ShowRevisionView, 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", "") - context["revision_guid"] = self.kwargs.get("revision_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")) - try: - revision = AnnotationRevision.objects.select_related("parent_revision").get(revision_guid=kwargs.get("revision_guid", "")) - except AnnotationRevision.DoesNotExist: - return RedirectView.as_view(url=reverse("404error")) - return collection, image, annotation, revision - - def get(self, request, *args, **kwargs): - collection, image, annotation, revision = self.check_kwargs(kwargs) - self.check_kwargs(kwargs) - context = self.get_context_data(**kwargs) - context["collection"] = collection - context["image"] = image - context["annotation"] = annotation - context["revision"] = revision - context["tags_data"] = revision.get_tags_json() - print(revision.creation_comment) - context["comment"] = revision.creation_comment.first() - return render(request, 'iconolab/detail_revision.html', context) + + def get_context_data(self, **kwargs): + context = super(ShowRevisionView, 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', '') + context['revision_guid'] = self.kwargs.get('revision_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')) + try: + revision = AnnotationRevision.objects.select_related('parent_revision').get(revision_guid=kwargs.get('revision_guid')) + except AnnotationRevision.DoesNotExist: + return RedirectView.as_view(url=reverse('404error')) + return collection, image, annotation, revision + + def get(self, request, *args, **kwargs): + collection, image, annotation, revision = self.check_kwargs(kwargs) + self.check_kwargs(kwargs) + context = self.get_context_data(**kwargs) + context['collection'] = collection + context['image'] = image + context['annotation'] = annotation + context['revision'] = revision + context['tags_data'] = revision.get_tags_json() + print(revision.creation_comment) + context['comment'] = revision.creation_comment.first() + return render(request, 'iconolab/detail_revision.html', context) - + class MergeProposalView(View): - - def get(self, request, *args, **kwargs): - # Handle merge form display here - pass - - def post(self, request, *args, **kwargs): - # Handle merge form submit here - pass - - + + def get(self, request, *args, **kwargs): + # Handle merge form display here + pass + + def post(self, request, *args, **kwargs): + # Handle merge form submit here + pass + + class NotFoundErrorView(View): - def get(self, request, *args, **kwargs): - # Handle image display here - pass - + def get(self, request, *args, **kwargs): + # Handle image display here + pass + @csrf_protect @require_POST def post_comment_iconolab(request, next=None, using=None): - """ - Post a comment. - HTTP POST is required. If ``POST['submit'] == "preview"`` or if there are - errors a preview template, ``comments/preview.html``, will be rendered. - """ - # Fill out some initial data fields from an authenticated user, if present - data = request.POST.copy() - if request.user.is_authenticated(): - if not data.get('name', ''): - data["name"] = request.user.get_full_name() or request.user.get_username() - if not data.get('email', ''): - data["email"] = request.user.email + ''' + Post a comment. + HTTP POST is required. If ``POST['submit'] == 'preview'`` or if there are + errors a preview template, ``comments/preview.html``, will be rendered. + ''' + # Fill out some initial data fields from an authenticated user, if present + data = request.POST.copy() + if request.user.is_authenticated(): + if not data.get('name', ''): + data['name'] = request.user.get_full_name() or request.user.get_username() + if not data.get('email', ''): + data['email'] = request.user.email - # Look up the object we're trying to comment about - ctype = data.get("content_type") - object_pk = data.get("object_pk") - if ctype is None or object_pk is None: - return CommentPostBadRequest("Missing content_type or object_pk field.") - try: - model = apps.get_model(*ctype.split(".", 1)) - target = model._default_manager.using(using).get(pk=object_pk) - except TypeError: - return CommentPostBadRequest( - "Invalid content_type value: %r" % escape(ctype)) - except AttributeError: - return CommentPostBadRequest( - "The given content-type %r does not resolve to a valid model." % escape(ctype)) - except ObjectDoesNotExist: - return CommentPostBadRequest( - "No object matching content-type %r and object PK %r exists." % ( - escape(ctype), escape(object_pk))) - except (ValueError, ValidationError) as e: - return CommentPostBadRequest( - "Attempting go get content-type %r and object PK %r exists raised %s" % ( - escape(ctype), escape(object_pk), e.__class__.__name__)) + # Look up the object we're trying to comment about + ctype = data.get('content_type') + object_pk = data.get('object_pk') + if ctype is None or object_pk is None: + return CommentPostBadRequest('Missing content_type or object_pk field.') + try: + model = apps.get_model(*ctype.split('.', 1)) + target = model._default_manager.using(using).get(pk=object_pk) + except TypeError: + return CommentPostBadRequest( + 'Invalid content_type value: %r' % escape(ctype)) + except AttributeError: + return CommentPostBadRequest( + 'The given content-type %r does not resolve to a valid model.' % escape(ctype)) + except ObjectDoesNotExist: + return CommentPostBadRequest( + 'No object matching content-type %r and object PK %r exists.' % ( + escape(ctype), escape(object_pk))) + except (ValueError, ValidationError) as e: + return CommentPostBadRequest( + 'Attempting go get content-type %r and object PK %r exists raised %s' % ( + escape(ctype), escape(object_pk), e.__class__.__name__)) - # Do we want to preview the comment? - preview = "preview" in data + # Do we want to preview the comment? + preview = 'preview' in data - # Construct the comment form - form = django_comments.get_form()(target, data=data) + # Construct the comment form + form = django_comments.get_form()(target, data=data) + + # Check security information + if form.security_errors(): + return CommentPostBadRequest( + 'The comment form failed security verification: %s' % escape(str(form.security_errors()))) - # Check security information - if form.security_errors(): - return CommentPostBadRequest( - "The comment form failed security verification: %s" % escape(str(form.security_errors()))) + # If there are errors or if we requested a preview show the comment + if form.errors: + return render(request, 'iconolab/detail_annotation.html', { + 'comment_form': form, + 'next': data.get('next', next), + 'annotation': target, + 'annotation_guid': target.annotation_guid, + 'image_guid': target.image.image_guid, + 'collection_name': target.image.item.collection.name, + 'tags_data': target.current_revision.get_tags_json() + }, + ) - # If there are errors or if we requested a preview show the comment - if form.errors: - return render(request, "iconolab/detail_annotation.html", { - "comment_form": form, - "next": data.get("next", next), - "annotation": target, - "annotation_guid": target.annotation_guid, - "image_guid": target.image.image_guid, - "collection_name": target.image.item.collection.name, - "tags_data": target.current_revision.get_tags_json() - }, - ) + # Otherwise create the comment + comment = form.get_comment_object() + comment.ip_address = request.META.get('REMOTE_ADDR', None) + if request.user.is_authenticated(): + comment.user = request.user + + # Signal that the comment is about to be saved + responses = signals.comment_will_be_posted.send( + sender=comment.__class__, + comment=comment, + request=request + ) - # Otherwise create the comment - comment = form.get_comment_object() - comment.ip_address = request.META.get("REMOTE_ADDR", None) - if request.user.is_authenticated(): - comment.user = request.user - - # Signal that the comment is about to be saved - responses = signals.comment_will_be_posted.send( - sender=comment.__class__, - comment=comment, - request=request - ) + for (receiver, response) in responses: + if response is False: + return CommentPostBadRequest( + 'comment_will_be_posted receiver %r killed the comment' % receiver.__name__) - for (receiver, response) in responses: - if response is False: - return CommentPostBadRequest( - "comment_will_be_posted receiver %r killed the comment" % receiver.__name__) + # Save the comment and signal that it was saved + comment.save() + + + signals.comment_was_posted.send( + sender=comment.__class__, + comment=comment, + request=request + ) + + # Creating metacategories here as apparently there is no way to make it work easily woth django_comments_xtd + for metacategory in form.cleaned_data.get("metacategories", []): + if 'xtd_comment' in comment: + metacategory_info = MetaCategoryInfo.objects.create( + comment = comment['xtd_comment'], + metacategory = metacategory + ) - # Save the comment and signal that it was saved - comment.save() - signals.comment_was_posted.send( - sender=comment.__class__, - comment=comment, - request=request - ) - - return next_redirect(request, fallback=next or 'comments-comment-done', - c=comment._get_pk_val()) \ No newline at end of file + return next_redirect(request, fallback=next or 'comments-comment-done', + c=comment._get_pk_val()) \ No newline at end of file