# HG changeset patch # User durandn # Date 1467122045 -7200 # Node ID b319db67a5f3eb1fb4ca1f23b77f5034467c8879 # Parent aed809b3a075bde74f7f5a882a2cc5f439c63cdf work on comments (in annotation form, list in annotation detail, post in annotation detail isn't working yet) diff -r aed809b3a075 -r b319db67a5f3 requirements.txt --- a/requirements.txt Tue Jun 28 15:50:57 2016 +0200 +++ b/requirements.txt Tue Jun 28 15:54:05 2016 +0200 @@ -1,16 +1,16 @@ -diff-match-patch==20121119 -Django==1.9.7 -django-model-utils==2.5 -django-notifications-hq==1.1 -django-reversion==2.0.1 -django-reversion-compare==0.6.2 -django-revision==0.1.6 -djangorestframework==3.3.3 -gitdb==0.6.4 -GitPython==2.0.5 -jsonfield==1.0.3 -Pillow==3.2.0 -psycopg2==2.6.1 -pytz==2016.4 -smmap==0.9.0 -sorl-thumbnail==12.4a1 +diff-match-patch==20121119 +Django==1.9.7 +django-comments-xtd==1.5.3 +django-contrib-comments==1.7.1 +django-model-utils==2.5 +django-notifications-hq==1.1 +djangorestframework==3.3.3 +gitdb==0.6.4 +GitPython==2.0.5 +jsonfield==1.0.3 +Pillow==3.2.0 +psycopg2==2.6.1 +pytz==2016.4 +six==1.10.0 +smmap==0.9.0 +sorl-thumbnail==12.4a1 diff -r aed809b3a075 -r b319db67a5f3 src/iconolab/forms/annotations.py --- a/src/iconolab/forms/annotations.py Tue Jun 28 15:50:57 2016 +0200 +++ b/src/iconolab/forms/annotations.py Tue Jun 28 15:54:05 2016 +0200 @@ -1,19 +1,20 @@ -from django.forms import ModelForm, TypedMultipleChoiceField, HiddenInput, CharField, MultipleHiddenInput +from django import forms from iconolab.models import AnnotationRevision import json -class MultipleTagsField(TypedMultipleChoiceField): +class MultipleTagsField(forms.TypedMultipleChoiceField): pass -class AnnotationRevisionForm(ModelForm): - tags = CharField() +class AnnotationRevisionForm(forms.ModelForm): + tags = forms.CharField() + comment = forms.CharField(widget=forms.Textarea) class Meta: model = AnnotationRevision fields = ('title', 'description', 'fragment') widgets = { - 'fragment': HiddenInput(), - 'tags': HiddenInput() + 'fragment': forms.HiddenInput(), + 'tags': forms.HiddenInput() } def tags_json(self): diff -r aed809b3a075 -r b319db67a5f3 src/iconolab/forms/comments.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/iconolab/forms/comments.py Tue Jun 28 15:54:05 2016 +0200 @@ -0,0 +1,16 @@ +from django import forms +from django.utils.translation import ugettext_lazy as _ +from django_comments_xtd.forms import XtdCommentForm +from iconolab.models import MetaCategory + +class IconolabCommentForm(XtdCommentForm): + metacategories = forms.ModelMultipleChoiceField(queryset=MetaCategory.objects.all()) + + def __init__(self, *args, **kwargs): + super(IconolabCommentForm, self).__init__(*args, **kwargs) + self.fields.pop('email') + + def get_comment_create_data(self): + data = super(IconolabCommentForm, self).get_comment_create_data() + data.update({'metacategories': self.cleaned_data['metacategories']}) + return data \ No newline at end of file diff -r aed809b3a075 -r b319db67a5f3 src/iconolab/settings/__init__.py --- a/src/iconolab/settings/__init__.py Tue Jun 28 15:50:57 2016 +0200 +++ b/src/iconolab/settings/__init__.py Tue Jun 28 15:54:05 2016 +0200 @@ -53,15 +53,19 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'notifications', - 'reversion', - #'reversion_compare', + 'django.contrib.sites', + 'django_comments', + 'django_comments_xtd', 'iconolab.apps.IconolabApp', 'sorl.thumbnail', ] -ADD_REVERSION_ADMIN=True +COMMENTS_APP = "django_comments_xtd" +COMMENTS_XTD_MODEL = "iconolab.models.IconolabComment" +COMMENTS_XTD_FORM_CLASS = 'iconolab.forms.comments.IconolabCommentForm' +COMMENTS_XTD_MAX_THREAD_LEVEL = 0 +SITE_ID = 1 MIDDLEWARE_CLASSES = [ 'django.middleware.security.SecurityMiddleware', diff -r aed809b3a075 -r b319db67a5f3 src/iconolab/settings/dev.py.tmpl --- a/src/iconolab/settings/dev.py.tmpl Tue Jun 28 15:50:57 2016 +0200 +++ b/src/iconolab/settings/dev.py.tmpl Tue Jun 28 15:54:05 2016 +0200 @@ -49,6 +49,9 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django.contrib.sites', + 'django_comments', + 'django_comments_xtd', 'notifications', 'reversion', 'reversion_compare', @@ -56,8 +59,11 @@ 'sorl.thumbnail', ] -ADD_REVERSION_ADMIN=True +COMMENTS_APP = "django_comments_xtd" +COMMENTS_XTD_MODEL = "iconolab.models.IconolabComment" +COMMENTS_XTD_MAX_THREAD_LEVEL = 0 +SITE_ID = 1 MIDDLEWARE_CLASSES = [ 'django.middleware.security.SecurityMiddleware', diff -r aed809b3a075 -r b319db67a5f3 src/iconolab/templates/iconolab/change_annotation.html --- a/src/iconolab/templates/iconolab/change_annotation.html Tue Jun 28 15:50:57 2016 +0200 +++ b/src/iconolab/templates/iconolab/change_annotation.html Tue Jun 28 15:54:05 2016 +0200 @@ -92,6 +92,12 @@
+
+ + +
diff -r aed809b3a075 -r b319db67a5f3 src/iconolab/templates/iconolab/detail_annotation.html --- a/src/iconolab/templates/iconolab/detail_annotation.html Tue Jun 28 15:50:57 2016 +0200 +++ b/src/iconolab/templates/iconolab/detail_annotation.html Tue Jun 28 15:54:05 2016 +0200 @@ -1,13 +1,13 @@ {% extends 'iconolab_base.html' %} +{% load i18n %} {% load staticfiles %} - +{% load comments %} +{% load comments_xtd %} {% load thumbnail %} - {% load iconolab_tags %} {% block content %} - Revoir l'image
@@ -33,11 +33,48 @@

