dev data kfet
This commit is contained in:
parent
2013fec68b
commit
8346dd65d1
5 changed files with 129 additions and 1276 deletions
|
@ -107,3 +107,9 @@ class Command(MyBaseCommand):
|
|||
# ---
|
||||
|
||||
call_command('loadbdadevdata')
|
||||
|
||||
# ---
|
||||
# La K-Fêt
|
||||
# ---
|
||||
|
||||
call_command('loadkfetdevdata')
|
||||
|
|
123
kfet/management/commands/loadkfetdevdata.py
Normal file
123
kfet/management/commands/loadkfetdevdata.py
Normal file
|
@ -0,0 +1,123 @@
|
|||
"""
|
||||
Crée des utilisateurs, des articles et des opérations aléatoires
|
||||
"""
|
||||
|
||||
import os
|
||||
import random
|
||||
from datetime import timedelta
|
||||
|
||||
from django.utils import timezone
|
||||
from django.contrib.auth.models import User, Group, Permission, ContentType
|
||||
|
||||
from gestioncof.management.base import MyBaseCommand
|
||||
from gestioncof.models import CofProfile
|
||||
from kfet.models import Account, Article, OperationGroup, Operation, Transfer, \
|
||||
Checkout
|
||||
|
||||
# Où sont stockés les fichiers json
|
||||
DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)),
|
||||
'data')
|
||||
|
||||
|
||||
class Command(MyBaseCommand):
|
||||
help = "Crée des utilisateurs, des articles et des opérations aléatoires"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# ---
|
||||
# Groupes
|
||||
# ---
|
||||
|
||||
Group.objects.filter(name__icontains='K-Fêt').delete()
|
||||
|
||||
group_chef = Group(name="K-Fêt César")
|
||||
group_boy = Group(name="K-Fêt Légionnaire")
|
||||
|
||||
group_chef.save()
|
||||
group_boy.save()
|
||||
|
||||
permissions_chef = Permission.objects.filter(
|
||||
content_type__in=ContentType.objects.filter(
|
||||
app_label='kfet'))
|
||||
permissions_boy = Permission.objects.filter(
|
||||
codename__in=['is_team', 'perform_deposit'])
|
||||
|
||||
group_chef.permissions.add(*permissions_chef)
|
||||
group_boy.permissions.add(*permissions_boy)
|
||||
|
||||
# ---
|
||||
# Comptes
|
||||
# ---
|
||||
|
||||
gaulois = CofProfile.objects.filter(user__last_name='Gaulois')
|
||||
gaulois_trigramme = map('{:03d}'.format, range(50))
|
||||
|
||||
romains = CofProfile.objects.filter(user__last_name='Romain')
|
||||
romains_trigramme = map(lambda x: str(100+x), range(50))
|
||||
|
||||
for (profile, trigramme) in zip(gaulois, gaulois_trigramme):
|
||||
account, _ = Account.objects.get_or_create(
|
||||
trigramme=trigramme,
|
||||
cofprofile=profile
|
||||
)
|
||||
|
||||
if profile.user.first_name == 'Abraracourcix':
|
||||
profile.user.groups.add(group_chef)
|
||||
|
||||
for (profile, trigramme) in zip(romains, romains_trigramme):
|
||||
account, _ = Account.objects.get_or_create(
|
||||
trigramme=trigramme,
|
||||
cofprofile=profile
|
||||
)
|
||||
|
||||
if random.random() > 0.75:
|
||||
profile.user.groups.add(group_boy)
|
||||
|
||||
# Compte liquide
|
||||
|
||||
liq_user, _ = User.objects.get_or_create(username='liquide')
|
||||
liq_profile, _ = CofProfile.objects.get_or_create(user=liq_user)
|
||||
account = Account.objects.get_or_create(cofprofile=liq_profile,
|
||||
trigramme='LIQ')
|
||||
|
||||
# ---
|
||||
# Opérations
|
||||
# ---
|
||||
|
||||
articles = Article.objects.all()
|
||||
accounts = Account.objects.all()
|
||||
checkout = Checkout.objects.all()[0]
|
||||
|
||||
num_op = 100
|
||||
past_date = 3600*24*5
|
||||
|
||||
for i in range(num_op):
|
||||
account = random.choice(accounts)
|
||||
amount = 0
|
||||
at = timezone.now() - timedelta(
|
||||
seconds=random.randint(0, past_date))
|
||||
|
||||
opegroup = OperationGroup(
|
||||
on_acc=account,
|
||||
checkout=checkout,
|
||||
at=at,
|
||||
is_cof=account.cofprofile.is_cof)
|
||||
|
||||
opegroup.save()
|
||||
|
||||
for j in range(random.randint(1, 4)):
|
||||
# For now, all operations are purchases, w/o addcost
|
||||
article = random.choice(articles)
|
||||
nb = random.randint(1, 5)
|
||||
|
||||
ope = Operation(
|
||||
group=opegroup,
|
||||
type=Operation.PURCHASE,
|
||||
amount=-article.price*nb,
|
||||
article=article,
|
||||
article_nb=nb
|
||||
)
|
||||
ope.save()
|
||||
amount += ope.amount
|
||||
|
||||
opegroup.amount = amount
|
||||
opegroup.save()
|
File diff suppressed because it is too large
Load diff
|
@ -1,98 +0,0 @@
|
|||
[
|
||||
{
|
||||
"model": "auth.group",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"name": "K-F\u00eat chef",
|
||||
"permissions": [
|
||||
115,
|
||||
116,
|
||||
117,
|
||||
118,
|
||||
119,
|
||||
120,
|
||||
133,
|
||||
134,
|
||||
135,
|
||||
130,
|
||||
131,
|
||||
132,
|
||||
136,
|
||||
137,
|
||||
138,
|
||||
121,
|
||||
122,
|
||||
123,
|
||||
127,
|
||||
128,
|
||||
129,
|
||||
124,
|
||||
125,
|
||||
126,
|
||||
188,
|
||||
189,
|
||||
190,
|
||||
169,
|
||||
176,
|
||||
183,
|
||||
170,
|
||||
171,
|
||||
182,
|
||||
172,
|
||||
178,
|
||||
177,
|
||||
181,
|
||||
175,
|
||||
179,
|
||||
173,
|
||||
174,
|
||||
184,
|
||||
180,
|
||||
139,
|
||||
140,
|
||||
141,
|
||||
142,
|
||||
143,
|
||||
144,
|
||||
166,
|
||||
167,
|
||||
168,
|
||||
163,
|
||||
164,
|
||||
165,
|
||||
151,
|
||||
152,
|
||||
153,
|
||||
154,
|
||||
155,
|
||||
156,
|
||||
185,
|
||||
186,
|
||||
187,
|
||||
145,
|
||||
146,
|
||||
147,
|
||||
148,
|
||||
149,
|
||||
150,
|
||||
160,
|
||||
161,
|
||||
162,
|
||||
157,
|
||||
158,
|
||||
159
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "auth.group",
|
||||
"pk": 2,
|
||||
"fields": {
|
||||
"name": "K-F\u00eat girl",
|
||||
"permissions": [
|
||||
172,
|
||||
173
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
Loading…
Reference in a new issue