remotes/origin/setup
Mukhtar 10 years ago
commit e664ffe627
  1. 19
      archilance/management/commands/generate_perm_groups.py
  2. 74
      archilance/management/commands/generate_projects.py
  3. 52
      archilance/management/commands/generate_realties.py
  4. 18
      archilance/management/commands/generate_superuser.py
  5. 77
      archilance/management/commands/generate_users.py
  6. 10
      archilance/settings/base.py
  7. 11
      archilance/util.py
  8. 11
      users/models.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='Заказчики')

@ -6,7 +6,8 @@ import pydash as _; _.map = _.map_; _.filter = _.filter_
import random import random
from archilance import util 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): class Command(BaseCommand):
@ -17,38 +18,41 @@ class Command(BaseCommand):
# Fields: # Fields:
#
# [('files', True),
# ('answers', True), # ('customer', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'),
# ('order', True), # ('specialization', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'),
# ('candidates', True),
# ('reviews', True), # ('answers', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'),
# ('customer', True), # ('candidates', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'),
# ('realty', True), # ('files', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'),
# ('specialization', True), # ('order', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'),
# # ('realty', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'),
# ('id', False), # ('reviews', 'Relation? True', 'Null? True', '(relation)', 'Hidden? False'),
# ('budget', False),
# ('budget_by_agreement', False),
# ('created', False),
# ('cro', False), # ('budget', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'),
# ('currency', False), # ('created', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'),
# ('name', False), # ('currency', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'),
# ('price_and_term_required', False), # ('deal_type', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'),
# ('deal_type', False), # ('name', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'),
# ('term', False), # ('state', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'),
# ('term_type', False), # ('term', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'),
# ('text', False), # ('term_type', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'),
# ('work_type', False), # ('work_type', 'Relation? False', 'Null? False', 'Blank? False', 'Hidden? False'),
# ('state', 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): def create_project(i):
# project = Project() project = Project(
# pr.specialization =
# pr.
return Project.objects.create(
budget=util.random_amount(), budget=util.random_amount(),
budget_by_agreement=_.sample((True, False)), budget_by_agreement=_.sample((True, False)),
created=util.random_date(), created=util.random_date(),
@ -62,7 +66,13 @@ class Command(BaseCommand):
text='Project %s text' % i, text='Project %s text' % i,
work_type=_.sample(Project.WORK_TYPES)[0], work_type=_.sample(Project.WORK_TYPES)[0],
state='active', 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)

@ -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)

@ -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')

@ -7,7 +7,7 @@ import random
from archilance import util from archilance import util
from specializations.models import Specialization from specializations.models import Specialization
from users.models import User from users.models import User, GENDERS
class Command(BaseCommand): class Command(BaseCommand):
@ -17,22 +17,61 @@ class Command(BaseCommand):
print('---------------------------------------') print('---------------------------------------')
User.objects.create_superuser('admin@example.com', '123456')
contractor_group = Group.objects.create(name='Исполнители') # # Fields:
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) # ('contractor_specializations', 'Relation? True', 'Null? False', '(relation)', 'Hidden? False'),
# customer_group.permissions.add(proj_perms, spec_perms, ct_register) # ('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): def create_user(i):
@ -40,13 +79,21 @@ class Command(BaseCommand):
return User.objects.create( return User.objects.create(
first_name='User-%s' % i, first_name='User-%s' % i,
username=username,
email='%s@example.com' % username, email='%s@example.com' % username,
is_active=True, is_active=True,
contractor_status=_.sample(User.STATUSES)[0],
) )
users = _.times(create_user, 50) users = _.times(create_user, 50)
contractor_group = Group.objects.get(name='Исполнители')
customer_group = Group.objects.get(name='Заказчики')
for user in users: for user in users:
user.set_password('123') user.set_password('123')
user.groups.add(customer_group if user.pk % 2 == 0 else contractor_group) 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() user.save()

@ -15,6 +15,7 @@ DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
# Application definition # Application definition
DJANGO_APPS = [ DJANGO_APPS = [
@ -84,6 +85,7 @@ TEMPLATES = [
WSGI_APPLICATION = 'archilance.wsgi.application' WSGI_APPLICATION = 'archilance.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
@ -105,6 +107,7 @@ DATABASES = {
} }
} }
# Password validation # Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
@ -189,6 +192,7 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/ # https://docs.djangoproject.com/en/1.9/howto/static-files/
@ -236,3 +240,9 @@ EMAIL_USE_TLS = False
EMAIL_USE_SSL = False EMAIL_USE_SSL = False
EMAIL_TIMEOUT = 60 EMAIL_TIMEOUT = 60
EMAIL_DEFAULT = 'noreply@archilance.ru' EMAIL_DEFAULT = 'noreply@archilance.ru'
SHELL_PLUS_POST_IMPORTS = ( # Extra auto imports
('archilance', 'util'),
('pprint', ('pprint', 'pformat')),
)

@ -1,4 +1,5 @@
from django.utils import timezone from django.utils import timezone
from pprint import pprint, pformat
import pydash as _; _.map = _.map_; _.filter = _.filter_ import pydash as _; _.map = _.map_; _.filter = _.filter_
import random import random
@ -38,3 +39,13 @@ def random_date():
def random_amount(): def random_amount():
return random.random() * random.choice((100, 1000, 10000)) 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)

@ -7,6 +7,12 @@ from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, Abstra
from specializations.models import Specialization from specializations.models import Specialization
GENDERS = (
('male', 'Мужской'),
('female', 'Женский'),
)
class UserManager(BaseUserManager): class UserManager(BaseUserManager):
def create_user(self, username, email, password=None, **kwargs): def create_user(self, username, email, password=None, **kwargs):
# import code; code.interact(local=dict(globals(), **locals())) # import code; code.interact(local=dict(globals(), **locals()))
@ -35,11 +41,6 @@ class CustomerUserManager(models.Manager):
def get_queryset(self): def get_queryset(self):
return super().get_queryset().filter(groups__name='Заказчики') return super().get_queryset().filter(groups__name='Заказчики')
GENDERS = (
('male', 'Мужской'),
('female', 'Женский'),
)
class ContractorFinancialInfo(models.Model): class ContractorFinancialInfo(models.Model):
RESIDENCIES = ( RESIDENCIES = (

Loading…
Cancel
Save