diff --git a/archilance/management/commands/generate_perm_groups.py b/archilance/management/commands/generate_perm_groups.py new file mode 100644 index 0000000..abd9f39 --- /dev/null +++ b/archilance/management/commands/generate_perm_groups.py @@ -0,0 +1,19 @@ +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 archilance import util + + +class Command(BaseCommand): + def handle(self, *args, **options): + print('---------------------------------------') + print('Generating permission groups...') + print('---------------------------------------') + + + Group.objects.create(name='Исполнители') + Group.objects.create(name='Заказчики') diff --git a/archilance/management/commands/generate_projects.py b/archilance/management/commands/generate_projects.py index 0ab0bc8..620c680 100644 --- a/archilance/management/commands/generate_projects.py +++ b/archilance/management/commands/generate_projects.py @@ -6,7 +6,8 @@ import pydash as _; _.map = _.map_; _.filter = _.filter_ import random from archilance import util -from projects.models import Project, CURRENCIES, TERMS +from projects.models import Project, CURRENCIES, TERMS, Specialization, Realty +from users.models import User class Command(BaseCommand): @@ -17,38 +18,41 @@ class Command(BaseCommand): # Fields: - # - # [('files', True), - # ('answers', True), - # ('order', True), - # ('candidates', True), - # ('reviews', True), - # ('customer', True), - # ('realty', True), - # ('specialization', True), - # - # ('id', False), - # ('budget', False), - # ('budget_by_agreement', False), - # ('created', False), - # ('cro', False), - # ('currency', False), - # ('name', False), - # ('price_and_term_required', False), - # ('deal_type', False), - # ('term', False), - # ('term_type', False), - # ('text', False), - # ('work_type', False), - # ('state', False)] + + + # ('customer', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'), + # ('specialization', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'), + + # ('answers', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('candidates', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('files', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('order', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('realty', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('reviews', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + + + + # ('budget', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('created', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('currency', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('deal_type', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('name', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('state', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('term', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('term_type', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('work_type', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + + # ('budget_by_agreement', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('cro', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('id', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('price_and_term_required', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('text', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + + def create_project(i): - # project = Project() - # pr.specialization = - # pr. - - return Project.objects.create( + project = Project( budget=util.random_amount(), budget_by_agreement=_.sample((True, False)), created=util.random_date(), @@ -62,7 +66,13 @@ class Command(BaseCommand): text='Project %s text' % i, work_type=_.sample(Project.WORK_TYPES)[0], state='active', - ) + + project.specialization = Specialization.objects.root_nodes()[0].get_descendants().order_by('?').first() + project.realty = Realty.objects.order_by('?').first() + project.customer = User.objects.filter(groups__name='Заказчики', is_active=True, is_superuser=False).order_by('?').first() + + project.save() + return project - projects = _.times(create_project, 1000) + _.times(create_project, 1000) diff --git a/archilance/management/commands/generate_realties.py b/archilance/management/commands/generate_realties.py new file mode 100644 index 0000000..9e5c988 --- /dev/null +++ b/archilance/management/commands/generate_realties.py @@ -0,0 +1,52 @@ +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 archilance import util +from common.models import Location +from projects.models import Realty, BuildingClassfication, ConstructionType +from users.models import User + + +class Command(BaseCommand): + def handle(self, *args, **options): + print('---------------------------------------') + print('Generating realties...') + print('---------------------------------------') + + + # # Fields: + # + # + # ('building_classification', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'), + # ('construction_type', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'), + # ('user', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'), + # + # ('projects', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('location', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # + # + # + # ('name', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + + + + _.times(lambda i: BuildingClassfication.objects.create(name='Build. classif. %s' % i), 50) + _.times(lambda i: ConstructionType.objects.create(name='Constr. type %s' % i), 50) + + + def create_realty(i): + realty = Realty(name='Realty %s' % i) + + realty.building_classification = BuildingClassfication.objects.order_by('?').first() + realty.construction_type = ConstructionType.objects.order_by('?').first() + realty.location = Location.objects.root_nodes()[0].get_descendants().order_by('?').first() + realty.user = User.objects.filter(groups__name='Заказчики', is_active=True, is_superuser=False).order_by('?').first() + + realty.save() + return realty + + _.times(create_realty, 100) diff --git a/archilance/management/commands/generate_superuser.py b/archilance/management/commands/generate_superuser.py new file mode 100644 index 0000000..0941d23 --- /dev/null +++ b/archilance/management/commands/generate_superuser.py @@ -0,0 +1,18 @@ +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 archilance import util +from users.models import User + + +class Command(BaseCommand): + def handle(self, *args, **options): + print('---------------------------------------') + print('Generating superusers...') + print('---------------------------------------') + + User.objects.create_superuser('admin@example.com', '123456') diff --git a/archilance/management/commands/generate_users.py b/archilance/management/commands/generate_users.py index 0f5353f..17b5c19 100644 --- a/archilance/management/commands/generate_users.py +++ b/archilance/management/commands/generate_users.py @@ -7,7 +7,7 @@ import random from archilance import util from specializations.models import Specialization -from users.models import User +from users.models import User, GENDERS class Command(BaseCommand): @@ -17,22 +17,61 @@ class Command(BaseCommand): print('---------------------------------------') - 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) + # # Fields: # - # contractor_group.permissions.add(spec_perms, ct_register) - # customer_group.permissions.add(proj_perms, spec_perms, ct_register) + # ('contractor_specializations', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'), + # ('groups', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'), + # ('user_permissions', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'), + + # ('answers', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('contractor_financial_info', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('location', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('logentry', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('orders', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('portfolios', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('projects', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('realties', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('recipent_messages', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('recipent_notes', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('registrationprofile', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('reviews', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('sender_messages', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('sender_notes', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('social_auth', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('team', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('Team_users+', 'Relation? True', 'Null? True', '(relation)', 'Hidden? True'), + # ('teams', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + # ('User_contractor_specializations+', 'Relation? True', 'Null? True', '(relation)', 'Hidden? True'), + # ('User_groups+', 'Relation? True', 'Null? True', '(relation)', 'Hidden? True'), + # ('User_user_permissions+', 'Relation? True', 'Null? True', '(relation)', 'Hidden? True'), + # ('work_sell', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'), + + + + # ('contractor_status', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('created', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('data_joined', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('email', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('last_time_visit', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('password', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + # ('username', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'), + + # ('avatar', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('cro', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('date_of_birth', 'Relation? False', 'Null? True', 'Blank? True', 'Hidden? False'), + # ('first_name', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('gender', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('id', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('is_active', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('is_superuser', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('last_login', 'Relation? False', 'Null? True', 'Blank? True', 'Hidden? False'), + # ('last_name', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('patronym', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('phone', 'Relation? False', 'Null? True', 'Blank? True', 'Hidden? False'), + # ('skype', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + # ('website', 'Relation? False', 'Null? False', 'Blank? True', 'Hidden? False'), + def create_user(i): @@ -40,13 +79,21 @@ class Command(BaseCommand): return User.objects.create( first_name='User-%s' % i, + username=username, email='%s@example.com' % username, is_active=True, + contractor_status=_.sample(User.STATUSES)[0], ) users = _.times(create_user, 50) + + contractor_group = Group.objects.get(name='Исполнители') + customer_group = Group.objects.get(name='Заказчики') + for user in users: user.set_password('123') user.groups.add(customer_group if user.pk % 2 == 0 else contractor_group) + user.contractor_specializations = Specialization.objects.order_by('?')[:_.random(1, 5)] + user.save() diff --git a/archilance/settings/base.py b/archilance/settings/base.py index 716584e..8eeb4dc 100644 --- a/archilance/settings/base.py +++ b/archilance/settings/base.py @@ -15,6 +15,7 @@ DEBUG = True ALLOWED_HOSTS = [] + # Application definition DJANGO_APPS = [ @@ -84,6 +85,7 @@ TEMPLATES = [ WSGI_APPLICATION = 'archilance.wsgi.application' + # Database # https://docs.djangoproject.com/en/1.9/ref/settings/#databases @@ -105,6 +107,7 @@ DATABASES = { } } + # Password validation # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators @@ -189,6 +192,7 @@ USE_L10N = True USE_TZ = True + # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.9/howto/static-files/ @@ -236,3 +240,9 @@ EMAIL_USE_TLS = False EMAIL_USE_SSL = False EMAIL_TIMEOUT = 60 EMAIL_DEFAULT = 'noreply@archilance.ru' + + +SHELL_PLUS_POST_IMPORTS = ( # Extra auto imports + ('archilance', 'util'), + ('pprint', ('pprint', 'pformat')), +) diff --git a/archilance/util.py b/archilance/util.py index 49b766e..6b8f157 100644 --- a/archilance/util.py +++ b/archilance/util.py @@ -1,4 +1,5 @@ from django.utils import timezone +from pprint import pprint, pformat import pydash as _; _.map = _.map_; _.filter = _.filter_ import random @@ -38,3 +39,13 @@ def random_date(): def random_amount(): return random.random() * random.choice((100, 1000, 10000)) + + +def model_fields(model, width=200): + pprint([( + f.name, + 'Relation? %s' % f.is_relation, + 'Null? %s' % f.null, + 'Blank? %s' % f.blank if not f.is_relation else '(relation)', + 'Hidden? %s' % (f.is_hidden() if hasattr(f, 'is_hidden') else False), + ) for f in model._meta.get_fields(include_hidden=True)], width=width) diff --git a/users/models.py b/users/models.py index 47293d7..fe84289 100644 --- a/users/models.py +++ b/users/models.py @@ -7,6 +7,12 @@ from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, Abstra from specializations.models import Specialization +GENDERS = ( + ('male', 'Мужской'), + ('female', 'Женский'), +) + + class UserManager(BaseUserManager): def create_user(self, username, email, password=None, **kwargs): # import code; code.interact(local=dict(globals(), **locals())) @@ -35,11 +41,6 @@ class CustomerUserManager(models.Manager): def get_queryset(self): return super().get_queryset().filter(groups__name='Заказчики') -GENDERS = ( - ('male', 'Мужской'), - ('female', 'Женский'), -) - class ContractorFinancialInfo(models.Model): RESIDENCIES = (