src/iconolab/views.py
author Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
Fri, 01 Jul 2016 10:40:02 +0200
changeset 43 ccc449ef6f16
parent 42 51257e2701d9
child 47 aec0f3381736
permissions -rw-r--r--
Fixing drawing component
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
     1
from django.apps import apps
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
     2
from django.shortcuts import HttpResponse, get_object_or_404, render
6
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     3
from django.http import Http404
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     4
from django.contrib.auth.decorators import login_required
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
     5
from django.views.generic import View, RedirectView
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
     6
from django.views.generic.base import ContextMixin
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
     7
from django.views.decorators.csrf import csrf_protect
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
     8
from django.views.decorators.http import require_POST
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
     9
from django.core.urlresolvers import reverse
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    10
from django.core.exceptions import ObjectDoesNotExist, ValidationError
38
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
    11
from django.contrib.contenttypes.models import ContentType
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
    12
from django.contrib.sites.models import Site
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
    13
from django.conf import settings
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    14
from iconolab.models import Annotation, AnnotationRevision, Collection, Image, IconolabComment
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
    15
from iconolab.forms.annotations import AnnotationRevisionForm
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    16
import datetime
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    17
import django_comments
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    18
from django_comments import signals
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    19
from django_comments.views.utils import next_redirect, confirmation_view
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
    20
6
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    21
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    22
class GlobalHomepageView(View):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    23
	def get(self, request, *args, **kwargs):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    24
		# Handle homepage view here
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    25
		return render(request, 'iconolab/home.html');
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    26
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    27
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    28
class CollectionHomepageView(View, ContextMixin):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    29
	def get(self, request, *args, **kwargs):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    30
		context = super(CollectionHomepageView, self).get_context_data(**kwargs)
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    31
		context["collection_name"] = self.kwargs.get("collection_name", "")
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    32
		return render(request, 'iconolab/collection_home.html', context);
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    33
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    34
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    35
class ShowImageView(View, ContextMixin):
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    36
	
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    37
	def check_kwargs(self, kwargs):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    38
		try:
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    39
			collection = Collection.objects.get(name=kwargs.get("collection_name", ""))
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    40
		except Collection.DoesNotExist:
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    41
			return RedirectView.as_view(url=reverse("404error"))
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    42
		try:
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
    43
			image = Image.objects.get(image_guid=kwargs.get("image_guid", ""))
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    44
		except Image.DoesNotExist:
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    45
			return RedirectView.as_view(url=reverse("404error"))
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    46
		return collection, image
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    47
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    48
	def get(self, request, *args, **kwargs):
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    49
		collection, image = self.check_kwargs(kwargs)
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    50
		context = super(ShowImageView, self).get_context_data(**kwargs)
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    51
		context["collection_name"] = self.kwargs.get("collection_name", "")
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    52
		context["image_guid"] = self.kwargs.get("image_guid", "")
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    53
		context["collection"] = collection
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    54
		context["image"] = image
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    55
		return render(request, 'iconolab/detail_image.html', context);
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    56
	
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    57
class CreateAnnotationView(View, ContextMixin):
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    58
	
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    59
	def get_context_data(self, **kwargs):
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    60
		context = super(CreateAnnotationView, self).get_context_data(**kwargs)
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    61
		context["collection_name"] = self.kwargs.get("collection_name", "")
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
    62
		context["image_guid"] = self.kwargs.get("image_guid", "")
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    63
		return context
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    64
	
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    65
	def check_kwargs(self, kwargs):
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    66
		try:
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    67
			collection = Collection.objects.get(name=kwargs.get("collection_name", ""))
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    68
		except Collection.DoesNotExist:
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    69
			return RedirectView.as_view(url=reverse("404error"))
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    70
		try:
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
    71
			image = Image.objects.get(image_guid=kwargs.get("image_guid", ""))
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    72
		except Image.DoesNotExist:
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    73
			return RedirectView.as_view(url=reverse("404error"))
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    74
		return collection, image
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    75
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    76
	def get(self, request, *args, **kwargs):
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    77
		collection, image = self.check_kwargs(kwargs)
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    78
		annotation_form = AnnotationRevisionForm()
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    79
		context = self.get_context_data(**kwargs)
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    80
		context["image"] = image
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    81
		context["form"] = annotation_form
