-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_accessibility_preferences.py
More file actions
59 lines (53 loc) · 2.44 KB
/
add_accessibility_preferences.py
File metadata and controls
59 lines (53 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Migration script to add accessibility preferences column to User table.
"""
import json
from app import app, db
from models import User
from modules.accessibility import AccessibilityPreferences
def add_accessibility_column():
"""Add accessibility_preferences column to the User table"""
with app.app_context():
# Check if we need to add the column (should already be there from models.py update)
try:
# Try to access the column to see if it exists
users = User.query.limit(1).all()
if users and hasattr(users[0], 'accessibility_preferences'):
print("Column 'accessibility_preferences' already exists in User table")
else:
raise Exception("Column does not exist")
except Exception as e:
print(f"Error checking column: {str(e)}")
# Column doesn't exist or other error, try to add it through SQL (just in case)
try:
with db.engine.connect() as conn:
conn.execute(db.text('ALTER TABLE user ADD COLUMN accessibility_preferences TEXT'))
conn.commit()
print("Added 'accessibility_preferences' column to User table")
except Exception as e:
print(f"Error adding column: {str(e)}")
print("The column may already exist or there was an error adding it.")
# Set default accessibility preferences for all users
try:
# Default preferences dictionary
default_prefs = {
'high_contrast_mode': False,
'large_text_mode': False,
'screen_reader_optimized': False,
'reduce_animations': False,
'keyboard_navigation': False,
'auto_announce_changes': False
}
# Update all users with default preferences
users = User.query.all()
for user in users:
if not user.accessibility_preferences:
user.accessibility_preferences = json.dumps(default_prefs)
db.session.commit()
print(f"Set default accessibility preferences for {len(users)} users")
except Exception as e:
db.session.rollback()
print(f"Error setting default preferences: {str(e)}")
if __name__ == "__main__":
add_accessibility_column()
print("Accessibility migration completed")