| author | Harris Baptiste <harris.baptiste@iri.centrepompidou.fr> |
| Wed, 17 Aug 2016 18:36:44 +0200 | |
| changeset 124 | e5267573edd8 |
| parent 116 | 1e2caa72bf2f |
| child 125 | e13fed7f0837 |
| permissions | -rw-r--r-- |
|
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:
13
diff
changeset
|
1 |
from django.db import models, transaction |
|
33
f9d4c9a63e4e
Backend work on tags (needs testing) + model changes (image_guid, Tag)
durandn
parents:
30
diff
changeset
|
2 |
from django.conf import settings |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
3 |
from django.contrib.auth.models import User |
|
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
4 |
from django.contrib.contenttypes.fields import GenericForeignKey |
|
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
5 |
from django.contrib.contenttypes.models import ContentType |
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
6 |
from django_comments_xtd.models import XtdComment |
| 48 | 7 |
from django.utils.text import slugify |
|
90
8d7815ecd211
signals are now sent in model methods rather than views
durandn
parents:
89
diff
changeset
|
8 |
import iconolab.signals.handlers as iconolab_signals |
| 48 | 9 |
import uuid, json, re, requests, urllib |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
10 |
|
|
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
11 |
|
|
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
12 |
class Tag(models.Model): |
|
104
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
13 |
label = models.CharField(max_length=255, blank=True, null=True) |
|
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
14 |
label_slug = models.SlugField(blank=True, null=True) |
| 48 | 15 |
link = models.URLField(unique=True) |
16 |
description = models.CharField(max_length=255, blank=True, null=True) |
|
17 |
collection = models.ForeignKey('Collection', blank=True, null=True) |
|
18 |
||
19 |
def is_internal(self): |
|
20 |
return self.link.startswith(settings.INTERNAL_TAGS_URL) |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
21 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
22 |
|
|
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:
13
diff
changeset
|
23 |
class TaggingInfo(models.Model): |
| 48 | 24 |
revision = models.ForeignKey('AnnotationRevision', on_delete=models.CASCADE) |
25 |
tag = models.ForeignKey('Tag', on_delete=models.CASCADE) |
|
26 |
accuracy = models.IntegerField() |
|
27 |
relevancy = models.IntegerField() |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
28 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
29 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
30 |
class Collection(models.Model): |
|
64
4d1e369e85d4
Added a verbose name field for collection objects, home view now gets a list of all collections
durandn
parents:
62
diff
changeset
|
31 |
name = models.SlugField(max_length=50, unique=True) |
|
4d1e369e85d4
Added a verbose name field for collection objects, home view now gets a list of all collections
durandn
parents:
62
diff
changeset
|
32 |
verbose_name = models.CharField(max_length=50, null=True, blank=True) |
| 48 | 33 |
description = models.CharField(max_length=255) |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
34 |
|
| 48 | 35 |
def __str__(self): |
36 |
return self.name |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
37 |
|
|
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:
13
diff
changeset
|
38 |
|
|
31
e34b70a00488
adding annotations list
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
30
diff
changeset
|
39 |
class Item(models.Model): |
| 48 | 40 |
collection = models.ForeignKey(Collection, related_name="items") |
|
65
625ed1ba472f
Work on item model + item view to show items with multiple images instead of image detail + fix thumbnails in templates
durandn
parents:
64
diff
changeset
|
41 |
item_guid = models.UUIDField(default=uuid.uuid4, editable=False) |
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
42 |
|
| 48 | 43 |
|
|
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:
13
diff
changeset
|
44 |
class ItemMetadata(models.Model): |
| 48 | 45 |
item = models.OneToOneField('Item', related_name='metadatas') |
| 110 | 46 |
authors = models.CharField(max_length=255, default="") |
47 |
school = models.CharField(max_length=255, default="") |
|
48 |
designation = models.CharField(max_length=255, default="") |
|
49 |
datation = models.CharField(max_length=255, default="") |
|
50 |
technics = models.CharField(max_length=255, default="") |
|
51 |
measurements = models.CharField(max_length=255, default="") |
|
52 |
create_or_usage_location = models.CharField(max_length=255, default="") |
|
53 |
discovery_context = models.CharField(max_length=255, default="") |
|
54 |
conservation_location = models.CharField(max_length=255, default="") |
|
55 |
photo_credits = models.CharField(max_length=255, default="") |
|
56 |
inventory_number = models.CharField(max_length=255, default="") |
|
57 |
joconde_ref = models.CharField(max_length=255, default="") |
|
58 |
||
59 |
@property |
|
60 |
def get_joconde_url(self): |
|
61 |
return self.joconde_ref |
|
|
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:
13
diff
changeset
|
62 |
|
|
31
e34b70a00488
adding annotations list
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
30
diff
changeset
|
63 |
|
|
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:
13
diff
changeset
|
64 |
class ImageStats(models.Model): |
| 48 | 65 |
image = models.OneToOneField('Image', related_name='stats', blank=False, null=False) |
66 |
views_count = models.IntegerField(blank=True, null=True, default=0) |
|
67 |
annotations_count = models.IntegerField(blank=True, null=True, default=0) |
|
68 |
submitted_revisions_count = models.IntegerField(blank=True, null=True, default=0) |
|
69 |
comments_count = models.IntegerField(blank=True, null=True, default=0) |
|
70 |
folders_inclusion_count = models.IntegerField(blank=True, null=True, default=0) |
|
71 |
tag_count = models.IntegerField(blank=True, null=True, default=0) |
|
|
85
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
72 |
|
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
73 |
def set_tags_stats(self): |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
74 |
self.tag_count = Tag.objects.filter(tagginginfo__revision__annotation__image = self.image).distinct().count() |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
75 |
|
| 93 | 76 |
@transaction.atomic |
|
85
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
77 |
def update_stats(self): |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
78 |
self.annotations_count = 0 |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
79 |
self.submitted_revisions_count = 0 |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
80 |
self.comments_count = 0 |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
81 |
image_annotations = Annotation.objects.filter(image=self.image) |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
82 |
# views_count - Can't do much about views count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
83 |
# annotations_count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
84 |
self.annotations_count = image_annotations.count() |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
85 |
# submitted_revisions_count & comment_count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
86 |
for annotation in image_annotations.all(): |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
87 |
annotation_revisions = annotation.revisions |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
88 |
self.submitted_revisions_count += annotation_revisions.count() |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
89 |
|
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
90 |
self.comments_count += XtdComment.objects.for_app_models("iconolab.annotation").filter( |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
91 |
object_pk = annotation.pk, |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
92 |
).count() |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
93 |
# tag_count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
94 |
self.tag_count = Tag.objects.filter(tagginginfo__revision__annotation__image = self.image).distinct().count() |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
95 |
self.save() |
|
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:
13
diff
changeset
|
96 |
|
| 101 | 97 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
98 |
class Image(models.Model): |
| 48 | 99 |
image_guid = models.UUIDField(default=uuid.uuid4, editable=False) |
100 |
name = models.CharField(max_length=200) |
|
101 |
media = models.ImageField(upload_to='uploads/', height_field='height', width_field='width') |
|
102 |
item = models.ForeignKey('Item', related_name='images', null=True, blank=True) |
|
103 |
height = models.IntegerField(null=False, blank=False) |
|
104 |
width = models.IntegerField(null=False, blank=False) |
|
105 |
created = models.DateTimeField(auto_now_add=True, null=True) |
|
|
116
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
106 |
|
|
106
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
107 |
@property |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
108 |
def collection(self): |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
109 |
return self.item.collection.name |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
110 |
|
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
111 |
@property |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
112 |
def title(self): |
|
116
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
113 |
return self.item.metadatas.designation |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
114 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
115 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
116 |
def authors(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
117 |
return self.item.metadatas.authors |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
118 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
119 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
120 |
def school(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
121 |
return self.item.metadatas.school |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
122 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
123 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
124 |
def designation(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
125 |
return self.item.metadatas.designation |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
126 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
127 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
128 |
def datation(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
129 |
return self.item.metadatas.datation |
|
106
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
130 |
|
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
131 |
@property |
|
116
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
132 |
def technics(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
133 |
return self.item.metadatas.technics |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
134 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
135 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
136 |
def measurements(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
137 |
return self.item.metadatas.measurements |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
138 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
139 |
def __str__(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
140 |
return self.name |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
141 |
|
|
116
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
142 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
143 |
def tags(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
144 |
tag_list = [] |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
145 |
for annotation in self.annotations.all(): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
146 |
revision_tags = annotation.current_revision.tags.all() |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
147 |
tag_list = [tag.label for tag in revision_tags] |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
148 |
return tag_list |
|
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:
13
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:
13
diff
changeset
|
150 |
class AnnotationManager(models.Manager): |
| 48 | 151 |
|
152 |
# Call Annotation.objects.create_annotation to initialize a new Annotation with its associated AnnotationStats and initial AnnotationRevision |
|
153 |
@transaction.atomic |
|
154 |
def create_annotation(self, author, image, title='', description='', fragment='', tags_json='[]'): |
|
155 |
# Create annotation object |
|
156 |
new_annotation = Annotation( |
|
157 |
image=image, |
|
158 |
author=author |
|
159 |
) |
|
160 |
new_annotation.save() |
|
161 |
||
162 |
# Create initial revision |
|
163 |
initial_revision = AnnotationRevision( |
|
164 |
annotation=new_annotation, |
|
165 |
author=author, |
|
166 |
title=title, |
|
167 |
description=description, |
|
168 |
fragment=fragment, |
|
169 |
state=AnnotationRevision.ACCEPTED |
|
170 |
) |
|
171 |
initial_revision.save() |
|
172 |
initial_revision.set_tags(tags_json) |
|
173 |
||
174 |
new_annotation.current_revision = initial_revision |
|
175 |
new_annotation.save() |
|
176 |
||
177 |
# Create stats object |
|
178 |
new_annotation_stats = AnnotationStats(annotation=new_annotation) |
|
179 |
new_annotation_stats.save() |
|
|
85
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
180 |
new_annotation_stats.set_tags_stats() |
| 48 | 181 |
new_annotation.stats = new_annotation_stats |
182 |
new_annotation.save() |
|
183 |
return new_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:
13
diff
changeset
|
184 |
|
| 101 | 185 |
|
|
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:
13
diff
changeset
|
186 |
class AnnotationStats(models.Model): |
| 48 | 187 |
annotation = models.OneToOneField('Annotation', related_name='stats', blank=False, null=False) |
188 |
submitted_revisions_count = models.IntegerField(blank=True, null=True, default=1) |
|
|
97
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
189 |
awaiting_revisions_count = models.IntegerField(blank=True, null=True, default=0) |
| 48 | 190 |
accepted_revisions_count = models.IntegerField(blank=True, null=True, default=1) |
191 |
contributors_count = models.IntegerField(blank=True, null=True, default=1) |
|
192 |
views_count = models.IntegerField(blank=True, null=True, default=0) |
|
193 |
comments_count = models.IntegerField(blank=True, null=True, default=0) |
|
194 |
tag_count = models.IntegerField(blank=True, null=True, default=0) |
|
195 |
||
|
85
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
196 |
@property |
| 48 | 197 |
def contributors(self): |
|
97
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
198 |
user_ids_list = self.annotation.revisions.filter(state__in=[AnnotationRevision.ACCEPTED, AnnotationRevision.STUDIED]).values_list("author__id", flat=True) |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
199 |
return User.objects.filter(id__in=user_ids_list).distinct() |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
200 |
|
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
201 |
@property |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
202 |
def commenters(self): |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
203 |
user_ids_list = IconolabComment.objects.filter(content_type__app_label="iconolab", content_type__model="annotation", object_pk=self.annotation.id).values_list("user__id", flat=True) |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
204 |
return User.objects.filter(id__in=user_ids_list).distinct() |
|
85
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
205 |
|
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
206 |
def set_tags_stats(self): |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
207 |
self.tag_count = Tag.objects.filter(tagginginfo__revision__annotation = self.annotation).distinct().count() |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
208 |
|
| 93 | 209 |
@transaction.atomic |
|
85
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
210 |
def update_stats(self): |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
211 |
# views_count - Can't do much about views count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
212 |
# submitted_revisions_count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
213 |
annotation_revisions = self.annotation.revisions |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
214 |
self.submitted_revisions_count = annotation_revisions.count() |
|
97
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
215 |
# aawaiting_revisions_count |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
216 |
self.awaiting_revisions_count = annotation_revisions.filter(state=AnnotationRevision.AWAITING).count() |
|
85
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
217 |
# accepted_revisions_count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
218 |
self.accepted_revisions_count = annotation_revisions.filter(state=AnnotationRevision.ACCEPTED).count() + annotation_revisions.filter(state=AnnotationRevision.STUDIED).count() |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
219 |
# comment_count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
220 |
self.comments_count = XtdComment.objects.for_app_models("iconolab.annotation").filter( |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
221 |
object_pk = self.annotation.pk, |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
222 |
).count() |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
223 |
# contributors_count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
224 |
self.contributors_count = len(self.contributors) |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
225 |
# tag_count |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
226 |
self.tag_count = Tag.objects.filter(tagginginfo__revision__annotation = self.annotation).distinct().count() |
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
227 |
|
|
49b3f22948d5
work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents:
77
diff
changeset
|
228 |
self.save() |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
229 |
|
| 101 | 230 |
|
|
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:
13
diff
changeset
|
231 |
class Annotation(models.Model): |
| 48 | 232 |
annotation_guid = models.UUIDField(default=uuid.uuid4, editable=False) |
233 |
image = models.ForeignKey('Image', related_name='annotations', on_delete=models.CASCADE) |
|
234 |
source_revision = models.ForeignKey('AnnotationRevision', related_name='source_related_annotation', blank=True, null=True) |
|
235 |
current_revision = models.OneToOneField('AnnotationRevision', related_name='current_for_annotation', blank=True, null=True) |
|
236 |
author = models.ForeignKey(User, null=True) |
|
237 |
created = models.DateTimeField(auto_now_add=True, null=True) |
|
238 |
||
239 |
objects = AnnotationManager() |
|
240 |
||
|
97
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
241 |
@property |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
242 |
def awaiting_revisions_count(self): |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
243 |
return self.revisions.filter(state=AnnotationRevision.AWAITING).distinct().count() |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
244 |
|
|
106
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
245 |
@property |
|
124
e5267573edd8
search engine
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
116
diff
changeset
|
246 |
def collection(self): |
|
e5267573edd8
search engine
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
116
diff
changeset
|
247 |
return self.image.collection |
|
e5267573edd8
search engine
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
116
diff
changeset
|
248 |
|
|
e5267573edd8
search engine
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
116
diff
changeset
|
249 |
@property |
|
106
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
250 |
def tags(self): |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
251 |
return [tag.label for tag in self.current_revision.tags.all()] |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
252 |
|
|
97
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
253 |
|
| 48 | 254 |
# Call to create a new revision, possibly from a merge |
255 |
@transaction.atomic |
|
256 |
def make_new_revision(self, author, title, description, fragment, tags_json): |
|
257 |
if author == self.author: |
|
258 |
# We're creating an automatically accepted revision |
|
259 |
new_revision_state = AnnotationRevision.ACCEPTED |
|
260 |
else: |
|
261 |
# Revision will require validation |
|
262 |
new_revision_state = AnnotationRevision.AWAITING |
|
263 |
new_revision = AnnotationRevision( |
|
264 |
annotation = self, |
|
265 |
parent_revision=self.current_revision, |
|
266 |
title=title, |
|
267 |
description=description, |
|
268 |
author=author, |
|
269 |
fragment=fragment, |
|
270 |
state=new_revision_state |
|
271 |
) |
|
272 |
new_revision.save() |
|
273 |
new_revision.set_tags(tags_json) |
|
274 |
if new_revision.state == AnnotationRevision.ACCEPTED: |
|
275 |
self.current_revision = new_revision |
|
276 |
self.save() |
|
|
104
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
277 |
print(new_revision) |
|
90
8d7815ecd211
signals are now sent in model methods rather than views
durandn
parents:
89
diff
changeset
|
278 |
iconolab_signals.revision_created.send(sender=AnnotationRevision, instance=new_revision) |
| 48 | 279 |
return new_revision |
280 |
||
281 |
# Call when we're validating an awaiting revision whose parent is the current revision AS IT WAS CREATED |
|
282 |
@transaction.atomic |
|
283 |
def validate_existing_revision(self, revision_to_validate): |
|
|
62
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
284 |
if revision_to_validate.parent_revision == self.current_revision and revision_to_validate.state == AnnotationRevision.AWAITING: |
| 48 | 285 |
self.current_revision = revision_to_validate |
286 |
revision_to_validate.state = AnnotationRevision.ACCEPTED |
|
287 |
revision_to_validate.save() |
|
288 |
self.save() |
|
|
90
8d7815ecd211
signals are now sent in model methods rather than views
durandn
parents:
89
diff
changeset
|
289 |
iconolab_signals.revision_accepted.send(sender=AnnotationRevision, instance=revision_to_validate) |
|
62
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
290 |
|
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
291 |
# Call to reject a |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
292 |
@transaction.atomic |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
293 |
def reject_existing_revision(self, revision_to_reject): |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
294 |
if revision_to_reject.state == AnnotationRevision.AWAITING: |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
295 |
revision_to_reject.state = AnnotationRevision.REJECTED |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
296 |
revision_to_reject.save() |
|
98
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
297 |
iconolab_signals.revision_rejected.send(sender=AnnotationRevision, instance=revision_to_reject) |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
298 |
|
| 48 | 299 |
# Call when we're validating an awaiting revision whose parent isn't the current revision OR IF IT WAS CHANGED BY THE ANNOTATION AUTHOR |
300 |
@transaction.atomic |
|
301 |
def merge_existing_revision(self, title, description, fragment, tags, revision_to_merge): |
|
| 77 | 302 |
merged_revision = self.make_new_revision(author=self.author, title=title, description=description, fragment=fragment, tags_json=tags) |
| 48 | 303 |
merged_revision.merge_parent_revision = revision_to_merge |
304 |
merged_revision.save() |
|
|
62
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
305 |
revision_to_merge.state = AnnotationRevision.STUDIED |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
306 |
revision_to_merge.save() |
|
90
8d7815ecd211
signals are now sent in model methods rather than views
durandn
parents:
89
diff
changeset
|
307 |
iconolab_signals.revision_accepted.send(sender=AnnotationRevision, instance=revision_to_merge) |
| 48 | 308 |
self.current_revision=merged_revision |
309 |
self.save() |
|
| 77 | 310 |
return merged_revision |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
311 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
312 |
|
|
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:
13
diff
changeset
|
313 |
class AnnotationRevision(models.Model): |
| 48 | 314 |
|
315 |
AWAITING = 0 |
|
316 |
ACCEPTED = 1 |
|
317 |
REJECTED = 2 |
|
|
62
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
318 |
STUDIED = 3 |
| 48 | 319 |
|
320 |
REVISION_STATES = ( |
|
321 |
(AWAITING, 'awaiting'), |
|
322 |
(ACCEPTED, 'accepted'), |
|
|
62
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
323 |
(REJECTED, 'rejected'), |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
324 |
(STUDIED, 'studied'), |
| 48 | 325 |
) |
326 |
||
327 |
revision_guid = models.UUIDField(default=uuid.uuid4) |
|
328 |
annotation = models.ForeignKey('Annotation', related_name='revisions', null=False, blank=False) |
|
329 |
parent_revision = models.ForeignKey('AnnotationRevision', related_name='child_revisions', blank=True, null=True) |
|
330 |
merge_parent_revision = models.ForeignKey('AnnotationRevision', related_name='child_revisions_merge', blank=True, null=True) |
|
331 |
author = models.ForeignKey(User, null=True) |
|
332 |
title = models.CharField(max_length=255) |
|
333 |
description = models.TextField(null=True) |
|
334 |
fragment = models.TextField() |
|
335 |
tags = models.ManyToManyField('Tag', through='TaggingInfo', through_fields=('revision', 'tag')) |
|
336 |
state = models.IntegerField(choices=REVISION_STATES, default=AWAITING) |
|
337 |
created = models.DateTimeField(auto_now_add=True, null=True) |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
338 |
|
| 48 | 339 |
def set_tags(self, tags_json_string): |
340 |
try: |
|
341 |
tags_dict = json.loads(tags_json_string) |
|
342 |
except ValueError: |
|
343 |
pass |
|
344 |
for tag_data in tags_dict: |
|
345 |
tag_string = tag_data.get("tag_input") |
|
346 |
tag_accuracy = tag_data.get("accuracy", 0) |
|
347 |
tag_relevancy = tag_data.get("relevancy", 0) |
|
348 |
||
349 |
if tag_string.startswith("http://") or tag_string.startswith("https://"): #check if url |
|
350 |
if Tag.objects.filter(link=tag_string).exists(): #check if tag already exists |
|
351 |
tag_obj = Tag.objects.get(link=tag_string) |
|
352 |
else: |
|
353 |
tag_obj = Tag.objects.create( |
|
354 |
link = tag_string, |
|
355 |
) |
|
356 |
else: |
|
357 |
new_tag_link = settings.BASE_URL+'/'+slugify(tag_string) |
|
358 |
if Tag.objects.filter(link=new_tag_link).exists(): |
|
359 |
# Somehow we received a label for an existing tag |
|
360 |
tag_obj = Tag.objects.get(link=new_tag_link) |
|
361 |
else: |
|
362 |
tag_obj = Tag.objects.create( |
|
363 |
label = tag_string, |
|
|
104
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
364 |
label_slug = slugify(tag_string), |
| 48 | 365 |
description = "", |
366 |
link = settings.INTERNAL_TAGS_URL+'/'+slugify(tag_string), |
|
367 |
collection = self.annotation.image.item.collection |
|
368 |
) |
|
369 |
tag_info = TaggingInfo.objects.create( |
|
370 |
tag=tag_obj, |
|
371 |
revision=self, |
|
372 |
accuracy = tag_accuracy, |
|
373 |
relevancy = tag_relevancy |
|
374 |
) |
|
375 |
||
376 |
def get_tags_json(self): |
|
377 |
||
|
54
147c8a8b66b6
streamlined templates for easy navigation and missing info + handled fr.dbpedia tags
durandn
parents:
53
diff
changeset
|
378 |
def fetch_from_dbpedia(uri, lang, source): |
| 48 | 379 |
sparql_template = 'select distinct * where { <<%uri%>> rdfs:label ?l FILTER( langMatches( lang(?l), "<%lang%>" ) ) }' |
380 |
sparql_query = re.sub("<%uri%>", uri, re.sub("<%lang%>", lang, sparql_template)) |
|
|
54
147c8a8b66b6
streamlined templates for easy navigation and missing info + handled fr.dbpedia tags
durandn
parents:
53
diff
changeset
|
381 |
sparql_query_url = source+'sparql' |
|
98
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
382 |
try: |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
383 |
dbpedia_resp = requests.get( |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
384 |
sparql_query_url, |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
385 |
params={ |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
386 |
"query": sparql_query, |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
387 |
"format": "json" |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
388 |
} |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
389 |
) |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
390 |
except: |
|
104
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
391 |
# dbpedia is down, will be handled with database label |
|
98
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
392 |
pass |
| 96 | 393 |
try: |
394 |
results = json.loads(dbpedia_resp.text).get("results", {}) |
|
395 |
except: |
|
396 |
# if error with json, results is empty |
|
397 |
results = {} |
|
398 |
variable_bindings = results.get("bindings", None) |
|
|
104
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
399 |
label_data = {} |
| 58 | 400 |
if variable_bindings: |
|
104
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
401 |
label_data = variable_bindings.pop() |
|
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
402 |
return label_data.get("l", {"value": False}).get("value") |
| 48 | 403 |
|
404 |
final_list = [] |
|
405 |
for tagging_info in self.tagginginfo_set.select_related("tag").all(): |
|
406 |
if tagging_info.tag.is_internal(): |
|
407 |
final_list.append({ |
|
408 |
"tag_label": tagging_info.tag.label, |
|
409 |
"tag_link": tagging_info.tag.link, |
|
410 |
"accuracy": tagging_info.accuracy, |
|
|
89
23679a6def77
fixed error on stats (comments count not updating correctly for images)
durandn
parents:
85
diff
changeset
|
411 |
"relevancy": tagging_info.relevancy, |
|
23679a6def77
fixed error on stats (comments count not updating correctly for images)
durandn
parents:
85
diff
changeset
|
412 |
"is_internal": tagging_info.tag.is_internal() |
| 48 | 413 |
}) |
414 |
else: |
|
415 |
tag_link = tagging_info.tag.link |
|
416 |
#import label from external |
|
417 |
externaL_repos_fetch_dict = { |
|
418 |
"http://dbpedia.org/": fetch_from_dbpedia, |
|
|
53
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
419 |
"http://fr.dbpedia.org/": fetch_from_dbpedia |
| 48 | 420 |
} |
|
53
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
421 |
try: |
|
54
147c8a8b66b6
streamlined templates for easy navigation and missing info + handled fr.dbpedia tags
durandn
parents:
53
diff
changeset
|
422 |
(source, fetch_label) = next(item for item in externaL_repos_fetch_dict.items() if tag_link.startswith(item[0])) |
|
147c8a8b66b6
streamlined templates for easy navigation and missing info + handled fr.dbpedia tags
durandn
parents:
53
diff
changeset
|
423 |
tag_label = fetch_label(tag_link, "fr", source) |
|
104
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
424 |
if not tag_label: # Error happened and we got False as a fetch return |
|
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
425 |
tag_label = tagging_info.tag.label |
|
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
426 |
else: |
|
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
427 |
tagging_info.tag.label = tag_label |
|
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
428 |
tagging_info.tag.save() |
|
53
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
429 |
final_list.append({ |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
430 |
"tag_label": tag_label, |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
431 |
"tag_link": tag_link, |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
432 |
"accuracy": tagging_info.accuracy, |
|
89
23679a6def77
fixed error on stats (comments count not updating correctly for images)
durandn
parents:
85
diff
changeset
|
433 |
"relevancy": tagging_info.relevancy, |
|
23679a6def77
fixed error on stats (comments count not updating correctly for images)
durandn
parents:
85
diff
changeset
|
434 |
"is_internal": tagging_info.tag.is_internal() |
|
53
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
435 |
}) |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
436 |
except StopIteration: |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
437 |
pass |
| 48 | 438 |
return json.dumps(final_list) |
| 101 | 439 |
|
| 48 | 440 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
441 |
class IconolabComment(XtdComment): |
| 48 | 442 |
revision = models.ForeignKey('AnnotationRevision', related_name='creation_comment', null=True, blank=True) |
443 |
metacategories = models.ManyToManyField('MetaCategory', through='MetaCategoryInfo', through_fields=('comment', 'metacategory')) |
|
| 68 | 444 |
|
445 |
objects = XtdComment.objects |
|
446 |
||
447 |
class Meta: |
|
448 |
ordering = ["thread_id", "id"] |
|
| 48 | 449 |
|
|
97
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
450 |
# Get page for considered comment, with COMMENTS_PER_PAGE_DEFAULT comments per page |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
451 |
def get_comment_page(self): |
|
100
8ec8aced3f68
small fixes on comment page calculation + added functionality to clear unread notification from button in user home + quick css fixes
durandn
parents:
98
diff
changeset
|
452 |
return (self._default_manager.for_app_models("iconolab.annotation").filter( |
|
8ec8aced3f68
small fixes on comment page calculation + added functionality to clear unread notification from button in user home + quick css fixes
durandn
parents:
98
diff
changeset
|
453 |
object_pk=self.object_pk, |
| 101 | 454 |
).filter(thread_id__gte=self.thread_id).filter(order__lte=self.order).count() +1) // settings.COMMENTS_PER_PAGE_DEFAULT + 1 |
455 |
||
|
97
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
456 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
457 |
class MetaCategory(models.Model): |
|
97
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
458 |
NONE = 0 # Notifies nobody |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
459 |
CONTRIBUTORS = 1 # Notifies contributors (revision owners) on target annotation |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
460 |
COMMENTERS = 2 # Notifies commenters (contributors + comment owners) on target annotation |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
461 |
COLLECTION_ADMINS = 3 # Notifies collection admins |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
462 |
|
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
463 |
NOTIFIED_USERS = ( |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
464 |
(NONE, 'none'), |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
465 |
(CONTRIBUTORS, 'contributors'), |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
466 |
(COMMENTERS, 'commenters'), |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
467 |
(COLLECTION_ADMINS, 'collection admins'), |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
468 |
) |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
469 |
|
| 48 | 470 |
collection = models.ForeignKey(Collection) |
471 |
label = models.CharField(max_length=255) |
|
|
97
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
472 |
triggers_notifications = models.IntegerField(choices=NOTIFIED_USERS, default=NONE) |
|
f747c112e8f4
Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents:
96
diff
changeset
|
473 |
|
| 48 | 474 |
def __str__(self): |
475 |
return self.label |
|
476 |
||
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
477 |
|
|
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
478 |
class MetaCategoryInfo(models.Model): |
| 48 | 479 |
comment = models.ForeignKey('IconolabComment', on_delete=models.CASCADE) |
480 |
metacategory = models.ForeignKey('MetaCategory', on_delete=models.CASCADE) |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
481 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
482 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
483 |
class CommentAttachement(models.Model): |
| 48 | 484 |
|
485 |
LINK = 0 |
|
486 |
IMAGE = 1 |
|
487 |
PDF = 2 |
|
488 |
COMMENT_CHOICES = ( |
|
489 |
(LINK, 'link'), |
|
490 |
(IMAGE, 'image'), |
|
491 |
(PDF, 'pdf') |
|
492 |
) |
|
493 |
||
494 |
comment = models.ForeignKey('IconolabComment', related_name='attachments', on_delete=models.CASCADE) |
|
495 |
attachment_type = models.IntegerField(choices=COMMENT_CHOICES, default=0) |
|
496 |
data = models.TextField(blank=False) |