| author | ymh <ymh.work@gmail.com> |
| Thu, 27 Jun 2013 22:31:40 +0200 | |
| changeset 48 | f4fadc1b9d70 |
| parent 36 | f770159c3cee |
| child 55 | bcbd95da9be2 |
| permissions | -rw-r--r-- |
| 0 | 1 |
# -*- coding: utf-8 -*- |
2 |
''' |
|
3 |
Created on Jun 8, 2013 |
|
4 |
||
5 |
@author: ymh |
|
6 |
''' |
|
|
48
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
7 |
from core import settings |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
8 |
from core.models.term import Term |
| 0 | 9 |
from django.db import models |
|
48
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
10 |
from django.db.models import signals |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
11 |
from django.dispatch import receiver |
| 0 | 12 |
import urlparse |
13 |
||
14 |
# Create your models here. |
|
15 |
class Notice(models.Model): |
|
16 |
||
17 |
ref = models.CharField(max_length=20, null=True, blank=True, unique=True) |
|
18 |
adpt = models.TextField(null=True, blank=True) |
|
19 |
appl = models.CharField(max_length=1024, null=True, blank=True) |
|
20 |
aptn = models.TextField(null=True, blank=True) |
|
21 |
attr = models.TextField(null=True, blank=True) |
|
22 |
autr = models.CharField(max_length=1024, null=True, blank=True) |
|
23 |
autr_terms = models.ManyToManyField(Term, related_name="autr+", limit_choices_to = {'thesaurus__label': 'autr'}, through='AutrNoticeTerm') |
|
24 |
bibl = models.TextField(null=True, blank=True) |
|
25 |
comm = models.TextField(null=True, blank=True) |
|
26 |
contact = models.CharField(max_length=1024, null=True, blank=True) |
|
27 |
coor = models.CharField(max_length=1024, null=True, blank=True) |
|
28 |
copy = models.CharField(max_length=1024, null=True, blank=True) |
|
29 |
dacq = models.CharField(max_length=1024, null=True, blank=True) |
|
30 |
data = models.CharField(max_length=512, null=True, blank=True) |
|
31 |
dation = models.CharField(max_length=512, null=True, blank=True) |
|
32 |
ddpt = models.CharField(max_length=512, null=True, blank=True) |
|
33 |
decv = models.CharField(max_length=1024, null=True, blank=True) |
|
34 |
deno = models.CharField(max_length=1024, null=True, blank=True) |
|
35 |
depo = models.CharField(max_length=1024, null=True, blank=True) |
|
36 |
desc = models.TextField(null=True, blank=True) |
|
37 |
desy = models.CharField(max_length=512, null=True, blank=True) |
|
38 |
dims = models.CharField(max_length=2048, null=True, blank=True) |
|
39 |
dmaj = models.DateField(null=True, blank=True) |
|
40 |
dmis = models.DateField(null=True, blank=True) |
|
41 |
domn = models.CharField(max_length=512, null=True, blank=True) |
|
42 |
domn_terms = models.ManyToManyField(Term, related_name="domn+", limit_choices_to = {'thesaurus__label': 'domn'}, through='DomnNoticeTerm') |
|
43 |
drep = models.CharField(max_length=1024, null=True, blank=True) |
|
44 |
ecol = models.CharField(max_length=512, null=True, blank=True) |
|
45 |
ecol_terms = models.ManyToManyField(Term, related_name="ecol+", limit_choices_to = {'thesaurus__label': 'ecol'}, through='EcolNoticeTerm') |
|
46 |
epoq = models.CharField(max_length=512, null=True, blank=True) |
|
47 |
epoq_terms = models.ManyToManyField(Term, related_name="epoq+", limit_choices_to = {'thesaurus__label': 'epoq'}, through='EpoqNoticeTerm') |
|
48 |
etat = models.TextField(null=True, blank=True) |
|
49 |
expo = models.TextField(null=True, blank=True) |
|
50 |
gene = models.CharField(max_length=1024, null=True, blank=True) |
|
51 |
geohi = models.CharField(max_length=1024, null=True, blank=True) |
|
52 |
hist = models.TextField(null=True, blank=True) |
|
53 |
image = models.BooleanField() |
|
54 |
insc = models.CharField(max_length=1024, null=True, blank=True) |
|
55 |
inv = models.CharField(max_length=2048, null=True, blank=True) |
|
56 |
label = models.CharField(max_length=512, null=True, blank=True) |
|
57 |
labo = models.CharField(max_length=1024, null=True, blank=True) |
|
58 |
lieux = models.CharField(max_length=1024, null=True, blank=True) |
|
59 |
lieux_terms = models.ManyToManyField(Term, related_name="lieux+", limit_choices_to = {'thesaurus__label': 'lieux'}, through='LieuxNoticeTerm') |
|
60 |
loca = models.CharField(max_length=512, null=True, blank=True) |
|
61 |
loca2 = models.CharField(max_length=512, null=True, blank=True) |
|
62 |
mill = models.CharField(max_length=512, null=True, blank=True) |
|
63 |
milu = models.CharField(max_length=512, null=True, blank=True) |
|
64 |
mosa = models.CharField(max_length=512, null=True, blank=True) |
|
65 |
msgcom = models.TextField(null=True, blank=True) |
|
66 |
museo = models.CharField(max_length=512, null=True, blank=True) |
|
67 |
nsda = models.CharField(max_length=512, null=True, blank=True) |
|
68 |
onom = models.TextField(null=True, blank=True) |
|
69 |
paut = models.TextField(null=True, blank=True) |
|
70 |
pdat = models.TextField(null=True, blank=True) |
|
71 |
pdec = models.TextField(null=True, blank=True) |
|
72 |
peoc = models.CharField(max_length=512, null=True, blank=True) |
|
73 |
peri = models.CharField(max_length=512, null=True, blank=True) |
|
74 |
peri_terms = models.ManyToManyField(Term, related_name="peri+", limit_choices_to = {'thesaurus__label': 'peri'}, through='PeriNoticeTerm') |
|
75 |
peru = models.CharField(max_length=1024, null=True, blank=True) |
|
76 |
phot = models.CharField(max_length=1024, null=True, blank=True) |
|
77 |
pins = models.TextField(null=True, blank=True) |
|
78 |
plieux = models.TextField(null=True, blank=True) |
|
79 |
prep = models.TextField(null=True, blank=True) |
|
80 |
puti = models.TextField(null=True, blank=True) |
|
81 |
reda = models.CharField(max_length=1024, null=True, blank=True) |
|
82 |
refim = models.CharField(max_length=2048, null=True, blank=True) |
|
83 |
repr = models.TextField(null=True, blank=True) |
|
84 |
repr_terms = models.ManyToManyField(Term, related_name="repr+", limit_choices_to = {'thesaurus__label': 'repr'}, through='ReprNoticeTerm') |
|
85 |
srep = models.CharField(max_length=1024, null=True, blank=True) |
|
| 33 | 86 |
srep_terms = models.ManyToManyField(Term, related_name="srep+", limit_choices_to = {'thesaurus__label': 'srep'}, through='SrepNoticeTerm') |
| 0 | 87 |
stat = models.CharField(max_length=1024, null=True, blank=True) |
88 |
tech = models.CharField(max_length=2048, null=True, blank=True) |
|
89 |
tico = models.TextField(null=True, blank=True) |
|
90 |
titr = models.TextField(null=True, blank=True) |
|
91 |
util = models.CharField(max_length=1024, null=True, blank=True) |
|
92 |
video = models.CharField(max_length=2048, null=True, blank=True) |
|
93 |
www = models.CharField(max_length=512, null=True, blank=True) |
|
94 |
||
95 |
class Meta: |
|
96 |
app_label = 'core' |
|
97 |
||
98 |
class NoticeImage(models.Model): |
|
|
36
f770159c3cee
Remove unique constraint on image/notice
ymh <ymh.work@gmail.com>
parents:
33
diff
changeset
|
99 |
relative_url = models.URLField(max_length='1024', null=False, blank=False, unique=False) |
| 0 | 100 |
notice = models.ForeignKey(Notice, related_name="images") |
101 |
||
102 |
class Meta: |
|
103 |
app_label = 'core' |
|
|
36
f770159c3cee
Remove unique constraint on image/notice
ymh <ymh.work@gmail.com>
parents:
33
diff
changeset
|
104 |
unique_together = (("relative_url", "notice"),) |
| 0 | 105 |
|
106 |
||
107 |
@property |
|
108 |
def url(self): |
|
109 |
return urlparse.urljoin(settings.JOCONDE_IMAGE_BASE_URL , self.relative_url) |
|
110 |
||
111 |
||
112 |
class NoticeTerm(models.Model): |
|
113 |
||
114 |
notice = models.ForeignKey(Notice) |
|
115 |
term = models.ForeignKey(Term) |
|
116 |
||
117 |
#optionnal rdf graph uri describing the relationship |
|
118 |
graph = models.URLField(max_length=2048, null=True, blank=True) |
|
119 |
||
120 |
class Meta: |
|
121 |
app_label = 'core' |
|
122 |
||
123 |
||
124 |
class AutrNoticeTerm(NoticeTerm): |
|
125 |
class Meta: |
|
126 |
app_label = 'core' |
|
127 |
||
128 |
class DomnNoticeTerm(NoticeTerm): |
|
129 |
class Meta: |
|
130 |
app_label = 'core' |
|
131 |
||
132 |
class EcolNoticeTerm(NoticeTerm): |
|
133 |
class Meta: |
|
134 |
app_label = 'core' |
|
135 |
||
136 |
class EpoqNoticeTerm(NoticeTerm): |
|
137 |
class Meta: |
|
138 |
app_label = 'core' |
|
139 |
||
140 |
class LieuxNoticeTerm(NoticeTerm): |
|
141 |
class Meta: |
|
142 |
app_label = 'core' |
|
143 |
||
144 |
class PeriNoticeTerm(NoticeTerm): |
|
145 |
class Meta: |
|
146 |
app_label = 'core' |
|
147 |
||
148 |
class ReprNoticeTerm(NoticeTerm): |
|
149 |
class Meta: |
|
150 |
app_label = 'core' |
|
| 33 | 151 |
|
152 |
class SrepNoticeTerm(NoticeTerm): |
|
153 |
class Meta: |
|
154 |
app_label = 'core' |
|
|
48
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
155 |
|
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
156 |
def increment_nb_notice(term, inc): |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
157 |
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
|
158 |
term.save |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
159 |
|
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
160 |
@receiver(signals.post_save, sender=NoticeTerm) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
161 |
def notice_term_created(sender, **kwargs): |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
162 |
instance = kwargs.get('instance', None) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
163 |
created = kwargs.get('created', None) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
164 |
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
|
165 |
return |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
166 |
increment_nb_notice(instance.term, 1) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
167 |
|
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
168 |
@receiver(signals.post_delete, sender=NoticeTerm) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
169 |
def notice_term_deleted(sender, **kwargs): |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
170 |
instance = kwargs.get('instance', None) |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
171 |
if instance is None: |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
172 |
return |
|
f4fadc1b9d70
cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents:
36
diff
changeset
|
173 |
increment_nb_notice(instance.term, -1) |