104 lines
3.5 KiB
Batchfile
104 lines
3.5 KiB
Batchfile
@echo off
|
|
REM Setup script for Django Manufacturing App on Windows
|
|
|
|
REM Check if Python is installed
|
|
python --version >nul 2>&1
|
|
if %errorlevel% neq 0 (
|
|
echo Python is not installed. Please install Python 3.8 or higher.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
REM Check Python version
|
|
for /f "tokens=2" %%i in ('python --version') do set PYTHON_VERSION=%%i
|
|
for /f "tokens=1,2 delims=." %%a in ("%PYTHON_VERSION%") do (
|
|
set PYTHON_MAJOR=%%a
|
|
set PYTHON_MINOR=%%b
|
|
)
|
|
|
|
if %PYTHON_MAJOR% lss 3 (
|
|
echo Python version 3.8 or higher is required. Current version: %PYTHON_VERSION%
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
if %PYTHON_MAJOR% equ 3 if %PYTHON_MINOR% lss 8 (
|
|
echo Python version 3.8 or higher is required. Current version: %PYTHON_VERSION%
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo Setting up virtual environment for Django Manufacturing App...
|
|
|
|
REM Create virtual environment
|
|
python -m venv venv
|
|
|
|
REM Activate virtual environment
|
|
call venv\Scripts\activate
|
|
|
|
REM Upgrade pip
|
|
python -m pip install --upgrade pip
|
|
|
|
REM Install requirements
|
|
pip install -r requirements.txt
|
|
|
|
REM Create .env file if it doesn't exist
|
|
if not exist .env (
|
|
echo Creating .env file...
|
|
(
|
|
echo # Django Settings
|
|
echo DEBUG=True
|
|
echo SECRET_KEY=your-development-secret-key
|
|
echo ALLOWED_HOSTS=localhost,127.0.0.1
|
|
echo.
|
|
echo # Database Settings (SQLite for development^)
|
|
echo # For PostgreSQL in production, uncomment and set these:
|
|
echo # DATABASE_URL=postgres://user:password@host:port/dbname
|
|
echo # DB_NAME=your_db_name
|
|
echo # DB_USER=your_db_user
|
|
echo # DB_PASSWORD=your_db_password
|
|
echo # DB_HOST=your_db_host
|
|
echo # DB_PORT=5432
|
|
echo.
|
|
echo # Email Settings (optional^)
|
|
echo # EMAIL_HOST=your_email_host
|
|
echo # EMAIL_PORT=587
|
|
echo # EMAIL_USE_TLS=True
|
|
echo # EMAIL_HOST_USER=your_email_user
|
|
echo # EMAIL_HOST_PASSWORD=your_email_password
|
|
) > .env
|
|
echo Please update the .env file with your actual settings.
|
|
)
|
|
|
|
REM Create logs directory
|
|
echo Creating logs directory...
|
|
mkdir logs 2>nul
|
|
|
|
REM Run migrations
|
|
echo Running database migrations...
|
|
python manage.py makemigrations
|
|
python manage.py migrate
|
|
|
|
REM Create superuser (optional)
|
|
echo Creating superuser...
|
|
echo from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@example.com', 'admin') | python manage.py shell
|
|
|
|
REM Create admin role with all permissions
|
|
echo Creating admin role with all permissions...
|
|
echo from apps.accounts.models import Role, Permission; admin_role, _ = Role.objects.get_or_create(name='Admin', description='Superuser role with all permissions'); permissions = Permission.objects.all(); [admin_role.rolepermission_set.get_or_create(permission=p) for p in permissions]; print('Admin role created with all permissions') | python manage.py shell
|
|
|
|
REM Assign admin role to admin user
|
|
echo Assigning Admin role to admin user...
|
|
echo from apps.accounts.models import User, UserRole, Role; admin_user = User.objects.get(username='admin'); admin_role = Role.objects.get(name='Admin'); UserRole.objects.get_or_create(user=admin_user, role=admin_role); print('Admin role assigned to admin user') | python manage.py shell
|
|
|
|
REM Populate sample data
|
|
echo Populating sample dashboard widgets...
|
|
python manage.py populate_sample_widgets
|
|
|
|
echo Populating sample data...
|
|
python manage.py populate_sample_data
|
|
|
|
echo Setup complete!
|
|
echo To activate the virtual environment, run: venv\Scripts\activate
|
|
echo To start the development server, run: python manage.py runserver
|
|
pause |