43
ccc449ef6f16 Fixing drawing component
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 42
diff changeset
    82
		context["tags_data"] = "[]"
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    83
		return render(request, 'iconolab/change_annotation.html', context) 
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    84
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
    85
	def post(self, request, *args, **kwargs):
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    86
		collection, image = self.check_kwargs(kwargs)
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    87
		collection_name = kwargs["collection_name"]
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
    88
		image_guid = kwargs["image_guid"]
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    89
		annotation_form = AnnotationRevisionForm(request.POST)
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    90
		if annotation_form.is_valid():
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    91
			author = request.user
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    92
			title = annotation_form.cleaned_data["title"]
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    93
			description = annotation_form.cleaned_data["description"]
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
    94
			fragment = annotation_form.cleaned_data["fragment"]
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    95
			tags_json = annotation_form.cleaned_data["tags"]
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
    96
			new_annotation = Annotation.objects.create_annotation(author, image, title=title, description=description, fragment=fragment, tags_json=tags_json)
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    97
			revision_comment = annotation_form.cleaned_data["comment"]
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    98
			IconolabComment.objects.create(
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
    99
				comment = revision_comment,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   100
				revision = new_annotation.current_revision,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   101
				content_type = ContentType.objects.get(app_label="iconolab", model="annotation"),
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   102
				content_object = new_annotation,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   103
				site = Site.objects.get(id=settings.SITE_ID),
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   104
				object_pk = new_annotation.id,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   105
				user = request.user,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   106
				user_name = request.user.username
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   107
			)
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
   108
			return RedirectView.as_view(url=reverse("annotation_detail", kwargs={'collection_name': collection_name, 'image_guid': image_guid, 'annotation_guid': new_annotation.annotation_guid}))(request)
43
ccc449ef6f16 Fixing drawing component
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 42
diff changeset
   109
		print(annotation_form.errors)
ccc449ef6f16 Fixing drawing component
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 42
diff changeset
   110
		return HttpResponse("error")
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   111
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   112
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   113
class ShowAnnotationView(View, ContextMixin):
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   114
	
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   115
	def get_context_data(self, **kwargs):
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   116
		context = super(ShowAnnotationView, self).get_context_data(**kwargs)
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   117
		context["collection_name"] = self.kwargs.get("collection_name", "")
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   118
		context["image_guid"] = self.kwargs.get("image_guid", "")
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   119
		context["annotation_guid"] = self.kwargs.get("annotation_guid", "")
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   120
		return context
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   121
	
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   122
	def check_kwargs(self, kwargs):
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   123
		try:
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   124
			collection = Collection.objects.get(name=kwargs.get("collection_name", ""))
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   125
		except Collection.DoesNotExist:
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   126
			return RedirectView.as_view(url=reverse("404error"))
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   127
		try:
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   128
			image = Image.objects.get(image_guid=kwargs.get("image_guid", ""))
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   129
		except Image.DoesNotExist:
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   130
			return RedirectView.as_view(url=reverse("404error"))
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   131
		try:
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   132
			annotation = Annotation.objects.select_related("current_revision").get(annotation_guid=kwargs.get("annotation_guid", ""))
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   133
		except Annotation.DoesNotExist:
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   134
			return RedirectView.as_view(url=reverse("404error"))
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   135
		return collection, image, annotation
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   136
	
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   137
	def get(self, request, *args, **kwargs):
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   138
		collection, image, annotation = self.check_kwargs(kwargs)
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   139
		self.check_kwargs(kwargs)
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   140
		context = self.get_context_data(**kwargs)
38
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   141
		context["collection"] = collection
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   142
		context["image"] = image
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   143
		context["annotation"] = annotation
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   144
		context["tags_data"] = annotation.current_revision.get_tags_json()
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   145
		return render(request, 'iconolab/detail_annotation.html', context)
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   146
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   147
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   148
class EditAnnotationView(View, ContextMixin):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   149
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   150
	def get_context_data(self, **kwargs):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   151
		context = super(EditAnnotationView, self).get_context_data(**kwargs)
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   152
		context["collection_name"] = self.kwargs.get("collection_name", "")
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
   153
		context["image_guid"] = self.kwargs.get("image_guid", "")
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   154
		context["annotation_guid"] = self.kwargs.get("annotation_guid", "")
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   155
		return context
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   156
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   157
	def check_kwargs(self, kwargs):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   158
		try:
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   159
			collection = Collection.objects.get(name=kwargs.get("collection_name", ""))
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   160
		except Collection.DoesNotExist:
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   161
			return RedirectView.as_view(url=reverse("404error"))
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   162
		try:
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
   163
			image = Image.objects.get(image_guid=kwargs.get("image_guid", ""))
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
   164
		except Image.DoesNotExist:
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
   165
			return RedirectView.as_view(url=reverse("404error"))
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
   166
		try:
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   167
			annotation = Annotation.objects.select_related("current_revision").get(annotation_guid=kwargs.get("annotation_guid", ""))
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   168
		except Annotation.DoesNotExist:
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   169
			return RedirectView.as_view(url=reverse("404error"))
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
   170
		return collection, image, annotation
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   171
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   172
	def get(self, request, *args, **kwargs):
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
   173
		collection, image, annotation = self.check_kwargs(kwargs)
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
   174
		annotation_form = AnnotationRevisionForm(instance=annotation.current_revision)
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   175
		context = self.get_context_data(**kwargs)
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
   176
		context["image"] = image
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   177
		context["annotation"] = annotation
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   178
		context["form"] = annotation_form
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   179
		context["tags_data"] = annotation.current_revision.get_tags_json()
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   180
		return render(request, 'iconolab/change_annotation.html', context) 
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   181
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   182
	def post(self, request, *args, **kwargs):