Title: {{ annotation.current_revision.title }}

Description: {{ annotation.current_revision.description }}

Tags: {{ annotation.current_revision.tags }}

-

Fragment: {{ annotation.current_revision.fragment }}

Editer | Proposer une révision
+
+ {% get_comment_list for annotation as comment_list %} +
+ {% for comment in comment_list %} +
+ {{ comment.name }} +
+
+

{{ comment.comment }}

+
{{ comment.submit_date }} -  + {% if comment.allow_thread %} - {% trans "Reply" %}{% endif %}
+
+ {% endfor %} +
+
+
+ {% if user.is_authenticated %} + {% get_comment_form for annotation as comment_form %} +
+ {% csrf_token %} + {{ comment_form.content_type }} + {{ comment_form.object_pk }} + {{ comment_form.timestamp }} + {{ comment_form.security_hash }} + +
+ +
+
+ + +
+ +
+ {% endif %} +
{% endblock %} diff -r aed809b3a075 -r b319db67a5f3 src/iconolab/urls.py --- a/src/iconolab/urls.py Tue Jun 28 15:50:57 2016 +0200 +++ b/src/iconolab/urls.py Tue Jun 28 15:54:05 2016 +0200 @@ -31,8 +31,10 @@ url(r'^collections/(?P[a-z]+)/images/(?P[^/]+)/annotations/(?P[^/]+)/detail$', views.ShowAnnotationView.as_view(), name='annotation_detail'), url(r'^collections/(?P[a-z]+)/images/(?P[^/]+)/annotations/(?P[^/]+)/edit$', login_required(views.EditAnnotationView.as_view()), name='annotation_edit'), url(r'^collections/(?P[a-z]+)/images/(?P[^/]+)/annotations/(?P[^/]+)/revisions/(?P[0-9]+)/merge$', login_required(views.MergeProposalView.as_view()), name='annotation_merge'), + url(r'errors/404', views.NotFoundErrorView.as_view(), name="404error"), url(r'^rest', include('restapi.urls')), url(r'^account/', include('iconolab.auth.urls', namespace='account')), + url(r'^comments/', include('django_comments_xtd.urls')) ] urlpatterns += staticfiles_urlpatterns() diff -r aed809b3a075 -r b319db67a5f3 src/iconolab/views.py --- a/src/iconolab/views.py Tue Jun 28 15:50:57 2016 +0200 +++ b/src/iconolab/views.py Tue Jun 28 15:54:05 2016 +0200 @@ -4,19 +4,31 @@ from django.views.generic import View, RedirectView from django.views.generic.base import ContextMixin from django.core.urlresolvers import reverse -from iconolab.models import Annotation, Collection, Image +from django.contrib.contenttypes.models import ContentType +from django.contrib.sites.models import Site +from django.conf import settings +from iconolab.models import Annotation, Collection, Image, IconolabComment from iconolab.forms.annotations import AnnotationRevisionForm -import json +import json, datetime def make_tags_json(annotation_revision): final_list = [] - for tagging_info in annotation_revision.tagginginfo_set.all(): - final_list.append({ - "tag_label": tagging_info.tag.label, - "tag_link": tagging_info.tag.link, - "accuracy": tagging_info.accuracy, - "relevancy": tagging_info.relevancy - }) + for tagging_info in annotation_revision.tagginginfo_set.select_related("tag").all(): + if tagging_info.tag.is_internal(): + final_list.append({ + "tag_label": tagging_info.tag.label, + "tag_link": tagging_info.tag.link, + "accuracy": tagging_info.accuracy, + "relevancy": tagging_info.relevancy + }) + else: + #import label from dbpedia + final_list.append({ + "tag_label": "", + "tag_link": tagging_info.tag.link, + "accuracy": tagging_info.accuracy, + "relevancy": tagging_info.relevancy + }) return json.dumps(final_list) class GlobalHomepageView(View): @@ -124,6 +136,8 @@ collection, image, annotation = self.check_kwargs(kwargs) self.check_kwargs(kwargs) context = self.get_context_data(**kwargs) + context["collection"] = collection + context["image"] = collection context["annotation"] = annotation return render(request, 'iconolab/detail_annotation.html', context) @@ -174,10 +188,21 @@ revision_description = annotation_form.cleaned_data["description"] revision_fragment = annotation_form.cleaned_data["fragment"] revision_tags_json = annotation_form.cleaned_data["tags"] - annotation.make_new_revision(revision_author, revision_title, revision_description, revision_fragment, revision_tags_json) + new_revision = annotation.make_new_revision(revision_author, revision_title, revision_description, revision_fragment, revision_tags_json) + revision_comment = annotation_form.cleaned_data["comment"] + IconolabComment.objects.create( + comment = revision_comment, + revision = new_revision, + content_type = ContentType.objects.get(app_label="iconolab", model="annotation"), + content_object = annotation, + site = Site.objects.get(id=settings.SITE_ID), + object_pk = annotation.id, + user = request.user, + user_name = request.user.username + ) return RedirectView.as_view(url=reverse("annotation_detail", kwargs={'collection_name': collection_name, 'image_guid': image_guid, 'annotation_guid': annotation_guid}))(request) print(annotation_form.errors) - return HttpResponse("wow") + return HttpResponse("wow errors") class MergeProposalView(View):