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 01a76d4..45454d9 100644 --- a/archilance/settings/base.py +++ b/archilance/settings/base.py @@ -233,3 +233,9 @@ REST_FRAMEWORK = { } SITE_ID = 1 + + +SHELL_PLUS_POST_IMPORTS = ( # Extra auto imports + ('archilance', 'util'), + ('pprint', ('pprint', 'pformat')), +) diff --git a/archilance/settings/dev.py b/archilance/settings/dev.py index 0ad6f0c..6b726ba 100644 --- a/archilance/settings/dev.py +++ b/archilance/settings/dev.py @@ -1,7 +1,5 @@ from .base import * -AUTH_PASSWORD_VALIDATORS = [] - # INSTALLED_APPS += ['debug_toolbar',] try: 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 62b9833..451e133 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 = ( @@ -54,20 +55,20 @@ class ContractorFinancialInfo(models.Model): ('legal_entity', 'ИП и юридическое лицо'), ) - fio = models.CharField(max_length=255) + credit_card_number = models.CharField(max_length=50) date_of_birth = models.DateTimeField() - phone = models.CharField(max_length=30) - residency = models.CharField(max_length=50, choices=RESIDENCIES) + fio = models.CharField(max_length=255) + inn = models.CharField(max_length=100) legal_status = models.CharField(max_length=30, choices=LEGAL_STATUSES) - passport_series = models.CharField(max_length=6) + passport_issue_date = models.DateTimeField() + passport_issued_by = models.CharField(max_length=255) passport_number = models.CharField(max_length=10) + passport_scan = models.ImageField(upload_to='users/contractors/') + passport_series = models.CharField(max_length=6) + phone = models.CharField(max_length=30) + residency = models.CharField(max_length=50, choices=RESIDENCIES) subdivision_code = models.CharField(max_length=10) - passport_issued_by = models.CharField(max_length=255) - passport_issue_date = models.DateTimeField() - inn = models.CharField(max_length=100) yandex_money = models.CharField(max_length=50) - credit_card_number = models.CharField(max_length=50) - passport_scan = models.ImageField(upload_to='users/contractors/') def __str__(self): return self.fio @@ -83,26 +84,26 @@ class User(AbstractBaseUser, PermissionsMixin): ('busy', 'Занят'), ) - username = models.CharField(max_length=50, unique=True) - first_name = models.CharField(max_length=255, blank=True) - last_name = models.CharField(max_length=255, blank=True) - patronym = models.CharField(max_length=255, blank=True) - email = models.EmailField(max_length=255, unique=True, db_index=True) - is_active = models.BooleanField(default=True) + avatar = models.ImageField(upload_to='users/avatars/', blank=True) + contractor_financial_info = models.OneToOneField(ContractorFinancialInfo, related_name='contractor',blank=True, null=True) + contractor_specializations = TreeManyToManyField(Specialization, related_name='contractors', blank=True) + contractor_status = models.CharField(default='free', max_length=20, choices=STATUSES) created = models.DateTimeField(default=timezone.now) + cro = models.BooleanField(default=False) data_joined = models.DateTimeField(default=timezone.now) + date_of_birth = models.DateTimeField(null=True,blank=True) + email = models.EmailField(max_length=255, unique=True, db_index=True) + first_name = models.CharField(max_length=255, blank=True) + gender = models.CharField(max_length=30, choices=GENDERS, blank=True) + is_active = models.BooleanField(default=True) + last_name = models.CharField(max_length=255, blank=True) last_time_visit = models.DateTimeField(default=timezone.now) - contractor_specializations = TreeManyToManyField(Specialization, related_name='contractors', blank=True) - contractor_status = models.CharField(default='free', max_length=20, choices=STATUSES) - contractor_financial_info = models.OneToOneField(ContractorFinancialInfo, related_name='contractor',blank=True, null=True) location = TreeForeignKey('common.Location', related_name='users', null=True, blank=True) + patronym = models.CharField(max_length=255, blank=True) + phone = models.CharField(max_length=30, blank=True, null=True) skype = models.CharField(max_length=100, blank=True) - gender = models.CharField(max_length=30, choices=GENDERS, blank=True) - cro = models.BooleanField(default=False) + username = models.CharField(max_length=50, unique=True) website = models.CharField(max_length=255, blank=True) - date_of_birth = models.DateTimeField(null=True,blank=True) - avatar = models.ImageField(upload_to='users/avatars/', blank=True) - phone = models.CharField(max_length=30, blank=True, null=True) @property def is_staff(self):