30
7ff344b4bf6d functionality: creation of new annotation from scratch
durandn
parents: 24
diff changeset
   183
		collection, image, annotation = self.check_kwargs(kwargs)
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   184
		collection_name = kwargs["collection_name"]
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
   185
		image_guid = kwargs["image_guid"]
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   186
		annotation_guid = kwargs["annotation_guid"]
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   187
		annotation_form = AnnotationRevisionForm(request.POST)
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   188
		if annotation_form.is_valid():
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   189
			revision_author = request.user
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   190
			revision_title = annotation_form.cleaned_data["title"]
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   191
			revision_description = annotation_form.cleaned_data["description"]
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   192
			revision_fragment = annotation_form.cleaned_data["fragment"]
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   193
			revision_tags_json = annotation_form.cleaned_data["tags"]
38
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   194
			new_revision = annotation.make_new_revision(revision_author, revision_title, revision_description, revision_fragment, revision_tags_json)
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   195
			revision_comment = annotation_form.cleaned_data["comment"]
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   196
			comment = IconolabComment.objects.create(
38
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   197
				comment = revision_comment,
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   198
				revision = new_revision,
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   199
				content_type = ContentType.objects.get(app_label="iconolab", model="annotation"),
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   200
				content_object = annotation,
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   201
				site = Site.objects.get(id=settings.SITE_ID),
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   202
				object_pk = annotation.id,
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   203
				user = request.user,
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   204
				user_name = request.user.username
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   205
			)
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   206
			print(comment.revision)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   207
			print(new_revision.creation_comment.first())
33
f9d4c9a63e4e Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents: 30
diff changeset
   208
			return RedirectView.as_view(url=reverse("annotation_detail", kwargs={'collection_name': collection_name, 'image_guid': image_guid, 'annotation_guid': annotation_guid}))(request)
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   209
		print(annotation_form.errors)
38
b319db67a5f3 work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet)
durandn
parents: 35
diff changeset
   210
		return HttpResponse("wow errors")
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   211
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   212
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   213
class ShowRevisionView(View, ContextMixin):
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   214
	
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   215
	def get_context_data(self, **kwargs):
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   216
		context = super(ShowRevisionView, self).get_context_data(**kwargs)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   217
		context["collection_name"] = self.kwargs.get("collection_name", "")
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   218
		context["image_guid"] = self.kwargs.get("image_guid", "")
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   219
		context["annotation_guid"] = self.kwargs.get("annotation_guid", "")
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   220
		context["revision_guid"] = self.kwargs.get("revision_guid", "")
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   221
		return context
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   222
	
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   223
	def check_kwargs(self, kwargs):
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   224
		try:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   225
			collection = Collection.objects.get(name=kwargs.get("collection_name", ""))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   226
		except Collection.DoesNotExist:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   227
			return RedirectView.as_view(url=reverse("404error"))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   228
		try:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   229
			image = Image.objects.get(image_guid=kwargs.get("image_guid", ""))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   230
		except Image.DoesNotExist:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   231
			return RedirectView.as_view(url=reverse("404error"))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   232
		try:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   233
			annotation = Annotation.objects.select_related("current_revision").get(annotation_guid=kwargs.get("annotation_guid", ""))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   234
		except Annotation.DoesNotExist:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   235
			return RedirectView.as_view(url=reverse("404error"))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   236
		try:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   237
			revision = AnnotationRevision.objects.select_related("parent_revision").get(revision_guid=kwargs.get("revision_guid", ""))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   238
		except AnnotationRevision.DoesNotExist:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   239
			return RedirectView.as_view(url=reverse("404error"))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   240
		return collection, image, annotation, revision
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   241
	
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   242
	def get(self, request, *args, **kwargs):
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   243
		collection, image, annotation, revision = self.check_kwargs(kwargs)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   244
		self.check_kwargs(kwargs)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   245
		context = self.get_context_data(**kwargs)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   246
		context["collection"] = collection
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   247
		context["image"] = image
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   248
		context["annotation"] = annotation
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   249
		context["revision"] = revision
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   250
		context["tags_data"] = revision.get_tags_json()
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   251
		print(revision.creation_comment)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   252
		context["comment"] = revision.creation_comment.first()
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   253
		return render(request, 'iconolab/detail_revision.html', context)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   254
