forked from agit8or1/clientst0r
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·117 lines (95 loc) · 3.4 KB
/
setup.py
File metadata and controls
executable file
·117 lines (95 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
"""
Client St0r Installation Setup Script
Creates default organization and initial data
"""
import os
import sys
import django
# Setup Django environment
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()
from django.contrib.auth.models import User
from core.models import Organization
from django.db import IntegrityError
from django.utils.text import slugify
def setup_organization():
"""Create default organization with user input."""
print("\n" + "="*60)
print(" Client St0r - Initial Setup")
print("="*60 + "\n")
# Check if organizations already exist
if Organization.objects.exists():
print("✓ Organizations already exist in database")
org = Organization.objects.first()
print(f" Default organization: {org.name}")
return org
# Ask for business name
print("Let's create your organization...")
business_name = input("\nBusiness Name (Organization): ").strip()
while not business_name:
print("❌ Business name cannot be empty")
business_name = input("Business Name (Organization): ").strip()
# Generate slug
slug = slugify(business_name)
# Handle slug conflicts
if Organization.objects.filter(slug=slug).exists():
counter = 1
original_slug = slug
while Organization.objects.filter(slug=slug).exists():
slug = f"{original_slug}-{counter}"
counter += 1
try:
org = Organization.objects.create(
name=business_name,
slug=slug,
is_active=True,
)
print(f"\n✓ Created organization: {org.name}")
print(f" Slug: {org.slug}")
return org
except IntegrityError as e:
print(f"\n❌ Error creating organization: {e}")
sys.exit(1)
def create_demo_floorplan(org):
"""Create demo office floor plan for organization."""
from django.core.management import call_command
print("\n" + "-"*60)
create_demo = input("Create demo office floor plan? (y/n) [y]: ").strip().lower()
if create_demo in ['', 'y', 'yes']:
print("\nCreating demo office floor plan...")
try:
call_command('seed_demo_floorplan', '--organization-id', str(org.id))
print("✓ Demo floor plan created successfully")
except Exception as e:
print(f"⚠ Warning: Could not create demo floor plan: {e}")
else:
print("Skipped demo floor plan creation")
def main():
"""Main setup function."""
try:
# Create organization
org = setup_organization()
# Create demo floor plan
create_demo_floorplan(org)
print("\n" + "="*60)
print(" Setup Complete!")
print("="*60)
print(f"\nYour organization: {org.name}")
print(f"Organization slug: {org.slug}")
print("\nNext steps:")
print(" 1. Create a superuser: python manage.py createsuperuser")
print(" 2. Start the server: python manage.py runserver")
print(" 3. Visit http://localhost:8000/admin")
print("\n")
except KeyboardInterrupt:
print("\n\n❌ Setup cancelled by user")
sys.exit(1)
except Exception as e:
print(f"\n❌ Setup failed: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == '__main__':
main()