| author | ymh <ymh.work@gmail.com> |
| Mon, 03 Feb 2014 02:31:21 +0100 | |
| changeset 334 | 169b7cfd1f58 |
| parent 175 | 7331ecc46cba |
| permissions | -rw-r--r-- |
| 0 | 1 |
# -*- coding: utf-8 -*- |
| 334 | 2 |
# |
3 |
# Copyright Institut de Recherche et d'Innovation © 2014 |
|
4 |
# |
|
5 |
# contact@iri.centrepompidou.fr |
|
6 |
# |
|
7 |
# Ce code a été développé pour un premier usage dans JocondeLab, projet du |
|
8 |
# ministère de la culture et de la communication visant à expérimenter la |
|
9 |
# recherche sémantique dans la base Joconde |
|
10 |
# (http://jocondelab.iri-research.org/). |
|
11 |
# |
|
12 |
# Ce logiciel est régi par la licence CeCILL-C soumise au droit français et |
|
13 |
# respectant les principes de diffusion des logiciels libres. Vous pouvez |
|
14 |
# utiliser, modifier et/ou redistribuer ce programme sous les conditions |
|
15 |
# de la licence CeCILL-C telle que diffusée par le CEA, le CNRS et l'INRIA |
|
16 |
# sur le site "http://www.cecill.info". |
|
17 |
# |
|
18 |
# En contrepartie de l'accessibilité au code source et des droits de copie, |
|
19 |
# de modification et de redistribution accordés par cette licence, il n'est |
|
20 |
# offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, |
|
21 |
# seule une responsabilité restreinte pèse sur l'auteur du programme, le |
|
22 |
# titulaire des droits patrimoniaux et les concédants successifs. |
|
23 |
# |
|
24 |
# A cet égard l'attention de l'utilisateur est attirée sur les risques |
|
25 |
# associés au chargement, à l'utilisation, à la modification et/ou au |
|
26 |
# développement et à la reproduction du logiciel par l'utilisateur étant |
|
27 |
# donné sa spécificité de logiciel libre, qui peut le rendre complexe à |
|
28 |
# manipuler et qui le réserve donc à des développeurs et des professionnels |
|
29 |
# avertis possédant des connaissances informatiques approfondies. Les |
|
30 |
# utilisateurs sont donc invités à charger et tester l'adéquation du |
|
31 |
# logiciel à leurs besoins dans des conditions permettant d'assurer la |
|
32 |
# sécurité de leurs systèmes et ou de leurs données et, plus généralement, |
|
33 |
# à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. |
|
34 |
# |
|
35 |
# Le fait que vous puissiez accéder à cet en-tête signifie que vous avez |
|
36 |
# pris connaissance de la licence CeCILL-C, et que vous en avez accepté les |
|
37 |
# termes. |
|
38 |
# |
|
| 0 | 39 |
''' |
40 |
Created on Jun 8, 2013 |
|
41 |
||
42 |
@author: ymh |
|
43 |
''' |
|
44 |
from django.db import models |
|
|
48
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
45 |
from django.db.models import signals |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
46 |
from django.dispatch import receiver |
| 334 | 47 |
|
48 |
from core import settings |
|
49 |
from core.models.term import Term |
|
50 |
||
| 0 | 51 |
|
52 |
# Create your models here. |
|
53 |
class Notice(models.Model): |
|
54 |
||
55 |
ref = models.CharField(max_length=20, null=True, blank=True, unique=True) |
|
56 |
adpt = models.TextField(null=True, blank=True) |
|
57 |
appl = models.CharField(max_length=1024, null=True, blank=True) |
|
58 |
aptn = models.TextField(null=True, blank=True) |
|
59 |
attr = models.TextField(null=True, blank=True) |
|
60 |
autr = models.CharField(max_length=1024, null=True, blank=True) |
|
61 |
autr_terms = models.ManyToManyField(Term, related_name="autr+", limit_choices_to = {'thesaurus__label': 'autr'}, through='AutrNoticeTerm') |
|
62 |
bibl = models.TextField(null=True, blank=True) |
|
63 |
comm = models.TextField(null=True, blank=True) |
|
64 |
contact = models.CharField(max_length=1024, null=True, blank=True) |
|
65 |
coor = models.CharField(max_length=1024, null=True, blank=True) |
|
66 |
copy = models.CharField(max_length=1024, null=True, blank=True) |
|
67 |
dacq = models.CharField(max_length=1024, null=True, blank=True) |
|
68 |
data = models.CharField(max_length=512, null=True, blank=True) |
|
69 |
dation = models.CharField(max_length=512, null=True, blank=True) |
|
70 |
ddpt = models.CharField(max_length=512, null=True, blank=True) |
|
71 |
decv = models.CharField(max_length=1024, null=True, blank=True) |
|
72 |
deno = models.CharField(max_length=1024, null=True, blank=True) |
|
73 |
depo = models.CharField(max_length=1024, null=True, blank=True) |
|
74 |
desc = models.TextField(null=True, blank=True) |
|
75 |
desy = models.CharField(max_length=512, null=True, blank=True) |
|
76 |
dims = models.CharField(max_length=2048, null=True, blank=True) |
|
77 |
dmaj = models.DateField(null=True, blank=True) |
|
78 |
dmis = models.DateField(null=True, blank=True) |
|
79 |
domn = models.CharField(max_length=512, null=True, blank=True) |
|
80 |
domn_terms = models.ManyToManyField(Term, related_name="domn+", limit_choices_to = {'thesaurus__label': 'domn'}, through='DomnNoticeTerm') |
|
81 |
drep = models.CharField(max_length=1024, null=True, blank=True) |
|
82 |
ecol = models.CharField(max_length=512, null=True, blank=True) |
|
83 |
ecol_terms = models.ManyToManyField(Term, related_name="ecol+", limit_choices_to = {'thesaurus__label': 'ecol'}, through='EcolNoticeTerm') |
|
84 |
epoq = models.CharField(max_length=512, null=True, blank=True) |
|
85 |
epoq_terms = models.ManyToManyField(Term, related_name="epoq+", limit_choices_to = {'thesaurus__label': 'epoq'}, through='EpoqNoticeTerm') |
|
86 |
etat = models.TextField(null=True, blank=True) |
|
87 |
expo = models.TextField(null=True, blank=True) |
|
88 |
gene = models.CharField(max_length=1024, null=True, blank=True) |
|
89 |
geohi = models.CharField(max_length=1024, null=True, blank=True) |
|
90 |
hist = models.TextField(null=True, blank=True) |
|
91 |
image = models.BooleanField() |
|
92 |
insc = models.CharField(max_length=1024, null=True, blank=True) |
|
93 |
inv = models.CharField(max_length=2048, null=True, blank=True) |
|
94 |
label = models.CharField(max_length=512, null=True, blank=True) |
|
95 |
labo = models.CharField(max_length=1024, null=True, blank=True) |
|
96 |
lieux = models.CharField(max_length=1024, null=True, blank=True) |
|
97 |
lieux_terms = models.ManyToManyField(Term, related_name="lieux+", limit_choices_to = {'thesaurus__label': 'lieux'}, through='LieuxNoticeTerm') |
|
98 |
loca = models.CharField(max_length=512, null=True, blank=True) |
|
99 |
loca2 = models.CharField(max_length=512, null=True, blank=True) |
|
100 |
mill = models.CharField(max_length=512, null=True, blank=True) |
|
101 |
milu = models.CharField(max_length=512, null=True, blank=True) |
|
102 |
mosa = models.CharField(max_length=512, null=True, blank=True) |
|
103 |
msgcom = models.TextField(null=True, blank=True) |
|
104 |
museo = models.CharField(max_length=512, null=True, blank=True) |
|
105 |
nsda = models.CharField(max_length=512, null=True, blank=True) |
|
106 |
onom = models.TextField(null=True, blank=True) |
|
107 |
paut = models.TextField(null=True, blank=True) |
|
108 |
pdat = models.TextField(null=True, blank=True) |
|
109 |
pdec = models.TextField(null=True, blank=True) |
|
110 |
peoc = models.CharField(max_length=512, null=True, blank=True) |
|
111 |
peri = models.CharField(max_length=512, null=True, blank=True) |
|
112 |
peri_terms = models.ManyToManyField(Term, related_name="peri+", limit_choices_to = {'thesaurus__label': 'peri'}, through='PeriNoticeTerm') |
|
113 |
peru = models.CharField(max_length=1024, null=True, blank=True) |
|
114 |
phot = models.CharField(max_length=1024, null=True, blank=True) |
|
115 |
pins = models.TextField(null=True, blank=True) |
|
116 |
plieux = models.TextField(null=True, blank=True) |
|
117 |
prep = models.TextField(null=True, blank=True) |
|
118 |
puti = models.TextField(null=True, blank=True) |
|
119 |
reda = models.CharField(max_length=1024, null=True, blank=True) |
|
120 |
refim = models.CharField(max_length=2048, null=True, blank=True) |
|
121 |
repr = models.TextField(null=True, blank=True) |
|
122 |
repr_terms = models.ManyToManyField(Term, related_name="repr+", limit_choices_to = {'thesaurus__label': 'repr'}, through='ReprNoticeTerm') |
|
123 |
srep = models.CharField(max_length=1024, null=True, blank=True) |
|
| 33 | 124 |
srep_terms = models.ManyToManyField(Term, related_name="srep+", limit_choices_to = {'thesaurus__label': 'srep'}, through='SrepNoticeTerm') |
| 0 | 125 |
stat = models.CharField(max_length=1024, null=True, blank=True) |
126 |
tech = models.CharField(max_length=2048, null=True, blank=True) |
|
127 |
tico = models.TextField(null=True, blank=True) |
|
128 |
titr = models.TextField(null=True, blank=True) |
|
129 |
util = models.CharField(max_length=1024, null=True, blank=True) |
|
130 |
video = models.CharField(max_length=2048, null=True, blank=True) |
|
131 |
www = models.CharField(max_length=512, null=True, blank=True) |
|
|
55
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
132 |
|
|
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
133 |
def thumbnails(): #@NoSelf |
|
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
134 |
doc = """Docstring""" #@UnusedVariable |
|
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
135 |
|
|
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
136 |
def fget(self): |
|
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
137 |
return [img for img in self.images.all() if img.url.split('.')[-2].endswith("_v")] |
|
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
138 |
|
|
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
139 |
return locals() |
|
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
140 |
|
|
bcbd95da9be2
add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents:
48
diff
changeset
|
141 |
thumbnails = property(**thumbnails()) |
| 175 | 142 |
|
143 |
def large_images(): #@NoSelf |
|
144 |
doc = """Docstring""" #@UnusedVariable |
|
145 |
||
146 |
def fget(self): |
|
147 |
return [img.url for img in self.images.filter(large=True).order_by('order')] |
|
148 |
||
149 |
return locals() |
|
150 |
||
151 |
large_images = property(**large_images()) |
|
| 0 | 152 |
|
153 |
class Meta: |
|
154 |
app_label = 'core' |
|
155 |
||
156 |
class NoticeImage(models.Model): |
|
|
36
f770159c3cee
Remove unique constraint on image/notice
ymh <ymh.work@gmail.com>
parents:
33
diff
changeset
|
157 |
relative_url = models.URLField(max_length='1024', null=False, blank=False, unique=False) |
| 0 | 158 |
notice = models.ForeignKey(Notice, related_name="images") |
| 175 | 159 |
order = models.IntegerField(default=0, null=True) |
160 |
large = models.BooleanField(default=True) |
|
161 |
main = models.BooleanField(default=False) |
|
| 0 | 162 |
|
163 |
class Meta: |
|
164 |
app_label = 'core' |
|
|
36
f770159c3cee
Remove unique constraint on image/notice
ymh <ymh.work@gmail.com>
parents:
33
diff
changeset
|
165 |
unique_together = (("relative_url", "notice"),) |
| 0 | 166 |
|
167 |
||
168 |
@property |
|
169 |
def url(self): |
|
| 175 | 170 |
return settings.JOCONDE_IMAGE_BASE_URL + self.relative_url |
| 0 | 171 |
|
172 |
||
173 |
class NoticeTerm(models.Model): |
|
174 |
||
175 |
notice = models.ForeignKey(Notice) |
|
176 |
term = models.ForeignKey(Term) |
|
177 |
||
178 |
#optionnal rdf graph uri describing the relationship |
|
179 |
graph = models.URLField(max_length=2048, null=True, blank=True) |
|
180 |
||
181 |
class Meta: |
|
182 |
app_label = 'core' |
|
183 |
||
184 |
||
185 |
class AutrNoticeTerm(NoticeTerm): |
|
186 |
class Meta: |
|
187 |
app_label = 'core' |
|
188 |
||
189 |
class DomnNoticeTerm(NoticeTerm): |
|
190 |
class Meta: |
|
191 |
app_label = 'core' |
|
192 |
||
193 |
class EcolNoticeTerm(NoticeTerm): |
|
194 |
class Meta: |
|
195 |
app_label = 'core' |
|
196 |
||
197 |
class EpoqNoticeTerm(NoticeTerm): |
|
198 |
class Meta: |
|
199 |
app_label = 'core' |
|
200 |
||
201 |
class LieuxNoticeTerm(NoticeTerm): |
|
202 |
class Meta: |
|
203 |
app_label = 'core' |
|
204 |
||
205 |
class PeriNoticeTerm(NoticeTerm): |
|
206 |
class Meta: |
|
207 |
app_label = 'core' |
|
208 |
||
209 |
class ReprNoticeTerm(NoticeTerm): |
|
210 |
class Meta: |
|
211 |
app_label = 'core' |
|
| 33 | 212 |
|
213 |
class SrepNoticeTerm(NoticeTerm): |
|
214 |
class Meta: |
|
215 |
app_label = 'core' |
|
|
48
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
216 |
|
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
217 |
def increment_nb_notice(term, inc): |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
218 |
term.nb_notice = term.nb_notice + inc |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
219 |
term.save |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
220 |
|
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
221 |
@receiver(signals.post_save, sender=NoticeTerm) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
222 |
def notice_term_created(sender, **kwargs): |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
223 |
instance = kwargs.get('instance', None) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
224 |
created = kwargs.get('created', None) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
225 |
if instance is None or not created: |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
226 |
return |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
227 |
increment_nb_notice(instance.term, 1) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
228 |
|
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
229 |
@receiver(signals.post_delete, sender=NoticeTerm) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
230 |
def notice_term_deleted(sender, **kwargs): |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
231 |
instance = kwargs.get('instance', None) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
232 |
if instance is None: |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
233 |
return |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
234 |
increment_nb_notice(instance.term, -1) |