| author | durandn |
| Thu, 07 Jul 2016 16:34:31 +0200 | |
| changeset 62 | 8702ab13783e |
| parent 58 | 9f7e484baf73 |
| child 64 | 4d1e369e85d4 |
| 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 |
8 |
import uuid, json, re, requests, urllib |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
9 |
|
|
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 |
class Tag(models.Model): |
| 48 | 12 |
label = models.SlugField(blank=True, null=True) |
13 |
link = models.URLField(unique=True) |
|
14 |
description = models.CharField(max_length=255, blank=True, null=True) |
|
15 |
collection = models.ForeignKey('Collection', blank=True, null=True) |
|
16 |
||
17 |
def is_internal(self): |
|
18 |
return self.link.startswith(settings.INTERNAL_TAGS_URL) |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
19 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
20 |
|
|
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
|
21 |
class TaggingInfo(models.Model): |
| 48 | 22 |
revision = models.ForeignKey('AnnotationRevision', on_delete=models.CASCADE) |
23 |
tag = models.ForeignKey('Tag', on_delete=models.CASCADE) |
|
24 |
accuracy = models.IntegerField() |
|
25 |
relevancy = models.IntegerField() |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
26 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
27 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
28 |
class Collection(models.Model): |
| 48 | 29 |
name = models.CharField(max_length=50, unique=True) |
30 |
description = models.CharField(max_length=255) |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
31 |
|
| 48 | 32 |
def __str__(self): |
33 |
return self.name |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
34 |
|
|
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
|
35 |
|
|
31
e34b70a00488
adding annotations list
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
30
diff
changeset
|
36 |
class Item(models.Model): |
| 48 | 37 |
collection = models.ForeignKey(Collection, related_name="items") |
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
38 |
|
| 48 | 39 |
|
|
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
|
40 |
class ItemMetadata(models.Model): |
| 48 | 41 |
item = models.OneToOneField('Item', related_name='metadatas') |
42 |
joconde_ref = models.CharField(max_length=20, null=False, blank=False, unique=True) |
|
43 |
domain = models.CharField(max_length=255) |
|
44 |
title = models.CharField(max_length=255) |
|
45 |
description = models.CharField(max_length=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:
13
diff
changeset
|
46 |
|
|
31
e34b70a00488
adding annotations list
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
30
diff
changeset
|
47 |
|
|
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
|
48 |
class ImageStats(models.Model): |
| 48 | 49 |
image = models.OneToOneField('Image', related_name='stats', blank=False, null=False) |
50 |
views_count = models.IntegerField(blank=True, null=True, default=0) |
|
51 |
annotations_count = models.IntegerField(blank=True, null=True, default=0) |
|
52 |
submitted_revisions_count = models.IntegerField(blank=True, null=True, default=0) |
|
53 |
comments_count = models.IntegerField(blank=True, null=True, default=0) |
|
54 |
folders_inclusion_count = models.IntegerField(blank=True, null=True, default=0) |
|
55 |
tag_count = models.IntegerField(blank=True, null=True, default=0) |
|
|
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
|
56 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
57 |
class Image(models.Model): |
| 48 | 58 |
image_guid = models.UUIDField(default=uuid.uuid4, editable=False) |
59 |
name = models.CharField(max_length=200) |
|
60 |
media = models.ImageField(upload_to='uploads/', height_field='height', width_field='width') |
|
61 |
item = models.ForeignKey('Item', related_name='images', null=True, blank=True) |
|
62 |
height = models.IntegerField(null=False, blank=False) |
|
63 |
width = models.IntegerField(null=False, blank=False) |
|
64 |
created = models.DateTimeField(auto_now_add=True, null=True) |
|
65 |
||
66 |
def __str__(self): |
|
67 |
return self.name |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
68 |
|
|
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
|
69 |
# # Folders |
|
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
|
70 |
# class Folder(models.Model): |
| 48 | 71 |
# label = models.CharField(max_length=255) |
72 |
# owner = models.ForeignKey(User) |
|
73 |
# images = models.ManyToManyField(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:
13
diff
changeset
|
74 |
# |
| 48 | 75 |
# def __str__(self): |
76 |
# return label |
|
|
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
|
77 |
|
|
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
|
78 |
class AnnotationManager(models.Manager): |
| 48 | 79 |
|
80 |
# Call Annotation.objects.create_annotation to initialize a new Annotation with its associated AnnotationStats and initial AnnotationRevision |
|
81 |
@transaction.atomic |
|
82 |
def create_annotation(self, author, image, title='', description='', fragment='', tags_json='[]'): |
|
83 |
# Create annotation object |
|
84 |
new_annotation = Annotation( |
|
85 |
image=image, |
|
86 |
author=author |
|
87 |
) |
|
88 |
new_annotation.save() |
|
89 |
||
90 |
# Create initial revision |
|
91 |
initial_revision = AnnotationRevision( |
|
92 |
annotation=new_annotation, |
|
93 |
author=author, |
|
94 |
title=title, |
|
95 |
description=description, |
|
96 |
fragment=fragment, |
|
97 |
state=AnnotationRevision.ACCEPTED |
|
98 |
) |
|
99 |
initial_revision.save() |
|
100 |
initial_revision.set_tags(tags_json) |
|
101 |
||
102 |
new_annotation.current_revision = initial_revision |
|
103 |
new_annotation.save() |
|
104 |
||
105 |
# Create stats object |
|
106 |
new_annotation_stats = AnnotationStats(annotation=new_annotation) |
|
107 |
new_annotation_stats.save() |
|
108 |
new_annotation.stats = new_annotation_stats |
|
109 |
new_annotation.save() |
|
110 |
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
|
111 |
|
|
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
|
112 |
class AnnotationStats(models.Model): |
| 48 | 113 |
annotation = models.OneToOneField('Annotation', related_name='stats', blank=False, null=False) |
114 |
submitted_revisions_count = models.IntegerField(blank=True, null=True, default=1) |
|
115 |
accepted_revisions_count = models.IntegerField(blank=True, null=True, default=1) |
|
116 |
contributors_count = models.IntegerField(blank=True, null=True, default=1) |
|
117 |
views_count = models.IntegerField(blank=True, null=True, default=0) |
|
118 |
comments_count = models.IntegerField(blank=True, null=True, default=0) |
|
119 |
tag_count = models.IntegerField(blank=True, null=True, default=0) |
|
120 |
||
121 |
def contributors(self): |
|
|
62
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
122 |
contributors = [] |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
123 |
for revision in self.annotation.revisions.filter(state__in=[AnnotationRevision.ACCEPTED, AnnotationRevision.STUDIED]): |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
124 |
if revision.author not in contributors: |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
125 |
contributors.append(revision.author) |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
126 |
print(contributors) |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
127 |
return contributors |
|
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
|
128 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
129 |
|
|
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
|
130 |
class Annotation(models.Model): |
| 48 | 131 |
annotation_guid = models.UUIDField(default=uuid.uuid4, editable=False) |
132 |
image = models.ForeignKey('Image', related_name='annotations', on_delete=models.CASCADE) |
|
133 |
source_revision = models.ForeignKey('AnnotationRevision', related_name='source_related_annotation', blank=True, null=True) |
|
134 |
current_revision = models.OneToOneField('AnnotationRevision', related_name='current_for_annotation', blank=True, null=True) |
|
135 |
author = models.ForeignKey(User, null=True) |
|
136 |
created = models.DateTimeField(auto_now_add=True, null=True) |
|
137 |
||
138 |
objects = AnnotationManager() |
|
139 |
||
140 |
def update_stats(self): |
|
141 |
pass |
|
142 |
||
143 |
# Call to create a new revision, possibly from a merge |
|
144 |
@transaction.atomic |
|
145 |
def make_new_revision(self, author, title, description, fragment, tags_json): |
|
146 |
if author == self.author: |
|
147 |
# We're creating an automatically accepted revision |
|
148 |
new_revision_state = AnnotationRevision.ACCEPTED |
|
149 |
else: |
|
150 |
# Revision will require validation |
|
151 |
new_revision_state = AnnotationRevision.AWAITING |
|
152 |
new_revision = AnnotationRevision( |
|
153 |
annotation = self, |
|
154 |
parent_revision=self.current_revision, |
|
155 |
title=title, |
|
156 |
description=description, |
|
157 |
author=author, |
|
158 |
fragment=fragment, |
|
159 |
state=new_revision_state |
|
160 |
) |
|
161 |
new_revision.save() |
|
162 |
new_revision.set_tags(tags_json) |
|
163 |
if new_revision.state == AnnotationRevision.ACCEPTED: |
|
164 |
self.current_revision = new_revision |
|
165 |
self.save() |
|
166 |
return new_revision |
|
167 |
||
168 |
# Call when we're validating an awaiting revision whose parent is the current revision AS IT WAS CREATED |
|
169 |
@transaction.atomic |
|
170 |
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
|
171 |
if revision_to_validate.parent_revision == self.current_revision and revision_to_validate.state == AnnotationRevision.AWAITING: |
| 48 | 172 |
self.current_revision = revision_to_validate |
173 |
revision_to_validate.state = AnnotationRevision.ACCEPTED |
|
174 |
revision_to_validate.save() |
|
175 |
self.save() |
|
|
62
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
176 |
|
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
177 |
# 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
|
178 |
@transaction.atomic |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
revision_to_reject.save() |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
183 |
|
| 48 | 184 |
# Call when we're validating an awaiting revision whose parent isn't the current revision OR IF IT WAS CHANGED BY THE ANNOTATION AUTHOR |
185 |
@transaction.atomic |
|
186 |
def merge_existing_revision(self, title, description, fragment, tags, revision_to_merge): |
|
187 |
merged_revision = self.make_new_revision(author=self.author, title=title, description=description, fragment=fragment, tags=tags) |
|
188 |
merged_revision.merge_parent_revision = revision_to_merge |
|
189 |
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
|
190 |
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
|
191 |
revision_to_merge.save() |
| 48 | 192 |
self.current_revision=merged_revision |
193 |
self.save() |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
194 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
195 |
|
|
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
|
196 |
class AnnotationRevision(models.Model): |
| 48 | 197 |
|
198 |
AWAITING = 0 |
|
199 |
ACCEPTED = 1 |
|
200 |
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
|
201 |
STUDIED = 3 |
| 48 | 202 |
|
203 |
REVISION_STATES = ( |
|
204 |
(AWAITING, 'awaiting'), |
|
205 |
(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
|
206 |
(REJECTED, 'rejected'), |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
207 |
(STUDIED, 'studied'), |
| 48 | 208 |
) |
209 |
||
210 |
revision_guid = models.UUIDField(default=uuid.uuid4) |
|
211 |
annotation = models.ForeignKey('Annotation', related_name='revisions', null=False, blank=False) |
|
212 |
parent_revision = models.ForeignKey('AnnotationRevision', related_name='child_revisions', blank=True, null=True) |
|
213 |
merge_parent_revision = models.ForeignKey('AnnotationRevision', related_name='child_revisions_merge', blank=True, null=True) |
|
214 |
author = models.ForeignKey(User, null=True) |
|
215 |
title = models.CharField(max_length=255) |
|
216 |
description = models.TextField(null=True) |
|
217 |
fragment = models.TextField() |
|
218 |
tags = models.ManyToManyField('Tag', through='TaggingInfo', through_fields=('revision', 'tag')) |
|
219 |
state = models.IntegerField(choices=REVISION_STATES, default=AWAITING) |
|
220 |
created = models.DateTimeField(auto_now_add=True, null=True) |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
221 |
|
| 48 | 222 |
def set_tags(self, tags_json_string): |
223 |
try: |
|
224 |
tags_dict = json.loads(tags_json_string) |
|
225 |
except ValueError: |
|
226 |
pass |
|
227 |
for tag_data in tags_dict: |
|
228 |
tag_string = tag_data.get("tag_input") |
|
229 |
tag_accuracy = tag_data.get("accuracy", 0) |
|
230 |
tag_relevancy = tag_data.get("relevancy", 0) |
|
231 |
||
232 |
if tag_string.startswith("http://") or tag_string.startswith("https://"): #check if url |
|
233 |
if Tag.objects.filter(link=tag_string).exists(): #check if tag already exists |
|
234 |
tag_obj = Tag.objects.get(link=tag_string) |
|
235 |
else: |
|
236 |
tag_obj = Tag.objects.create( |
|
237 |
link = tag_string, |
|
238 |
) |
|
239 |
else: |
|
240 |
new_tag_link = settings.BASE_URL+'/'+slugify(tag_string) |
|
241 |
if Tag.objects.filter(link=new_tag_link).exists(): |
|
242 |
# Somehow we received a label for an existing tag |
|
243 |
tag_obj = Tag.objects.get(link=new_tag_link) |
|
244 |
else: |
|
245 |
tag_obj = Tag.objects.create( |
|
246 |
label = tag_string, |
|
247 |
description = "", |
|
248 |
link = settings.INTERNAL_TAGS_URL+'/'+slugify(tag_string), |
|
249 |
collection = self.annotation.image.item.collection |
|
250 |
) |
|
251 |
tag_info = TaggingInfo.objects.create( |
|
252 |
tag=tag_obj, |
|
253 |
revision=self, |
|
254 |
accuracy = tag_accuracy, |
|
255 |
relevancy = tag_relevancy |
|
256 |
) |
|
257 |
||
258 |
def get_tags_json(self): |
|
259 |
||
|
54
147c8a8b66b6
streamlined templates for easy navigation and missing info + handled fr.dbpedia tags
durandn
parents:
53
diff
changeset
|
260 |
def fetch_from_dbpedia(uri, lang, source): |
| 48 | 261 |
sparql_template = 'select distinct * where { <<%uri%>> rdfs:label ?l FILTER( langMatches( lang(?l), "<%lang%>" ) ) }' |
262 |
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
|
263 |
sparql_query_url = source+'sparql' |
| 48 | 264 |
dbpedia_resp = requests.get( |
265 |
sparql_query_url, |
|
266 |
params={ |
|
267 |
"query": sparql_query, |
|
268 |
"format": "json" |
|
269 |
} |
|
270 |
) |
|
| 49 | 271 |
results = json.loads(dbpedia_resp.text).get("results", {}) |
272 |
variable_bindings = results.get("bindings") |
|
| 58 | 273 |
if variable_bindings: |
274 |
label_json = variable_bindings.pop() |
|
275 |
else: |
|
276 |
label_json = {"l": {"value": "ERROR_LABEL"}} |
|
| 49 | 277 |
return label_json.get("l").get("value") |
| 48 | 278 |
|
279 |
final_list = [] |
|
280 |
for tagging_info in self.tagginginfo_set.select_related("tag").all(): |
|
281 |
if tagging_info.tag.is_internal(): |
|
282 |
final_list.append({ |
|
283 |
"tag_label": tagging_info.tag.label, |
|
284 |
"tag_link": tagging_info.tag.link, |
|
285 |
"accuracy": tagging_info.accuracy, |
|
286 |
"relevancy": tagging_info.relevancy |
|
287 |
}) |
|
288 |
else: |
|
289 |
tag_link = tagging_info.tag.link |
|
290 |
#import label from external |
|
291 |
externaL_repos_fetch_dict = { |
|
292 |
"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
|
293 |
"http://fr.dbpedia.org/": fetch_from_dbpedia |
| 48 | 294 |
} |
|
53
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
295 |
try: |
|
54
147c8a8b66b6
streamlined templates for easy navigation and missing info + handled fr.dbpedia tags
durandn
parents:
53
diff
changeset
|
296 |
(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
|
297 |
tag_label = fetch_label(tag_link, "fr", source) |
|
53
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
298 |
final_list.append({ |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
299 |
"tag_label": tag_label, |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
300 |
"tag_link": tag_link, |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
301 |
"accuracy": tagging_info.accuracy, |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
302 |
"relevancy": tagging_info.relevancy |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
303 |
}) |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
304 |
except StopIteration: |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
305 |
pass |
| 48 | 306 |
return json.dumps(final_list) |
307 |
||
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
308 |
class IconolabComment(XtdComment): |
| 48 | 309 |
revision = models.ForeignKey('AnnotationRevision', related_name='creation_comment', null=True, blank=True) |
310 |
metacategories = models.ManyToManyField('MetaCategory', through='MetaCategoryInfo', through_fields=('comment', 'metacategory')) |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
311 |
|
| 48 | 312 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
313 |
class MetaCategory(models.Model): |
| 48 | 314 |
collection = models.ForeignKey(Collection) |
315 |
label = models.CharField(max_length=255) |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
316 |
|
| 48 | 317 |
def __str__(self): |
318 |
return self.label |
|
319 |
||
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
320 |
|
|
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
321 |
class MetaCategoryInfo(models.Model): |
| 48 | 322 |
comment = models.ForeignKey('IconolabComment', on_delete=models.CASCADE) |
323 |
metacategory = models.ForeignKey('MetaCategory', on_delete=models.CASCADE) |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
324 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
325 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
326 |
class CommentAttachement(models.Model): |
| 48 | 327 |
|
328 |
LINK = 0 |
|
329 |
IMAGE = 1 |
|
330 |
PDF = 2 |
|
331 |
COMMENT_CHOICES = ( |
|
332 |
(LINK, 'link'), |
|
333 |
(IMAGE, 'image'), |
|
334 |
(PDF, 'pdf') |
|
335 |
) |
|
336 |
||
337 |
comment = models.ForeignKey('IconolabComment', related_name='attachments', on_delete=models.CASCADE) |
|
338 |
attachment_type = models.IntegerField(choices=COMMENT_CHOICES, default=0) |
|
339 |
data = models.TextField(blank=False) |