You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.9 KiB
118 lines
3.9 KiB
# from cms_pages.models import Menu, CmsPage
|
|
# from django.contrib import sites
|
|
# from django.core.files import File
|
|
# from django.db import connection
|
|
# from django.db.models import Q
|
|
# from pprint import pprint, pformat
|
|
# from wagtail.wagtailcore.models import Page
|
|
# import copy
|
|
# import eav.models
|
|
# import inspect
|
|
# import itertools
|
|
# import json
|
|
# import os
|
|
# import requests
|
|
# import util
|
|
|
|
from django.contrib.auth.models import Group, Permission
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.core.management import BaseCommand
|
|
from django.utils import timezone
|
|
import pydash as _;
|
|
|
|
_.map = _.map_; _.filter = _.filter_
|
|
import random
|
|
|
|
from projects.models import Project
|
|
from registration.models import RegistrationProfile
|
|
from specializations.models import Specialization
|
|
from users.models import User
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
print('---------------------------------------')
|
|
print('Generating data...')
|
|
print('---------------------------------------')
|
|
|
|
|
|
def take(coll, n):
|
|
chunk = coll[0:n]
|
|
del coll[0:n]
|
|
return chunk
|
|
|
|
def take_random(coll, n):
|
|
if n == 0:
|
|
return []
|
|
|
|
chunk = _.sample(coll, n)
|
|
|
|
for item in chunk:
|
|
coll.remove(item)
|
|
|
|
return chunk
|
|
|
|
def take_one_random(coll):
|
|
if len(coll) == 0:
|
|
return None
|
|
|
|
return coll.pop(_.random(0, len(coll)-1))
|
|
|
|
def random_phone():
|
|
return '+7' + str(_.sample((917, 964, 965, 987, 912, 935))) + str(_.random(1000000, 9999999))
|
|
|
|
def random_date():
|
|
return timezone.datetime(_.random(2012, 2018), _.random(1, 12), _.random(1, 28))
|
|
|
|
def random_amount():
|
|
return random.random() * random.choice((100, 1000, 10000))
|
|
|
|
|
|
User.objects.create_superuser('admin@example.com', '123456')
|
|
|
|
contractor_group = Group.objects.create(name='Исполнители')
|
|
customer_group = Group.objects.create(name='Заказчики')
|
|
|
|
# ct_proj = ContentType.objects.get_for_model(Project)
|
|
# ct_spec = ContentType.objects.get_for_model(Specialization)
|
|
# ct_register = ContentType.objects.get_for_model(RegistrationProfile)
|
|
#
|
|
#
|
|
# proj_perms = Permission.objects.filter(content_type=ct_proj)
|
|
# spec_perms = Permission.objects.filter(content_type=ct_spec)
|
|
# ct_register = Permission.objects.filter(content_type=ct_register)
|
|
#
|
|
# contractor_group.permissions.add(spec_perms, ct_register)
|
|
# customer_group.permissions.add(proj_perms, spec_perms, ct_register)
|
|
|
|
|
|
|
|
_root = Specialization.objects.create(name='_root')
|
|
|
|
stages = ('A','B','C','D')
|
|
|
|
for s1 in stages:
|
|
x = Specialization.objects.create(name='Стадия %s' % s1, parent=_root)
|
|
for s2 in stages:
|
|
y = Specialization.objects.create(name='Стадия %s-%s' % (s1,s2), parent=x)
|
|
for s3 in stages:
|
|
z = Specialization.objects.create(name='Стадия %s-%s-%s' % (s1,s2,s3), parent=y)
|
|
for s4 in stages:
|
|
Specialization.objects.create(name='Стадия %s-%s-%s-%s' % (s1,s2,s3,s4), parent=z)
|
|
|
|
|
|
def create_user(i):
|
|
username = 'user-%s' % i
|
|
|
|
return User.objects.create(
|
|
first_name='User-%s' % i,
|
|
email='%s@example.com' % username,
|
|
is_active=True,
|
|
)
|
|
|
|
users = _.times(create_user, 50)
|
|
|
|
for user in users:
|
|
user.set_password('123')
|
|
user.groups.add(customer_group if user.pk % 2 == 0 else contractor_group)
|
|
user.save()
|
|
|