35
31d4f0e86723 added backend json handling for tags (properly tested/corrected) + corrected templates to replace image_ref with image_guid
durandn
parents: 34
diff changeset
   255
		
24
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   256
class MergeProposalView(View):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   257
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   258
	def get(self, request, *args, **kwargs):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   259
		# Handle merge form display here
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   260
		pass
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   261
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   262
	def post(self, request, *args, **kwargs):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   263
		# Handle merge form submit here
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   264
		pass
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   265
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   266
	
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   267
class NotFoundErrorView(View):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   268
	def get(self, request, *args, **kwargs):
6b6b183447a2 work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents: 22
diff changeset
   269
		# Handle image display here
42
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   270
		pass
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   271
	
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   272
@csrf_protect
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   273
@require_POST
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   274
def post_comment_iconolab(request, next=None, using=None):
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   275
	"""
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   276
	Post a comment.
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   277
	HTTP POST is required. If ``POST['submit'] == "preview"`` or if there are
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   278
	errors a preview template, ``comments/preview.html``, will be rendered.
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   279
	"""
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   280
	# Fill out some initial data fields from an authenticated user, if present
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   281
	data = request.POST.copy()
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   282
	if request.user.is_authenticated():
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   283
		if not data.get('name', ''):
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   284
			data["name"] = request.user.get_full_name() or request.user.get_username()
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   285
		if not data.get('email', ''):
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   286
			data["email"] = request.user.email
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   287
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   288
	# Look up the object we're trying to comment about
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   289
	ctype = data.get("content_type")
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   290
	object_pk = data.get("object_pk")
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   291
	if ctype is None or object_pk is None:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   292
		return CommentPostBadRequest("Missing content_type or object_pk field.")
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   293
	try:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   294
		model = apps.get_model(*ctype.split(".", 1))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   295
		target = model._default_manager.using(using).get(pk=object_pk)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   296
	except TypeError:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   297
		return CommentPostBadRequest(
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   298
			"Invalid content_type value: %r" % escape(ctype))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   299
	except AttributeError:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   300
		return CommentPostBadRequest(
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   301
			"The given content-type %r does not resolve to a valid model." % escape(ctype))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   302
	except ObjectDoesNotExist:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   303
		return CommentPostBadRequest(
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   304
			"No object matching content-type %r and object PK %r exists." % (
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   305
				escape(ctype), escape(object_pk)))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   306
	except (ValueError, ValidationError) as e:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   307
		return CommentPostBadRequest(
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   308
			"Attempting go get content-type %r and object PK %r exists raised %s" % (
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   309
				escape(ctype), escape(object_pk), e.__class__.__name__))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   310
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   311
	# Do we want to preview the comment?
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   312
	preview = "preview" in data
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   313
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   314
	# Construct the comment form
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   315
	form = django_comments.get_form()(target, data=data)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   316
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   317
	# Check security information
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   318
	if form.security_errors():
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   319
		return CommentPostBadRequest(
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   320
			"The comment form failed security verification: %s" % escape(str(form.security_errors())))
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   321
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   322
	# If there are errors or if we requested a preview show the comment
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   323
	if form.errors:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   324
		return render(request, "iconolab/detail_annotation.html", {
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   325
				"comment_form": form,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   326
				"next": data.get("next", next),
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   327
				"annotation": target,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   328
				"annotation_guid": target.annotation_guid,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   329
				"image_guid": target.image.image_guid,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   330
				"collection_name": target.image.item.collection.name,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   331
				"tags_data": target.current_revision.get_tags_json()
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   332
			},
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   333
		)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   334
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   335
	# Otherwise create the comment
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   336
	comment = form.get_comment_object()
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   337
	comment.ip_address = request.META.get("REMOTE_ADDR", None)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   338
	if request.user.is_authenticated():
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   339
		comment.user = request.user
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   340
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   341
	# Signal that the comment is about to be saved
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   342
	responses = signals.comment_will_be_posted.send(
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   343
		sender=comment.__class__,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   344
		comment=comment,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   345
		request=request
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   346
	)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   347
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   348
	for (receiver, response) in responses:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   349
		if response is False:
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   350
			return CommentPostBadRequest(
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   351
				"comment_will_be_posted receiver %r killed the comment" % receiver.__name__)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   352
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   353
	# Save the comment and signal that it was saved
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   354
	comment.save()
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   355
	signals.comment_was_posted.send(
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   356
		sender=comment.__class__,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   357
		comment=comment,
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   358
		request=request
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   359
	)
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   360
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   361
	return next_redirect(request, fallback=next or 'comments-comment-done',
51257e2701d9 streamlined comment system, replicated post_comment view so form errors redirect on the annotation page and not on a preview page + added revision detail view and links for specific revisions from the comments
durandn
parents: 38
diff changeset
   362
						 c=comment._get_pk_val())