Add automatic template versioning system
- Add TEMPLATE_VERSION constant (1.3.0) to track UI changes - Create check_template_version() to compare embedded vs current version - Embed version marker as HTML comment in generated template - Auto-regenerate template when version mismatch detected - Show clear status messages: "Template up-to-date" or "regenerating" - Document versioning system in CLAUDE.md with usage guidelines Benefits: - No manual template deletion required when code updates - Users automatically get latest UI features on restart - Clear version tracking for template changes - Prevents stale template issues To update template: increment TEMPLATE_VERSION when HTML/CSS/JS changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
27
CLAUDE.md
27
CLAUDE.md
@@ -121,11 +121,28 @@ The entire Flask application lives in `rotary_phone_web.py` (~2000 lines). This
|
||||
- **Extra Button Sounds**: Separate PyAudio instance to prevent blocking main recording
|
||||
- **Hook Detection**: Direct GPIO reads during playback/recording loops for immediate response
|
||||
|
||||
### HTML Template Generation
|
||||
The Flask app generates `templates/index.html` programmatically on first run. The template is defined as a string in the Python code and written to disk. To update the UI:
|
||||
1. Delete `templates/` directory
|
||||
2. Restart the application
|
||||
3. Updated template will be regenerated
|
||||
### HTML Template Generation and Versioning
|
||||
The Flask app generates `templates/index.html` programmatically with automatic version tracking:
|
||||
|
||||
**Version System:**
|
||||
- `TEMPLATE_VERSION` constant (line ~84) tracks template changes
|
||||
- Version embedded as HTML comment: `<!-- TEMPLATE_VERSION: 1.3.0 -->`
|
||||
- `check_template_version()` compares embedded version with current code version
|
||||
- Template auto-regenerates on version mismatch
|
||||
|
||||
**How It Works:**
|
||||
1. On startup, `check_template_version()` reads existing template
|
||||
2. If version matches `TEMPLATE_VERSION`, template is up-to-date
|
||||
3. If version mismatches or template missing, regeneration occurs automatically
|
||||
4. User sees: "Template up-to-date (v1.3.0)" or "Template version mismatch - regenerating"
|
||||
|
||||
**When to Update:**
|
||||
- Increment `TEMPLATE_VERSION` whenever HTML/CSS/JS changes are made
|
||||
- Format: "X.Y.Z" (major.minor.patch)
|
||||
- Add comment describing the change
|
||||
|
||||
**Manual Regeneration:**
|
||||
If needed, delete `templates/` directory and restart - not required with version system
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
@@ -80,6 +80,9 @@ BACKUP_ON_WRITE = BACKUP_CONFIG.get('backup_on_write', True)
|
||||
# Web server settings
|
||||
WEB_PORT = SYS_CONFIG['web']['port']
|
||||
|
||||
# Template version - increment this when HTML template changes
|
||||
TEMPLATE_VERSION = "1.3.0" # Updated: Added download all recordings feature
|
||||
|
||||
# Flask app
|
||||
app = Flask(__name__)
|
||||
app.config['MAX_CONTENT_LENGTH'] = SYS_CONFIG['web']['max_upload_size_mb'] * 1024 * 1024
|
||||
@@ -924,6 +927,22 @@ def get_local_ip():
|
||||
except:
|
||||
return "127.0.0.1"
|
||||
|
||||
def check_template_version(template_file):
|
||||
"""Check if template needs regeneration based on version"""
|
||||
if not os.path.exists(template_file):
|
||||
return False # Template doesn't exist, needs creation
|
||||
|
||||
try:
|
||||
with open(template_file, 'r') as f:
|
||||
content = f.read()
|
||||
# Look for version comment in template
|
||||
if f'<!-- TEMPLATE_VERSION: {TEMPLATE_VERSION} -->' in content:
|
||||
return True # Version matches, no regeneration needed
|
||||
else:
|
||||
return False # Version mismatch or missing, needs regeneration
|
||||
except:
|
||||
return False # Error reading, regenerate to be safe
|
||||
|
||||
def main():
|
||||
"""Main entry point for the wedding phone application"""
|
||||
# Create templates directory and HTML template
|
||||
@@ -931,14 +950,21 @@ def main():
|
||||
templates_dir = os.path.join(script_dir, 'templates')
|
||||
os.makedirs(templates_dir, exist_ok=True)
|
||||
|
||||
# Create the HTML template if it doesn't exist
|
||||
# Check if template needs regeneration
|
||||
template_file = os.path.join(templates_dir, 'index.html')
|
||||
if not os.path.exists(template_file):
|
||||
print(f"Creating template at {template_file}")
|
||||
template_up_to_date = check_template_version(template_file)
|
||||
|
||||
if not template_up_to_date:
|
||||
if os.path.exists(template_file):
|
||||
print(f"Template version mismatch - regenerating template at {template_file}")
|
||||
else:
|
||||
print(f"Creating new template at {template_file}")
|
||||
|
||||
with open(template_file, 'w') as f:
|
||||
f.write('''<!DOCTYPE html>
|
||||
f.write(f'''<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- TEMPLATE_VERSION: {TEMPLATE_VERSION} -->
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Rotary Phone Control Panel</title>
|
||||
@@ -2030,8 +2056,8 @@ def main():
|
||||
</body>
|
||||
</html>''')
|
||||
else:
|
||||
print(f"Template already exists at {template_file}")
|
||||
|
||||
print(f"Template up-to-date (v{TEMPLATE_VERSION}) at {template_file}")
|
||||
|
||||
# Start phone handling in separate thread
|
||||
phone_thread = threading.Thread(target=phone.phone_loop, daemon=True)
|
||||
phone_thread.start()
|
||||
|
||||
Reference in New Issue
Block a user