# Static Files Fix for HAVEN GRAZURI Advance

## Problem Description

When `DEBUG = False` in the Django settings, the following issues occur:

1. **Client names overlap** in tables, making them difficult to read
2. **Images don't appear** on the website

These issues are related to how static files are served in production mode (when `DEBUG = False`). In development mode (`DEBUG = True`), Django serves static files automatically, but in production, the web server (Apache/cPanel) needs to be configured correctly to serve these files.

## Solution Overview

We've created three scripts to fix these issues:

1. `fix_static_production.py` - Enhances the `.htaccess` file for better static file handling
2. `verify_static_fix.py` - Verifies the static file configuration and adds missing CSS/JS files
3. `update_settings_production.py` - Updates Django settings for proper static file configuration

## How to Use the Fix

### Step 1: Run the Fix Scripts

```bash
# Run the fix script to enhance .htaccess and collect static files
python fix_static_production.py

# Run the verification script to check configuration and add missing files
python verify_static_fix.py

# Update settings to set DEBUG=False and ensure proper configuration
python update_settings_production.py
```

### Step 2: Restart the Web Server

After running the scripts, restart your web server to apply the changes.

### Step 3: Test the Website

Verify that:
- Client names are displaying correctly (not overlapping)
- Images are loading properly

## Technical Details

### Key Changes Made

#### 1. Settings Configuration

- Set `DEBUG = False` for production
- Configured `STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')`
- Added `STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]`
- Ensured proper `STATIC_URL` and `MEDIA_URL` settings

#### 2. URL Configuration

- Added patterns to serve media files through Django in both debug and production modes
- Added patterns to serve static files through Django only in debug mode

#### 3. .htaccess Configuration

- Enhanced rewrite rules for static files with fallbacks
- Added security headers
- Enabled compression for better performance
- Added caching for static files

#### 4. CSS/JS Fixes

- Added `table-fix.css` with styles for client names and tables
- Added `table-fix.js` to apply classes to tables and ensure responsive wrappers

### File Permissions

The scripts set the following permissions:
- Directories: `755` (rwxr-xr-x)
- Files: `644` (rw-r--r--)

## Troubleshooting

### Images Still Not Loading

1. Check if the images exist in the `media` directory
2. Verify that the `.htaccess` file has the correct rewrite rules
3. Check file permissions (should be `644` for files)
4. Clear your browser cache

### Client Names Still Overlapping

1. Verify that `table-fix.css` and `table-fix.js` are included in `base.html`
2. Check if the CSS and JS files exist in both `static/css` and `staticfiles/css` directories
3. Run `python manage.py collectstatic` to ensure all static files are collected

## Rollback Plan

If you need to revert the changes:

1. Restore the backup files from the `backups` directory:
   ```bash
   cp backups/settings_production.py.bak branch_system/settings_production.py
   cp backups/.htaccess.bak .htaccess
   cp backups/urls.py.bak branch_system/urls.py
   ```

2. Restart the web server

## Additional Notes

- The fix ensures that static files are served correctly by the web server when `DEBUG = False`
- The `.htaccess` file is configured to try multiple locations for static files
- The CSS and JS fixes ensure that client names are displayed correctly in tables

## Support

If you encounter any issues with this fix, please contact the development team for assistance.