| author | Harris Baptiste <harris.baptiste@iri.centrepompidou.fr> |
| Tue, 23 Aug 2016 18:01:08 +0200 | |
| changeset 151 | 797460904f77 |
| parent 139 | 3e0a5286b257 |
| child 176 | ef200c865025 |
| 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 |
|
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
22 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
23 |
return self.label_slug+":"+self.label |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
24 |
|
|
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
|
25 |
class TaggingInfo(models.Model): |
| 48 | 26 |
revision = models.ForeignKey('AnnotationRevision', on_delete=models.CASCADE) |
27 |
tag = models.ForeignKey('Tag', on_delete=models.CASCADE) |
|
28 |
accuracy = models.IntegerField() |
|
29 |
relevancy = models.IntegerField() |
|
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
30 |
|
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
31 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
32 |
return self.tag.label_slug+":to:"+self.revision.revision_guid |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
33 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
34 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
35 |
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
|
36 |
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
|
37 |
verbose_name = models.CharField(max_length=50, null=True, blank=True) |
|
126
b5aa7e6f6a01
updated apps in dev.py.tmpl and deleted unused code
durandn
parents:
123
diff
changeset
|
38 |
description = models.TextField(null=True) |
| 122 | 39 |
image = models.ImageField(upload_to='uploads/', height_field='height', width_field='width', null=True, blank=True) |
40 |
height = models.IntegerField(null=True, blank=True) |
|
41 |
width = models.IntegerField(null=True, blank=True) |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
42 |
|
| 48 | 43 |
def __str__(self): |
44 |
return self.name |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
45 |
|
|
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 |
class Item(models.Model): |
| 48 | 48 |
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
|
49 |
item_guid = models.UUIDField(default=uuid.uuid4, editable=False) |
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
50 |
|
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
51 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
52 |
return str(self.item_guid)+":from:"+self.collection.name |
| 48 | 53 |
|
|
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
|
54 |
class ItemMetadata(models.Model): |
| 48 | 55 |
item = models.OneToOneField('Item', related_name='metadatas') |
| 110 | 56 |
authors = models.CharField(max_length=255, default="") |
57 |
school = models.CharField(max_length=255, default="") |
|
58 |
designation = models.CharField(max_length=255, default="") |
|
59 |
datation = models.CharField(max_length=255, default="") |
|
60 |
technics = models.CharField(max_length=255, default="") |
|
61 |
measurements = models.CharField(max_length=255, default="") |
|
62 |
create_or_usage_location = models.CharField(max_length=255, default="") |
|
63 |
discovery_context = models.CharField(max_length=255, default="") |
|
64 |
conservation_location = models.CharField(max_length=255, default="") |
|
65 |
photo_credits = models.CharField(max_length=255, default="") |
|
66 |
inventory_number = models.CharField(max_length=255, default="") |
|
67 |
joconde_ref = models.CharField(max_length=255, default="") |
|
68 |
||
69 |
@property |
|
70 |
def get_joconde_url(self): |
|
|
136
81d82b1f431a
generating joconde external url + small change on comment submit button + small change on __str__ for metacategories
durandn
parents:
134
diff
changeset
|
71 |
return settings.JOCONDE_NOTICE_BASE_URL+self.joconde_ref.rjust(11, '0') |
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
72 |
|
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
73 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
74 |
return "metadatas:for:"+str(self.item.item_guid) |
|
24
6b6b183447a2
work on models + auth register/login system + adapted existing app and templates so editing annotations is working as before + created empty templates to fill
durandn
parents:
13
diff
changeset
|
75 |
|
|
31
e34b70a00488
adding annotations list
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
30
diff
changeset
|
76 |
|
|
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 |
class ImageStats(models.Model): |
| 48 | 78 |
image = models.OneToOneField('Image', related_name='stats', blank=False, null=False) |
79 |
views_count = models.IntegerField(blank=True, null=True, default=0) |
|
80 |
annotations_count = models.IntegerField(blank=True, null=True, default=0) |
|
81 |
submitted_revisions_count = models.IntegerField(blank=True, null=True, default=0) |
|
82 |
comments_count = models.IntegerField(blank=True, null=True, default=0) |
|
83 |
folders_inclusion_count = models.IntegerField(blank=True, null=True, default=0) |
|
84 |
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
|
85 |
|
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
86 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
87 |
return "stats:for:"+self.image.image_guid |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
88 |
|
|
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
|
89 |
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
|
90 |
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
|
91 |
|
| 93 | 92 |
@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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
# 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
|
99 |
# 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
|
100 |
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
|
101 |
# 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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
|
|
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
|
106 |
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
|
107 |
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
|
108 |
).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
|
109 |
# 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
|
110 |
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
|
111 |
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
|
112 |
|
| 101 | 113 |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
114 |
class Image(models.Model): |
| 48 | 115 |
image_guid = models.UUIDField(default=uuid.uuid4, editable=False) |
116 |
name = models.CharField(max_length=200) |
|
117 |
media = models.ImageField(upload_to='uploads/', height_field='height', width_field='width') |
|
118 |
item = models.ForeignKey('Item', related_name='images', null=True, blank=True) |
|
119 |
height = models.IntegerField(null=False, blank=False) |
|
120 |
width = models.IntegerField(null=False, blank=False) |
|
121 |
created = models.DateTimeField(auto_now_add=True, null=True) |
|
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
122 |
|
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
123 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
124 |
return str(self.image_guid)+":"+self.name |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
125 |
|
|
106
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
126 |
@property |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
127 |
def collection(self): |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
128 |
return self.item.collection.name |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
129 |
|
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
130 |
@property |
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
131 |
def title(self): |
|
116
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
132 |
return self.item.metadatas.designation |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
133 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
134 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
135 |
def authors(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
136 |
return self.item.metadatas.authors |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
137 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
138 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
139 |
def school(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
140 |
return self.item.metadatas.school |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
141 |
|
|
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 designation(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
144 |
return self.item.metadatas.designation |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
145 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
146 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
147 |
def datation(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
148 |
return self.item.metadatas.datation |
|
106
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
149 |
|
|
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
150 |
@property |
|
116
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
151 |
def technics(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
152 |
return self.item.metadatas.technics |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
153 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
154 |
@property |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
155 |
def measurements(self): |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
156 |
return self.item.metadatas.measurements |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
157 |
|
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
158 |
@property |
|
151
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
159 |
def tag_labels(self): |
|
116
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
160 |
tag_list = [] |
|
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
161 |
for annotation in self.annotations.all(): |
|
151
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
162 |
revision_tags = json.loads(annotation.current_revision.get_tags_json()) |
|
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
163 |
tag_list += [tag_infos['tag_label'] for tag_infos in revision_tags if tag_infos.get('tag_label') is not None] #deal with |
|
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
164 |
print("tag_list") |
|
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
165 |
print(tag_list) |
|
116
1e2caa72bf2f
updated indexes
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
110
diff
changeset
|
166 |
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
|
167 |
|
|
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
|
168 |
class AnnotationManager(models.Manager): |
| 48 | 169 |
|
170 |
# Call Annotation.objects.create_annotation to initialize a new Annotation with its associated AnnotationStats and initial AnnotationRevision |
|
171 |
@transaction.atomic |
|
172 |
def create_annotation(self, author, image, title='', description='', fragment='', tags_json='[]'): |
|
173 |
# Create annotation object |
|
174 |
new_annotation = Annotation( |
|
175 |
image=image, |
|
176 |
author=author |
|
177 |
) |
|
178 |
new_annotation.save() |
|
179 |
||
180 |
# Create initial revision |
|
181 |
initial_revision = AnnotationRevision( |
|
182 |
annotation=new_annotation, |
|
183 |
author=author, |
|
184 |
title=title, |
|
185 |
description=description, |
|
186 |
fragment=fragment, |
|
187 |
state=AnnotationRevision.ACCEPTED |
|
188 |
) |
|
189 |
initial_revision.save() |
|
190 |
initial_revision.set_tags(tags_json) |
|
191 |
||
192 |
# Create stats object |
|
193 |
new_annotation_stats = AnnotationStats(annotation=new_annotation) |
|
194 |
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
|
195 |
new_annotation_stats.set_tags_stats() |
| 123 | 196 |
|
197 |
# Link everything to parent |
|
198 |
new_annotation.current_revision = initial_revision |
|
| 48 | 199 |
new_annotation.stats = new_annotation_stats |
200 |
new_annotation.save() |
|
|
134
350bdfe7c289
sending revision_created signal when creating an annotation
durandn
parents:
133
diff
changeset
|
201 |
iconolab_signals.revision_created.send(sender=AnnotationRevision, instance=initial_revision) |
| 48 | 202 |
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
|
203 |
|
| 101 | 204 |
|
|
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
|
205 |
class AnnotationStats(models.Model): |
| 48 | 206 |
annotation = models.OneToOneField('Annotation', related_name='stats', blank=False, null=False) |
207 |
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
|
208 |
awaiting_revisions_count = models.IntegerField(blank=True, null=True, default=0) |
| 48 | 209 |
accepted_revisions_count = models.IntegerField(blank=True, null=True, default=1) |
210 |
contributors_count = models.IntegerField(blank=True, null=True, default=1) |
|
211 |
views_count = models.IntegerField(blank=True, null=True, default=0) |
|
212 |
comments_count = models.IntegerField(blank=True, null=True, default=0) |
|
213 |
tag_count = models.IntegerField(blank=True, null=True, default=0) |
|
214 |
||
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
215 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
216 |
return "stats:for:"+str(self.annotation_guid) |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
217 |
|
|
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
|
218 |
@property |
| 48 | 219 |
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
|
220 |
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
|
221 |
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
|
222 |
|
|
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
|
223 |
@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
|
224 |
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
|
225 |
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
|
226 |
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
|
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 |
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
|
229 |
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
|
230 |
|
| 93 | 231 |
@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
|
232 |
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
|
233 |
# 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
|
234 |
# 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
|
235 |
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
|
236 |
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
|
237 |
# 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
|
238 |
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
|
239 |
# 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
|
240 |
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
|
241 |
# 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
|
242 |
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
|
243 |
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
|
244 |
).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
|
245 |
# 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
|
246 |
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
|
247 |
# 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
|
248 |
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
|
249 |
|
|
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
|
250 |
self.save() |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
251 |
|
| 101 | 252 |
|
|
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
|
253 |
class Annotation(models.Model): |
| 48 | 254 |
annotation_guid = models.UUIDField(default=uuid.uuid4, editable=False) |
255 |
image = models.ForeignKey('Image', related_name='annotations', on_delete=models.CASCADE) |
|
256 |
source_revision = models.ForeignKey('AnnotationRevision', related_name='source_related_annotation', blank=True, null=True) |
|
257 |
current_revision = models.OneToOneField('AnnotationRevision', related_name='current_for_annotation', blank=True, null=True) |
|
258 |
author = models.ForeignKey(User, null=True) |
|
259 |
created = models.DateTimeField(auto_now_add=True, null=True) |
|
260 |
||
261 |
objects = AnnotationManager() |
|
262 |
||
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
263 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
264 |
return str(self.annotation_guid)+":"+self.current_revision.title |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
265 |
|
|
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
|
266 |
@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
|
267 |
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
|
268 |
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
|
269 |
|
|
106
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
270 |
@property |
|
139
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
271 |
def accepted_revisions_count(self): |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
272 |
return self.revisions.filter(state=AnnotationRevision.ACCEPTED).distinct().count() |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
273 |
|
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
274 |
@property |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
275 |
def rejected_revisions_count(self): |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
276 |
return self.revisions.filter(state=AnnotationRevision.REJECTED).distinct().count() |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
277 |
|
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
278 |
@property |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
279 |
def studied_revisions_count(self): |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
280 |
return self.revisions.filter(state=AnnotationRevision.STUDIED).distinct().count() |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
281 |
|
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
282 |
@property |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
283 |
def total_revisions_count(self): |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
284 |
return self.revisions.distinct().count() |
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
285 |
|
|
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
286 |
@property |
|
124
e5267573edd8
search engine
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
116
diff
changeset
|
287 |
def collection(self): |
|
e5267573edd8
search engine
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
116
diff
changeset
|
288 |
return self.image.collection |
|
e5267573edd8
search engine
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
116
diff
changeset
|
289 |
|
|
e5267573edd8
search engine
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
116
diff
changeset
|
290 |
@property |
|
151
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
291 |
def tag_labels(self): |
|
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
292 |
current_revision_tags = json.loads(self.current_revision.get_tags_json()) |
|
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
293 |
print("tagss") |
|
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
294 |
print(current_revision_tags) |
|
797460904f77
indexing using tag labels
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
139
diff
changeset
|
295 |
return [tag_infos['tag_label'] for tag_infos in current_revision_tags if tag_infos.get('tag_label') is not None ] |
|
106
233bda6f2865
iconolab search
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
104
diff
changeset
|
296 |
|
|
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
|
297 |
|
| 48 | 298 |
# Call to create a new revision, possibly from a merge |
299 |
@transaction.atomic |
|
300 |
def make_new_revision(self, author, title, description, fragment, tags_json): |
|
301 |
if author == self.author: |
|
302 |
# We're creating an automatically accepted revision |
|
303 |
new_revision_state = AnnotationRevision.ACCEPTED |
|
304 |
else: |
|
305 |
# Revision will require validation |
|
306 |
new_revision_state = AnnotationRevision.AWAITING |
|
307 |
new_revision = AnnotationRevision( |
|
308 |
annotation = self, |
|
309 |
parent_revision=self.current_revision, |
|
310 |
title=title, |
|
311 |
description=description, |
|
312 |
author=author, |
|
313 |
fragment=fragment, |
|
314 |
state=new_revision_state |
|
315 |
) |
|
316 |
new_revision.save() |
|
317 |
new_revision.set_tags(tags_json) |
|
318 |
if new_revision.state == AnnotationRevision.ACCEPTED: |
|
319 |
self.current_revision = new_revision |
|
320 |
self.save() |
|
|
90
8d7815ecd211
signals are now sent in model methods rather than views
durandn
parents:
89
diff
changeset
|
321 |
iconolab_signals.revision_created.send(sender=AnnotationRevision, instance=new_revision) |
| 48 | 322 |
return new_revision |
323 |
||
324 |
# Call when we're validating an awaiting revision whose parent is the current revision AS IT WAS CREATED |
|
325 |
@transaction.atomic |
|
326 |
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
|
327 |
if revision_to_validate.parent_revision == self.current_revision and revision_to_validate.state == AnnotationRevision.AWAITING: |
| 48 | 328 |
self.current_revision = revision_to_validate |
329 |
revision_to_validate.state = AnnotationRevision.ACCEPTED |
|
330 |
revision_to_validate.save() |
|
331 |
self.save() |
|
|
90
8d7815ecd211
signals are now sent in model methods rather than views
durandn
parents:
89
diff
changeset
|
332 |
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
|
333 |
|
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
334 |
# 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
|
335 |
@transaction.atomic |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
336 |
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
|
337 |
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
|
338 |
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
|
339 |
revision_to_reject.save() |
|
98
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
340 |
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
|
341 |
|
| 48 | 342 |
# Call when we're validating an awaiting revision whose parent isn't the current revision OR IF IT WAS CHANGED BY THE ANNOTATION AUTHOR |
343 |
@transaction.atomic |
|
344 |
def merge_existing_revision(self, title, description, fragment, tags, revision_to_merge): |
|
| 77 | 345 |
merged_revision = self.make_new_revision(author=self.author, title=title, description=description, fragment=fragment, tags_json=tags) |
| 48 | 346 |
merged_revision.merge_parent_revision = revision_to_merge |
347 |
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
|
348 |
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
|
349 |
revision_to_merge.save() |
|
90
8d7815ecd211
signals are now sent in model methods rather than views
durandn
parents:
89
diff
changeset
|
350 |
iconolab_signals.revision_accepted.send(sender=AnnotationRevision, instance=revision_to_merge) |
| 48 | 351 |
self.current_revision=merged_revision |
352 |
self.save() |
|
| 77 | 353 |
return merged_revision |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
354 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
355 |
|
|
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
|
356 |
class AnnotationRevision(models.Model): |
| 48 | 357 |
|
358 |
AWAITING = 0 |
|
359 |
ACCEPTED = 1 |
|
360 |
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
|
361 |
STUDIED = 3 |
| 48 | 362 |
|
363 |
REVISION_STATES = ( |
|
364 |
(AWAITING, 'awaiting'), |
|
365 |
(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
|
366 |
(REJECTED, 'rejected'), |
|
8702ab13783e
design work on templates, redirect to home on /, implemented accept and reject revisions shortcuts when applicable
durandn
parents:
58
diff
changeset
|
367 |
(STUDIED, 'studied'), |
| 48 | 368 |
) |
369 |
||
370 |
revision_guid = models.UUIDField(default=uuid.uuid4) |
|
371 |
annotation = models.ForeignKey('Annotation', related_name='revisions', null=False, blank=False) |
|
372 |
parent_revision = models.ForeignKey('AnnotationRevision', related_name='child_revisions', blank=True, null=True) |
|
373 |
merge_parent_revision = models.ForeignKey('AnnotationRevision', related_name='child_revisions_merge', blank=True, null=True) |
|
374 |
author = models.ForeignKey(User, null=True) |
|
375 |
title = models.CharField(max_length=255) |
|
376 |
description = models.TextField(null=True) |
|
377 |
fragment = models.TextField() |
|
378 |
tags = models.ManyToManyField('Tag', through='TaggingInfo', through_fields=('revision', 'tag')) |
|
379 |
state = models.IntegerField(choices=REVISION_STATES, default=AWAITING) |
|
380 |
created = models.DateTimeField(auto_now_add=True, null=True) |
|
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
381 |
|
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
382 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
383 |
return str(self.revision_guid)+":"+self.title |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
384 |
|
| 48 | 385 |
def set_tags(self, tags_json_string): |
386 |
try: |
|
387 |
tags_dict = json.loads(tags_json_string) |
|
388 |
except ValueError: |
|
389 |
pass |
|
390 |
for tag_data in tags_dict: |
|
391 |
tag_string = tag_data.get("tag_input") |
|
392 |
tag_accuracy = tag_data.get("accuracy", 0) |
|
393 |
tag_relevancy = tag_data.get("relevancy", 0) |
|
394 |
||
395 |
if tag_string.startswith("http://") or tag_string.startswith("https://"): #check if url |
|
396 |
if Tag.objects.filter(link=tag_string).exists(): #check if tag already exists |
|
397 |
tag_obj = Tag.objects.get(link=tag_string) |
|
398 |
else: |
|
399 |
tag_obj = Tag.objects.create( |
|
400 |
link = tag_string, |
|
401 |
) |
|
402 |
else: |
|
403 |
new_tag_link = settings.BASE_URL+'/'+slugify(tag_string) |
|
404 |
if Tag.objects.filter(link=new_tag_link).exists(): |
|
405 |
# Somehow we received a label for an existing tag |
|
406 |
tag_obj = Tag.objects.get(link=new_tag_link) |
|
407 |
else: |
|
408 |
tag_obj = Tag.objects.create( |
|
409 |
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
|
410 |
label_slug = slugify(tag_string), |
| 48 | 411 |
description = "", |
412 |
link = settings.INTERNAL_TAGS_URL+'/'+slugify(tag_string), |
|
413 |
collection = self.annotation.image.item.collection |
|
414 |
) |
|
415 |
tag_info = TaggingInfo.objects.create( |
|
416 |
tag=tag_obj, |
|
417 |
revision=self, |
|
418 |
accuracy = tag_accuracy, |
|
419 |
relevancy = tag_relevancy |
|
420 |
) |
|
421 |
||
422 |
def get_tags_json(self): |
|
423 |
||
|
54
147c8a8b66b6
streamlined templates for easy navigation and missing info + handled fr.dbpedia tags
durandn
parents:
53
diff
changeset
|
424 |
def fetch_from_dbpedia(uri, lang, source): |
| 48 | 425 |
sparql_template = 'select distinct * where { <<%uri%>> rdfs:label ?l FILTER( langMatches( lang(?l), "<%lang%>" ) ) }' |
426 |
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
|
427 |
sparql_query_url = source+'sparql' |
|
98
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
428 |
try: |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
429 |
dbpedia_resp = requests.get( |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
430 |
sparql_query_url, |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
431 |
params={ |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
432 |
"query": sparql_query, |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
433 |
"format": "json" |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
434 |
} |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
435 |
) |
|
2b738b88d483
workon on notifications: user home, user notifications page, triggers in signals
durandn
parents:
97
diff
changeset
|
436 |
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
|
437 |
# 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
|
438 |
pass |
| 96 | 439 |
try: |
440 |
results = json.loads(dbpedia_resp.text).get("results", {}) |
|
441 |
except: |
|
442 |
# if error with json, results is empty |
|
443 |
results = {} |
|
444 |
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
|
445 |
label_data = {} |
| 58 | 446 |
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
|
447 |
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
|
448 |
return label_data.get("l", {"value": False}).get("value") |
| 48 | 449 |
|
450 |
final_list = [] |
|
451 |
for tagging_info in self.tagginginfo_set.select_related("tag").all(): |
|
452 |
if tagging_info.tag.is_internal(): |
|
453 |
final_list.append({ |
|
454 |
"tag_label": tagging_info.tag.label, |
|
455 |
"tag_link": tagging_info.tag.link, |
|
456 |
"accuracy": tagging_info.accuracy, |
|
|
89
23679a6def77
fixed error on stats (comments count not updating correctly for images)
durandn
parents:
85
diff
changeset
|
457 |
"relevancy": tagging_info.relevancy, |
|
23679a6def77
fixed error on stats (comments count not updating correctly for images)
durandn
parents:
85
diff
changeset
|
458 |
"is_internal": tagging_info.tag.is_internal() |
| 48 | 459 |
}) |
460 |
else: |
|
461 |
tag_link = tagging_info.tag.link |
|
462 |
#import label from external |
|
463 |
externaL_repos_fetch_dict = { |
|
464 |
"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
|
465 |
"http://fr.dbpedia.org/": fetch_from_dbpedia |
| 48 | 466 |
} |
|
53
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
467 |
try: |
|
54
147c8a8b66b6
streamlined templates for easy navigation and missing info + handled fr.dbpedia tags
durandn
parents:
53
diff
changeset
|
468 |
(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
|
469 |
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
|
470 |
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
|
471 |
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
|
472 |
else: |
|
3c4150867fe7
Added fallback tag label storing in database for external tags in case external source is down (rudimentary)
durandn
parents:
101
diff
changeset
|
473 |
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
|
474 |
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
|
475 |
final_list.append({ |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
476 |
"tag_label": tag_label, |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
477 |
"tag_link": tag_link, |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
478 |
"accuracy": tagging_info.accuracy, |
|
89
23679a6def77
fixed error on stats (comments count not updating correctly for images)
durandn
parents:
85
diff
changeset
|
479 |
"relevancy": tagging_info.relevancy, |
|
23679a6def77
fixed error on stats (comments count not updating correctly for images)
durandn
parents:
85
diff
changeset
|
480 |
"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
|
481 |
}) |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
482 |
except StopIteration: |
|
ed9acfa5dd6e
collection home page + tags in revision_detail view + optimization in views + fixture for demo
durandn
parents:
49
diff
changeset
|
483 |
pass |
| 48 | 484 |
return json.dumps(final_list) |
| 101 | 485 |
|
| 48 | 486 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
487 |
class IconolabComment(XtdComment): |
| 48 | 488 |
revision = models.ForeignKey('AnnotationRevision', related_name='creation_comment', null=True, blank=True) |
489 |
metacategories = models.ManyToManyField('MetaCategory', through='MetaCategoryInfo', through_fields=('comment', 'metacategory')) |
|
| 68 | 490 |
|
491 |
objects = XtdComment.objects |
|
492 |
||
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
493 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
494 |
return self.id |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
495 |
|
| 68 | 496 |
class Meta: |
497 |
ordering = ["thread_id", "id"] |
|
| 48 | 498 |
|
|
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
|
499 |
# 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
|
500 |
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
|
501 |
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
|
502 |
object_pk=self.object_pk, |
| 101 | 503 |
).filter(thread_id__gte=self.thread_id).filter(order__lte=self.order).count() +1) // settings.COMMENTS_PER_PAGE_DEFAULT + 1 |
504 |
||
|
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
|
505 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
506 |
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
|
507 |
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
|
508 |
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
|
509 |
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
|
510 |
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
|
511 |
|
|
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
|
512 |
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
|
513 |
(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
|
514 |
(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
|
515 |
(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
|
516 |
(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
|
517 |
) |
|
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
|
518 |
|
|
139
3e0a5286b257
collection home work (list and tabs) + adjusted image list template+ various design fixes
durandn
parents:
137
diff
changeset
|
519 |
collection = models.ForeignKey(Collection, related_name="metacategories") |
| 48 | 520 |
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
|
521 |
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
|
522 |
|
| 48 | 523 |
def __str__(self): |
524 |
return self.label |
|
525 |
||
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
526 |
|
|
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
527 |
class MetaCategoryInfo(models.Model): |
| 48 | 528 |
comment = models.ForeignKey('IconolabComment', on_delete=models.CASCADE) |
529 |
metacategory = models.ForeignKey('MetaCategory', on_delete=models.CASCADE) |
|
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
530 |
|
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
531 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
532 |
return "metacategory:"+self.metacategory.label+":on:"+self.comment.id |
|
6
37baf9d13f32
first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
533 |
|
|
37
aed809b3a075
Corrected Tag methods bugs + Added comment classes and migration
durandn
parents:
35
diff
changeset
|
534 |
class CommentAttachement(models.Model): |
| 48 | 535 |
|
536 |
LINK = 0 |
|
537 |
IMAGE = 1 |
|
538 |
PDF = 2 |
|
539 |
COMMENT_CHOICES = ( |
|
540 |
(LINK, 'link'), |
|
541 |
(IMAGE, 'image'), |
|
542 |
(PDF, 'pdf') |
|
543 |
) |
|
544 |
||
545 |
comment = models.ForeignKey('IconolabComment', related_name='attachments', on_delete=models.CASCADE) |
|
546 |
attachment_type = models.IntegerField(choices=COMMENT_CHOICES, default=0) |
|
|
132
4728f6c0102e
Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents:
126
diff
changeset
|
547 |
data = models.TextField(blank=False) |
|
4728f6c0102e
Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents:
126
diff
changeset
|
548 |
|
|
4728f6c0102e
Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents:
126
diff
changeset
|
549 |
class UserProfile(models.Model): |
|
133
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
550 |
user = models.OneToOneField(User, related_name='profile', on_delete=models.CASCADE) |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
551 |
administers_collection = models.ForeignKey('Collection', related_name='collection', blank=True, null=True) |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
552 |
|
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
553 |
def __str__(self): |
|
088195b2a6cc
iconolab profile to user relation is now one to one field + added panel for collection admin user tools (to be added) in user home + (simple) django admin for iconolab objects
durandn
parents:
132
diff
changeset
|
554 |
return "profile:"+self.user.username |