# HG changeset patch # User durandn # Date 1467121857 -7200 # Node ID aed809b3a075bde74f7f5a882a2cc5f439c63cdf # Parent 79dc00f6e9a62d4d61d07b3b9a7263183d60b4c7 Corrected Tag methods bugs + Added comment classes and migration diff -r 79dc00f6e9a6 -r aed809b3a075 src/iconolab/migrations/0002_auto_20160627_1320.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/iconolab/migrations/0002_auto_20160627_1320.py Tue Jun 28 15:50:57 2016 +0200 @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-06-27 13:20 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_comments_xtd', '0001_initial'), + ('iconolab', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='CommentAttachement', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('attachment_type', models.IntegerField(choices=[(0, 'link'), (1, 'image'), (2, 'pdf')], default=0)), + ('data', models.TextField()), + ], + ), + migrations.CreateModel( + name='IconolabComment', + fields=[ + ('xtdcomment_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='django_comments_xtd.XtdComment')), + ], + options={ + 'permissions': [('can_moderate', 'Can moderate comments')], + 'verbose_name': 'comment', + 'verbose_name_plural': 'comments', + 'abstract': False, + 'ordering': ('submit_date',), + }, + bases=('django_comments_xtd.xtdcomment',), + ), + migrations.CreateModel( + name='MetaCategory', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('label', models.CharField(max_length=255)), + ('collection', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='iconolab.Collection')), + ], + ), + migrations.CreateModel( + name='MetaCategoryInfo', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('comment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='iconolab.IconolabComment')), + ('metacategory', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='iconolab.MetaCategory')), + ], + ), + migrations.AddField( + model_name='iconolabcomment', + name='metacategories', + field=models.ManyToManyField(blank=True, null=True, through='iconolab.MetaCategoryInfo', to='iconolab.MetaCategory'), + ), + migrations.AddField( + model_name='iconolabcomment', + name='revision', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='creation_comment', to='iconolab.AnnotationRevision'), + ), + migrations.AddField( + model_name='commentattachement', + name='comment', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='iconolab.IconolabComment'), + ), + ] diff -r 79dc00f6e9a6 -r aed809b3a075 src/iconolab/models.py --- a/src/iconolab/models.py Tue Jun 28 12:52:33 2016 +0200 +++ b/src/iconolab/models.py Tue Jun 28 15:50:57 2016 +0200 @@ -3,6 +3,7 @@ from django.contrib.auth.models import User from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType +from django_comments_xtd.models import XtdComment import uuid, json @@ -13,16 +14,16 @@ collection = models.ForeignKey('Collection', blank=True, null=True) def is_internal(self): - return link.startswith(settings.BASE_URL) + return self.link.startswith(settings.BASE_URL) + class TaggingInfo(models.Model): revision = models.ForeignKey('AnnotationRevision', on_delete=models.CASCADE) tag = models.ForeignKey('Tag', on_delete=models.CASCADE) accuracy = models.IntegerField() relevancy = models.IntegerField() - -# fonds Ingres - Musee de la Poste + class Collection(models.Model): name = models.CharField(max_length=50, unique=True) description = models.CharField(max_length=255) @@ -33,7 +34,8 @@ class Item(models.Model): collection = models.ForeignKey(Collection, related_name="items") - + + class ItemMetadata(models.Model): item = models.OneToOneField('Item', related_name='metadatas') joconde_ref = models.CharField(max_length=20, null=False, blank=False, unique=True) @@ -42,7 +44,6 @@ description = models.CharField(max_length=255) - class ImageStats(models.Model): image = models.OneToOneField('Image', related_name='stats', blank=False, null=False) views_count = models.IntegerField(blank=True, null=True, default=0) @@ -177,6 +178,7 @@ self.current_revision=merged_revision self.save() + class AnnotationRevision(models.Model): AWAITING = 0 @@ -189,7 +191,6 @@ (REJECTED, 'rejected') ) - revision_guid = models.UUIDField(default=uuid.uuid4) annotation = models.ForeignKey('Annotation', related_name='revisions', null=False, blank=False) parent_revision = models.ForeignKey('AnnotationRevision', related_name='reverse_parent_revision', blank=True, null=True) @@ -198,7 +199,7 @@ title = models.CharField(max_length=255) description = models.TextField(null=True) fragment = models.TextField() - tags = models.ManyToManyField('Tag', through='TaggingInfo', through_fields=('revision', 'tag'), blank=True, null=True) + tags = models.ManyToManyField('Tag', through='TaggingInfo', through_fields=('revision', 'tag')) state = models.IntegerField(choices=REVISION_STATES, default=AWAITING) created = models.DateTimeField(auto_now_add=True, null=True) @@ -209,11 +210,11 @@ pass for tag_data in tags_dict: tag_string = tag_data.get("tag_input") - tag_accuracy = tag_data.get("accuracy") - tag_relevancy = tag_data.get("relevancy") + tag_accuracy = tag_data.get("accuracy", 0) + tag_relevancy = tag_data.get("relevancy", 0) if tag_string.startswith("http://"): #check if url - if Tag.objects.exists(link=tag_string): #check if tag already exists + if Tag.objects.filter(link=tag_string).exists(): #check if tag already exists tag_obj = Tag.objects.get(link=tag_string) else: tag_obj = Tag.objects.create( @@ -232,97 +233,37 @@ accuracy = tag_accuracy, relevancy = tag_relevancy ) - - + + +class IconolabComment(XtdComment): + revision = models.ForeignKey('AnnotationRevision', related_name='creation_comment', null=True, blank=True) + metacategories = models.ManyToManyField('MetaCategory', through='MetaCategoryInfo', through_fields=('comment', 'metacategory')) + + +class MetaCategory(models.Model): + collection = models.ForeignKey(Collection) + label = models.CharField(max_length=255) + + def __str__(self): + return self.label -#class MetaCategory(models.Model): -# collection = models.ForeignKey(Collection) -# label = models.CharField(max_length=200) -# -# def __str__(self): -# return self.label -# -# class Meta: -# verbose_name_plural = 'Metacategories' -# -# -# class Comment(models.Model): -# author = models.ForeignKey(User) -# created = models.DateTimeField(blank=False, null=False, auto_now_add=True) -# annotation_revision = models.ForeignKey(AnnotationRevision, blank=True, null=True) -# target = models.ForeignKey('Comment', blank=True, null=True) -# content = models.TextField(blank=True) -# metacategories = models.ManyToManyField(MetaCategory) -# -# -# class CommentAttachement(models.Model): -# -# LINK = 0 -# IMAGE = 1 -# PDF = 2 -# COMMENT_CHOICES = ( -# (LINK, 'link'), -# (IMAGE, 'image'), -# (PDF, 'pdf') -# ) -# comment = models.ForeignKey(Comment, on_delete=models.CASCADE, related_name='attachments') -# main_annotation = models.ForeignKey(Annotation) -# attachment_type = models.IntegerField(choices=COMMENT_CHOICES, default=0) -# created_date = models.DateTimeField(auto_now_add=True) -# data = models.TextField(blank=False) -# -# -# # Activity & Notification -# -# class Activity(models.Model): -# -# NEW_COMMENT = 0 -# NEW_REVISION = 1 -# NEW_COMMENT_ON_REVISION = 2 -# NEW_EXPERT_CALL = 3 -# NEW_EXPERT_ANSWER = 4 -# NEW_REFERENCE = 5 -# -# ACTIVITY_VERBS = ( -# (NEW_COMMENT, 'New comment'), -# (NEW_REVISION, 'New revision'), -# (NEW_COMMENT_ON_REVISION, 'New comment on a revision'), -# (NEW_EXPERT_CALL, 'New expert call'), -# (NEW_EXPERT_ANSWER, 'New expert answer'), -# (NEW_REFERENCE, 'New reference'), -# ) -# -# verb = models.IntegerField(choices=ACTIVITY_VERBS) -# actor = models.ForeignKey(User) -# -# target_content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) -# target_object_id = models.PositiveIntegerField() -# target = GenericForeignKey('target_content_type', 'target_object_id') -# -# action_content_type = models.ForeignKey(ContentType, related_name='activity_action', on_delete=models.CASCADE, null=True, blank=True) -# action_object_id = models.PositiveIntegerField(null=True, blank=True) -# action_content = GenericForeignKey('action_content_type', 'action_object_id') -# -# created_date = models.DateTimeField(auto_now_add=True) -# -# def __str__(self): -# return '%s:%s' % (author.name, verbe) -# -# -# class Notification(models.Model): -# -# UNREAD = 0 -# READ = 1 -# DELETED = 2 -# -# STATUS = ( -# (UNREAD, 'Unread'), -# (READ, 'Read'), -# (DELETED, 'Deleted') -# ) -# -# activity = models.ForeignKey(Activity) -# user = models.ForeignKey(User) -# status = models.IntegerField(choices=STATUS, default=UNREAD) -# created_date = models.DateTimeField(auto_now_add=True) + +class MetaCategoryInfo(models.Model): + comment = models.ForeignKey('IconolabComment', on_delete=models.CASCADE) + metacategory = models.ForeignKey('MetaCategory', on_delete=models.CASCADE) + +class CommentAttachement(models.Model): + + LINK = 0 + IMAGE = 1 + PDF = 2 + COMMENT_CHOICES = ( + (LINK, 'link'), + (IMAGE, 'image'), + (PDF, 'pdf') + ) + + comment = models.ForeignKey('IconolabComment', related_name='attachments', on_delete=models.CASCADE) + attachment_type = models.IntegerField(choices=COMMENT_CHOICES, default=0) + data = models.TextField(blank=False) \ No newline at end of file