| author | ymh <ymh.work@gmail.com> |
| Thu, 02 Apr 2015 22:52:54 +0200 | |
| changeset 613 | 4bb38d03e430 |
| parent 545 | c752fdee555b |
| child 693 | 09e00f38d177 |
| permissions | -rw-r--r-- |
| 47 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
| 443 | 3 |
import datetime |
4 |
||
| 66 | 5 |
from django.conf import settings |
|
266
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
6 |
from django.contrib.auth.models import AbstractUser |
| 47 | 7 |
from django.db import models |
| 443 | 8 |
|
9 |
from hdabo import utils |
|
| 72 | 10 |
from hdabo.utils import Property, normalize |
| 47 | 11 |
|
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
12 |
|
|
266
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
13 |
# User Class, due to migration to django 1.6.5 |
|
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
14 |
class User(AbstractUser): |
|
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
15 |
class Meta: |
|
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
16 |
db_table = 'auth_user' |
|
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
17 |
|
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
18 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
19 |
class SortedModelManager(models.Manager): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
20 |
use_for_related_fields = True |
| 545 | 21 |
def get_queryset(self): |
22 |
qs = super(SortedModelManager, self).get_queryset() |
|
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
23 |
if getattr(self, 'through', None) is not None and getattr(self.through, 'Meta', None) is not None and getattr(self.through.Meta, 'ordering', None) is not None: |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
24 |
qs = qs.order_by(*[self.through._meta.db_table + "." + f for f in self.through.Meta.ordering]) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
25 |
return qs |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
26 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
27 |
|
| 47 | 28 |
class Organisation(models.Model): |
29 |
hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
30 |
name = models.CharField(max_length=512, unique=False, blank=False, null=False) |
|
31 |
location = models.CharField(max_length=512, unique=False, blank=True, null=True) |
|
32 |
website = models.CharField(max_length=2048, unique=False, blank=True, null=True) |
|
33 |
||
34 |
class Author(models.Model): |
|
35 |
hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
36 |
lastname = models.CharField(max_length=512, unique=False, blank=True, null=True) |
|
37 |
firstname = models.CharField(max_length=512, unique=False, blank=True, null=True) |
|
38 |
||
39 |
class TimePeriod(models.Model): |
|
40 |
TIME_PERIOD_CHOICES = ( |
|
41 |
(1, u'Primaire'), |
|
42 |
(2, u'Collège'), |
|
43 |
(3, u'Lycée'), |
|
44 |
) |
|
45 |
TIME_PERIOD_DICT = { |
|
46 |
u'Primaire': 1, |
|
47 |
u'Collège': 2, |
|
48 |
u'Lycée': 3, |
|
49 |
} |
|
50 |
label = models.CharField(max_length=512, unique=False, blank=False, null=False) |
|
51 |
school_period = models.IntegerField(choices=TIME_PERIOD_CHOICES) |
|
| 443 | 52 |
natural_key = models.CharField(max_length=512, unique=True, blank=False, null=False) |
53 |
||
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
54 |
objects = SortedModelManager() |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
55 |
|
| 47 | 56 |
class Meta: |
57 |
unique_together = ("label", "school_period") |
|
58 |
||
59 |
def __unicode__(self): |
|
60 |
return unicode(self.label) |
|
61 |
||
62 |
class Domain(models.Model): |
|
63 |
DOMAIN_PERIOD_CHOICES = ( |
|
64 |
(0, u'Global'), |
|
65 |
(1, u'Primaire'), |
|
66 |
(2, u'Collège'), |
|
67 |
(3, u'Lycée'), |
|
68 |
) |
|
69 |
DOMAIN_PERIOD_DICT = { |
|
70 |
u'Global': 0, |
|
71 |
u'Primaire': 1, |
|
72 |
u'Collège': 2, |
|
73 |
u'Lycée': 3, |
|
74 |
} |
|
75 |
label = models.CharField(max_length=512, unique=False, blank=False, null=False) |
|
76 |
school_period = models.IntegerField(choices=DOMAIN_PERIOD_CHOICES) |
|
| 443 | 77 |
natural_key = models.CharField(max_length=512, unique=True, blank=False, null=False) |
| 47 | 78 |
|
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
79 |
objects = SortedModelManager() |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
80 |
|
| 47 | 81 |
class Meta: |
82 |
unique_together = ("label", "school_period") |
|
83 |
||
84 |
def __unicode__(self): |
|
85 |
return unicode(self.label) |
|
86 |
||
87 |
||
88 |
class DocumentFormat(models.Model): |
|
89 |
label = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
90 |
||
91 |
def __unicode__(self): |
|
92 |
return unicode(self.label) |
|
93 |
||
94 |
class TagCategory(models.Model): |
|
95 |
label = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
| 443 | 96 |
natural_key = models.CharField(max_length=512, unique=False, blank=False, null=False, db_index=True) |
| 47 | 97 |
|
98 |
def __unicode__(self): |
|
99 |
return unicode(self.label) |
|
100 |
||
101 |
class Meta: |
|
102 |
verbose_name_plural = "TagCategories" |
|
103 |
||
104 |
class Tag(models.Model): |
|
105 |
TAG_URL_STATUS_CHOICES = ( |
|
106 |
(0, "null_result"), |
|
107 |
(1, "redirection"), |
|
108 |
(2, "homonyme"), |
|
109 |
(3, "match"), |
|
|
108
4b73a767a6c0
backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents:
104
diff
changeset
|
110 |
(4, "unsematized"), |
| 47 | 111 |
) |
112 |
||
113 |
TAG_URL_STATUS_DICT = { |
|
114 |
"null_result":0, |
|
115 |
"redirection":1, |
|
116 |
"homonyme":2, |
|
117 |
"match":3, |
|
|
108
4b73a767a6c0
backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents:
104
diff
changeset
|
118 |
"unsemantized":4, |
| 47 | 119 |
} |
120 |
||
121 |
label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True) |
|
|
108
4b73a767a6c0
backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents:
104
diff
changeset
|
122 |
alternative_label = models.CharField(max_length=1024, unique=False, blank=True, null=True) |
| 72 | 123 |
normalized_label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True, editable=False) |
|
108
4b73a767a6c0
backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents:
104
diff
changeset
|
124 |
created_at = models.DateTimeField(auto_now_add=True) |
| 69 | 125 |
original_label = models.CharField(max_length=1024, unique=False, blank=False, null=False, editable=False) |
| 47 | 126 |
alias = models.CharField(max_length=1024, unique=False, blank=True, null=True) |
127 |
category = models.ForeignKey(TagCategory, null=True, blank=True) |
|
|
266
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
128 |
wikipedia_url = models.URLField(max_length=2048, blank=True, null=True, db_index=True) |
|
119
e3ebe3545f72
first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
114
diff
changeset
|
129 |
wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True, db_index=True) |
|
266
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
130 |
alternative_wikipedia_url = models.URLField(max_length=2048, blank=True, null=True, db_index=True) |
|
119
e3ebe3545f72
first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
114
diff
changeset
|
131 |
alternative_wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True, db_index=True) |
|
e3ebe3545f72
first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
114
diff
changeset
|
132 |
url_status = models.IntegerField(choices=TAG_URL_STATUS_CHOICES, blank=True, null=True, default=None, db_index=True) |
|
266
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
133 |
dbpedia_uri = models.URLField(max_length=2048, blank=True, null=True, db_index=True) |
| 47 | 134 |
popularity = models.IntegerField(blank=False, null=False, default=0, db_index=True) |
| 443 | 135 |
#natural_key = models.CharField(max_length=7168, blank=True, null=True, db_index=True) |
136 |
#TODO: find a proper key. natural key is not really a key. |
|
137 |
natural_key = models.CharField(max_length=7168, blank=False, null=False, db_index=True) |
|
138 |
||
139 |
||
140 |
def __init__(self, *args, **kwargs): |
|
141 |
models.Model.__init__(self, *args, **kwargs) |
|
142 |
self.force_natural_key = False |
|
| 47 | 143 |
|
144 |
@Property |
|
145 |
def url_status_text(): #@NoSelf |
|
146 |
def fget(self): |
|
147 |
return self.TAG_URL_STATUS_CHOICES[self.url_status][1] |
|
148 |
||
| 72 | 149 |
return locals() |
| 443 | 150 |
|
151 |
def calculate_natural_key(self): |
|
152 |
parts = [ |
|
153 |
utils.sanitize(self.label if hasattr(self,'label') else ''), |
|
154 |
utils.sanitize(self.normalized_label if hasattr(self,'normalized_label') else ''), |
|
155 |
utils.sanitize(self.original_label if hasattr(self,'original_label') else ''), |
|
156 |
self.wikipedia_url.split("/")[-1].rstrip('/') if hasattr(self,'wikipedia_url') and self.wikipedia_url else "" |
|
157 |
] |
|
158 |
return ('_'.join(parts))[:7168] |
|
159 |
||
| 72 | 160 |
|
161 |
def save(self, *args, **kwargs): |
|
| 443 | 162 |
if self.label and not self.normalized_label: |
163 |
self._normalized_label = normalize(self.label) |
|
164 |
if not self.force_natural_key: |
|
165 |
self.natural_key = self.calculate_natural_key() |
|
| 85 | 166 |
super(Tag, self).save(*args, **kwargs) |
167 |
||
168 |
class Meta: |
|
169 |
unique_together = (('label', 'original_label', 'url_status'),) |
|
| 47 | 170 |
|
171 |
class Location(models.Model): |
|
172 |
name = models.CharField(max_length=512, unique=False, blank=False, null=False) |
|
173 |
insee = models.CharField(max_length=5, unique=True, blank=False, null=False) |
|
174 |
||
175 |
def __unicode__(self): |
|
176 |
return unicode("%s : %s" % (self.name, self.insee)) |
|
177 |
||
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
178 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
179 |
def generate_m2m_setter(m2m_field_name): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
180 |
|
| 443 | 181 |
def set_m2m_field(self, lst): |
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
182 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
183 |
m2m_manager = getattr(self, m2m_field_name) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
184 |
m2m_manager.clear() |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
185 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
186 |
through_klass = set_m2m_field.cache.get('through_klass', None) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
187 |
if through_klass is None: |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
188 |
field = getattr(self.__class__, m2m_field_name) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
189 |
through_klass = field.through |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
190 |
set_m2m_field.cache['through_klass'] = through_klass |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
191 |
for f in through_klass._meta.fields: |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
192 |
if isinstance(f, models.ForeignKey) and f.name != "datasheet": |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
193 |
set_m2m_field.cache['target_obj_field_name'] = f.name |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
194 |
break |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
195 |
target_obj_field_name = set_m2m_field.cache['target_obj_field_name'] |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
196 |
|
| 443 | 197 |
for i, obj in enumerate(lst): |
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
198 |
kwargs = { |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
199 |
'datasheet': self, |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
200 |
'sort_value' : i, |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
201 |
target_obj_field_name: obj |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
202 |
} |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
203 |
new_rel = through_klass(**kwargs) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
204 |
new_rel.save() |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
205 |
set_m2m_field.cache = {} |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
206 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
207 |
return set_m2m_field |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
208 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
209 |
|
| 47 | 210 |
class Datasheet(models.Model): |
211 |
hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False) |
|
|
197
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
212 |
author = models.ForeignKey(Author, null=True, blank=True, serialize=False) |
|
200
23b2b36e5118
Merge with 72aa63f8365dbcc4606aa066ecbdd91aabdbf7a9
ymh <ymh.work@gmail.com>
diff
changeset
|
213 |
organisation = models.ForeignKey(Organisation, serialize=False, null=True) |
|
197
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
214 |
title = models.CharField(max_length=2048, unique=False, blank=False, null=False, serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
215 |
description = models.TextField(blank=True, null=True, serialize=False) |
|
266
825ff4d6a8ac
reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents:
200
diff
changeset
|
216 |
url = models.URLField(max_length=2048, blank=True, null=True, serialize=False) |
|
197
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
217 |
domains = models.ManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Global']}, related_name="datasheets", through="Datasheet_domains", serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
218 |
primary_periods = models.ManyToManyField(TimePeriod, limit_choices_to={'school_period':TimePeriod.TIME_PERIOD_DICT[u'Primaire']}, related_name="primary_periods_datasheets", through="Datasheet_primary_periods", serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
219 |
college_periods = models.ManyToManyField(TimePeriod, limit_choices_to={'school_period':TimePeriod.TIME_PERIOD_DICT[u'Collège']}, related_name="college_periods_datasheets", through="Datasheet_college_periods", serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
220 |
highschool_periods = models.ManyToManyField(TimePeriod, limit_choices_to={'school_period':TimePeriod.TIME_PERIOD_DICT[u'Lycée']}, related_name="highschool_periods_datasheets", through="Datasheet_highschool_periods", serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
221 |
primary_themes = models.ManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Primaire']}, related_name="primary_themes_datasheets", through="Datasheet_primary_themes", serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
222 |
college_themes = models.ManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Collège']}, related_name="college_themes_datasheets", through="Datasheet_college_themes", serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
223 |
highschool_themes = models.ManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Lycée']}, related_name="highschool_themes_datasheets", through="Datasheet_highschool_themes", serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
224 |
town = models.ForeignKey(Location, null=True, blank=True, serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
225 |
format = models.ForeignKey(DocumentFormat, null=True, blank=True, serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
226 |
original_creation_date = models.DateField(serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
227 |
original_modification_date = models.DateField(serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
228 |
modification_datetime = models.DateTimeField(auto_now=True, serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
229 |
validation_date = models.DateTimeField(null=True, blank=True, serialize=False) |
| 47 | 230 |
validated = models.BooleanField(default=False, db_index=True) |
|
197
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
231 |
validator = models.ForeignKey(User, null=True, blank=True, serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
232 |
manual_order = models.BooleanField(default=False, db_index=True, serialize=False) |
|
72aa63f8365d
update datasheet model for serializasation and dumpdata.
cavaliet
parents:
181
diff
changeset
|
233 |
tags = models.ManyToManyField(Tag, through='TaggedSheet', serialize=False) |
| 47 | 234 |
|
| 181 | 235 |
def natural_key(self): |
236 |
return self.hda_id |
|
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
237 |
|
| 47 | 238 |
def validate(self, user): |
239 |
self.validation_date = datetime.datetime.now() |
|
240 |
self.validated = True |
|
241 |
self.validator = user |
|
242 |
self.save() |
|
243 |
||
244 |
def unvalidate(self): |
|
245 |
self.validation_date = datetime.datetime.min |
|
246 |
self.validated = False |
|
247 |
self.validator = None |
|
248 |
self.save() |
|
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
249 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
250 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
251 |
set_domains = generate_m2m_setter("domains") |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
252 |
|
| 47 | 253 |
@Property |
254 |
def domains_list(): #@NoSelf |
|
255 |
def fget(self): |
|
256 |
return [d.label for d in self.domains.all()] |
|
257 |
||
258 |
return locals() |
|
259 |
||
260 |
@Property |
|
261 |
def domains_text(): #@NoSelf |
|
262 |
def fget(self): |
|
263 |
return "; ".join(self.domains_list) |
|
264 |
||
265 |
return locals() |
|
266 |
||
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
267 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
268 |
set_primary_periods = generate_m2m_setter("primary_periods") |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
269 |
|
| 47 | 270 |
@Property |
271 |
def primary_periods_list(): #@NoSelf |
|
272 |
def fget(self): |
|
273 |
return [d.label for d in self.primary_periods.all()] |
|
274 |
||
275 |
return locals() |
|
276 |
||
277 |
||
278 |
@Property |
|
279 |
def primary_periods_text(): #@NoSelf |
|
280 |
def fget(self): |
|
281 |
return "; ".join(self.primary_periods_list) |
|
282 |
||
283 |
return locals() |
|
284 |
||
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
285 |
set_college_periods = generate_m2m_setter("college_periods") |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
286 |
|
| 47 | 287 |
@Property |
288 |
def college_periods_list(): #@NoSelf |
|
289 |
def fget(self): |
|
290 |
return [d.label for d in self.college_periods.all()] |
|
291 |
||
292 |
return locals() |
|
293 |
||
294 |
@Property |
|
295 |
def college_periods_text(): #@NoSelf |
|
296 |
def fget(self): |
|
297 |
return "; ".join(self.college_periods_list) |
|
298 |
||
299 |
return locals() |
|
300 |
||
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
301 |
set_highschool_periods = generate_m2m_setter("highschool_periods") |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
302 |
|
| 47 | 303 |
@Property |
304 |
def highschool_periods_list(): #@NoSelf |
|
305 |
def fget(self): |
|
306 |
return [d.label for d in self.highschool_periods.all()] |
|
307 |
||
308 |
return locals() |
|
309 |
||
310 |
@Property |
|
311 |
def highschool_periods_text(): #@NoSelf |
|
312 |
def fget(self): |
|
313 |
return "; ".join(self.highschool_periods_list) |
|
314 |
||
315 |
return locals() |
|
316 |
||
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
317 |
set_primary_themes = generate_m2m_setter("primary_themes") |
| 47 | 318 |
|
319 |
@Property |
|
320 |
def primary_themes_list(): #@NoSelf |
|
321 |
def fget(self): |
|
322 |
return [d.label for d in self.primary_themes.all()] |
|
323 |
||
324 |
return locals() |
|
325 |
||
326 |
||
327 |
@Property |
|
328 |
def primary_themes_text(): #@NoSelf |
|
329 |
def fget(self): |
|
330 |
return "; ".join(self.primary_themes_list) |
|
331 |
||
332 |
return locals() |
|
333 |
||
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
334 |
set_college_themes = generate_m2m_setter("college_themes") |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
335 |
|
| 47 | 336 |
@Property |
337 |
def college_themes_list(): #@NoSelf |
|
338 |
def fget(self): |
|
339 |
return [d.label for d in self.college_themes.all()] |
|
340 |
||
341 |
return locals() |
|
342 |
||
343 |
@Property |
|
344 |
def college_themes_text(): #@NoSelf |
|
345 |
def fget(self): |
|
346 |
return "; ".join(self.college_themes_list) |
|
347 |
||
348 |
return locals() |
|
349 |
||
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
350 |
set_highschool_themes = generate_m2m_setter("highschool_themes") |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
351 |
|
| 47 | 352 |
@Property |
353 |
def highschool_themes_list(): #@NoSelf |
|
354 |
def fget(self): |
|
355 |
return [d.label for d in self.highschool_themes.all()] |
|
356 |
||
357 |
return locals() |
|
358 |
||
359 |
@Property |
|
360 |
def highschool_themes_text(): #@NoSelf |
|
361 |
def fget(self): |
|
362 |
return "; ".join(self.highschool_themes_list) |
|
363 |
||
364 |
return locals() |
|
365 |
||
366 |
@Property |
|
367 |
def town_text(): #@NoSelf |
|
368 |
def fget(self): |
|
369 |
return self.town.name if self.town else "" |
|
370 |
||
371 |
return locals() |
|
372 |
||
373 |
@Property |
|
374 |
def tags_text(): #@NoSelf |
|
375 |
def fget(self): |
|
376 |
return "; ".join([t.label for t in self.tags.all()]) |
|
377 |
||
378 |
return locals() |
|
379 |
||
| 96 | 380 |
@models.permalink |
381 |
def get_absolute_url(self): |
|
382 |
return ('display_datasheet', (), { |
|
383 |
'ds_id': self.hda_id |
|
384 |
}) |
|
385 |
||
| 47 | 386 |
|
387 |
class TaggedSheet(models.Model): |
|
388 |
datasheet = models.ForeignKey(Datasheet) |
|
389 |
tag = models.ForeignKey(Tag) |
|
|
108
4b73a767a6c0
backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents:
104
diff
changeset
|
390 |
created_at = models.DateTimeField(auto_now_add=True) |
| 47 | 391 |
original_order = models.IntegerField(null=False, blank=False, default=0) |
392 |
order = models.IntegerField(null=False, blank=False, default=0, db_index=True) |
|
393 |
index_note = models.FloatField(null=False, blank=False, default=0.0, db_index=True) |
|
| 66 | 394 |
wikipedia_revision_id = models.BigIntegerField(unique=False, blank=True, null=True) |
395 |
||
396 |
@Property |
|
397 |
def wikipedia_verion_permalink(): #@NoSelf |
|
398 |
def fget(self): |
|
399 |
return settings.WIKIPEDIA_VERSION_PERMALINK_TEMPLATE % (unicode(self.wikipedia_revision_id)) |
|
400 |
||
401 |
return locals() |
|
|
104
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
402 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
403 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
404 |
class SortedDatasheetLink(models.Model): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
405 |
datasheet = models.ForeignKey(Datasheet, db_index=True, null=False, blank=False) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
406 |
sort_value = models.IntegerField(null=False, blank=False) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
407 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
408 |
class Meta: |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
409 |
abstract = True |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
410 |
ordering = ['sort_value'] |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
411 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
412 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
413 |
class Datasheet_domains(SortedDatasheetLink): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
414 |
domain = models.ForeignKey(Domain, db_index=True, null=False, blank=False) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
415 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
416 |
class Datasheet_highschool_periods(SortedDatasheetLink): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
417 |
timeperiod = models.ForeignKey(TimePeriod, db_index=True, null=False, blank=False) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
418 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
419 |
class Datasheet_highschool_themes(SortedDatasheetLink): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
420 |
domain = models.ForeignKey(Domain, db_index=True, null=False, blank=False) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
421 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
422 |
class Datasheet_college_periods(SortedDatasheetLink): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
423 |
timeperiod = models.ForeignKey(TimePeriod, db_index=True, null=False, blank=False) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
424 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
425 |
class Datasheet_college_themes(SortedDatasheetLink): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
426 |
domain = models.ForeignKey(Domain, db_index=True, null=False, blank=False) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
427 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
428 |
class Datasheet_primary_periods(SortedDatasheetLink): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
429 |
timeperiod = models.ForeignKey(TimePeriod, db_index=True, null=False, blank=False) |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
430 |
|
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
431 |
class Datasheet_primary_themes(SortedDatasheetLink): |
|
28a2c02ef6c8
Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents:
96
diff
changeset
|
432 |
domain = models.ForeignKey(Domain, db_index=True, null=False, blank=False) |
| 275 | 433 |
|
434 |
||
435 |
# Evolution pour Hda 2 : folders of datasheets |
|
436 |
class Folder(models.Model): |
|
437 |
url = models.URLField(max_length=2048, unique=True, blank=False, null=False) |
|
438 |
title = models.CharField(max_length=2048, blank=True, null=True) |
|
439 |
description = models.TextField(blank=True, null=True) |
|
440 |
datasheets = models.ManyToManyField(Datasheet) |
|
441 |
||
442 |
||
443 |