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:
@@ -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