| author | ymh <ymh.work@gmail.com> |
| Thu, 09 Jun 2011 16:34:28 +0200 | |
| changeset 15 | a9136d8f0b4a |
| parent 11 | 143ab88d17f8 |
| child 18 | 65b887db0ff3 |
| child 19 | e2f27df4e17b |
| permissions | -rw-r--r-- |
| 0 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
3 |
from django.contrib.auth.models import User |
|
4 |
from django.db import models |
|
5 |
from hdabo.utils import Property |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
6 |
from hdabo.fields import SortedManyToManyField |
| 0 | 7 |
import datetime |
8 |
||
9 |
class Organisation(models.Model): |
|
10 |
hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
11 |
name = models.CharField(max_length=512, unique=False, blank=False, null=False) |
|
12 |
location = models.CharField(max_length=512, unique=False, blank=True, null=True) |
|
13 |
website = models.CharField(max_length=1024, unique=False, blank=True, null=True) |
|
14 |
||
15 |
||
16 |
class Author(models.Model): |
|
17 |
hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
18 |
lastname = models.CharField(max_length=512, unique=False, blank=True, null=True) |
|
19 |
firstname = models.CharField(max_length=512, unique=False, blank=True, null=True) |
|
20 |
||
21 |
class TimePeriod(models.Model): |
|
22 |
TIME_PERIOD_CHOICES = ( |
|
23 |
(1,u'Primaire'), |
|
24 |
(2,u'Collège'), |
|
25 |
(3,u'Lycée'), |
|
26 |
) |
|
27 |
TIME_PERIOD_DICT = { |
|
28 |
u'Primaire': 1, |
|
29 |
u'Collège': 2, |
|
30 |
u'Lycée': 3, |
|
31 |
} |
|
32 |
label = models.CharField(max_length=512, unique=False, blank=False, null=False) |
|
33 |
school_period = models.IntegerField(choices=TIME_PERIOD_CHOICES) |
|
34 |
||
35 |
class Meta: |
|
36 |
unique_together = ("label", "school_period") |
|
37 |
||
38 |
def __unicode__(self): |
|
39 |
return unicode(self.label) |
|
40 |
||
41 |
||
42 |
class Domain(models.Model): |
|
43 |
DOMAIN_PERIOD_CHOICES = ( |
|
44 |
(0,u'Global'), |
|
45 |
(1,u'Primaire'), |
|
46 |
(2,u'Collège'), |
|
47 |
(3,u'Lycée'), |
|
48 |
) |
|
49 |
DOMAIN_PERIOD_DICT = { |
|
50 |
u'Global': 0, |
|
51 |
u'Primaire': 1, |
|
52 |
u'Collège': 2, |
|
53 |
u'Lycée': 3, |
|
54 |
} |
|
55 |
label = models.CharField(max_length=512, unique=False, blank=False, null=False) |
|
56 |
school_period = models.IntegerField(choices=DOMAIN_PERIOD_CHOICES) |
|
57 |
||
58 |
class Meta: |
|
59 |
unique_together = ("label", "school_period") |
|
60 |
||
61 |
def __unicode__(self): |
|
62 |
return unicode(self.label) |
|
63 |
||
64 |
||
65 |
class DocumentFormat(models.Model): |
|
66 |
label = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
67 |
||
68 |
def __unicode__(self): |
|
69 |
return unicode(self.label) |
|
70 |
||
71 |
class Tag(models.Model): |
|
| 3 | 72 |
TAG_URL_STATUS_CHOICES = ( |
|
15
a9136d8f0b4a
add commant to reorder tags and query wikipedia
ymh <ymh.work@gmail.com>
parents:
11
diff
changeset
|
73 |
(0,"null_result"), |
| 3 | 74 |
(1,"redirection"), |
75 |
(2,"homonyme"), |
|
|
15
a9136d8f0b4a
add commant to reorder tags and query wikipedia
ymh <ymh.work@gmail.com>
parents:
11
diff
changeset
|
76 |
(3,"match"), |
| 3 | 77 |
) |
78 |
||
79 |
TAG_URL_STATUS_DICT = { |
|
|
15
a9136d8f0b4a
add commant to reorder tags and query wikipedia
ymh <ymh.work@gmail.com>
parents:
11
diff
changeset
|
80 |
"null_result":0, |
| 3 | 81 |
"redirection":1, |
82 |
"homonyme":2, |
|
|
15
a9136d8f0b4a
add commant to reorder tags and query wikipedia
ymh <ymh.work@gmail.com>
parents:
11
diff
changeset
|
83 |
"match":3, |
| 3 | 84 |
} |
85 |
||
| 0 | 86 |
label = models.CharField(max_length=1024, unique=True, blank=False, null=False) |
87 |
original_label = models.CharField(max_length=1024, unique=False, blank=True, null=True, editable=False) |
|
88 |
alias = models.CharField(max_length=1024, unique=False, blank=True, null=True) |
|
89 |
wikipedia_url = models.URLField(verify_exists=False, max_length=512, blank=True, null=True) |
|
|
15
a9136d8f0b4a
add commant to reorder tags and query wikipedia
ymh <ymh.work@gmail.com>
parents:
11
diff
changeset
|
90 |
wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True) |
| 3 | 91 |
url_status = models.IntegerField(choices=TAG_URL_STATUS_CHOICES, blank=True, null=True, default=None) |
| 0 | 92 |
dbpedia_uri = models.URLField(verify_exists=False, max_length=512, blank=True, null=True) |
93 |
wikipedia_activated = models.BooleanField(default=False) |
|
94 |
||
95 |
||
96 |
class TagCategory(models.Model): |
|
97 |
label = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
98 |
||
99 |
def __unicode__(self): |
|
100 |
return unicode(self.label) |
|
101 |
||
102 |
class Location(models.Model): |
|
103 |
name = models.CharField(max_length=512, unique=False, blank=False, null=False) |
|
104 |
insee = models.CharField(max_length=5, unique=True, blank=False, null=False) |
|
105 |
||
106 |
def __unicode__(self): |
|
107 |
return unicode("%s : %s"%(self.name, self.insee)) |
|
108 |
||
109 |
class Datasheet(models.Model): |
|
110 |
hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
111 |
author = models.ForeignKey(Author, null=True, blank=True) |
|
112 |
organisation = models.ForeignKey(Organisation) |
|
113 |
title = models.CharField(max_length=2048, unique=False, blank=False, null=False) |
|
114 |
description = models.TextField(blank=True, null=True) |
|
115 |
url = models.URLField(verify_exists=False, max_length=512, blank=True, null=True) |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
116 |
domains = SortedManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Global']}, related_name="datasheets") |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
117 |
primary_periods = SortedManyToManyField(TimePeriod, limit_choices_to={'school_period':TimePeriod.TIME_PERIOD_DICT[u'Primaire']}, related_name="primary_periods_datasheets") |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
118 |
college_periods = SortedManyToManyField(TimePeriod, limit_choices_to={'school_period':TimePeriod.TIME_PERIOD_DICT[u'Collège']}, related_name="college_periods_datasheets") |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
119 |
highschool_periods = SortedManyToManyField(TimePeriod, limit_choices_to={'school_period':TimePeriod.TIME_PERIOD_DICT[u'Lycée']}, related_name="highschool_periods_datasheets") |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
120 |
primary_themes = SortedManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Primaire']}, related_name="primary_themes_datasheets") |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
121 |
college_themes = SortedManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Collège']}, related_name="college_themes_datasheets") |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
122 |
highschool_themes = SortedManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Lycée']}, related_name="highschool_themes_datasheets") |
| 0 | 123 |
town = models.ForeignKey(Location, null=True, blank=True) |
124 |
format = models.ForeignKey(DocumentFormat, null=True, blank=True) |
|
125 |
original_creation_date = models.DateField() |
|
126 |
original_modification_date = models.DateField() |
|
127 |
modification_datetime = models.DateTimeField(auto_now=True) |
|
| 2 | 128 |
validation_date = models.DateTimeField(null=True, blank=True) |
129 |
validated = models.BooleanField(default=False) |
|
130 |
validator = models.ForeignKey(User, null=True, blank=True) |
|
| 0 | 131 |
tags = models.ManyToManyField(Tag, through='TaggedSheet') |
132 |
||
133 |
||
134 |
def validate(self, user): |
|
135 |
self.validation_date = datetime.datetime.now() |
|
136 |
self.validated = True |
|
137 |
self.validator = user |
|
138 |
self.save() |
|
139 |
||
140 |
def unvalidate(self): |
|
141 |
self.validation_date = datetime.datetime.min |
|
142 |
self.validated = False |
|
143 |
self.validator = None |
|
144 |
self.save() |
|
145 |
||
146 |
@Property |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
147 |
def domains_list(): #@NoSelf |
| 0 | 148 |
def fget(self): |
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
149 |
return [d.label for d in self.domains.all()] |
| 0 | 150 |
|
151 |
return locals() |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
152 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
153 |
@Property |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
154 |
def domains_text(): #@NoSelf |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
155 |
def fget(self): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
156 |
return "; ".join(self.domains_list) |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
157 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
158 |
return locals() |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
159 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
160 |
@Property |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
161 |
def primary_periods_list(): #@NoSelf |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
162 |
def fget(self): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
163 |
return [d.label for d in self.primary_periods.all()] |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
164 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
165 |
return locals() |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
166 |
|
| 0 | 167 |
|
168 |
@Property |
|
169 |
def primary_periods_text(): #@NoSelf |
|
170 |
def fget(self): |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
171 |
return "; ".join(self.primary_periods_list) |
| 0 | 172 |
|
173 |
return locals() |
|
174 |
||
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
175 |
@Property |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
176 |
def college_periods_list(): #@NoSelf |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
177 |
def fget(self): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
178 |
return [d.label for d in self.college_periods.all()] |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
179 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
180 |
return locals() |
| 0 | 181 |
|
182 |
@Property |
|
183 |
def college_periods_text(): #@NoSelf |
|
184 |
def fget(self): |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
185 |
return "; ".join(self.college_periods_list) |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
186 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
187 |
return locals() |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
188 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
189 |
@Property |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
190 |
def highschool_periods_list(): #@NoSelf |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
191 |
def fget(self): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
192 |
return [d.label for d in self.highschool_periods.all()] |
| 0 | 193 |
|
194 |
return locals() |
|
195 |
||
196 |
@Property |
|
197 |
def highschool_periods_text(): #@NoSelf |
|
198 |
def fget(self): |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
199 |
return "; ".join(self.highschool_periods_list) |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
200 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
201 |
return locals() |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
202 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
203 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
204 |
@Property |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
205 |
def primary_themes_list(): #@NoSelf |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
206 |
def fget(self): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
207 |
return [d.label for d in self.primary_themes.all()] |
| 0 | 208 |
|
209 |
return locals() |
|
210 |
||
211 |
||
212 |
@Property |
|
213 |
def primary_themes_text(): #@NoSelf |
|
214 |
def fget(self): |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
215 |
return "; ".join(self.primary_themes_list) |
| 0 | 216 |
|
217 |
return locals() |
|
218 |
||
219 |
@Property |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
220 |
def college_themes_list(): #@NoSelf |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
221 |
def fget(self): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
222 |
return [d.label for d in self.college_themes.all()] |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
223 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
224 |
return locals() |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
225 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
226 |
@Property |
| 0 | 227 |
def college_themes_text(): #@NoSelf |
228 |
def fget(self): |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
229 |
return "; ".join(self.college_themes_list) |
| 0 | 230 |
|
231 |
return locals() |
|
232 |
||
233 |
@Property |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
234 |
def highschool_themes_list(): #@NoSelf |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
235 |
def fget(self): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
236 |
return [d.label for d in self.highschool_themes.all()] |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
237 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
238 |
return locals() |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
239 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
240 |
@Property |
| 0 | 241 |
def highschool_themes_text(): #@NoSelf |
242 |
def fget(self): |
|
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
243 |
return "; ".join(self.highschool_themes_list) |
| 0 | 244 |
|
245 |
return locals() |
|
246 |
||
247 |
@Property |
|
248 |
def town_text(): #@NoSelf |
|
249 |
def fget(self): |
|
250 |
return self.town.name if self.town else "" |
|
251 |
||
252 |
return locals() |
|
253 |
||
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
254 |
@Property |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
255 |
def tags_text(): #@NoSelf |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
256 |
def fget(self): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
257 |
return "; ".join([t.label for t in self.tags.all()]) |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
258 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
259 |
return locals() |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
3
diff
changeset
|
260 |
|
| 0 | 261 |
|
262 |
class TaggedSheet(models.Model): |
|
263 |
datasheet = models.ForeignKey(Datasheet) |
|
264 |
tag = models.ForeignKey(Tag) |
|
| 2 | 265 |
original_order = models.IntegerField(default=0) |
266 |
order = models.IntegerField(default=0) |
|
267 |
index_note = models.FloatField(default=0.0) |
|
| 0 | 268 |
categories = models.ManyToManyField(TagCategory) |
| 3 | 269 |
|
270 |
||
| 0 | 271 |