8.2 KiB
Feature Update: MOC Auto-Generation & Favicon
🎉 New Features Added
1. ✅ Favicon (Already Existing)
Your repository already had a favicon implemented at app/static/favicon.ico. The favicon is properly integrated into your base templates and displays a LEGO brick icon in browser tabs.
Location: app/static/favicon.ico
Status: ✅ Already implemented and working
2. 🤖 MOC Auto-Generation (NEW)
Automatic MOC (My Own Creation) set number generation has been added to streamline creating and managing custom LEGO builds.
Default Behavior: GLOBAL NUMBERING - All users share the same MOC number sequence for system-wide unique IDs.
📦 Files Added
Services
app/services/moc_generator.py- MOC number generation serviceMOCNumberGenerator.generate_next_number()- Generate next sequential MOC numberMOCNumberGenerator.validate_moc_number()- Check if MOC number is availableMOCNumberGenerator.is_moc_number()- Verify MOC number format
Routes
app/routes/moc.py- API endpoints for MOC operationsGET /api/moc/generate- Generate next MOC numberPOST /api/moc/validate- Validate MOC number availabilityGET /api/moc/check-format- Check if number follows MOC format
Documentation
docs/MOC_AUTO_GENERATION.md- Comprehensive feature documentation- API reference
- Frontend integration examples
- Backend implementation guide
- Configuration options
- Troubleshooting guide
📝 Files Modified
App Initialization
app/__init__.py- Added MOC blueprint registrationfrom app.routes.moc import bp as moc_bp app.register_blueprint(moc_bp)
Routes Package
app/routes/__init__.py- Added MOC blueprint exportfrom app.routes.moc import bp as moc_bp __all__ = [..., 'moc_bp']
Services Package
app/services/__init__.py- Added MOCNumberGenerator exportfrom app.services.moc_generator import MOCNumberGenerator __all__ = [..., 'MOCNumberGenerator']
🔧 How It Works
MOC Number Format
- Pattern:
MOC-10000,MOC-10001,MOC-10002, etc. - Customizable Prefix: Default is "MOC" but can be changed
- Sequential: Automatically finds next available number
- Conflict-Free: Validates before assignment
- Global by Default: All users share the same sequence
Usage Example
Frontend (JavaScript):
// Toggle MOC mode - fetches global MOC number by default
document.getElementById('is_moc').addEventListener('change', function() {
if (this.checked) {
// Auto-fetch next GLOBAL MOC number
fetch('/api/moc/generate')
.then(response => response.json())
.then(data => {
document.getElementById('mocNumber').textContent = data.moc_number;
});
}
});
Backend (Python):
from app.services.moc_generator import MOCNumberGenerator
# Generate next GLOBAL MOC number (default)
moc_number = MOCNumberGenerator.generate_next_number(
user_id=None # None = global numbering
)
# Create MOC set
new_set = Set(
set_number=moc_number,
set_name="My Custom Castle",
is_moc=True,
moc_designer="John Doe",
theme="MOC",
year_released=2024
)
🎯 Key Features
Global Numbering (Default - STANDARD)
- All users share the same MOC number sequence
- Ensures system-wide unique MOC numbers
- MOC-10000 is unique across the entire system
- API:
user_scoped=falseor omit parameter (default) - Recommended for single household, organization, or guaranteed unique IDs
Per-User Numbering (Optional)
- Each user has their own MOC number sequence
- User A can have MOC-10000, User B can also have MOC-10000
- Prevents conflicts between users' custom builds
- API:
user_scoped=true - Use only if you need isolated numbering per user
Validation
- Checks for existing MOC numbers before assignment
- Prevents duplicate set numbers (globally or per-user)
- Validates MOC number format
📊 Database Integration
Existing MOC Support
Your Set model already includes full MOC support:
is_moc = db.Column(db.Boolean, default=False, nullable=False, index=True)
moc_designer = db.Column(db.String(100), nullable=True)
moc_description = db.Column(db.Text, nullable=True)
No database migration required! The auto-generation feature builds on your existing schema.
🚀 Next Steps
For Development
-
Pull Latest Changes
cd E:\LIM git pull origin main -
Test MOC Generation
python run.py # Navigate to http://localhost:5000/api/moc/generate -
Verify Endpoints
GET /api/moc/generate- Should return{"success": true, "moc_number": "MOC-10000", "user_scoped": false}- Check browser console for any JavaScript errors
For Frontend Integration
- Add MOC toggle to your "Add Set" form
- Implement JavaScript to call
/api/moc/generatewhen toggled - Display auto-generated MOC number to user
- Submit form with MOC fields populated
Configuration (Optional)
Edit app/services/moc_generator.py to customize:
DEFAULT_PREFIX = 'MOC'- Change to your preferred prefixDEFAULT_START = 10000- Change starting number
📚 Documentation
For complete details, see:
- MOC_AUTO_GENERATION.md - Full feature documentation
- API Examples - Included in documentation
- Frontend Integration - Complete HTML/JS examples
- Troubleshooting - Common issues and solutions
✅ Testing Checklist
- API endpoint accessible:
GET /api/moc/generate - Returns valid JSON response with
user_scoped: false - Sequential numbering works globally (MOC-10000, MOC-10001, etc.)
- Validation endpoint works:
POST /api/moc/validate - Frontend toggle shows/hides MOC section
- MOC number displays correctly in UI
- Can create MOC sets with auto-generated numbers
- MOC sets appear in dashboard with correct badge/indicator
🎨 UI Integration Recommendation
Consider adding to your "Add Set" template:
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" id="is_moc" name="is_moc">
<label class="form-check-label" for="is_moc">
<strong>This is a MOC (My Own Creation)</strong>
</label>
</div>
<!-- MOC Section (hidden by default) -->
<div id="mocSection" style="display: none;">
<div class="alert alert-success">
<i class="bi bi-lightbulb"></i>
MOC Number: <strong id="mocNumberDisplay">Loading...</strong>
</div>
<input type="text" class="form-control mb-3"
id="moc_designer" name="moc_designer"
placeholder="Designer/Creator Name">
<textarea class="form-control" id="moc_description"
name="moc_description" rows="3"
placeholder="MOC Description"></textarea>
</div>
🐛 Known Limitations
- No Recycling: Deleted MOC numbers are not reused (by design for data integrity)
- Sequential Only: Numbers must be sequential (no custom formats yet)
- Single Prefix: One prefix per installation (customizable but global)
💡 Future Enhancements
Potential improvements for future versions:
- Bulk MOC generation API
- Custom MOC number formats (e.g., MOC-YYYY-NNNN)
- MOC number recycling option
- Integration with Rebrickable for MOC imports
- MOC templates/categories
📞 Support
If you encounter any issues:
- Check
docs/MOC_AUTO_GENERATION.mdfor detailed guidance - Verify all files were pulled correctly from Git
- Check Flask logs for errors
- Open an issue on Gitea with error details
Summary
✅ Favicon: Already implemented and working
✅ MOC Auto-Generation: Now fully integrated with:
- Automatic sequential numbering (MOC-10000+)
- GLOBAL numbering as default (system-wide unique IDs)
- REST API endpoints for generation and validation
- Service layer for business logic
- Comprehensive documentation
- Optional per-user numbering if needed
Total Files Added: 3
Total Files Modified: 3
Total Lines of Code: ~500
All changes are backward compatible with your existing codebase. The MOC feature enhances your existing MOC support without breaking any current functionality.
Happy building! 🧱