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