createfixtures.py 20.3 KB
Newer Older
1
2
3
4
5
"""
Provides the command to generate fixtures
"""
# pylint: disable=invalid-name,no-member,too-few-public-methods
# pylint: disable=attribute-defined-outside-init,no-self-use
Tom van Bussel's avatar
Tom van Bussel committed
6
import math
7
8
import random
import string
Tom van Bussel's avatar
Tom van Bussel committed
9
from datetime import date, timedelta
Jelle Besseling's avatar
Jelle Besseling committed
10

11
from django.contrib.auth.models import User
Thom Wiggers's avatar
Thom Wiggers committed
12
from django.core.files.base import ContentFile
13
from django.core.management.base import BaseCommand
Tom van Bussel's avatar
Tom van Bussel committed
14
from django.utils import timezone
15

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
16
17
from activemembers.models import (Board, Committee, MemberGroupMembership,
                                  Society, MemberGroup)
18
from documents.models import Document
Tom van Bussel's avatar
Tom van Bussel committed
19
from events.models import Event
20
from members.models import Profile, Member, Membership
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
21
from newsletters.models import NewsletterItem, NewsletterEvent, Newsletter
Tom van Bussel's avatar
Tom van Bussel committed
22
23
24
25
from partners.models import Partner, Vacancy, VacancyCategory
from pizzas.models import Product
from utils.snippets import datetime_to_lectureyear

26
27
28
29
30
31
32
try:
    import factory
    from faker import Factory as FakerFactory
    from pydenticon import Generator as IconGenerator
except ImportError as error:
    raise Exception("Have you installed the dev-requirements? "
                    "Failed importing {}".format(error)) from error
33

34
35
36
_faker = FakerFactory.create('nl_NL')
_pizza_name_faker = FakerFactory.create('it_IT')
_current_tz = timezone.get_current_timezone()
Tom van Bussel's avatar
Tom van Bussel committed
37

38
39
40

def _generate_title():
    words = _faker.words(random.randint(1, 3))
Tom van Bussel's avatar
Tom van Bussel committed
41
    return ' '.join([word.capitalize() for word in words])
42
43


44
45
class _ProfileFactory(factory.Factory):
    class Meta:  # pylint: disable=missing-docstring
46
        model = Profile
47
48
49

    programme = random.choice(['computingscience', 'informationscience'])
    student_number = factory.LazyAttribute(
50
        lambda x: _faker.numerify(text="s#######"))
51
52
    starting_year = factory.LazyAttribute(
        lambda x: random.randint(1990, date.today().year))
53

54
55
56
    address_street = factory.LazyAttribute(lambda x: _faker.street_address())
    address_postal_code = factory.LazyAttribute(lambda x: _faker.postcode())
    address_city = factory.LazyAttribute(lambda x: _faker.city())
57
    address_country = random.choice(['NL', 'DE', 'BE'])
58

59
    phone_number = '+31{}'.format(_faker.numerify(text="##########"))
60
61
62


class Command(BaseCommand):
63
    """Command to create fake data to populate the site"""
64
65
66
    help = "Creates fake data to test the site with"

    def add_arguments(self, parser):
67
68
69
70
71
        """
        Adds arguments to the argument parser.

        :param parser: the argument parser
        """
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
72
73
74
75
76
        parser.add_argument(
            "-a",
            "--all",
            action='store_true',
            help="Fully populate a database with fixtures")
77
        parser.add_argument(
Tom van Bussel's avatar
Tom van Bussel committed
78
79
80
81
82
83
84
85
86
            "-b",
            "--board",
            type=int,
            help="The amount of fake boards to add")
        parser.add_argument(
            "-c",
            "--committee",
            type=int,
            help="The amount of fake committees to add")
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
87
88
89
90
91
        parser.add_argument(
            "-d",
            "--document",
            type=int,
            help="The amount of fake miscellaneous documents to add")
Tom van Bussel's avatar
Tom van Bussel committed
92
93
94
95
96
        parser.add_argument(
            "-e",
            "--event",
            type=int,
            help="The amount of fake events to add")
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
97
98
99
100
101
        parser.add_argument(
            "-n",
            "--newsletter",
            type=int,
            help="The amount of fake newsletters to add")
102
        parser.add_argument(
103
104
105
            "-p",
            "--partner",
            type=int,
106
            help="The amount of fake partners to add")
Tom van Bussel's avatar
Tom van Bussel committed
107
108
109
110
111
        parser.add_argument(
            "-i",
            "--pizza",
            type=int,
            help="The amount of fake pizzas to add")
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
112
113
114
115
116
        parser.add_argument(
            "-s",
            "--society",
            type=int,
            help="The amount of fake societies to add")
Tom van Bussel's avatar
Tom van Bussel committed
117
118
119
120
121
122
123
124
125
126
127
        parser.add_argument(
            "-u",
            "--user",
            type=int,
            help="The amount of fake users to add")
        parser.add_argument(
            "-w",
            "--vacancy",
            type=int,
            help="The amount of fake vacancies to add")

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
128
    def create_board(self, lecture_year):
129
130
131
132
133
        """
        Create a new board

        :param int lecture_year: the  lecture year this board was active
        """
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
134
135
        members = Member.objects.all()
        if len(members) < 6:
136
137
            self.stdout.write('Your database does not contain 6 users.')
            self.stdout.write(f'Creating {6 - len(members)} more users.')
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
138
139
140
            for __ in range(6 - len(members)):
                self.create_user()

Tom van Bussel's avatar
Tom van Bussel committed
141
142
        board = Board()

143
144
145
146
        board.name_nl = "Bestuur {}-{}".format(lecture_year, lecture_year + 1)
        board.name_en = "Board {}-{}".format(lecture_year, lecture_year + 1)
        board.description_nl = _faker.paragraph()
        board.description_en = _faker.paragraph()
Tom van Bussel's avatar
Tom van Bussel committed
147
148

        igen = IconGenerator(5, 5)  # 5x5 blocks
Thom Wiggers's avatar
Thom Wiggers committed
149
150
151
152
153
154
        icon = igen.generate(
            board.name_nl, 480, 480,
            padding=(10, 10, 10, 10),
            output_format='jpeg',
        )  # 620x620 pixels, with 10 pixels padding on each side
        board.photo.save(board.name_nl + '.jpeg', ContentFile(icon))
Tom van Bussel's avatar
Tom van Bussel committed
155
156

        board.since = date(year=lecture_year, month=9, day=1)
157
        board.until = date(year=lecture_year + 1, month=8, day=31)
Tom van Bussel's avatar
Tom van Bussel committed
158
        board.active = True
159
        board.contact_email = _faker.email()
Tom van Bussel's avatar
Tom van Bussel committed
160
161
162
163
164
165

        board.save()

        # Add members
        board_members = random.sample(list(members), random.randint(5, 6))
        for member in board_members:
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
166
            self.create_member_group_membership(member, board)
Tom van Bussel's avatar
Tom van Bussel committed
167
168

        # Make one member the chair
169
        chair = random.choice(board.membergroupmembership_set.all())
Tom van Bussel's avatar
Tom van Bussel committed
170
171
172
173
        chair.until = None
        chair.chair = True
        chair.save()

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
174
    def create_member_group(self, group_model):
175
        """
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
176
        Create a MemberGroup
177
        """
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
178
179
        members = Member.objects.all()
        if len(members) < 6:
180
181
            self.stdout.write('Your database does not contain 6 users.')
            self.stdout.write(f'Creating {6 - len(members)} more users.')
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
182
183
184
185
186
            for __ in range(6 - len(members)):
                self.create_user()
            members = Member.objects.all()

        member_group = group_model()
Tom van Bussel's avatar
Tom van Bussel committed
187

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
188
189
190
191
        member_group.name_nl = _generate_title()
        member_group.name_en = member_group.name_nl
        member_group.description_nl = _faker.paragraph()
        member_group.description_en = _faker.paragraph()
Tom van Bussel's avatar
Tom van Bussel committed
192
193

        igen = IconGenerator(5, 5)  # 5x5 blocks
Thom Wiggers's avatar
Thom Wiggers committed
194
        icon = igen.generate(
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
195
            member_group.name_nl, 480, 480,
Thom Wiggers's avatar
Thom Wiggers committed
196
197
198
            padding=(10, 10, 10, 10),
            output_format='jpeg',
        )  # 620x620 pixels, with 10 pixels padding on each side
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
199
200
        member_group.photo.save(
            member_group.name_nl + '.jpeg', ContentFile(icon))
Tom van Bussel's avatar
Tom van Bussel committed
201

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
202
        member_group.since = _faker.date_time_between("-10y", "+30d")
Tom van Bussel's avatar
Tom van Bussel committed
203
204
205
206

        if random.random() < 0.1:
            now = date.today()
            month = timedelta(days=30)
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
207
208
            member_group.until = _faker.date_time_between_dates(
                member_group.since, now + 2 * month).date()
Tom van Bussel's avatar
Tom van Bussel committed
209

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
210
211
        member_group.active = random.random() < 0.9
        member_group.contact_email = _faker.email()
Tom van Bussel's avatar
Tom van Bussel committed
212

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
213
        member_group.save()
Tom van Bussel's avatar
Tom van Bussel committed
214
215

        # Add members
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
216
        committee_members = random.sample(list(members), random.randint(2, 6))
Tom van Bussel's avatar
Tom van Bussel committed
217
        for member in committee_members:
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
218
            self.create_member_group_membership(member, member_group)
Tom van Bussel's avatar
Tom van Bussel committed
219
220

        # Make one member the chair
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
221
        chair = random.choice(member_group.membergroupmembership_set.all())
Tom van Bussel's avatar
Tom van Bussel committed
222
223
224
        chair.until = None
        chair.chair = True
        chair.save()
225

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
226
    def create_member_group_membership(self, member, group):
227
        """
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
228
        Create member group membership
229
230

        :param member: the member to add to the committee
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
231
        :param group: the group to add the member to
232
        """
233
        membership = MemberGroupMembership()
Tom van Bussel's avatar
Tom van Bussel committed
234
235

        membership.member = member
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
236
        membership.group = group
Tom van Bussel's avatar
Tom van Bussel committed
237
238
239

        today = date.today()
        month = timedelta(days=30)
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
240
        membership.since = _faker.date_time_between_dates(group.since,
241
                                                          today + month).date()
Tom van Bussel's avatar
Tom van Bussel committed
242
243

        if random.random() < 0.2 and membership.since < today:
244
245
            membership.until = _faker.date_time_between_dates(membership.since,
                                                              today).date()
Tom van Bussel's avatar
Tom van Bussel committed
246
247
248

        membership.save()

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
249
    def create_event(self):
250
251
252
        """
        Create an event
        """
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
253
254
        groups = MemberGroup.objects.all()
        if len(groups) == 0:
255
256
257
            self.stdout.write('Your database does not contain any '
                              'member groups.')
            self.stdout.write('Creating a committee.')
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
258
259
            self.create_member_group(Committee)
            groups = MemberGroup.objects.all()
Tom van Bussel's avatar
Tom van Bussel committed
260
261
        event = Event()

262
        event.title_nl = _generate_title()
Tom van Bussel's avatar
Tom van Bussel committed
263
        event.title_en = event.title_nl
264
265
        event.description_nl = _faker.paragraph()
        event.description_en = _faker.paragraph()
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
266
        event.start = _faker.date_time_between("-30d", "+120d", _current_tz)
Tom van Bussel's avatar
Tom van Bussel committed
267
268
        duration = math.ceil(random.expovariate(0.2))
        event.end = event.start + timedelta(hours=duration)
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
269
        event.organiser = random.choice(groups)
Tom van Bussel's avatar
Tom van Bussel committed
270
271
272
273
        event.category = random.choice(Event.EVENT_CATEGORIES)

        if random.random() < 0.5:
            week = timedelta(days=7)
274
275
276
277
278
279
280
281
282
283
284
285
286
287
            event.registration_start = _faker.date_time_between_dates(
                datetime_start=event.start - 4 * week,
                datetime_end=event.start - week,
                tzinfo=_current_tz)
            event.registration_end = _faker.date_time_between_dates(
                datetime_start=event.registration_start,
                datetime_end=event.start,
                tzinfo=_current_tz)
            event.cancel_deadline = _faker.date_time_between_dates(
                datetime_start=event.registration_end,
                datetime_end=event.start,
                tzinfo=_current_tz)

        event.location_nl = _faker.street_address()
Tom van Bussel's avatar
Tom van Bussel committed
288
289
        event.location_en = event.location_nl
        event.map_location = event.location_nl
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
290
        event.send_cancel_email = False
Tom van Bussel's avatar
Tom van Bussel committed
291
292
293
294

        if random.random() < 0.5:
            event.price = random.randint(100, 2500) / 100
            event.fine = max(
295
296
297
                5.0,
                random.randint(round(100 * event.price),
                               round(500 * event.price)) / 100)
Tom van Bussel's avatar
Tom van Bussel committed
298
299
300
301
302
303
304
305
306

        if random.random() < 0.5:
            event.max_participants = random.randint(20, 200)

        event.published = random.random() < 0.9

        event.save()

    def create_partner(self):
307
        """Create a new random partner"""
Tom van Bussel's avatar
Tom van Bussel committed
308
309
310
        partner = Partner()

        partner.is_active = random.random() < 0.75
311
312
313
314
        partner.name = '{} {}'.format(
            _faker.company(),
            _faker.company_suffix()
        )
315
316
        partner.slug = _faker.slug()
        partner.link = _faker.uri()
317

318
        igen = IconGenerator(5, 5)  # 5x5 blocks
Thom Wiggers's avatar
Thom Wiggers committed
319
320
321
322
323
324
        icon = igen.generate(
            partner.name, 480, 480,
            padding=(10, 10, 10, 10),
            output_format='jpeg',
        )  # 620x620 pixels, with 10 pixels padding on each side
        partner.logo.save(partner.name + '.jpeg', ContentFile(icon))
325

326
327
328
        partner.address = _faker.street_address()
        partner.zip_code = _faker.postcode()
        partner.city = _faker.city()
329

Tom van Bussel's avatar
Tom van Bussel committed
330
331
        partner.save()

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
332
    def create_pizza(self):
333
        """Create a new random pizza product"""
Tom van Bussel's avatar
Tom van Bussel committed
334
335
        product = Product()

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
336
        product.name = f'Pizza {_pizza_name_faker.last_name()}'
337
338
        product.description_nl = _faker.sentence()
        product.description_nl = _faker.sentence()
Tom van Bussel's avatar
Tom van Bussel committed
339
340
341
342
343
344
        product.price = random.randint(250, 1000) / 100
        product.available = random.random() < 0.9

        product.save()

    def create_user(self):
345
346
        """Create a new random user"""
        fakeprofile = _faker.profile()
Tom van Bussel's avatar
Tom van Bussel committed
347
348
349
350
351
352
353
354
355
        fakeprofile['password'] = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(16))
        user = User.objects.create_user(fakeprofile['username'],
                                        fakeprofile['mail'],
                                        fakeprofile['password'])
        user.first_name = fakeprofile['name'].split()[0]
        user.last_name = ' '.join(fakeprofile['name'].split()[1:])

356
        profile = _ProfileFactory()
357
358
359
        profile.user_id = user.id
        profile.birthday = fakeprofile['birthdate']
        profile.website = fakeprofile['website'][0]
Tom van Bussel's avatar
Tom van Bussel committed
360
361

        igen = IconGenerator(5, 5)  # 5x5 blocks
Thom Wiggers's avatar
Thom Wiggers committed
362
363
364
365
366
367
368
        icon = igen.generate(
            user.username, 480, 480,
            padding=(10, 10, 10, 10),
            output_format='jpeg',
        )  # 620x620 pixels, with 10 pixels padding on each side
        profile.photo.save(fakeprofile['username'] + '.jpeg',
                           ContentFile(icon))
Tom van Bussel's avatar
Tom van Bussel committed
369
370
371

        membership = Membership()
        membership.user_id = user.id
372
        membership.since = _faker.date_time_between(
Tom van Bussel's avatar
Tom van Bussel committed
373
            start_date='-4y', end_date='now', tzinfo=None)
374
        membership.until = random.choice([_faker.date_time_between(
Tom van Bussel's avatar
Tom van Bussel committed
375
376
            start_date='-2y', end_date='+2y', tzinfo=None), None])
        membership.type = random.choice(
377
            [t[0] for t in Membership.MEMBERSHIP_TYPES])
Tom van Bussel's avatar
Tom van Bussel committed
378
379

        user.save()
380
        profile.save()
Tom van Bussel's avatar
Tom van Bussel committed
381
382
383
        membership.save()

    def create_vacancy(self, partners, categories):
384
385
386
387
388
389
        """
        Create a new random vacancy

        :param partners: the partners to choose a partner from
        :param categories: the categories to choose this vacancy from
        """
Tom van Bussel's avatar
Tom van Bussel committed
390
391
        vacancy = Vacancy()

392
        vacancy.title = _faker.job()
393
        vacancy.description = _faker.paragraph(nb_sentences=10)
394
        vacancy.link = _faker.uri()
395
396
397
398
399
400
401
402
403
404
405
406
407
408

        if random.random() < 0.75:
            vacancy.partner = random.choice(partners)
        else:
            vacancy.company_name = '{} {}'.format(
                _faker.company(),
                _faker.company_suffix()
            )
            igen = IconGenerator(5, 5)  # 5x5 blocks
            icon = igen.generate(
                vacancy.company_name, 480, 480,
                padding=(10, 10, 10, 10),
                output_format='jpeg',
            )  # 620x620 pixels, with 10 pixels padding on each side
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
409
410
            vacancy.company_logo.save(vacancy.company_name + '.jpeg',
                                      ContentFile(icon))
Tom van Bussel's avatar
Tom van Bussel committed
411
412
413

        vacancy.save()

414
415
        vacancy.categories.set(random.sample(list(categories),
                                             random.randint(0, 3)))
Tom van Bussel's avatar
Tom van Bussel committed
416
417

    def create_vacancy_category(self):
418
        """Create new random vacancy categories"""
Tom van Bussel's avatar
Tom van Bussel committed
419
420
        category = VacancyCategory()

421
422
423
        category.name_nl = _faker.text(max_nb_chars=30)
        category.name_en = _faker.text(max_nb_chars=30)
        category.slug = _faker.slug()
Tom van Bussel's avatar
Tom van Bussel committed
424
425
426

        category.save()

427
428
429
430
431
432
433
434
435
436
437
438
439
440
    def create_document(self):
        """Creates new random documents"""
        doc = Document()

        doc.name_nl = _faker.text(max_nb_chars=30)
        doc.name_en = _faker.text(max_nb_chars=30)
        doc.category = random.choice([c[0] for c in
                                      Document.DOCUMENT_CATEGORIES])
        doc.members_only = random.random() < 0.75
        doc.file_en.save('{}.txt'.format(doc.name_en), ContentFile(
            _faker.text(max_nb_chars=120)))
        doc.file_nl = doc.file_en
        doc.save()

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
    def create_newsletter(self):
        newsletter = Newsletter()

        newsletter.title_en = _generate_title()
        newsletter.title_nl = newsletter.title_en
        newsletter.description_nl = _faker.paragraph()
        newsletter.description_en = _faker.paragraph()
        newsletter.date = _faker.date_time_between("-3m", "+3m", _current_tz)

        newsletter.save()

        for i in range(random.randint(1, 5)):
            item = NewsletterItem()
            item.title_en = _generate_title()
            item.title_nl = item.title_en
            item.description_nl = _faker.paragraph()
            item.description_en = _faker.paragraph()
            item.newsletter = newsletter
            item.save()

        for i in range(random.randint(1, 5)):
            item = NewsletterEvent()
            item.title_en = _generate_title()
            item.title_nl = item.title_en
            item.description_nl = _faker.paragraph()
            item.description_en = _faker.paragraph()
            item.newsletter = newsletter

            item.what_en = item.title_en
            item.what_nl = item.what_en
            item.where_en = _faker.city()
            item.where_nl = item.where_en
            item.start_datetime = _faker.date_time_between("-1y", "+3m",
                                                           _current_tz)
            duration = math.ceil(random.expovariate(0.2))
            item.end_datetime = item.start_datetime + timedelta(hours=duration)

            if random.random() < 0.5:
                item.show_costs_warning = True
                item.price = random.randint(100, 2500) / 100
                item.penalty_costs = max(
                    5.0, random.randint(round(100 * item.price),
                                        round(500 * item.price)) / 100)

            item.save()

