setup.py 3.05 KB
Newer Older
Skia's avatar
Skia committed
1
import os
Skia's avatar
Skia committed
2 3
from django.core.management.base import BaseCommand, CommandError
from django.core.management import call_command
4
from django.conf import settings
Skia's avatar
Skia committed
5 6


7
from core.models import Group, User, Page, PageRev
Skia's avatar
Skia committed
8
from accounting.models import Customer, GeneralJournal, ProductType, Product
9
from club.models import Club
Skia's avatar
Skia committed
10
from subscription.models import Subscription, Subscriber
Skia's avatar
Skia committed
11 12 13 14

class Command(BaseCommand):
    help = "Set up a new instance of the Sith AE"

Skia's avatar
Skia committed
15 16 17
    def add_arguments(self, parser):
        parser.add_argument('--prod', action="store_true")

Skia's avatar
Skia committed
18 19
    def handle(self, *args, **options):
        try:
Skia's avatar
Skia committed
20
            os.unlink(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), 'db.sqlite3'))
Skia's avatar
Skia committed
21 22 23
            os.mkdir(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))+'/data')
        except Exception as e:
            print(e)
Skia's avatar
Skia committed
24 25 26
        call_command('migrate')
        u = User(username='root', last_name="", first_name="Bibou",
                 email="ae.info@utbm.fr",
Skia's avatar
Skia committed
27
                 date_of_birth="1942-06-12",
Skia's avatar
Skia committed
28 29 30
                 is_superuser=True, is_staff=True)
        u.set_password("plop")
        u.save()
31 32
        for g in settings.AE_GROUPS.values():
            Group(id=g['id'], name=g['name']).save()
33 34 35 36
        Club(name=settings.AE_MAIN_CLUB['name'], unix_name=settings.AE_MAIN_CLUB['unix_name'],
                address=settings.AE_MAIN_CLUB['address']).save()

        # Here we add a lot of test datas, that are not necessary for the Sith, but that provide a basic development environment
Skia's avatar
Skia committed
37 38
        if not options['prod']:
            print("Dev mode, adding some test data")
39
            s = User(username='skia', last_name="Kia", first_name="S'",
Skia's avatar
Skia committed
40
                     email="skia@git.an",
Skia's avatar
Skia committed
41
                     date_of_birth="1942-06-12",
Skia's avatar
Skia committed
42
                     is_superuser=True, is_staff=True)
43 44
            s.set_password("plop")
            s.save()
45 46
            u = User(username='guy', last_name="Carlier", first_name="Guy",
                     email="guy@git.an",
Skia's avatar
Skia committed
47
                     date_of_birth="1942-06-12",
48 49 50
                     is_superuser=False, is_staff=False)
            u.set_password("plop")
            u.save()
Skia's avatar
Skia committed
51
            p = Page(name='Aide_sur_la_syntaxe')
52 53 54 55 56
            p.set_lock(s)
            p.save()
            PageRev(page=p, title="Aide sur la syntaxe", author=s, content="""
Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
""").save()
Skia's avatar
Skia committed
57

Skia's avatar
Skia committed
58 59 60 61 62 63 64 65
            # Accounting test values:
            Customer(user=s, account_id="6568j").save()
            p = ProductType(name="Bières bouteilles")
            p.save()
            Product(name="Barbar", code="BARB", product_type=p, purchase_price="1.50", selling_price="1.7",
                    special_selling_price="1.6").save()
            GeneralJournal(start_date="2015-06-12", name="A15").save()

Skia's avatar
Skia committed
66 67 68 69
            # Subscription
            Subscription(member=Subscriber.objects.filter(pk=s.pk).first(), subscription_type=list(settings.AE_SUBSCRIPTIONS.keys())[0],
                    payment_method=settings.AE_PAYMENT_METHOD[0]).save()