create_users.py
3.74 KB
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
# -*- coding: utf-8 -*-
from django.contrib.auth.models import Group, User
from django.core.management.base import BaseCommand
from dictionary.models import Vocabulary
from accounts.models import UserSettings
class Command(BaseCommand):
args = 'none'
help = 'Creates default users'
def handle(self, **options):
create_users()
def create_users():
# observers = Group.objects.get(name=u'Obserwator')
lexicographers = Group.objects.get(name=u'Leksykograf')
superlexicographers = Group.objects.get(name=u'Superleksykograf')
patternmakers = Group.objects.get(name=u'Wzorzysta')
managers = Group.objects.get(name=u'Wydawca')
admins = Group.objects.get(name=u'Administrator')
vocab_sgjp = Vocabulary.objects.get(id='SGJP')
vocab_sjpdor = Vocabulary.objects.get(id='SJPDor')
vocab_zmiotki = Vocabulary.objects.get(id='zmiotki')
try:
vocab_wsjp = Vocabulary.objects.get(id='WSJP')
except Vocabulary.DoesNotExist:
vocab_wsjp = None
vocab_morfologik, created = \
Vocabulary.objects.get_or_create(id='Morfologik')
vocab_polimorf, created = Vocabulary.objects.get_or_create(id='PoliMorf')
User.objects.all().delete()
sgjp = User.objects.create_user('sgjp', 'sgjp@example.com', 'sgjp')
nzm = User.objects.create_user('nzm', 'nzm@example.com', 'nzm')
redsgjp = User.objects.create_user(
'redsgjp', 'redsgjp@example.com', 'redsgjp')
rednzm = User.objects.create_user('rednzm', 'rednzm@example.com', 'rednzm')
supersgjp = User.objects.create_user(
'supersgjp', 'supersgjp@example.com', 'supersgjp')
supernzm = User.objects.create_user(
'supernzm', 'supernzm@example.com', 'supernzm')
wzornik = User.objects.create_user(
'wzornik', 'wzornik@example.com', 'wzornik')
admin = User.objects.create_user('admin', 'admin@example.com', 'admin')
users = (sgjp, nzm, redsgjp, rednzm, supersgjp, supernzm, wzornik, admin)
for user in users:
UserSettings.objects.create(user=user)
admin.groups.add(admins)
sgjp_vocabs = (vocab_sgjp, vocab_sjpdor, vocab_zmiotki)
if vocab_wsjp:
sgjp_vocabs += (vocab_wsjp,)
nzm_vocabs = (vocab_zmiotki, vocab_morfologik, vocab_polimorf)
sgjp.groups.add(managers)
sgjp.managed_vocabularies = sgjp_vocabs
nzm.groups.add(managers)
for vocab in nzm_vocabs:
nzm.managed_vocabularies.add(vocab)
redsgjp.groups.add(lexicographers)
for vocab in sgjp_vocabs:
redsgjp.visible_vocabularies.add(vocab)
redsgjp.editable_vocabularies.add(vocab)
redsgjp.visible_vocabularies.add(vocab_polimorf)
rednzm.groups.add(lexicographers)
for vocab in nzm_vocabs:
rednzm.visible_vocabularies.add(vocab)
rednzm.editable_vocabularies.add(vocab)
rednzm.visible_vocabularies.add(vocab_sgjp)
if vocab_wsjp:
rednzm.visible_vocabularies.add(vocab_wsjp)
rednzm.visible_vocabularies.add(vocab_sjpdor)
supersgjp.groups.add(superlexicographers)
for vocab in sgjp_vocabs:
supersgjp.visible_vocabularies.add(vocab)
supersgjp.editable_vocabularies.add(vocab)
supersgjp.visible_vocabularies.add(vocab_polimorf)
supernzm.groups.add(superlexicographers)
for vocab in nzm_vocabs:
supernzm.visible_vocabularies.add(vocab)
supernzm.editable_vocabularies.add(vocab)
supernzm.visible_vocabularies.add(vocab_sgjp)
if vocab_wsjp:
supernzm.visible_vocabularies.add(vocab_wsjp)
supernzm.visible_vocabularies.add(vocab_sjpdor)
wzornik.groups.add(superlexicographers)
for vocab in sgjp_vocabs:
wzornik.visible_vocabularies.add(vocab)
wzornik.editable_vocabularies.add(vocab)
wzornik.visible_vocabularies.add(vocab_polimorf)
wzornik.groups.add(patternmakers)