-
Notifications
You must be signed in to change notification settings - Fork 70
/
load_sample_data.py
120 lines (114 loc) · 3.88 KB
/
load_sample_data.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from django.contrib.auth.models import User
from django.contrib.auth.models import Group
from orchestra.models import Certification
from orchestra.models import Worker
from orchestra.models import WorkerCertification
def load(workflow_version):
""" Loads workers for running the journalism workflow. """
for user_data in USERS:
# Create the user/worker objects and set the password.
username = user_data.pop('username')
password = user_data.pop('password')
certifications = user_data.pop('certifications')
user, _ = User.objects.update_or_create(
username=username,
defaults=user_data,
)
user.set_password(password)
user.save()
worker, _ = Worker.objects.update_or_create(user=user)
project_admins, created = Group.objects.get_or_create(
name='project_admins')
if created:
user.groups.add(project_admins)
# Grant the worker the desired certifications.
for certification_slug, certification_role in certifications:
certification = Certification.objects.get(
slug=certification_slug)
WorkerCertification.objects.update_or_create(
certification=certification,
worker=worker,
task_class=WorkerCertification.TaskClass.REAL,
role=certification_role)
USERS = [
{
'username': 'journalism-editor',
'first_name': 'Journalism',
'last_name': 'Editor',
'is_active': True,
'is_superuser': False,
'is_staff': False,
'email': 'noreply-journalism1@example.org',
'password': 'editor',
'certifications': [
('editor', WorkerCertification.Role.ENTRY_LEVEL),
]
},
{
'username': 'journalism-reporter-1',
'first_name': 'Journalism',
'last_name': 'Reporter1',
'is_active': True,
'is_superuser': False,
'is_staff': False,
'password': 'reporter',
'email': 'noreply-journalism2@example.org',
'certifications': [
('reporter', WorkerCertification.Role.ENTRY_LEVEL),
]
},
{
'username': 'journalism-reporter-2',
'first_name': 'Journalism',
'last_name': 'Reporter2',
'is_active': True,
'is_superuser': False,
'is_staff': False,
'password': 'reporter',
'email': 'noreply-journalism3@example.org',
'certifications': [
('reporter', WorkerCertification.Role.ENTRY_LEVEL),
('reporter', WorkerCertification.Role.REVIEWER),
],
},
{
'username': 'journalism-photographer-1',
'first_name': 'Journalism',
'last_name': 'Photographer1',
'is_active': True,
'is_superuser': False,
'is_staff': False,
'password': 'photographer',
'email': 'noreply-journalism4@example.org',
'certifications': [
('photographer', WorkerCertification.Role.ENTRY_LEVEL),
]
},
{
'username': 'journalism-photographer-2',
'first_name': 'Journalism',
'last_name': 'Photographer2',
'is_active': True,
'is_superuser': False,
'is_staff': False,
'password': 'photographer',
'email': 'noreply-journalism5@example.org',
'certifications': [
('photographer', WorkerCertification.Role.ENTRY_LEVEL),
('photographer', WorkerCertification.Role.REVIEWER),
]
},
{
'username': 'journalism-copy-editor',
'first_name': 'Journalism',
'last_name': 'CopyEditor',
'is_active': True,
'is_superuser': False,
'is_staff': False,
'password': 'copy-editor',
'email': 'noreply-journalism6@example.org',
'certifications': [
('copy_editor', WorkerCertification.Role.ENTRY_LEVEL),
]
},
]