Import Django model for the database
[vagrant-mail.git] / database / platal_models.py
CommitLineData
f497e0a9
NI
1# -*- coding: utf-8 -*-
2#***************************************************************************
3#* Copyright (C) 2015 Polytechnique.org *
4#* http://opensource.polytechnique.org/ *
5#* *
6#* This program is free software; you can redistribute it and/or modify *
7#* it under the terms of the GNU General Public License as published by *
8#* the Free Software Foundation; either version 2 of the License, or *
9#* (at your option) any later version. *
10#* *
11#* This program is distributed in the hope that it will be useful, *
12#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14#* GNU General Public License for more details. *
15#* *
16#* You should have received a copy of the GNU General Public License *
17#* along with this program; if not, write to the Free Software *
18#* Foundation, Inc., *
19#* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20#***************************************************************************/
21"""Django models which fit the latest version of Plat/al database
22
23Latest version synced: Plat/al 1.1.15
24https://github.com/Polytechnique-org/platal/tree/xorg/maint/upgrade
25
26This requires Django to work.
27"""
28import collections
29from django.db import models
30
31
32def is_ax_visible(field):
33 return field in ('public', 'ax')
34
35
36# Misc for Account/Profile
37# ========================
38
39
40class Skin(models.Model):
41 #id = models.IntegerField(primary_key=True)
42 name = models.CharField(max_length=96)
43 date = models.DateField()
44 comment = models.CharField(max_length=765)
45 auteur = models.CharField(max_length=90)
46 skin_tpl = models.CharField(max_length=96)
47 ext = models.CharField(max_length=9)
48 class Meta:
49 db_table = u'skins'
50
51 def __unicode__(self):
52 return self.name
53
54
55class EmailVirtualDomain(models.Model):
56 #id = models.IntegerField(primary_key=True)
57 name = models.CharField(max_length=765)
58 aliasing = models.ForeignKey('self', db_column='aliasing')
59 class Meta:
60 db_table = u'email_virtual_domains'
61
62 def __unicode__(self):
63 return self.name
64
65
66class ProfileSectionEnum(models.Model):
67 #id = models.IntegerField(primary_key=True)
68 text = models.CharField(max_length=150, unique=True)
69 class Meta:
70 db_table = u'profile_section_enum'
71
72 def __unicode__(self):
73 return self.text
74
75
76class GeolocCountry(models.Model):
77 iso_3166_1_a2 = models.CharField(max_length=6, primary_key=True)
78 iso_3166_1_a3 = models.CharField(max_length=9, unique=True)
79 iso_3166_1_num = models.IntegerField(unique=True)
80 worldregion = models.CharField(max_length=6, db_column='worldRegion', blank=True) # Field name made lowercase.
81 country = models.CharField(max_length=765, blank=True)
82 countryen = models.CharField(max_length=765, db_column='countryEn', blank=True) # Field name made lowercase.
83 capital = models.CharField(max_length=765)
84 nationality = models.CharField(max_length=765, blank=True)
85 nationalityen = models.CharField(max_length=765, db_column='nationalityEn', blank=True) # Field name made lowercase.
86 phoneprefix = models.IntegerField(null=True, db_column='phonePrefix', blank=True) # Field name made lowercase.
87 phoneformat = models.CharField(max_length=765, db_column='phoneFormat') # Field name made lowercase.
88 licenseplate = models.CharField(max_length=12, db_column='licensePlate', blank=True) # Field name made lowercase.
89 belongsto = models.ForeignKey('self', null=True, db_column='belongsTo', blank=True) # Field name made lowercase.
90 countryplain = models.CharField(max_length=765, db_column='countryPlain', blank=True) # Field name made lowercase.
91 class Meta:
92 db_table = u'geoloc_countries'
93
94 def __unicode__(self):
95 return self.iso_3166_1_a2
96
97
98# Account/Profile
99# ===============
100
101
102class AccountType(models.Model):
103 type = models.CharField(max_length=48, primary_key=True)
104 perms = models.CharField(max_length=321)
105 description = models.TextField(blank=True)
106 class Meta:
107 db_table = u'account_types'
108
109 def __unicode__(self):
110 return self.type
111
112
113class Account(models.Model):
114 uid = models.AutoField(primary_key=True)
115 hruid = models.CharField(max_length=255, unique=True)
116 type = models.ForeignKey(AccountType, null=True, db_column='type', blank=True)
117 user_perms = models.CharField(max_length=288, blank=True)
118 is_admin = models.BooleanField()
119 state = models.CharField(max_length=24)
120 password = models.CharField(max_length=120, blank=True)
121 token = models.CharField(max_length=96, blank=True)
122 weak_password = models.CharField(max_length=768, blank=True)
123 registration_date = models.DateTimeField()
124 flags = models.CharField(max_length=15)
125 comment = models.CharField(max_length=765, blank=True)
126 email = models.CharField(max_length=765, blank=True)
127 firstname = models.CharField(max_length=765, blank=True)
128 lastname = models.CharField(max_length=765, blank=True)
129 full_name = models.CharField(max_length=765, blank=True)
130 directory_name = models.CharField(max_length=765, blank=True)
131 sort_name = models.CharField(max_length=765, blank=True)
132 display_name = models.CharField(max_length=765, blank=True)
133 sex = models.CharField(max_length=18)
134 email_format = models.CharField(max_length=12)
135 skin = models.ForeignKey(Skin, null=True, db_column='skin', blank=True)
136 last_version = models.CharField(max_length=48)
137 best_domain = models.ForeignKey(EmailVirtualDomain, null=True, db_column='best_domain', blank=True)
138 from_email = models.CharField(max_length=765)
139 from_format = models.CharField(max_length=12)
140 class Meta:
141 db_table = u'accounts'
142
143 def __unicode__(self):
144 return u'%s (%s)' % (self.hruid, self.full_name)
145
146 @property
147 def profile(self):
148 return self.profiles.filter(perms='owner').get().profile
149
150
151class ProfileAlias(object):
152 def __init__(self, alias_of, kind, lastname, firstname=None):
153 self.alias_of = alias_of
154 self.kind = kind
155 self.lastname = lastname
156 self.firstname = alias_of.firstname if firstname is None else firstname
157
158 ALT_MARITAL = 'marital'
159 ALT_PSEUDO = 'pseudo'
160 ALT_ORDINARY = 'ordinary'
161
162 @property
163 def is_pseudo(self):
164 return self.kind == self.ALT_PSEUDO
165
166 def get_kind_display(self):
167 if self.kind == self.ALT_MARITAL:
168 if self.female:
169 return u"Mme"
170 else:
171 return u"M."
172 elif self.kind == self.ALT_PSEUDO:
173 return u"Pseudonyme"
174 else:
175 return u""
176
177 def __getattr__(self, attr):
178 return getattr(self.alias_of, attr)
179
180 def __repr__(self):
181 return '<ProfileAlias %s of %r>' % (self.kind, self.alias_of)
182
183
184class Profile(models.Model):
185
186 alias_of = None
187
188 def __init__(self, *args, **kwargs):
189 super(Profile, self).__init__(*args, **kwargs)
190 self._aliases = None
191
192 pid = models.AutoField(primary_key=True)
193 hrpid = models.CharField(max_length=255, unique=True)
194 xorg_id = models.IntegerField()
195 ax_id = models.CharField(max_length=24, blank=True)
196 birthdate = models.DateField(null=True, blank=True)
197 birthdate_ref = models.DateField(null=True, blank=True)
198 next_birthday = models.DateField(null=True, blank=True)
199 deathdate = models.DateField(null=True, blank=True)
200 deathdate_rec = models.DateField(null=True, blank=True)
201 sex = models.CharField(max_length=18)
202 section = models.ForeignKey(ProfileSectionEnum, null=True, db_column='section', blank=True)
203 cv = models.TextField(blank=True)
204 freetext = models.TextField(blank=True)
205 freetext_pub = models.CharField(max_length=21)
206 medals_pub = models.CharField(max_length=21)
207 alias_pub = models.CharField(max_length=21)
208 nationality1 = models.ForeignKey(GeolocCountry, null=True, db_column='nationality1', blank=True, related_name='natives')
209 nationality2 = models.ForeignKey(GeolocCountry, null=True, db_column='nationality2', blank=True, related_name='second_natives')
210 nationality3 = models.ForeignKey(GeolocCountry, null=True, db_column='nationality3', blank=True, related_name='third_natives')
211 email_directory = models.CharField(max_length=765, blank=True)
212 last_change = models.DateField()
213 title = models.CharField(max_length=12)
214
215 class Meta:
216 db_table = u'profiles'
217
218 def __unicode__(self):
219 return self.hrpid
220
221 @property
222 def is_alive(self):
223 return self.deathdate is None
224
225 @property
226 def account(self):
227 return self.accounts.filter(perms='owner').get().account
228
229 @property
230 def firstname(self):
231 return self.public_name.firstname_ordinary or self.public_name.firstname_main or self.public_name.firstname_initial
232
233 @property
234 def lastname(self):
235 return self.public_name.lastname_main or self.public_name.lastname_initial
236
237 @property
238 def lastname_display(self):
239 return self.public_name.lastname_ordinary or self.public_name.lastname_marital or self.public_name.lastname_main or self.public_name.lastname_initial
240
241 @property
242 def lastname_marital(self):
243 return self.public_name.lastname_marital
244
245 @property
246 def lastname_ordinary(self):
247 return self.public_name.lastname_ordinary
248
249 @property
250 def pseudonym(self):
251 return self.public_name.pseudonym
252
253 @property
254 def promo(self):
255 return self.profiledisplay.promo
256
257 @property
258 def female(self):
259 return self.sex == 'female'
260
261 @property
262 def nationality(self):
263 return self.nationality1 or self.nationality2 or self.nationality3
264
265 @property
266 def country_code(self):
267 nat = self.nationality
268 if nat is None:
269 return 'FR'
270 return nat.iso_3166_1_a2
271
272 @property
273 def country_name(self):
274 nat = self.nationality
275 if nat is None:
276 return u"France"
277 return nat.country
278
279 @property
280 def current_corps(self):
281 try:
282 return self.profilecorps.current
283 except ProfileCorps.DoesNotExist:
284 return None
285
286 def get_aliases(self, include_deviations=True):
287 if self._aliases is None:
288 self._aliases = []
289
290 alt_names = set([self.lastname])
291 if self.lastname_marital and self.lastname_marital not in alt_names:
292 alt_names.add(self.lastname_marital)
293 self._aliases.append(
294 ProfileAlias(self, ProfileAlias.ALT_MARITAL, self.lastname_marital))
295
296 if self.lastname_ordinary and self.lastname_ordinary not in alt_names:
297 # Some people filled 'ordinary' instead of 'marital'
298 alt_names.add(self.lastname_ordinary)
299 self._aliases.append(
300 ProfileAlias(self, ProfileAlias.ALT_ORDINARY, self.lastname_ordinary))
301
302 if self.pseudonym and self.pseudonym not in alt_names:
303 alt_names.add(self.pseudonym)
304 self._aliases.append(
305 ProfileAlias(self, ProfileAlias.ALT_PSEUDO, self.pseudonym, firstname=''))
306
307 if include_deviations:
308 return self._aliases
309 else:
310 return [a for a in self._aliases
311 if not a.lastname.startswith(self.lastname)
312 and not self.lastname.startswith(a.lastname)
313 ]
314
315 @property
316 def mobile_line(self):
317 if not hasattr(self, '_mobiles'):
318 mobiles = [phone
319 for phone in self.phones.all()
320 if phone.link_type == phone.LINK_USER and phone.tel_type == phone.KIND_MOBILE
321 ]
322 self._mobiles = sorted(mobiles, key=lambda p: p.tel_id)
323 if self._mobiles:
324 return self._mobiles[0]
325 return None
326
327 def sorted_addresses(self, for_ax=False):
328 personal_addresses = [addr
329 for addr in self.addresses.all()
330 if addr.is_home and (addr.ax_visible or not for_ax)
331 ]
332
333 address_phones = collections.defaultdict(lambda: collections.defaultdict(list))
334
335 for phone in self.phones.all():
336 if phone.is_address and (phone.ax_visible or not for_ax):
337 address_phones[phone.link_id][phone.tel_type].append(phone)
338
339 for address in personal_addresses:
340 addr_phones = {}
341 for kind, phones in address_phones[address.subid].items():
342 if phones:
343 addr_phones[kind] = sorted(phones, key=lambda p: p.tel_id)[0]
344 else:
345 addr_phones[kind] = None
346 address.phones = addr_phones
347
348 current = [addr for addr in personal_addresses if addr.current]
349 secondary = [addr for addr in personal_addresses if addr.secondary and not addr.current]
350 if not current:
351 current, secondary = secondary, []
352
353 return [(a, True) for a in current] + [(a, False) for a in secondary]
354
355 def sorted_educations(self):
356 edus = [edu for edu in self.educations.all() if edu.school and edu.school.abbreviation != 'X']
357 return sorted(edus, key=lambda edu: edu.entry_year)
358
359 def sorted_jobs(self):
360 jobs = sorted(self.jobs.all(), key=lambda j: (j.id, j.entry_year))
361 job_addresses = {}
362 for addr in self.addresses.all():
363 if addr.is_job:
364 job_addresses[addr.job_id] = addr
365
366 job_phones = collections.defaultdict(lambda: collections.defaultdict(list))
367 for phone in self.phones.all():
368 if phone.is_job:
369 job_phones[phone.link_id][phone.tel_type].append(phone)
370
371 for job in jobs:
372 job.address = job_addresses.get(job.id)
373 j_phones = {}
374 for kind, phones in job_phones[job.id].items():
375 if phones:
376 j_phones[kind] = sorted(phones, key=lambda p: p.tel_id)[0]
377 else:
378 j_phones[kind] = None
379 job.phones = j_phones
380
381 return jobs
382
383
384class AccountProfile(models.Model):
385 account = models.ForeignKey(Account, db_column='uid', related_name='profiles')
386 profile = models.ForeignKey(Profile, db_column='pid', related_name='accounts')
387 pkey = models.CompositeField(account, profile, primary_key=True)
388 perms = models.CharField(max_length=15)
389 class Meta:
390 db_table = u'account_profiles'
391
392 def __unicode__(self):
393 return u'%s -> %s' % (self.account.hruid, self.profile.hrpid)
394
395
396# Account-related
397# ===============
398
399
400class AccountAuthOpenid(models.Model):
401 #id = models.IntegerField(primary_key=True)
402 account = models.ForeignKey(Account, unique=True, null=True, db_column='uid', blank=True)
403 url = models.CharField(max_length=255, unique=True)
404 class Meta:
405 db_table = u'account_auth_openid'
406
407 def __unicode__(self):
408 return u"%s at %s" % (self.account, self.url)
409
410class AccountLostPassword(models.Model):
411 certificat = models.CharField(max_length=96, primary_key=True)
412 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
413 created = models.DateTimeField(null=True, blank=True)
414 class Meta:
415 db_table = u'account_lost_passwords'
416
417 def __unicode__(self):
418 return u"%s on %s" % (self.account.hruid, self.created)
419
420
421class AccountXnetLostPassword(models.Model):
422 account = models.ForeignKey(Account, primary_key=True, db_column='uid')
423 date = models.DateTimeField(null=True, blank=True)
424 hash = models.CharField(max_length=96)
425 class Meta:
426 db_table = u'account_xnet_lost_passwords'
427
428 def __unicode__(self):
429 return u"%s on %s" % (self.account.hruid, self.date)
430
431
432# Announces
433# =========
434
435
436class Announce(models.Model):
437 #id = models.IntegerField(primary_key=True)
438 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
439 creation_date = models.DateTimeField()
440 titre = models.CharField(max_length=765)
441 texte = models.TextField()
442 expiration = models.DateField()
443 promo_min = models.IntegerField()
444 promo_max = models.IntegerField()
445 flags = models.CharField(max_length=87)
446 noinvite = models.IntegerField()
447 post_id = models.IntegerField(null=True, blank=True, editable=False,
448 help_text=u"NNTP post identifier")
449 class Meta:
450 db_table = u'announces'
451
452 def __unicode__(self):
453 return u"%s: %s" % (self.id, self.titre)
454
455
456class AnnouncePhoto(models.Model):
457 eid = models.ForeignKey(Announce, primary_key=True, db_column='eid')
458 attachmime = models.CharField(max_length=12)
459 attach = models.TextField()
460 x = models.IntegerField()
461 y = models.IntegerField()
462 class Meta:
463 db_table = u'announce_photos'
464
465 def __unicode__(self):
466 return u"%s (%s, %d x %d)" % (self.eid, self.attachmime, self.x, self.y)
467
468
469class AnnounceRead(models.Model):
470 evt = models.ForeignKey(Announce)
471 account = models.ForeignKey(Account, db_column='uid')
472 pkey = models.CompositeField(evt, account, primary_key=True)
473 class Meta:
474 db_table = u'announce_read'
475
476 def __unicode__(self):
477 return u"%s: %s" % (self.account, self.evt)
478
479
480# Email routing
481# =============
482
483
484class EmailVirtual(models.Model):
485 email = models.CharField(max_length=255)
486 domain = models.ForeignKey(EmailVirtualDomain, db_column='domain')
487 pkey = models.CompositeField(email, domain, primary_key=True)
488 redirect = models.CharField(max_length=765)
489 type = models.CharField(max_length=21, blank=True)
490 expire = models.DateField()
491 class Meta:
492 db_table = u'email_virtual'
493
494 def __unicode__(self):
495 return u"%s@%s (%s)" % (self.email, self.domain, self.type)
496
497
498class EmailRedirectAccount(models.Model):
499 account = models.ForeignKey(Account, db_column='uid')
500 redirect = models.CharField(max_length=765)
501 pkey = models.CompositeField(account, redirect, primary_key=True)
502 rewrite = models.CharField(max_length=765)
503 type = models.CharField(max_length=30)
504 action = models.CharField(max_length=54)
505 broken_date = models.DateField()
506 broken_level = models.IntegerField()
507 last = models.DateField()
508 flags = models.CharField(max_length=24)
509 hash = models.CharField(max_length=96, blank=True)
510 allow_rewrite = models.BooleanField()
511 class Meta:
512 db_table = u'email_redirect_account'
513
514 def __unicode__(self):
515 return u"%s for %s (%s)" % (self.redirect, self.account.hruid, self.type)
516
517
518class EmailSourceAccount(models.Model):
519 email = models.CharField(max_length=255)
520 domain = models.ForeignKey(EmailVirtualDomain, db_column='domain')
521 pkey = models.CompositeField(email, domain, primary_key=True)
522
523 account = models.ForeignKey(Account, db_column='uid')
524 type = models.CharField(max_length=27)
525 flags = models.CharField(max_length=69)
526 expire = models.DateField(null=True, blank=True)
527 class Meta:
528 db_table = u'email_source_account'
529
530 def __unicode__(self):
531 return u"%s@%s (%s)" % (self.email, self.domain, self.type)
532
533
534class EmailSourceOther(models.Model):
535 email = models.CharField(max_length=255)
536 domain = models.ForeignKey(EmailVirtualDomain, db_column='domain')
537 pkey = models.CompositeField(email, domain, primary_key=True)
538
539 hrmid = models.CharField(max_length=765)
540 type = models.CharField(max_length=24, blank=True)
541 expire = models.DateField(null=True, blank=True)
542 class Meta:
543 db_table = u'email_source_other'
544
545 def __unicode__(self):
546 return u"%s@%s (%s)" % (self.email, self.domain, self.type)
547
548
549class EmailRedirectOther(models.Model):
550 hrmid = models.ForeignKey(EmailSourceOther, db_column='hrmid')
551 redirect = models.CharField(max_length=765)
552 pkey = models.CompositeField(hrmid, redirect, primary_key=True)
553 type = models.CharField(max_length=30)
554 action = models.CharField(max_length=54)
555 class Meta:
556 db_table = u'email_redirect_other'
557
558 def __unicode__(self):
559 return u"%s -> %s (%s)" % (self.hrmid, self.redirect, self.type)
560
561
562# innd-related
563# ============
564
565
566class InndForum(models.Model):
567 """ACLs for innd"""
568 id_innd = models.AutoField(primary_key=True)
569 ipmin = models.IntegerField(null=True, blank=True)
570 ipmax = models.IntegerField(null=True, blank=True)
571 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
572 read_perm = models.CharField(max_length=300, blank=True)
573 write_perm = models.CharField(max_length=300, blank=True)
574 priority = models.IntegerField(null=True, blank=True)
575 comment = models.TextField(blank=True)
576 class Meta:
577 db_table = u'forum_innd'
578
579 def __unicode__(self):
580 return "%d: %s" % (self.id_innd, self.account.hruid)
581
582
583class ForumProfile(models.Model):
584 account = models.ForeignKey(Account, primary_key=True, db_column='uid')
585 name = models.CharField(max_length=192)
586 mail = models.CharField(max_length=210)
587 sig = models.TextField()
588 flags = models.CharField(max_length=63)
589 tree_unread = models.CharField(max_length=24)
590 tree_read = models.CharField(max_length=24)
591 last_seen = models.DateTimeField()
592 class Meta:
593 db_table = u'forum_profiles'
594
595 def __unicode__(self):
596 return u"%s: %s" % (self.account.hruid, self.name)
597
598
599class Forum(models.Model):
600 fid = models.IntegerField(primary_key=True)
601 name = models.CharField(max_length=192)
602 class Meta:
603 db_table = u'forums'
604
605 def __unicode__(self):
606 return self.name
607
608
609class ForumSubs(models.Model):
610 forum = models.ForeignKey(Forum, db_column='fid')
611 account = models.ForeignKey(Account, db_column='uid')
612 pkey = models.CompositeField(forum, account, primary_key=True)
613 class Meta:
614 db_table = u'forum_subs'
615
616 def __unicode__(self):
617 return u"%s by %s" % (self.forum.name, self.account.hruid)
618
619
620# Payments
621# ========
622
623
624class PaymentBankAccount(models.Model):
625 #id = models.IntegerField(primary_key=True)
626 asso = models.ForeignKey('Group', blank=True, null=True)
627 iban = models.CharField(max_length=33)
628 owner = models.CharField(max_length=300)
629 status = models.CharField(max_length=36)
630 bic = models.CharField(max_length=11)
631 class Meta:
632 db_table = u'payment_bankaccounts'
633
634 def __unicode__(self):
635 return u'%s: %s' % (self.asso.name, self.account)
636
637
638class Payment(models.Model):
639 #id = models.IntegerField(primary_key=True)
640 text = models.CharField(max_length=765)
641 url = models.CharField(max_length=384)
642 flags = models.CharField(max_length=51)
643 amount_def = models.DecimalField(max_digits=12, decimal_places=2)
644 amount_min = models.DecimalField(max_digits=12, decimal_places=2)
645 amount_max = models.DecimalField(max_digits=12, decimal_places=2)
646 mail = models.CharField(max_length=192)
647 confirmation = models.TextField()
648 asso = models.ForeignKey('Group', null=True, blank=True)
649 rib = models.ForeignKey(PaymentBankAccount)
650 class Meta:
651 db_table = u'payments'
652
653 def __unicode__(self):
654 return u"%s: %s" % (self.id, self.text)
655
656
657class PaymentCodeC(models.Model):
658 id = models.IntegerField(primary_key=True)
659 text = models.CharField(max_length=192)
660 class Meta:
661 db_table = u'payment_codeC'
662
663 def __unicode__(self):
664 return self.text
665
666
667class PaymentCodeRCB(models.Model):
668 id = models.IntegerField(primary_key=True)
669 text = models.CharField(max_length=192)
670 codec = models.IntegerField(db_column='codeC') # Field name made lowercase.
671 class Meta:
672 db_table = u'payment_codeRCB'
673
674 def __unicode__(self):
675 return self.text
676
677
678class PaymentMethod(models.Model):
679 id = models.IntegerField(primary_key=True)
680 text = models.CharField(max_length=96)
681 include = models.CharField(max_length=96)
682 short_name = models.CharField(max_length=30)
683 flags = models.CharField(max_length=36, blank=True)
684 class Meta:
685 db_table = u'payment_methods'
686
687 def __unicode__(self):
688 return self.short_name
689
690
691class PaymentReconcilation(models.Model):
692 #id = models.IntegerField(primary_key=True)
693 method = models.ForeignKey(PaymentMethod)
694 period_start = models.DateField()
695 period_end = models.DateField()
696 status = models.CharField(max_length=33)
697 payment_count = models.IntegerField()
698 sum_amounts = models.DecimalField(max_digits=11, decimal_places=2)
699 sum_commissions = models.DecimalField(max_digits=11, decimal_places=2)
700 comments = models.TextField()
701 recongroup_id = models.IntegerField(null=True, blank=True)
702 class Meta:
703 db_table = u'payment_reconcilations'
704
705 def __unicode__(self):
706 return u"%s: %s" % (self.method, self.status)
707
708
709class PaymentTransaction(models.Model):
710 id = models.CharField(max_length=192, primary_key=True)
711 method = models.ForeignKey(PaymentMethod, null=True, blank=True)
712 account = models.ForeignKey(Account, db_column='uid')
713 ref = models.IntegerField()
714 fullref = models.CharField(max_length=45)
715 ts_confirmed = models.DateTimeField(null=True, blank=True)
716 ts_initiated = models.DateTimeField(null=True, blank=True)
717 amount = models.DecimalField(max_digits=11, decimal_places=2)
718 commission = models.DecimalField(null=True, max_digits=11, decimal_places=2, blank=True)
719 pkey = models.CharField(max_length=15)
720 comment = models.CharField(max_length=765)
721 status = models.CharField(max_length=27)
722 recon = models.ForeignKey(PaymentReconcilation, null=True, blank=True)
723 display = models.IntegerField()
724 class Meta:
725 db_table = u'payment_transactions'
726
727 def __unicode__(self):
728 return u"%s (%s)" % (self.fullref, self.ref)
729
730
731class PaymentTransfer(models.Model):
732 #id = models.IntegerField(primary_key=True)
733 recongroup_id = models.IntegerField()
734 payment = models.ForeignKey(Payment)
735 amount = models.DecimalField(max_digits=11, decimal_places=2)
736 account = models.ForeignKey(Account, null=True, blank=True)
737 message = models.CharField(max_length=765)
738 date = models.DateField(null=True, blank=True)
739 class Meta:
740 db_table = u'payment_transfers'
741
742 def __unicode__(self):
743 return u"%s: %s" % (self.id, self.amount)
744
745
746# Groups
747# ======
748
749
750class GroupDom(models.Model):
751 #id = models.IntegerField(primary_key=True)
752 name = models.TextField(db_column='nom')
753 cat = models.CharField(max_length=117)
754 class Meta:
755 db_table = u'group_dom'
756
757 def __unicode__(self):
758 return u"%s :: %s" % (self.cat, self.name)
759
760
761class Group(models.Model):
762 #id = models.IntegerField(primary_key=True)
763 name = models.CharField(max_length=765, db_column='nom')
764 diminutif = models.CharField(max_length=192, unique=True)
765 cat = models.CharField(max_length=117)
766 dom = models.ForeignKey(GroupDom, null=True, db_column='dom', blank=True)
767 descr = models.TextField()
768 logo = models.TextField(blank=True)
769 logo_mime = models.TextField(blank=True)
770 site = models.CharField(max_length=765)
771 mail = models.CharField(max_length=765)
772 resp = models.CharField(max_length=765)
773 forum = models.CharField(max_length=765)
774 mail_domain = models.CharField(max_length=765)
775 ax = models.IntegerField()
776 pub = models.CharField(max_length=21)
777 sub_url = models.CharField(max_length=765)
778 inscriptible = models.IntegerField()
779 unsub_url = models.CharField(max_length=765)
780 flags = models.CharField(max_length=117)
781 axdate = models.DateField(null=True, db_column='axDate', blank=True) # Field name made lowercase.
782 welcome_msg = models.TextField(blank=True)
783 event_order = models.CharField(max_length=8)
784 disable_mails = models.BooleanField()
785 status = models.CharField(max_length=117)
786 class Meta:
787 db_table = u'groups'
788
789 def __unicode__(self):
790 return self.name
791
792
793# Group::membership
794# -----------------
795
796
797class GroupMember(models.Model):
798 asso = models.ForeignKey(Group)
799 account = models.ForeignKey(Account, db_column='uid')
800 pkey = models.CompositeField(asso, account, primary_key=True)
801
802 perms = models.CharField(max_length=18)
803 comm = models.CharField(max_length=765, blank=True)
804 position = models.CharField(max_length=54, blank=True)
805 flags = models.CharField(max_length=18)
806 class Meta:
807 db_table = u'group_members'
808
809 def __unicode__(self):
810 return u"%s to %s" % (self.account.hruid, self.asso.name)
811
812
813class GroupMemberSubRequest(models.Model):
814 asso = models.ForeignKey(Group)
815 account = models.ForeignKey(Account, db_column='uid')
816 pkey = models.CompositeField(asso, account, primary_key=True)
817
818 ts = models.DateTimeField()
819 reason = models.TextField(blank=True)
820 class Meta:
821 db_table = u'group_member_sub_requests'
822
823 def __unicode__(self):
824 return u"%s to %s" % (self.account.hruid, self.asso.name)
825
826
827class GroupFormerMember(models.Model):
828 asso = models.ForeignKey(Group)
829 account = models.ForeignKey(Account, db_column='uid')
830 pkey = models.CompositeField(asso, account, primary_key=True)
831
832 remember = models.IntegerField()
833 unsubsciption_date = models.DateField()
834 class Meta:
835 db_table = u'group_former_members'
836
837 def __unicode__(self):
838 return u"%s to %s" % (self.account.hruid, self.asso.name)
839
840
841# Group::Announces
842# ----------------
843
844
845class GroupAnnounce(models.Model):
846 #id = models.IntegerField(primary_key=True)
847 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
848 asso = models.ForeignKey(Group)
849 create_date = models.DateTimeField()
850 titre = models.CharField(max_length=765)
851 texte = models.TextField()
852 contacts = models.TextField()
853 expiration = models.DateField()
854 promo_min = models.IntegerField()
855 promo_max = models.IntegerField()
856 flags = models.CharField(max_length=36)
857 post_id = models.IntegerField(null=True, blank=True,
858 help_text=u"NNTP post ID")
859 class Meta:
860 db_table = u'group_announces'
861
862 def __unicode__(self):
863 return u"%s: %s" % (self.asso.name, self.titre)
864
865
866class GroupAnnouncePhoto(models.Model):
867 eid = models.ForeignKey(GroupAnnounce, primary_key=True, db_column='eid')
868 attachmime = models.CharField(max_length=12)
869 attach = models.TextField()
870 x = models.IntegerField()
871 y = models.IntegerField()
872 class Meta:
873 db_table = u'group_announces_photo'
874
875 def __unicode__(self):
876 return u"%s (%s, %d x %d)" % (self.eid, self.attachmime, self.x, self.y)
877
878
879class GroupAnnounceRead(models.Model):
880 announce = models.ForeignKey(GroupAnnounce)
881 account = models.ForeignKey(Account, db_column='uid')
882 pkey = models.CompositeField(announce, account, primary_key=True)
883 class Meta:
884 db_table = u'group_announces_read'
885
886 def __unicode__(self):
887 return u"%s: %s" % (self.account.hruid, self.announce_id)
888
889
890# Group::Event
891# ------------
892
893
894class GroupEvent(models.Model):
895 eid = models.IntegerField(primary_key=True)
896 asso = models.ForeignKey(Group, null=True, blank=True)
897 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
898 intitule = models.CharField(max_length=300)
899 short_name = models.CharField(max_length=90)
900 paiement = models.ForeignKey(Payment, null=True, blank=True)
901 descriptif = models.TextField()
902 debut = models.DateTimeField()
903 fin = models.DateTimeField(null=True, blank=True)
904 show_participants = models.BooleanField()
905 deadline_inscription = models.DateField(null=True, blank=True)
906 noinvite = models.IntegerField()
907 accept_nonmembre = models.BooleanField()
908 archive = models.BooleanField()
909 subscription_notification = models.CharField(max_length=24)
910 class Meta:
911 db_table = u'group_events'
912
913 def __unicode__(self):
914 return u"%s: %s" % (self.asso.name, self.intitule)
915
916
917class GroupEventItem(models.Model):
918 event = models.ForeignKey(GroupEvent, db_column='eid')
919 item_id = models.IntegerField()
920 pkey = models.CompositeField(event, item_id, primary_key=True)
921
922 titre = models.CharField(max_length=300)
923 details = models.TextField()
924 montant = models.DecimalField(max_digits=12, decimal_places=2)
925 class Meta:
926 db_table = u'group_event_items'
927
928 def __unicode__(self):
929 return u"%s - %s" % (self.event, self.item_id)
930
931
932class GroupEventParticipant(models.Model):
933 event = models.ForeignKey(GroupEvent, db_column='eid')
934 item_id = models.IntegerField()
935 account = models.ForeignKey(Account, db_column='uid')
936 item = models.ForeignKey(GroupEventItem, to_field='pkey')
937 pkey = models.CompositeField(event, account, item, primary_key=True)
938
939 nb = models.IntegerField()
940 flags = models.CharField(max_length=42)
941 paid = models.FloatField()
942 class Meta:
943 db_table = u'group_event_participants'
944
945 def __unicode__(self):
946 return u"%s to %s" % (self.account.hruid, self.item)
947
948
949# Group::misc
950# -----------
951
952
953class GroupAuth(models.Model):
954 #id = models.IntegerField(primary_key=True)
955 privkey = models.CharField(max_length=120, unique=True)
956 name = models.CharField(max_length=96)
957 datafields = models.CharField(max_length=765)
958 returnurls = models.CharField(max_length=765)
959 last_used = models.DateField(null=True, blank=True)
960 group = models.ForeignKey(Group, null=True, blank=True)
961 flags = models.CharField(max_length=63, blank=True)
962 class Meta:
963 db_table = u'group_auth'
964
965 def __unicode__(self):
966 return self.name
967
968
969# Logging
970# =======
971
972
973class IpWatch(models.Model):
974 state = models.CharField(max_length=27)
975 detection = models.DateField(null=True, blank=True)
976 last = models.DateTimeField()
977 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
978 description = models.TextField()
979 ip = models.IntegerField(primary_key=True)
980 mask = models.IntegerField()
981 class Meta:
982 db_table = u'ip_watch'
983
984 def __unicode__(self):
985 return self.ip
986
987
988class LogAction(models.Model):
989 #id = models.IntegerField(primary_key=True)
990 text = models.CharField(max_length=96)
991 description = models.CharField(max_length=765)
992 class Meta:
993 db_table = u'log_actions'
994
995 def __unicode__(self):
996 return self.text
997
998
999class LogSession(models.Model):
1000 #id = models.IntegerField(primary_key=True)
1001 auth = models.CharField(max_length=18)
1002 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True, related_name='sessions')
1003 start = models.DateTimeField()
1004 host = models.CharField(max_length=384)
1005 sauth = models.CharField(max_length=18)
1006 suid = models.ForeignKey(Account, null=True, db_column='suid', blank=True, related_name='su_sessions')
1007 browser = models.CharField(max_length=765)
1008 forward_host = models.CharField(max_length=384, blank=True)
1009 flags = models.CharField(max_length=15)
1010 ip = models.IntegerField()
1011 forward_ip = models.IntegerField(null=True, blank=True)
1012 class Meta:
1013 db_table = u'log_sessions'
1014
1015 def __unicode__(self):
1016 return u"%s: %s@%s" % (self.id, self.account.hruid, self.host)
1017
1018
1019class LogLastSession(models.Model):
1020 account = models.ForeignKey(Account, primary_key=True, db_column='uid')
1021 id = models.ForeignKey(LogSession, db_column='id')
1022 class Meta:
1023 db_table = u'log_last_sessions'
1024
1025 def __unicode__(self):
1026 return self.account.hruid
1027
1028
1029class LogEvent(models.Model):
1030 stamp = models.DateTimeField(primary_key=True)
1031 session = models.ForeignKey(LogSession, db_column='session')
1032 action = models.ForeignKey(LogAction, db_column='action')
1033 data = models.TextField(blank=True)
1034 class Meta:
1035 db_table = u'log_events'
1036
1037 def __unicode__(self):
1038 return u"%s@%s: %s" % (self.session_id, self.stamp, self.action.text)
1039
1040
1041# Newsletters
1042# ===========
1043
1044
1045class Newsletter(models.Model):
1046 #id = models.IntegerField(primary_key=True)
1047 group = models.ForeignKey(Group, unique=True)
1048 name = models.CharField(max_length=765)
1049 criteria = models.CharField(max_length=42, blank=True)
1050 class Meta:
1051 db_table = u'newsletters'
1052
1053 def __unicode__(self):
1054 return self.name
1055
1056
1057class NewsletterIssue(models.Model):
1058 nlid = models.ForeignKey(Newsletter, unique=True, db_column='nlid')
1059 #id = models.IntegerField(primary_key=True)
1060 date = models.DateField()
1061 send_before = models.DateTimeField(null=True, blank=True)
1062 state = models.CharField(max_length=21)
1063 sufb_json = models.TextField(blank=True)
1064 title = models.CharField(max_length=765)
1065 head = models.TextField()
1066 signature = models.TextField()
1067 short_name = models.CharField(max_length=48, unique=True, blank=True)
1068 mail_title = models.CharField(max_length=765)
1069 unsubscribe = models.IntegerField()
1070 reply_to = models.CharField(max_length=765)
1071 class Meta:
1072 db_table = u'newsletter_issues'
1073
1074 def __unicode__(self):
1075 return self.title
1076
1077
1078class NewsletterCat(models.Model):
1079 cid = models.AutoField(primary_key=True)
1080 nlid = models.ForeignKey(Newsletter, db_column='nlid')
1081 pos = models.IntegerField()
1082 title = models.CharField(max_length=384)
1083 class Meta:
1084 db_table = u'newsletter_cat'
1085
1086 def __unicode__(self):
1087 return self.title
1088
1089
1090class NewsletterArt(models.Model):
1091 issue = models.ForeignKey(NewsletterIssue, db_column='id')
1092 aid = models.IntegerField()
1093 pkey = models.CompositeField(issue, aid, primary_key=True)
1094 cid = models.ForeignKey(NewsletterCat, null=True, db_column='cid', blank=True)
1095 pos = models.IntegerField()
1096 title = models.TextField()
1097 body = models.TextField()
1098 append = models.TextField()
1099 class Meta:
1100 db_table = u'newsletter_art'
1101
1102 def __unicode__(self):
1103 return u"%s: %s" % (self.issue_id, self.title)
1104
1105
1106class NewsletterIns(models.Model):
1107 account = models.ForeignKey(Account, db_column='uid')
1108 nl = models.ForeignKey(Newsletter, db_column='nlid')
1109 pkey = models.CompositeField(account, nl, primary_key=True)
1110 last = models.ForeignKey(NewsletterIssue, null=True, db_column='last', blank=True)
1111 hash = models.CharField(max_length=96, blank=True)
1112 class Meta:
1113 db_table = u'newsletter_ins'
1114
1115 def __unicode__(self):
1116 return u"%s to %s" % (self.account.hruid, self.nl.title)
1117
1118
1119# Profile
1120# =======
1121
1122
1123class ProfileDisplay(models.Model):
1124 profile = models.OneToOneField(Profile, primary_key=True, db_column='pid')
1125 yourself = models.CharField(max_length=765)
1126 public_name = models.CharField(max_length=765)
1127 private_name = models.CharField(max_length=765)
1128 directory_name = models.CharField(max_length=765)
1129 short_name = models.CharField(max_length=765)
1130 sort_name = models.CharField(max_length=765)
1131 promo = models.CharField(max_length=765)
1132 class Meta:
1133 db_table = u'profile_display'
1134
1135 def __unicode__(self):
1136 return self.profile.hrpid
1137
1138
1139class ProfilePhone(models.Model):
1140 LINK_ADDRESS = 'address'
1141 LINK_PRO = 'pro'
1142 LINK_USER = 'user'
1143 LINK_HQ = 'hq'
1144 LINK_GROUP = 'group'
1145 LINK_CHOICES = (
1146 (LINK_ADDRESS, u"Address"),
1147 (LINK_PRO, u"Pro"),
1148 (LINK_USER, u"User"),
1149 (LINK_HQ, u"HQ"),
1150 (LINK_GROUP, u"Group"),
1151 )
1152
1153 KIND_FIXED = 'fixed'
1154 KIND_MOBILE = 'mobile'
1155 KIND_FAX = 'fax'
1156 KIND_CHOICES = (
1157 (KIND_FIXED, u"Fixed"),
1158 (KIND_MOBILE, u"Mobile"),
1159 (KIND_FAX, u"Fax"),
1160 )
1161
1162 profile = models.ForeignKey(Profile, db_column='pid', related_name='phones')
1163 link_type = models.CharField(max_length=21, choices=LINK_CHOICES)
1164 link_id = models.IntegerField()
1165 tel_id = models.IntegerField()
1166 pkey = models.CompositeField(profile, link_type, link_id, tel_id, primary_key=True)
1167
1168 tel_type = models.CharField(max_length=18, choices=KIND_CHOICES)
1169 search_tel = models.CharField(max_length=75)
1170 display_tel = models.CharField(max_length=90)
1171 pub = models.CharField(max_length=21)
1172 comment = models.CharField(max_length=240)
1173
1174 class Meta:
1175 db_table = u'profile_phones'
1176
1177 def __unicode__(self):
1178 return u"%s: %s (%s)" % (self.profile.hrpid, self.display_tel, self.tel_type)
1179
1180 @property
1181 def is_address(self):
1182 return self.link_type == self.LINK_ADDRESS
1183
1184 @property
1185 def is_job(self):
1186 return self.link_type == self.LINK_PRO
1187
1188 @property
1189 def ax_visible(self):
1190 return is_ax_visible(self.pub)
1191
1192
1193class ProfilePhoto(models.Model):
1194 profile = models.OneToOneField(Profile, primary_key=True, db_column='pid', related_name='photo')
1195 attachmime = models.CharField(max_length=12)
1196 attach = models.TextField()
1197 x = models.IntegerField()
1198 y = models.IntegerField()
1199 pub = models.CharField(max_length=21)
1200 last_update = models.DateTimeField()
1201 class Meta:
1202 db_table = u'profile_photos'
1203
1204 def __unicode__(self):
1205 return self.profile.hrpid
1206
1207
1208class ProfilePrivateName(models.Model):
1209 profile = models.ForeignKey(Profile, db_column='pid', related_name='private_name')
1210 type = models.CharField(max_length=27)
1211 id = models.IntegerField()
1212 pkey = models.CompositeField(profile, type, id, primary_key=True)
1213 name = models.CharField(max_length=765)
1214 class Meta:
1215 db_table = u'profile_private_names'
1216
1217 def __unicode__(self):
1218 return u"%s: %s" % (self.profile.hrpid, self.type)
1219
1220
1221class ProfilePublicName(models.Model):
1222 profile = models.OneToOneField(Profile, primary_key=True, db_column='pid', related_name='public_name')
1223 lastname_initial = models.CharField(max_length=765)
1224 lastname_main = models.CharField(max_length=765)
1225 lastname_marital = models.CharField(max_length=765)
1226 lastname_ordinary = models.CharField(max_length=765)
1227 firstname_initial = models.CharField(max_length=765)
1228 firstname_main = models.CharField(max_length=765)
1229 firstname_ordinary = models.CharField(max_length=765)
1230 pseudonym = models.CharField(max_length=765)
1231 class Meta:
1232 db_table = u'profile_public_names'
1233
1234 def __unicode__(self):
1235 return self.profile.hrpid
1236
1237
1238# Profile::addresses
1239# ------------------
1240
1241
1242class ProfileAddress(models.Model):
1243
1244 KIND_HOME = 'home'
1245 KIND_HQ = 'hq'
1246 KIND_JOB = 'job'
1247 KIND_GROUP = 'group'
1248
1249 KIND_CHOICES = (
1250 (KIND_HOME, u"Home"),
1251 (KIND_HQ, u"Headquarters"),
1252 (KIND_JOB, u"Job"),
1253 (KIND_GROUP, u"Group"),
1254 )
1255
1256 profile = models.ForeignKey(Profile, db_column='pid', related_name='addresses')
1257 job = models.ForeignKey('ProfileJobEnum', db_column='jobid', blank=True, null=True,
1258 related_name='addresses')
1259 #job = models.IntegerField(db_column='jobid')
1260 group = models.ForeignKey('Group', db_column='groupid', blank=True, null=True)
1261 #groupid = models.IntegerField()
1262 addr_type = models.CharField(max_length=15, db_column='type', choices=KIND_CHOICES)
1263 subid = models.IntegerField(db_column='id')
1264 pkey = models.CompositeField(profile, job, group, addr_type, subid, primary_key=True)
1265 pjob_key = models.CompositeField(profile, subid)
1266 pjob = models.ForeignKey('ProfileJob', aux_field='pjob_key')
1267
1268 flags = models.CharField(max_length=180, blank=True)
1269 text = models.TextField()
1270 postaltext = models.TextField(db_column='postalText') # Field name made lowercase.
1271 formatted_address = models.TextField()
1272 types = models.CharField(max_length=891)
1273 latitude = models.FloatField(null=True, blank=True)
1274 longitude = models.FloatField(null=True, blank=True)
1275 southwest_latitude = models.FloatField(null=True, blank=True)
1276 southwest_longitude = models.FloatField(null=True, blank=True)
1277 northeast_latitude = models.FloatField(null=True, blank=True)
1278 northeast_longitude = models.FloatField(null=True, blank=True)
1279 location_type = models.CharField(max_length=54, blank=True)
1280 partial_match = models.IntegerField()
1281 pub = models.CharField(max_length=21)
1282 comment = models.CharField(max_length=765, blank=True)
1283 geocoding_date = models.DateField(null=True, blank=True)
1284 geocoding_calls = models.IntegerField()
1285 postal_code_fr = models.CharField(max_length=15, blank=True)
1286
1287 components = models.ManyToManyField('ProfileAddressComponentEnum',
1288 through='ProfileAddressComponent', related_name='addresses')
1289
1290 class Meta:
1291 db_table = u'profile_addresses'
1292
1293 def __unicode__(self):
1294 if self.addr_type == self.KIND_HOME:
1295 rel = self.profile.hrpid
1296 elif self.addr_type == self.KIND_HQ:
1297 if self.jobid:
1298 rel = unicode(self.job)
1299 else:
1300 rel = u"[BADJOB]"
1301 elif self.addr_type == self.KIND_GROUP:
1302 rel = unicode(self.group)
1303 else:
1304 rel = u"%s at %s" % (self.profile.hrpid, self.pjob.company)
1305 return u"%s address %d for %s" % (
1306 self.get_addr_type_display(), self.subid, rel)
1307
1308 @property
1309 def ax_visible(self):
1310 return is_ax_visible(self.pub)
1311
1312 def get_components_by_type(self):
1313 flags = collections.defaultdict(list)
1314 for component in self.components.all():
1315 for cp_type in component.types.split(','):
1316 flags[cp_type].append(component)
1317 return flags
1318
1319 @property
1320 def flag_list(self):
1321 return self.flags.split(',')
1322
1323 FLAG_CURRENT = 'current'
1324 FLAG_MAIL = 'mail'
1325 FLAG_SECONDARY = 'secondary'
1326
1327 @property
1328 def current(self):
1329 return self.FLAG_CURRENT in self.flag_list
1330
1331 @property
1332 def mail(self):
1333 return self.FLAG_MAIL in self.flag_list
1334
1335 @property
1336 def secondary(self):
1337 return self.FLAG_SECONDARY in self.flag_list
1338
1339 @property
1340 def is_home(self):
1341 return self.addr_type == self.KIND_HOME
1342
1343 @property
1344 def is_job(self):
1345 return self.addr_type == self.KIND_JOB
1346
1347
1348class ProfileAddressComponentEnum(models.Model):
1349 #id = models.BigIntegerField(primary_key=True)
1350 short_name = models.CharField(max_length=765)
1351 long_name = models.CharField(max_length=765)
1352 types = models.CharField(max_length=891)
1353 class Meta:
1354 db_table = u'profile_addresses_components_enum'
1355
1356 def __unicode__(self):
1357 return u'%s (%s)' % (self.short_name, self.types)
1358
1359
1360class ProfileAddressComponent(models.Model):
1361 profile = models.ForeignKey(Profile, db_column='pid')
1362 job = models.ForeignKey('ProfileJobEnum', db_column='jobid')
1363 group = models.ForeignKey(Group, db_column='groupid', blank=True, null=True)
1364 addr_type = models.CharField(max_length=15, db_column='type')
1365 subid = models.IntegerField(db_column='id')
1366 pkey = models.CompositeField(profile, job, group, addr_type, subid, primary_key=True)
1367
1368 component = models.ForeignKey(ProfileAddressComponentEnum, related_name='component_links')
1369 address = models.ForeignKey(ProfileAddress, related_name='component_links',
1370 aux_field='pkey')
1371 class Meta:
1372 db_table = u'profile_addresses_components'
1373
1374 def __unicode__(self):
1375 return u"%s (%s) for %s" % (
1376 self.component.long_name,
1377 self.component.types,
1378 self.address,
1379 )
1380
1381
1382# Profile::networking
1383# -------------------
1384
1385
1386class ProfileBinetEnum(models.Model):
1387 #id = models.IntegerField(primary_key=True)
1388 text = models.CharField(max_length=150)
1389 url = models.CharField(max_length=765)
1390 class Meta:
1391 db_table = u'profile_binet_enum'
1392
1393
1394class ProfileBinet(models.Model):
1395 profile = models.ForeignKey(Profile, db_column='pid')
1396 binet = models.ForeignKey(ProfileBinetEnum)
1397 pkey = models.CompositeField(profile, binet, primary_key=True)
1398 class Meta:
1399 db_table = u'profile_binets'
1400
1401
1402class ProfileHobby(models.Model):
1403 profile = models.ForeignKey(Profile, db_column='pid')
1404 id = models.IntegerField()
1405 pkey = models.CompositeField(profile, id, primary_key=True)
1406 type = models.CharField(max_length=18)
1407 text = models.CharField(max_length=765)
1408 pub = models.CharField(max_length=21)
1409 class Meta:
1410 db_table = u'profile_hobby'
1411
1412
1413class ProfileNetworkingEnum(models.Model):
1414 nwid = models.IntegerField(primary_key=True)
1415 name = models.CharField(max_length=90)
1416 icon = models.CharField(max_length=150)
1417 filter = models.CharField(max_length=18)
1418 network_type = models.CharField(max_length=18)
1419 link = models.CharField(max_length=765)
1420 class Meta:
1421 db_table = u'profile_networking_enum'
1422
1423
1424class ProfileNetworking(models.Model):
1425 profile = models.ForeignKey(Profile, db_column='pid')
1426 id = models.IntegerField()
1427 nwid = models.ForeignKey(ProfileNetworkingEnum, db_column='nwid')
1428 pkey = models.CompositeField(id, nwid, primary_key=True)
1429 address = models.CharField(max_length=765)
1430 pub = models.CharField(max_length=21)
1431 class Meta:
1432 db_table = u'profile_networking'
1433
1434
1435# Profile::corps
1436# --------------
1437
1438
1439class ProfileCorpsEnum(models.Model):
1440 #id = models.IntegerField(primary_key=True)
1441 name = models.CharField(max_length=255, unique=True)
1442 abbreviation = models.CharField(max_length=15, unique=True)
1443 still_exists = models.IntegerField()
1444 class Meta:
1445 db_table = u'profile_corps_enum'
1446
1447 def __unicode__(self):
1448 return self.name
1449
1450
1451class ProfileCorpsRankEnum(models.Model):
1452 #id = models.IntegerField(primary_key=True)
1453 name = models.CharField(max_length=255, unique=True)
1454 abbreviation = models.CharField(max_length=15, unique=True)
1455 class Meta:
1456 db_table = u'profile_corps_rank_enum'
1457
1458 def __unicode__(self):
1459 return self.name
1460
1461
1462class ProfileCorps(models.Model):
1463 profile = models.OneToOneField(Profile, primary_key=True, db_column='pid')
1464 original = models.ForeignKey(ProfileCorpsEnum, db_column='original_corpsid', related_name='original_members')
1465 current = models.ForeignKey(ProfileCorpsEnum, db_column='current_corpsid', related_name='current_members')
1466 rank = models.ForeignKey(ProfileCorpsRankEnum, db_column='rankid')
1467 # Ignored: corps is public information anyway.
1468 corps_pub = models.CharField(max_length=21)
1469 class Meta:
1470 db_table = u'profile_corps'
1471
1472 def __unicode__(self):
1473 return u"%s: %s" % (self.profile.hrpid, self.current.name)
1474
1475
1476# Profile::edu
1477# ------------
1478
1479
1480class ProfileEducationEnum(models.Model):
1481 #id = models.IntegerField(primary_key=True)
1482 name = models.CharField(max_length=255, unique=True, blank=True)
1483 abbreviation = models.CharField(max_length=765)
1484 url = models.CharField(max_length=765, blank=True)
1485 country = models.ForeignKey(GeolocCountry, null=True, db_column='country', blank=True)
1486 class Meta:
1487 db_table = u'profile_education_enum'
1488
1489 def __unicode__(self):
1490 return self.name
1491
1492 @property
1493 def short(self):
1494 return self.abbreviation or self.name
1495
1496
1497class ProfileEducationDegreeEnum(models.Model):
1498 #id = models.IntegerField(primary_key=True)
1499 degree = models.CharField(max_length=255, unique=True, blank=True)
1500 abbreviation = models.CharField(max_length=765)
1501 level = models.IntegerField()
1502 class Meta:
1503 db_table = u'profile_education_degree_enum'
1504
1505 def __unicode__(self):
1506 return self.degree
1507
1508
1509class ProfileEducationFieldEnum(models.Model):
1510 #id = models.IntegerField(primary_key=True)
1511 field = models.CharField(max_length=255, unique=True, blank=True)
1512 class Meta:
1513 db_table = u'profile_education_field_enum'
1514
1515 def __unicode__(self):
1516 return self.field
1517
1518
1519class ProfileEducation(models.Model):
1520 id = models.IntegerField()
1521 profile = models.ForeignKey(Profile, db_column='pid', related_name='educations')
1522 pkey = models.CompositeField(id, profile, primary_key=True)
1523
1524 school = models.ForeignKey(ProfileEducationEnum, null=True, db_column='eduid', blank=True)
1525 degree = models.ForeignKey(ProfileEducationDegreeEnum, null=True, db_column='degreeid', blank=True)
1526 field = models.ForeignKey(ProfileEducationFieldEnum, null=True, db_column='fieldid', blank=True)
1527 entry_year = models.IntegerField(null=True, blank=True)
1528 grad_year = models.IntegerField(null=True, blank=True)
1529 promo_year = models.IntegerField(null=True, blank=True)
1530 program = models.CharField(max_length=765, blank=True)
1531 flags = models.CharField(max_length=81)
1532 class Meta:
1533 db_table = u'profile_education'
1534
1535 def __unicode__(self):
1536 return u"%s: %s" % (self.profile.hrpid, self.edu.name)
1537
1538
1539class ProfileEducationDegree(models.Model):
1540 edu = models.ForeignKey(ProfileEducationEnum, db_column='eduid')
1541 degree = models.ForeignKey(ProfileEducationDegreeEnum, db_column='degreeid')
1542 pkey = models.CompositeField(edu, degree, primary_key=True)
1543 class Meta:
1544 db_table = u'profile_education_degree'
1545
1546 def __unicode__(self):
1547 return u"%s - %s" % (self.edu, self.degree)
1548
1549
1550# Profile::jobs
1551# -------------
1552
1553
1554class ProfileJobEnum(models.Model):
1555 #id = models.IntegerField(primary_key=True)
1556 name = models.CharField(max_length=255, unique=True)
1557 acronym = models.CharField(max_length=765, blank=True)
1558 url = models.CharField(max_length=765, blank=True)
1559 email = models.CharField(max_length=765, blank=True)
1560 holding = models.ForeignKey('self', null=True, db_column='holdingid', blank=True)
1561 naf_code = models.CharField(max_length=15, db_column='NAF_code', blank=True) # Field name made lowercase.
1562 ax_code = models.BigIntegerField(null=True, db_column='AX_code', blank=True) # Field name made lowercase.
1563 siren_code = models.CharField(max_length=9, null=True, db_column='SIREN_code', blank=True) # Field name made lowercase.
1564 class Meta:
1565 db_table = u'profile_job_enum'
1566
1567 def __unicode__(self):
1568 return self.name
1569
1570 @property
1571 def address(self):
1572 if not hasattr(self, '_address'):
1573
1574 self._address = None
1575 for address in self.addresses.all():
1576 if address.addr_type == address.KIND_HQ:
1577 self._address = address
1578 break
1579 return self._address
1580
1581
1582class ProfileJob(models.Model):
1583 id = models.IntegerField()
1584 profile = models.ForeignKey(Profile, db_column='pid', related_name='jobs')
1585 pkey = models.CompositeField(profile, id, primary_key=True)
1586
1587 company = models.ForeignKey(ProfileJobEnum, null=True, db_column='jobid', blank=True)
1588 description = models.CharField(max_length=765)
1589 url = models.CharField(max_length=765)
1590 email = models.CharField(max_length=765)
1591 pub = models.CharField(max_length=21)
1592 email_pub = models.CharField(max_length=21)
1593 entry_year = models.CharField(max_length=12, blank=True)
1594 class Meta:
1595 db_table = u'profile_job'
1596
1597 @property
1598 def ax_visible(self):
1599 return is_ax_visible(self.pub)
1600
1601 @property
1602 def ax_visible_email(self):
1603 return is_ax_visible(self.email_pub)
1604
1605 def __unicode__(self):
1606 return u"%s at %s" % (self.profile.hrpid, self.company.name if self.company else '<NONE>')
1607
1608
1609# Profile::job::terms
1610# -------------------
1611
1612
1613class ProfileJobTermEnum(models.Model):
1614 jtid = models.AutoField(primary_key=True)
1615 name = models.CharField(max_length=765)
1616 full_name = models.CharField(max_length=765)
1617 class Meta:
1618 db_table = u'profile_job_term_enum'
1619
1620 def __unicode__(self):
1621 return self.name
1622
1623
1624class ProfileJobTermRelation(models.Model):
1625 jtid_1 = models.ForeignKey(ProfileJobTermEnum, db_column='jtid_1', related_name='relations_from')
1626 jtid_2 = models.ForeignKey(ProfileJobTermEnum, db_column='jtid_2', related_name='relations_to')
1627 rel = models.CharField(max_length=24)
1628 computed = models.CharField(max_length=24)
1629 pkey = models.CompositeField(jtid_1, jtid_2, computed, primary_key=True)
1630 class Meta:
1631 db_table = u'profile_job_term_relation'
1632
1633 def __unicode__(self):
1634 return u"%s <-> %s" % (self.jtid_1.name, self.jtid_2.name)
1635
1636
1637class ProfileJobTermSearch(models.Model):
1638 search = models.CharField(max_length=150)
1639 job_term = models.ForeignKey(ProfileJobTermEnum, db_column='jtid')
1640 pkey = models.CompositeField(search, job_term, primary_key=True)
1641 class Meta:
1642 db_table = u'profile_job_term_search'
1643
1644 def __unicode__(self):
1645 return u"%s => %s" % (self.search, self.job_term.name)
1646
1647
1648class ProfileJobTerm(models.Model):
1649 profile = models.ForeignKey(Profile, db_column='pid')
1650 company = models.ForeignKey(ProfileJobEnum, db_column='jid')
1651 job = models.ForeignKey(ProfileJob, to_field='pkey')
1652 job_term = models.ForeignKey(ProfileJobTermEnum, db_column='jtid')
1653 computed = models.CharField(max_length=24)
1654 pkey = models.CompositeField(profile, company, job_term, primary_key=True)
1655 class Meta:
1656 db_table = u'profile_job_term'
1657
1658 def __unicode__(self):
1659 return u"%s at %s: %s" % (self.profile.hrpid, self.company.name, self.job_term.name)
1660
1661
1662class ProfileJobEntrepriseTerm(models.Model):
1663 job = models.ForeignKey(ProfileJobEnum, db_column='eid')
1664 job_term = models.ForeignKey(ProfileJobTermEnum, db_column='jtid')
1665 pkey = models.CompositeField(job, job_term, primary_key=True)
1666 class Meta:
1667 db_table = u'profile_job_entreprise_term'
1668
1669 def __unicode__(self):
1670 return u"%s: %s" % (self.job.name, self.job_term.name)
1671
1672
1673# Profile::skills
1674# ---------------
1675
1676
1677class ProfileLangSkillEnum(models.Model):
1678 iso_639_2b = models.CharField(max_length=9, primary_key=True)
1679 language = models.CharField(max_length=765)
1680 language_en = models.CharField(max_length=765)
1681 iso_639_2t = models.CharField(max_length=9)
1682 iso_639_1 = models.CharField(max_length=6, blank=True)
1683 class Meta:
1684 db_table = u'profile_langskill_enum'
1685
1686 def __unicode__(self):
1687 return self.iso_639_2b
1688
1689
1690class ProfileLangSkill(models.Model):
1691 profile = models.ForeignKey(Profile, db_column='pid')
1692 lang = models.ForeignKey(ProfileLangSkillEnum, db_column='lid')
1693 pkey = models.CompositeField(profile, lang, primary_key=True)
1694 level = models.IntegerField(null=True, blank=True)
1695 class Meta:
1696 db_table = u'profile_langskills'
1697
1698 def __unicode__(self):
1699 return u"%s: %s" % (self.profile.hrpid, self.lang.iso_639_2b)
1700
1701
1702class ProfileSkillEnum(models.Model):
1703 id = models.CharField(max_length=9, primary_key=True)
1704 text_fr = models.CharField(max_length=330)
1705 text_en = models.CharField(max_length=330)
1706 flags = models.CharField(max_length=15)
1707 axfreetext = models.TextField()
1708 class Meta:
1709 db_table = u'profile_skill_enum'
1710
1711 def __unicode__(self):
1712 return self.text_en
1713
1714
1715class ProfileSkill(models.Model):
1716 profile = models.ForeignKey(Profile, db_column='pid')
1717 skill = models.ForeignKey(ProfileSkillEnum, db_column='cid')
1718 pkey = models.CompositeField(profile, skill, primary_key=True)
1719 level = models.CharField(max_length=54)
1720 class Meta:
1721 db_table = u'profile_skills'
1722
1723 def __unicode__(self):
1724 return u"%s: %s" % (self.profile.hrpid, self.skill.text_en)
1725
1726
1727# Profile::medals
1728# ---------------
1729
1730
1731class ProfileMedalEnum(models.Model):
1732 #id = models.IntegerField(primary_key=True)
1733 type = models.CharField(max_length=30)
1734 text = models.CharField(max_length=765, blank=True)
1735 img = models.CharField(max_length=765, blank=True)
1736 flags = models.CharField(max_length=63)
1737 class Meta:
1738 db_table = u'profile_medal_enum'
1739
1740
1741class ProfileMedalGradeEnum(models.Model):
1742 medal = models.ForeignKey(ProfileMedalEnum, db_column='mid')
1743 gid = models.IntegerField()
1744 pkey = models.CompositeField(medal, gid, primary_key=True)
1745 text = models.CharField(max_length=765, blank=True)
1746 pos = models.IntegerField()
1747 class Meta:
1748 db_table = u'profile_medal_grade_enum'
1749
1750
1751class ProfileMedal(models.Model):
1752 profile = models.ForeignKey(Profile, db_column='pid')
1753 medal = models.ForeignKey(ProfileMedalEnum)
1754 gid = models.IntegerField()
1755 grade = models.ForeignKey(ProfileMedalGradeEnum, to_field='pkey')
1756 pkey = models.CompositeField(profile, medal, gid, primary_key=True)
1757 level = models.CharField(max_length=18)
1758 class Meta:
1759 db_table = u'profile_medals'
1760
1761
1762# Profile::mentor
1763# ---------------
1764
1765
1766class ProfileMentor(models.Model):
1767 profile = models.OneToOneField(Profile, primary_key=True, db_column='pid')
1768 expertise = models.TextField()
1769 class Meta:
1770 db_table = u'profile_mentor'
1771
1772
1773class ProfileMentorCountry(models.Model):
1774 profile = models.ForeignKey(Profile, db_column='pid')
1775 country = models.ForeignKey(GeolocCountry, db_column='country')
1776 pkey = models.CompositeField(profile, country, primary_key=True)
1777 class Meta:
1778 db_table = u'profile_mentor_country'
1779
1780
1781class ProfileMentorTerm(models.Model):
1782 profile = models.ForeignKey(Profile, db_column='pid')
1783 job_term = models.ForeignKey(ProfileJobTermEnum, db_column='jtid')
1784 pkey = models.CompositeField(profile, job_term, primary_key=True)
1785 class Meta:
1786 db_table = u'profile_mentor_term'
1787
1788
1789# Profile::partner
1790# ----------------
1791
1792
1793class ProfilePartnersharingEnum(models.Model):
1794 #id = models.IntegerField(primary_key=True)
1795 api_account = models.ForeignKey(Account, null=True, db_column='api_uid', blank=True)
1796 shortname = models.CharField(max_length=192)
1797 name = models.CharField(max_length=765)
1798 url = models.CharField(max_length=765)
1799 default_sharing_level = models.CharField(max_length=21, blank=True)
1800 has_directory = models.IntegerField()
1801 has_bulkmail = models.IntegerField()
1802 class Meta:
1803 db_table = u'profile_partnersharing_enum'
1804
1805
1806class ProfilePartnersharingSetting(models.Model):
1807 profile = models.ForeignKey(Profile, db_column='pid')
1808 partner = models.ForeignKey(ProfilePartnersharingEnum)
1809 pkey = models.CompositeField(profile, partner, primary_key=True)
1810 exposed_uid = models.CharField(max_length=765)
1811 sharing_level = models.CharField(max_length=21, blank=True)
1812 allow_email = models.CharField(max_length=18, blank=True)
1813 last_connection = models.DateTimeField(null=True, blank=True)
1814 class Meta:
1815 db_table = u'profile_partnersharing_settings'
1816
1817
1818class ProfilePhotoToken(models.Model):
1819 profile = models.ForeignKey(Profile, primary_key=True, db_column='pid')
1820 token = models.CharField(max_length=765)
1821 expires = models.DateTimeField()
1822 class Meta:
1823 db_table = u'profile_photo_tokens'
1824
1825
1826# Profile::misc
1827# -------------
1828
1829
1830class ProfileMergeIssue(models.Model):
1831 profile = models.ForeignKey(Profile, primary_key=True, db_column='pid')
1832 issues = models.CharField(max_length=144, blank=True)
1833 entry_year_ax = models.IntegerField(null=True, blank=True)
1834 deathdate_ax = models.DateField(null=True, blank=True)
1835 name = models.CharField(max_length=765, blank=True)
1836 name_type = models.IntegerField(null=True, blank=True)
1837 class Meta:
1838 db_table = u'profile_merge_issues'
1839
1840
1841class ProfileModification(models.Model):
1842 profile = models.ForeignKey(Profile, db_column='pid')
1843 account = models.ForeignKey(Account, db_column='uid')
1844 field = models.CharField(max_length=180)
1845 pkey = models.CompositeField(profile, field, primary_key=True)
1846 oldtext = models.TextField(db_column='oldText')
1847 newtext = models.TextField(db_column='newText')
1848 type = models.CharField(max_length=33)
1849 timestamp = models.DateTimeField()
1850 class Meta:
1851 db_table = u'profile_modifications'
1852
1853
1854class ProfileVisibilityEnum(models.Model):
1855 access_level = models.CharField(max_length=21, blank=True, primary_key=True)
1856 best_display_level = models.CharField(max_length=21, blank=True)
1857 display_levels = models.CharField(max_length=72, blank=True)
1858 class Meta:
1859 db_table = u'profile_visibility_enum'
1860
1861
1862
1863class ProfileDeltaten(models.Model):
1864 profile = models.OneToOneField(Profile, primary_key=True, db_column='pid')
1865 message = models.TextField()
1866 class Meta:
1867 db_table = u'profile_deltaten'
1868
1869
1870# Reminders
1871# =========
1872
1873
1874class ReminderType(models.Model):
1875 #type_id = models.IntegerField(primary_key=True)
1876 name = models.CharField(max_length=255, unique=True)
1877 weight = models.IntegerField()
1878 remind_delay_yes = models.IntegerField()
1879 remind_delay_no = models.IntegerField()
1880 remind_delay_dismiss = models.IntegerField()
1881 class Meta:
1882 db_table = u'reminder_type'
1883
1884
1885class Reminder(models.Model):
1886 account = models.ForeignKey(Account, db_column='uid')
1887 type = models.ForeignKey(ReminderType)
1888 pkey = models.CompositeField(account, type, primary_key=True)
1889 status = models.CharField(max_length=21)
1890 remind_last = models.DateTimeField()
1891 remind_next = models.DateTimeField(null=True, blank=True)
1892 class Meta:
1893 db_table = u'reminder'
1894
1895
1896class ReminderTip(models.Model):
1897 #id = models.IntegerField(primary_key=True)
1898 title = models.CharField(max_length=192)
1899 text = models.TextField()
1900 priority = models.IntegerField()
1901 expiration = models.DateField()
1902 promo_min = models.IntegerField()
1903 promo_max = models.IntegerField()
1904 state = models.CharField(max_length=18)
1905 class Meta:
1906 db_table = u'reminder_tips'
1907
1908
1909# Surveys
1910# =======
1911
1912
1913class Survey(models.Model):
1914 #id = models.IntegerField(primary_key=True)
1915 questions = models.TextField()
1916 title = models.CharField(max_length=765)
1917 description = models.TextField()
1918 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
1919 end = models.DateField()
1920 mode = models.IntegerField()
1921 promos = models.CharField(max_length=765)
1922 class Meta:
1923 db_table = u'surveys'
1924
1925
1926class SurveyVote(models.Model):
1927 #id = models.IntegerField(primary_key=True)
1928 survey = models.ForeignKey(Survey)
1929 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
1930 class Meta:
1931 db_table = u'survey_votes'
1932
1933
1934class SurveyAnswer(models.Model):
1935 #id = models.IntegerField(primary_key=True)
1936 vote = models.ForeignKey(SurveyVote)
1937 question_id = models.IntegerField()
1938 answer = models.TextField()
1939 class Meta:
1940 db_table = u'survey_answers'
1941
1942
1943# GApps
1944# =====
1945
1946
1947class GappsAccount(models.Model):
1948 l_userid = models.ForeignKey(Account, null=True, db_column='l_userid', blank=True)
1949 l_sync_password = models.BooleanField(default=True)
1950 l_activate_mail_redirection = models.BooleanField(default=True)
1951 g_account_id = models.CharField(max_length=48, blank=True)
1952 g_account_name = models.CharField(max_length=255, primary_key=True)
1953 g_domain = models.CharField(max_length=120, blank=True)
1954 g_first_name = models.CharField(max_length=120)
1955 g_last_name = models.CharField(max_length=120)
1956 g_status = models.CharField(max_length=39, blank=True)
1957 g_admin = models.BooleanField()
1958 g_suspension = models.CharField(max_length=768, blank=True)
1959 r_disk_usage = models.BigIntegerField(null=True, blank=True)
1960 r_creation = models.DateField(null=True, blank=True)
1961 r_last_login = models.DateField(null=True, blank=True)
1962 r_last_webmail = models.DateField(null=True, blank=True)
1963 class Meta:
1964 db_table = u'gapps_accounts'
1965
1966
1967class GappsNickname(models.Model):
1968 l_userid = models.ForeignKey(Account, null=True, db_column='l_userid', blank=True)
1969 g_account_name = models.CharField(max_length=768)
1970 g_nickname = models.CharField(max_length=255, primary_key=True)
1971 class Meta:
1972 db_table = u'gapps_nicknames'
1973
1974
1975class GappsQueue(models.Model):
1976 q_id = models.AutoField(primary_key=True)
1977 q_owner = models.ForeignKey(Account, null=True, blank=True, related_name='owned_gapps_jobs')
1978 q_recipient = models.ForeignKey(Account, null=True, blank=True, related_name='received_gapps_jobs')
1979 p_entry_date = models.DateTimeField()
1980 p_notbefore_date = models.DateTimeField()
1981 p_start_date = models.DateTimeField(null=True, blank=True)
1982 p_end_date = models.DateTimeField(null=True, blank=True)
1983 p_status = models.CharField(max_length=24)
1984 p_priority = models.CharField(max_length=27)
1985 p_admin_request = models.BooleanField()
1986 j_type = models.CharField(max_length=30)
1987 j_parameters = models.TextField(blank=True)
1988 r_softfail_date = models.DateTimeField(null=True, blank=True)
1989 r_softfail_count = models.IntegerField()
1990 r_result = models.CharField(max_length=768, blank=True)
1991 class Meta:
1992 db_table = u'gapps_queue'
1993
1994
1995class GappsReporting(models.Model):
1996 date = models.DateField(primary_key=True)
1997 num_accounts = models.IntegerField(null=True, blank=True)
1998 count_1_day_actives = models.IntegerField(null=True, blank=True)
1999 count_7_day_actives = models.IntegerField(null=True, blank=True)
2000 count_14_day_actives = models.IntegerField(null=True, blank=True)
2001 count_30_day_actives = models.IntegerField(null=True, blank=True)
2002 count_30_day_idle = models.IntegerField(null=True, blank=True)
2003 count_60_day_idle = models.IntegerField(null=True, blank=True)
2004 count_90_day_idle = models.IntegerField(null=True, blank=True)
2005 usage_in_bytes = models.BigIntegerField(null=True, blank=True)
2006 quota_in_mb = models.IntegerField(null=True, blank=True)
2007 class Meta:
2008 db_table = u'gapps_reporting'
2009
2010
2011
2012# Watch
2013# =====
2014
2015
2016class Watch(models.Model):
2017 account = models.ForeignKey(Account, primary_key=True, db_column='uid')
2018 flags = models.CharField(max_length=39)
2019 actions = models.CharField(max_length=105)
2020 last = models.DateTimeField()
2021 class Meta:
2022 db_table = u'watch'
2023
2024
2025class WatchGroup(models.Model):
2026 account = models.ForeignKey(Account, db_column='uid')
2027 group = models.ForeignKey(Group, db_column='groupid')
2028 pkey = models.CompositeField(account, group, primary_key=True)
2029 class Meta:
2030 db_table = u'watch_group'
2031
2032
2033class WatchNonins(models.Model):
2034 account = models.ForeignKey(Account, db_column='uid', related_name='watching')
2035 watched = models.ForeignKey(Account, db_column='ni', related_name='watched_by')
2036 pkey = models.CompositeField(account, watched, primary_key=True)
2037 class Meta:
2038 db_table = u'watch_nonins'
2039
2040
2041class WatchProfile(models.Model):
2042 profile = models.ForeignKey(Profile, db_column='pid')
2043 ts = models.DateTimeField()
2044 field = models.CharField(max_length=36)
2045 pkey = models.CompositeField(profile, field, primary_key=True)
2046 class Meta:
2047 db_table = u'watch_profile'
2048
2049
2050class WatchPromo(models.Model):
2051 account = models.ForeignKey(Account, db_column='uid')
2052 promo = models.IntegerField()
2053 pkey = models.CompositeField(account, promo, primary_key=True)
2054 class Meta:
2055 db_table = u'watch_promo'
2056
2057
2058# Postfix
2059# =======
2060
2061
2062class MxWatch(models.Model):
2063 host = models.CharField(max_length=192, primary_key=True)
2064 state = models.CharField(max_length=21, blank=True)
2065 text = models.TextField()
2066 class Meta:
2067 db_table = u'mx_watch'
2068
2069
2070class PostfixBlacklist(models.Model):
2071 email = models.CharField(max_length=255, primary_key=True)
2072 reject_text = models.CharField(max_length=192)
2073 class Meta:
2074 db_table = u'postfix_blacklist'
2075
2076
2077class PostfixMailseen(models.Model):
2078 crc = models.CharField(max_length=24, primary_key=True)
2079 nb = models.IntegerField()
2080 update_time = models.DateTimeField()
2081 create_time = models.DateTimeField()
2082 release = models.CharField(max_length=18)
2083 class Meta:
2084 db_table = u'postfix_mailseen'
2085
2086
2087class PostfixWhitelist(models.Model):
2088 email = models.CharField(max_length=255, primary_key=True)
2089 class Meta:
2090 db_table = u'postfix_whitelist'
2091
2092
2093# Register
2094# ========
2095
2096
2097class RegisterMarketing(models.Model):
2098 account = models.ForeignKey(Account, db_column='uid', related_name='received_marketings')
2099 sender = models.ForeignKey(Account, null=True, db_column='sender', blank=True, related_name='sent_marketings')
2100 email = models.CharField(max_length=765)
2101 pkey = models.CompositeField(account, email, primary_key=True)
2102
2103 date = models.DateField()
2104 last = models.DateField()
2105 nb = models.IntegerField()
2106 type = models.CharField(max_length=15, blank=True)
2107 hash = models.CharField(max_length=96)
2108 message = models.CharField(max_length=48)
2109 message_data = models.CharField(max_length=192, blank=True)
2110 personal_notes = models.TextField(blank=True)
2111 class Meta:
2112 db_table = u'register_marketing'
2113
2114
2115class RegisterMstat(models.Model):
2116 account = models.OneToOneField(Account, primary_key=True, db_column='uid', related_name='received_marketings_stats')
2117 sender = models.ForeignKey(Account, null=True, db_column='sender', blank=True, related_name='sent_marketings_stats')
2118 success = models.DateField()
2119 class Meta:
2120 db_table = u'register_mstats'
2121
2122
2123class RegisterPending(models.Model):
2124 account = models.OneToOneField(Account, primary_key=True, db_column='uid')
2125 forlife = models.CharField(max_length=255, unique=True)
2126 bestalias = models.CharField(max_length=255, unique=True)
2127 mailorg2 = models.CharField(max_length=765, blank=True)
2128 password = models.CharField(max_length=120)
2129 email = models.CharField(max_length=765)
2130 date = models.DateField()
2131 relance = models.DateField()
2132 naissance = models.DateField()
2133 hash = models.CharField(max_length=36)
2134 services = models.CharField(max_length=78)
2135 class Meta:
2136 db_table = u'register_pending'
2137
2138
2139class RegisterPendingXnet(models.Model):
2140 account = models.ForeignKey(Account, primary_key=True, db_column='uid', related_name='pending_xnet_register')
2141 hruid = models.ForeignKey(Account, unique=True, db_column='hruid', related_name='pending_xnet_register_by_hruid')
2142 email = models.CharField(max_length=765)
2143 date = models.DateField()
2144 last_date = models.DateField(null=True, blank=True)
2145 hash = models.CharField(max_length=36)
2146 sender_name = models.CharField(max_length=765)
2147 group_name = models.CharField(max_length=765)
2148 class Meta:
2149 db_table = u'register_pending_xnet'
2150
2151
2152class RegisterSubs(models.Model):
2153 account = models.ForeignKey(Account, db_column='uid')
2154 type = models.CharField(max_length=15)
2155 sub = models.CharField(max_length=96)
2156 domain = models.CharField(max_length=192)
2157 pkey = models.CompositeField(account, type, sub, domain, primary_key=True)
2158 class Meta:
2159 db_table = u'register_subs'
2160
2161
2162# Search
2163# ======
2164
2165
2166class SearchAutocomplete(models.Model):
2167 name = models.CharField(max_length=60)
2168 query = models.CharField(max_length=300)
2169 pkey = models.CompositeField(name, query, primary_key=True)
2170 result = models.TextField()
2171 generated = models.DateTimeField()
2172 class Meta:
2173 db_table = u'search_autocomplete'
2174
2175
2176class SearchName(models.Model):
2177 profile = models.ForeignKey(Profile, db_column='pid')
2178 token = models.CharField(max_length=765)
2179 pkey = models.CompositeField(profile, token, primary_key=True)
2180 score = models.IntegerField()
2181 soundex = models.CharField(max_length=12)
2182 flags = models.CharField(max_length=18)
2183 general_type = models.CharField(max_length=27)
2184 class Meta:
2185 db_table = u'search_name'
2186
2187
2188# Requests
2189# ========
2190
2191
2192class Request(models.Model):
2193 account = models.ForeignKey(Account, db_column='uid')
2194 type = models.CharField(max_length=48)
2195 data = models.TextField()
2196 stamp = models.DateTimeField()
2197 profile = models.ForeignKey(Profile, null=True, db_column='pid', blank=True)
2198 pkey = models.CompositeField(account, stamp, type, primary_key=True)
2199 class Meta:
2200 db_table = u'requests'
2201
2202
2203class RequestAnswer(models.Model):
2204 #id = models.IntegerField(primary_key=True)
2205 category = models.CharField(max_length=45)
2206 title = models.CharField(max_length=150)
2207 answer = models.TextField()
2208 class Meta:
2209 db_table = u'requests_answers'
2210
2211
2212class RequestHidden(models.Model):
2213 account = models.ForeignKey(Account, primary_key=True, db_column='uid')
2214 hidden_requests = models.TextField()
2215 class Meta:
2216 db_table = u'requests_hidden'
2217
2218
2219# Misc
2220# ====
2221
2222
2223class AXLetter(models.Model):
2224 #id = models.IntegerField(primary_key=True)
2225 short_name = models.CharField(max_length=48, unique=True, blank=True)
2226 subject = models.CharField(max_length=765)
2227 title = models.CharField(max_length=765)
2228 body = models.TextField()
2229 signature = models.TextField()
2230 promo_min = models.IntegerField()
2231 promo_max = models.IntegerField()
2232 subset = models.TextField(blank=True)
2233 subset_rm = models.IntegerField(null=True, blank=True)
2234 echeance = models.DateTimeField()
2235 date = models.DateField()
2236 bits = models.CharField(max_length=48)
2237 class Meta:
2238 db_table = u'axletter'
2239
2240
2241class Carva(models.Model):
2242 account = models.ForeignKey(Account, primary_key=True, db_column='uid')
2243 url = models.CharField(max_length=765)
2244 class Meta:
2245 db_table = u'carvas'
2246
2247
2248class Contact(models.Model):
2249 account = models.ForeignKey(Account, db_column='uid')
2250 contact = models.ForeignKey(Profile, db_column='contact')
2251 pkey = models.CompositeField(account, contact, primary_key=True)
2252 class Meta:
2253 db_table = u'contacts'
2254
2255
2256class Downtime(models.Model):
2257 debut = models.DateTimeField()
2258 duree = models.TimeField() # This field type is a guess.
2259 resume = models.CharField(max_length=765)
2260 description = models.TextField()
2261 services = models.CharField(max_length=54)
2262 class Meta:
2263 db_table = u'downtimes'
2264
2265
2266class EmailListModerate(models.Model):
2267 ml = models.CharField(max_length=192)
2268 domain = models.CharField(max_length=192)
2269 mid = models.IntegerField()
2270 pkey = models.CompositeField(ml, domain, mid, primary_key=True)
2271 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
2272 action = models.CharField(max_length=18)
2273 ts = models.DateTimeField()
2274 message = models.TextField(blank=True)
2275 handler = models.IntegerField(null=True, blank=True)
2276 class Meta:
2277 db_table = u'email_list_moderate'
2278
2279
2280class EmailSendSave(models.Model):
2281 account = models.OneToOneField(Account, primary_key=True, db_column='uid')
2282 data = models.TextField()
2283 class Meta:
2284 db_table = u'email_send_save'
2285
2286
2287class EmailWatch(models.Model):
2288 email = models.CharField(max_length=180, primary_key=True)
2289 state = models.CharField(max_length=27)
2290 detection = models.DateField(null=True, blank=True)
2291 last = models.DateTimeField()
2292 account = models.ForeignKey(Account, null=True, db_column='uid', blank=True)
2293 description = models.TextField()
2294 class Meta:
2295 db_table = u'email_watch'
2296
2297
2298class GeolocLanguage(models.Model):
2299 iso_3166_1_a2 = models.ForeignKey(GeolocCountry, db_column='iso_3166_1_a2')
2300 language = models.CharField(max_length=15)
2301 pkey = models.CompositeField(iso_3166_1_a2, language, primary_key=True)
2302 country = models.CharField(max_length=765, blank=True)
2303 countryplain = models.CharField(max_length=765, db_column='countryPlain', blank=True) # Field name made lowercase.
2304 class Meta:
2305 db_table = u'geoloc_languages'
2306
2307
2308class HomonymList(models.Model):
2309 hrmid = models.CharField(max_length=765)
2310 account = models.ForeignKey(Account, db_column='uid')
2311 pkey = models.CompositeField(hrmid, account, primary_key=True)
2312 class Meta:
2313 db_table = u'homonyms_list'
2314
2315
2316class UrlShortener(models.Model):
2317 alias = models.CharField(max_length=255, primary_key=True)
2318 url = models.TextField()
2319 class Meta:
2320 db_table = u'url_shortener'
2321