Skip to content

Conversation

@tobiascadee
Copy link
Collaborator

Summary

This PR upgrades the project from Python 3.8 to Python 3.12, bringing performance improvements, better error messages, security updates, and access to modern Python features.

Changes Made

Core Configuration

  • 📝 pyproject.toml: Updated requires-python from >=3.8 to >=3.12
  • 🐳 Dockerfile: Updated base image from python:3.8-bullseye to python:3.12-bookworm (more secure)
  • 📌 .python-version: Updated from 3.8 to 3.12

GitHub Actions

  • 🚀 .github/workflows/ci.yml: Updated Python version to 3.12 and upgraded action versions
  • 🔍 .github/workflows/lint.yml: Updated Python version to 3.12 and upgraded action versions

Testing Framework Modernization

  • Removed incompatible packages: django-nose and nose (not compatible with Python 3.12 due to removed `imp` module)
  • 🔧 Django settings: Removed `django_nose` from `INSTALLED_APPS` and switched to Django's default test runner
  • 🏭 factory-boy: Upgraded from 3.2.1 to 3.3.1 for Python 3.12 compatibility
  • 🎭 Faker: Updated to 37.5.3 for compatibility with newer factory-boy

Dependencies

  • 📦 uv.lock: Regenerated for Python 3.12 requirements
  • 🧹 Automatic cleanup: Removed `backports-zoneinfo` and `typing-extensions` (no longer needed in Python 3.12)

Testing

  • ✅ All Django system checks pass
  • ✅ All tests in `ordering.tests.test_core` module pass (15 tests)
  • ✅ Virtual environment confirmed using Python 3.12.11

Benefits of Python 3.12

  • 🚀 Performance improvements: Significant performance optimizations
  • 🐛 Better error messages: Improved error reporting and debugging
  • 🔒 Security updates: Latest security patches
  • 🆕 Modern syntax support: Access to latest Python language features
  • 📋 Enhanced typing: Better static type checking capabilities

This upgrade maintains all existing functionality while providing the benefits of Python 3.12.

tobiascadee and others added 11 commits June 27, 2025 08:32
This feature automatically creates new order rounds based on a configurable schedule, eliminating the need for manual creation every other Sunday.

## How It Works

The system uses a cron job that runs every 6 hours to check if a new order round should be created. When the conditions are met, it automatically creates a new order round with all the proper dates calculated based on your configuration.

## Configuration

All settings are managed through the Django admin interface under **Constance Config**:

### Core Settings
- **AUTO_CREATE_ORDERROUNDS**: Enable/disable the automation (default: False)
- **ORDERROUND_INTERVAL_WEEKS**: How often to create new rounds (default: 2 weeks)
- **ORDERROUND_CREATE_DAYS_AHEAD**: How far in advance to create rounds (default: 7 days)

### Timing Settings
- **ORDERROUND_OPEN_HOUR**: Hour when order rounds open, 24h format (default: 12)
- **ORDERROUND_CLOSE_HOUR**: Hour when order rounds close, 24h format (default: 3)
- **ORDERROUND_DURATION_HOURS**: How long order rounds stay open (default: 63 hours)
- **ORDERROUND_COLLECT_DAYS_AFTER**: Days after closing when products can be collected (default: 0)
- **ORDERROUND_COLLECT_HOUR**: Hour when products can be collected (default: 18)

### Coordinator Settings
- **ORDERROUND_DEFAULT_TRANSPORT_COORDINATOR**: Default transport coordinator user ID (default: 986)
- **ORDERROUND_DEFAULT_PICKUP_LOCATION**: Default pickup location ID (default: 1)

## Setup Instructions

1. **Enable the feature**:
   - Go to Django Admin → Constance Config
   - Set `AUTO_CREATE_ORDERROUNDS` to `True`

2. **Configure your schedule**:
   - Adjust the timing settings to match your current manual schedule
   - Current defaults: Opens Sunday at 12:00, closes Wednesday at 03:00, collect Wednesday at 18:00
   - Transport coordinator automatically set to user ID 986
   - Pickup location automatically set to location ID 1

3. **Set up cron** (if not already running):
   - The system uses django-cron which should already be configured
   - Make sure your deployment runs: `python manage.py runcrons`

## Manual Controls

### Admin Interface
- Go to Django Admin → Ordering → Order Rounds
- Select any order round and use the action "Create next order round automatically"
- This respects your automation settings but bypasses the timing checks

### Management Command
```bash
# Create the next order round
python manage.py create_orderround

# Preview what would be created (dry run)
python manage.py create_orderround --dry-run

# Force creation even if disabled or not needed
python manage.py create_orderround --force
```

## How Dates Are Calculated

The system calculates dates based on:

1. **Next Opening Date**:
   - If there's a previous round: adds the interval (e.g., 2 weeks) to the last round's opening date
   - If no previous rounds: uses the next Sunday

2. **Closing Date**: Opening date + duration hours (e.g., 72 hours later)

3. **Collection Date**: Closing date + collection days (e.g., same day if 0 days after)

**Example Schedule**:
- **Opens**: Sunday at 12:00 (noon)
- **Closes**: Wednesday at 03:00 (3 AM) - 63 hours later
- **Collect**: Wednesday at 18:00 (6 PM) - same day as closing

## Safety Features

- **No Duplicates**: Won't create a round if one already exists within the configured timeframe
- **Manual Override**: You can always create rounds manually - automation won't interfere
- **Configuration Checks**: Won't create rounds if automation is disabled
- **Error Logging**: All creation attempts are logged for troubleshooting

## Monitoring

- Check the **Log** section in Django admin for creation events
- Use the management command with `--dry-run` to preview upcoming rounds
- The cron job prints status messages that appear in your application logs

## Troubleshooting

### Order rounds aren't being created automatically
1. Check that `AUTO_CREATE_ORDERROUNDS` is set to `True`
2. Verify that django-cron is running (`python manage.py runcrons`)
3. Check if there's already a future round within your `ORDERROUND_CREATE_DAYS_AHEAD` setting
4. Look at the application logs for any error messages from the `AutoCreateOrderRounds` cron job

### Dates are wrong
1. Review your timing configuration in Constance Config
2. Use `python manage.py create_orderround --dry-run` to preview the next round
3. Check that your server timezone is set correctly

### Need to disable temporarily
1. Set `AUTO_CREATE_ORDERROUNDS` to `False` in Constance Config
2. The cron job will continue to run but won't create any rounds
3. You can still use manual creation methods

## Migration from Manual Process

1. **Before enabling**: Make sure your current manual schedule matches the configuration
2. **Enable gradually**: Start with `AUTO_CREATE_ORDERROUNDS = False` and test with the management command
3. **Monitor first few rounds**: Check that the automatically created rounds have the correct dates
4. **Keep manual backup**: You can always create rounds manually if needed
- Update pyproject.toml to require Python >= 3.12
- Update Dockerfile to use python:3.12-bookworm base image
- Update GitHub Actions workflows to use Python 3.12
- Update .python-version file to 3.12
- Remove django-nose and nose dependencies (not compatible with Python 3.12)
- Remove django_nose from Django settings and use default test runner
- Upgrade factory-boy to 3.3.1 and Faker to 37.5.3 for Python 3.12 compatibility
- Regenerate uv.lock file for Python 3.12 dependencies
- All tests passing with Python 3.12.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant