mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-21 23:42:14 +00:00
Start work on sample data command
This commit is contained in:
45
training/management/commands/generateSampleTrainingData.py
Normal file
45
training/management/commands/generateSampleTrainingData.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import datetime
|
||||
import random
|
||||
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from training import models
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Adds sample data to use for testing'
|
||||
can_import_settings = True
|
||||
|
||||
categories = []
|
||||
items = []
|
||||
|
||||
def handle(self, *args, **options):
|
||||
from django.conf import settings
|
||||
|
||||
if not (settings.DEBUG or settings.STAGING):
|
||||
raise CommandError('You cannot run this command in production')
|
||||
|
||||
random.seed('otherwise it is done by time, which could lead to inconsistant tests')
|
||||
|
||||
with transaction.atomic():
|
||||
self.setup_categories()
|
||||
self.setup_items()
|
||||
|
||||
def setup_categories(self):
|
||||
names = [(1, "Basic"), (2, "Sound"), (3, "Lighting"), (4, "Rigging"), (5, "Power"), (6, "Haulage")]
|
||||
|
||||
for i, name in names:
|
||||
category = models.TrainingCategory.objects.create(number=i, name=name)
|
||||
category.save()
|
||||
self.categories.append(category)
|
||||
|
||||
def setup_items(self):
|
||||
names = ["Motorised Power Towers", "Catering", "Forgetting Cables", "Gazebo Construction", "Balanced Audio", "Unbalanced Audio"]
|
||||
|
||||
for i,name in enumerate(names):
|
||||
item = models.TrainingItem.objects.create(category=random.choice(self.categories), number=random.randint(0, 100), name=name)
|
||||
self.items.append(item)
|
||||
Reference in New Issue
Block a user