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