487
488
489
490
491
492
    def handle(self, *args, **options):  # pylint: disable=too-many-branches
        """
        Handle the command being executed

        :param options: the passed-in options
        """
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
493
494
        opts = ['all', 'board', 'committee', 'event', 'partner', 'pizza',
                'user', 'vacancy', 'document', 'newsletter']
Tom van Bussel's avatar
Tom van Bussel committed
495
496

        if all([not options[opt] for opt in opts]):
497
498
            self.stdout.write("Use ./manage.py help createfixtures to find out"
                              " how to call this command")
499

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
500
        if options['all']:
501
502
            self.stdout.write('all argument given, overwriting'
                              ' all other inputs')
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
503
504
505
506
507
508
509
510
511
512
513
514
515
            options = {
                'user': 20,
                'board': 3,
                'committee': 3,
                'society': 3,
                'event': 20,
                'partner': 6,
                'vacancy': 4,
                'pizza': 5,
                'newsletter': 2,
                'document': 8
            }

Tom van Bussel's avatar
Tom van Bussel committed
516
517
        # Users need to be generated before boards and committees
        if options['user']:
518
            for __ in range(options['user']):
Tom van Bussel's avatar
Tom van Bussel committed
519
520
521
522
523
                self.create_user()

        if options['board']:
            lecture_year = datetime_to_lectureyear(date.today())
            for i in range(options['board']):
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
524
                self.create_board(lecture_year - i)
Tom van Bussel's avatar
Tom van Bussel committed
525

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
526
        # Member groups need to be generated before events
Tom van Bussel's avatar
Tom van Bussel committed
527
528
        if options['committee']:
            for __ in range(options['committee']):
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
529
530
531
532
533
                self.create_member_group(Committee)

        if options['society']:
            for __ in range(options['society']):
                self.create_member_group(Society)
Tom van Bussel's avatar
Tom van Bussel committed
534
535
536

        if options['event']:
            for __ in range(options['event']):
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
537
                self.create_event()
Tom van Bussel's avatar
Tom van Bussel committed
538
539

        # Partners need to be generated before vacancies
540
        if options['partner']:
Tom van Bussel's avatar
Tom van Bussel committed
541
542
            for __ in range(options['partner']):
                self.create_partner()
543

Tom van Bussel's avatar
Tom van Bussel committed
544
            # Make one of the partners the main partner
545
546
547
            try:
                Partner.objects.get(is_main_partner=True)
            except Partner.DoesNotExist:
Tom van Bussel's avatar
Tom van Bussel committed
548
549
550
551
                main_partner = random.choice(Partner.objects.all())
                main_partner.is_active = True
                main_partner.is_main_partner = True
                main_partner.save()
552

Tom van Bussel's avatar
Tom van Bussel committed
553
554
555
        if options['vacancy']:
            categories = VacancyCategory.objects.all()
            if not categories:
556
557
                self.stdout.write('No vacancy categories found. '
                                  'Creating 5 categories.')
Tom van Bussel's avatar
Tom van Bussel committed
558
559
560
                for __ in range(5):
                    self.create_vacancy_category()
                categories = VacancyCategory.objects.all()
561

Tom van Bussel's avatar
Tom van Bussel committed
562
563
564
            partners = Partner.objects.all()
            for __ in range(options['vacancy']):
                self.create_vacancy(partners, categories)
565

Tom van Bussel's avatar
Tom van Bussel committed
566
        if options['pizza']:
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
567
568
            for __ in range(options['pizza']):
                self.create_pizza()
Tom van Bussel's avatar
Tom van Bussel committed
569

Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
570
571
572
        if options['newsletter']:
            for __ in range(options['newsletter']):
                self.create_newsletter()
573
574
575
576

        if options['document']:
            for __ in range(options['document']):
                self.create_document()