PYTHON ?= python
RM ?= rm -f
+all:
+ $(PYTHON) manage.py migrate --noinput
+ $(PYTHON) manage.py populate_db
+ $(PYTHON) manage.py fake_email_accounts
+
install-deps:
$(PIP) install -r requirements.txt
-all:
- $(PYTHON) manage.py syncdb --noinput
+shell:
+ $(PYTHON) manage.py shell
clean:
$(RM) db.sqlite
"""
from __future__ import unicode_literals
+import datetime
+import django.utils.timezone
import factory
import factory.django
import re
'gege-a-l-accent'
"""
normstr = unicodedata.normalize('NFKD', string)
- asciitext = normstr.encode('ascii', 'ignore').decode('ascii')
- return re.sub(r'\W', '-', asciitext)
+ asciitext = normstr.encode('ascii', 'ignore').decode('ascii').lower()
+ return re.sub(r'[^-._a-zA-Z0-9]', '-', asciitext)
+# Define a list of names so that they are always the same accross builds
+FIRSTNAMES_F = (
+ 'Elisabeth',
+ 'Emmanuelle',
+ 'Marie',
+ 'Marie-Hélène',
+ 'Marthe',
+)
+FIRSTNAMES_M = (
+ 'Jean',
+ 'Jean-Baptiste',
+ 'Jacques',
+ 'Joseph',
+ 'Luc',
+ 'Marc',
+ 'Matthieu',
+ 'Paul',
+ 'Pierre',
+ 'Simon',
+ 'Thomas',
+)
+FIRSTNAMES = FIRSTNAMES_F + FIRSTNAMES_M
+LASTNAMES = (
+ 'Bibi',
+ 'Exemple',
+ 'De La Machine',
+ 'Le Testeur',
+)
+
class AccountFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.Account
- FIRSTNAMES_F = (
- 'Elisabeth',
- 'Emmanuelle',
- 'Marie',
- 'Marie-Hélène',
- )
- FIRSTNAMES_M = (
- 'Jean',
- 'Jean-Baptiste',
- 'Jean-Pierre',
- 'Jacques',
- 'Joseph',
- 'Luc',
- 'Marc',
- 'Matthieu',
- 'Pierre',
- 'Simon',
- )
- FIRSTNAMES = FIRSTNAMES_F + FIRSTNAMES_M
- LASTNAMES = (
- 'Bibi',
- 'Exemple',
- 'De La Machine',
- 'Le Testeur',
- )
-
firstname = factory.Sequence(lambda n: FIRSTNAMES[n % len(FIRSTNAMES)])
lastname = factory.Sequence(lambda n: LASTNAMES[n % len(LASTNAMES)])
- hruid = models.CharField(max_length=255, unique=True)
- type = models.ForeignKey(AccountType, null=True, db_column='type', blank=True)
- user_perms = models.CharField(max_length=288, blank=True)
- is_admin = models.BooleanField()
- state = models.CharField(max_length=24)
- password = models.CharField(max_length=120, blank=True)
- token = models.CharField(max_length=96, blank=True)
- weak_password = models.CharField(max_length=768, blank=True)
- registration_date = models.DateTimeField()
- flags = models.CharField(max_length=15)
- comment = models.CharField(max_length=765, blank=True)
- email = models.CharField(max_length=765, blank=True)
- firstname = models.CharField(max_length=765, blank=True)
- lastname = models.CharField(max_length=765, blank=True)
- full_name = models.CharField(max_length=765, blank=True)
- directory_name = models.CharField(max_length=765, blank=True)
- sort_name = models.CharField(max_length=765, blank=True)
- display_name = models.CharField(max_length=765, blank=True)
- sex = models.CharField(max_length=18)
- email_format = models.CharField(max_length=12)
- skin = models.ForeignKey(Skin, null=True, db_column='skin', blank=True)
- last_version = models.CharField(max_length=48)
- best_domain = models.ForeignKey(EmailVirtualDomain, null=True, db_column='best_domain', blank=True)
- from_email = models.CharField(max_length=765)
- from_format = models.CharField(max_length=12)
-
+ full_name = factory.LazyAttribute(lambda o: '%s %s' % (o.firstname, o.lastname))
+ directory_name = factory.LazyAttribute(lambda o: '%s %s' % (o.firstname, o.lastname))
+ sort_name = factory.LazyAttribute(lambda o: '%s %s' % (o.lastname, o.firstname))
+ display_name = factory.LazyAttribute(lambda o: '%s %s' % (o.firstname, o.lastname))
+ sex = factory.Sequence(lambda n: 'female' if n % len(FIRSTNAMES) < len(FIRSTNAMES_F) else 'male')
+ hruid = factory.LazyAttributeSequence(
+ lambda o, n: emailify('%s.%s.%d' % (o.firstname, o.lastname, n)))
+ registration_date = factory.Sequence(
+ lambda n: datetime.date(2000, 1, 1) + datetime.timedelta(days=n))
#* Foundation, Inc., *
#* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
#***************************************************************************/
-"""Define the data which must be initially in the database"""
+"""Create fake email accounts in the database for testing purpose"""
from __future__ import unicode_literals
+from django.core.management.base import BaseCommand
+from ... import factories, models
-# XXX TODO Find a Django-way to do this
-AccountType...
+
+class Command(BaseCommand):
+ help = "Create fake email accounts in the database"
+
+ def handle(self, *args, **options):
+ # Remove every account from the database
+ models.Account.objects.all().delete()
+
+ # Create several accounts
+ for i in range(20):
+ account = factories.AccountFactory.create()
--- /dev/null
+# -*- coding: utf-8 -*-
+#***************************************************************************
+#* Copyright (C) 2015 Polytechnique.org *
+#* http://opensource.polytechnique.org/ *
+#* *
+#* This program is free software; you can redistribute it and/or modify *
+#* it under the terms of the GNU General Public License as published by *
+#* the Free Software Foundation; either version 2 of the License, or *
+#* (at your option) any later version. *
+#* *
+#* This program is distributed in the hope that it will be useful, *
+#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
+#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+#* GNU General Public License for more details. *
+#* *
+#* You should have received a copy of the GNU General Public License *
+#* along with this program; if not, write to the Free Software *
+#* Foundation, Inc., *
+#* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+#***************************************************************************/
+"""Populate the database with initial data"""
+from __future__ import unicode_literals
+
+from django.core.management.base import BaseCommand
+from ... import models
+
+
+class Command(BaseCommand):
+ help = "Populate the database with initial data"
+
+ def populate_account_types(self):
+ account_types = (
+ ('ax', 'groups,directory_ax,directory_hidden,edit_directory,user', "Personnel de l'AX"),
+ ('fx', 'groups,directory_ax,user', "Personnel de la FX"),
+ ('master', 'groups,mail,directory_private,forums,lists,payment,user', "Master de l'X"),
+ ('phd', 'groups,mail,directory_private,forums,lists,payment,user', "Docteur de l'X"),
+ ('pi', 'groups,forums,lists,user', "Elève du programme international"),
+ ('school', 'groups,directory_ax,user', "Personnel de l'X"),
+ ('virtual', '', None),
+ ('x', 'groups,mail,directory_private,forums,lists,payment,gapps,user', "Polytechnicien"),
+ ('xnet', 'groups', None),
+ )
+ for t, perms, desc in account_types:
+ models.AccountType(type=t, perms=perms, description=desc).save()
+
+ def handle(self, *args, **options):
+ self.populate_account_types()
class AccountType(models.Model):
type = models.CharField(max_length=48, primary_key=True)
perms = models.CharField(max_length=321)
- description = models.TextField(blank=True)
+ description = models.TextField(blank=True, null=True)
class Meta:
db_table = 'account_types'
hruid = models.CharField(max_length=255, unique=True)
type = models.ForeignKey(AccountType, null=True, db_column='type', blank=True)
user_perms = models.CharField(max_length=288, blank=True)
- is_admin = models.BooleanField()
+ is_admin = models.BooleanField(default=False)
state = models.CharField(max_length=24)
password = models.CharField(max_length=120, blank=True)
token = models.CharField(max_length=96, blank=True)
-Django>=1.7.0,<1.8.0
+Django>=1.8.0,<1.9.0
factory_boy>=2.3.1,<3.0.0
DEBUG = True
INSTALLED_APPS = (
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
+ # 'django.contrib.admin',
+ # 'django.contrib.auth',
+ # 'django.contrib.contenttypes',
+ # 'django.contrib.sessions',
+ # 'django.contrib.messages',
+ # 'django.contrib.staticfiles',
'platal',
)
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
-USE_TZ = True
+USE_TZ = False
SECRET_KEY = 'Key for development purpose only ;)'