-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev_createDummyUsermeta.py
executable file
·106 lines (95 loc) · 2.43 KB
/
dev_createDummyUsermeta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Bep Marketplace ELE
# Copyright (c) 2016-2022 Kolibri Solutions
# License: See LICENSE file or https://github.com/KolibriSolutions/BepMarketplace/blob/master/LICENSE
#
"""
Create semirandom usermeta for users. Used for init populate dev environment.
"""
import argparse
import django
import sys
import os
parser = argparse.ArgumentParser(description="Populate the database with initial values for usermeta")
parser.add_argument('--mode', nargs='?', const=1, type=str, default='debug', help='debug/production')
MODE = parser.parse_args().mode
if MODE not in ["debug", "production"]:
sys.exit(1)
if MODE == 'debug':
os.environ['DJANGO_SETTINGS_MODULE'] = 'BepMarketplace.settings_development'
elif MODE == 'production':
os.environ['DJANGO_SETTINGS_MODULE'] = 'BepMarketplace.settings'
django.setup()
from index.models import UserMeta
from django.contrib.auth.models import User
from random import choice
from django.conf import settings
from proposals.models import Proposal
from students.models import Application
from timeline.utils import get_timeslot
cohorts = [
'2010',
'2011',
'2012',
'2013',
'2014',
'2015'
]
ects = [
10,
20,
30,
40,
50,
60,
70,
80,
90,
100,
110,
120,
130,
140,
150,
160,
170,
180,
190,
200
]
study = [
'Automotive',
'Elektrotechniek',
'Elektrotechniek',
'Elektrotechniek',
]
NUMSTDS = 50
print("generating usermeta")
for n in range(1, NUMSTDS):
std = User.objects.get(username="std{}".format(n))
um, created = UserMeta.objects.get_or_create(User=std)
um.ECTS = choice(ects)
um.Cohort = choice(cohorts)
um.Study = choice(study)
um.Fullname = "std {}".format(n)
um.EnrolledBEP = True
um.TimeSlot.add(get_timeslot())
um.save()
print("generated for {}".format(std))
print("generating applications")
projects = Proposal.objects.filter(Status=4, TimeSlot=get_timeslot())
Application.objects.all().delete()
for n in range(1, NUMSTDS):
std = User.objects.get(username="std{}".format(n))
projs = []
for i in range(0, settings.MAX_NUM_APPLICATIONS):
app = Application()
while True:
p = choice(projects)
if p not in projs:
projs.append(p)
break
app.Proposal = choice(projects)
app.Student = std
app.Priority = i + 1
app.save()
print("generated for {}".format(std))