0
# Configuration and Utilities
1
2
Panoramix provides extensive configuration options and utility functions for customizing the application behavior, database connections, authentication, and data processing.
3
4
## Capabilities
5
6
### Application Configuration
7
8
Core application settings that control Panoramix behavior and performance.
9
10
```python { .api }
11
# Panoramix-specific configuration constants
12
ROW_LIMIT = 5000 # Default row limit for queries
13
WEBSERVER_THREADS = 8 # Number of web server threads
14
PANORAMIX_WEBSERVER_PORT = 8088 # Default web server port
15
```
16
17
### Flask Configuration
18
19
Standard Flask application configuration options.
20
21
```python { .api }
22
# Flask core settings
23
SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h' # Application secret key for sessions
24
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db') # Default database URI
25
CSRF_ENABLED = True # CSRF protection enabled
26
DEBUG = True # Debug mode enabled
27
```
28
29
### Flask-AppBuilder Configuration
30
31
Settings for the Flask-AppBuilder admin interface and authentication system.
32
33
```python { .api }
34
# Application branding
35
APP_NAME = "Panoramix" # Application display name
36
APP_ICON = "/static/chaudron_white.png" # Application icon path
37
38
# Authentication configuration
39
AUTH_TYPE = AUTH_DB # Database authentication type
40
41
# Available authentication types
42
AUTH_DB = "db" # Database authentication
43
AUTH_OID = "oid" # OpenID authentication
44
AUTH_LDAP = "ldap" # LDAP authentication
45
AUTH_REMOTE_USER = "remote_user" # Remote user authentication
46
AUTH_OAUTH = "oauth" # OAuth authentication
47
48
# Optional authentication settings
49
AUTH_ROLE_ADMIN = 'Admin' # Admin role name
50
AUTH_ROLE_PUBLIC = 'Public' # Public role name
51
AUTH_USER_REGISTRATION = True # Allow user self-registration
52
AUTH_USER_REGISTRATION_ROLE = "Public" # Default role for new users
53
AUTH_LDAP_SERVER = "ldap://ldapserver.new" # LDAP server URL
54
55
# Internationalization
56
BABEL_DEFAULT_LOCALE = 'en' # Default language locale
57
BABEL_DEFAULT_FOLDER = 'translations' # Translation files folder
58
LANGUAGES = { # Supported languages
59
'en': {'flag': 'us', 'name': 'English'},
60
'fr': {'flag': 'fr', 'name': 'French'},
61
}
62
```
63
64
### File Upload Configuration
65
66
Settings for handling file uploads in the web interface.
67
68
```python { .api }
69
# File upload directories
70
UPLOAD_FOLDER = basedir + '/app/static/uploads/' # General uploads
71
IMG_UPLOAD_FOLDER = basedir + '/app/static/uploads/' # Image uploads
72
IMG_UPLOAD_URL = '/static/uploads/' # Image URL path
73
```
74
75
76
## Utility Functions
77
78
Helper functions for common data processing and parsing operations.
79
80
### Date and Time Parsing
81
82
```python { .api }
83
def parse_human_datetime(s):
84
"""
85
Convert human-readable datetime strings to datetime objects.
86
87
Supports natural language date expressions like:
88
- "now"
89
- "yesterday"
90
- "2 hours ago"
91
- "next week"
92
- "2023-01-15"
93
94
Args:
95
s (str): Human-readable datetime string
96
97
Returns:
98
datetime.datetime: Parsed datetime object
99
100
Raises:
101
ValueError: If string cannot be parsed
102
"""
103
104
def parse_human_timedelta(s):
105
"""
106
Parse human-readable time delta strings.
107
108
Supports expressions like:
109
- "1 hour"
110
- "30 minutes"
111
- "2 days"
112
- "1 week"
113
114
Args:
115
s (str): Human-readable time delta string
116
117
Returns:
118
datetime.timedelta: Parsed timedelta object
119
120
Raises:
121
ValueError: If string cannot be parsed
122
"""
123
124
def dttm_from_timtuple(d):
125
"""
126
Convert time tuple to datetime object.
127
128
Args:
129
d (time.struct_time): Time tuple from time module
130
131
Returns:
132
datetime.datetime: Converted datetime object
133
"""
134
```
135
136
## Usage Examples
137
138
### Custom Configuration
139
140
```python
141
# Create custom configuration file: config.py
142
import os
143
144
# Override default settings
145
ROW_LIMIT = 10000 # Increase row limit
146
PANORAMIX_WEBSERVER_PORT = 9999 # Use different port
147
DEBUG = False # Disable debug mode
148
149
# Custom database connection
150
SQLALCHEMY_DATABASE_URI = 'postgresql://user:pass@localhost/panoramix'
151
152
# Custom authentication
153
AUTH_TYPE = AUTH_LDAP # Use LDAP authentication
154
AUTH_LDAP_SERVER = "ldap://ldapserver.company.com"
155
156
# Custom branding
157
APP_NAME = "Company Analytics"
158
APP_ICON = "/static/company_logo.png"
159
```
160
161
### Using Utility Functions
162
163
```python
164
from panoramix.utils import parse_human_datetime, parse_human_timedelta
165
166
# Parse natural language dates
167
start_date = parse_human_datetime("7 days ago")
168
end_date = parse_human_datetime("now")
169
170
# Parse time deltas
171
time_window = parse_human_timedelta("2 hours")
172
173
# Use in queries
174
result = table.query(
175
metrics=['count'],
176
since=start_date.isoformat(),
177
until=end_date.isoformat(),
178
granularity='hour'
179
)
180
```
181
182
### Environment-Specific Configuration
183
184
```python
185
# Development configuration
186
class DevelopmentConfig:
187
DEBUG = True
188
SQLALCHEMY_DATABASE_URI = 'sqlite:///dev.db'
189
ROW_LIMIT = 1000
190
191
# Production configuration
192
class ProductionConfig:
193
DEBUG = False
194
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
195
ROW_LIMIT = 50000
196
WEBSERVER_THREADS = 16
197
198
# Load configuration based on environment
199
import os
200
config_name = os.environ.get('PANORAMIX_ENV', 'development')
201
```
202
203
### Security Configuration
204
205
```python
206
# Enhanced security settings
207
SECRET_KEY = os.environ.get('SECRET_KEY') or 'generate-random-key'
208
CSRF_ENABLED = True
209
WTF_CSRF_ENABLED = True
210
211
# Database security
212
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
213
SQLALCHEMY_POOL_PRE_PING = True # Verify connections
214
215
# Authentication security
216
AUTH_USER_REGISTRATION = False # Disable self-registration
217
AUTH_USER_REGISTRATION_ROLE = None # No default role for new users
218
```
219
220
## Command Line Entry Point
221
222
```python { .api }
223
# Command line script: panoramix/bin/panoramix
224
"""
225
Panoramix command-line entry point.
226
227
Usage:
228
python panoramix/bin/panoramix
229
230
Configuration:
231
- Reads PANORAMIX_WEBSERVER_PORT from config
232
- Uses Gunicorn in production (DEBUG=False)
233
- Uses Flask dev server in development (DEBUG=True)
234
- Configures worker processes and threading
235
"""
236
```
237
238
Usage:
239
240
```bash
241
# Start development server
242
python panoramix/bin/panoramix
243
244
# Production deployment with custom port
245
PANORAMIX_WEBSERVER_PORT=8080 python panoramix/bin/panoramix
246
247
# Using environment variables
248
export DATABASE_URL="postgresql://user:pass@localhost/panoramix"
249
export SECRET_KEY="your-secret-key"
250
python panoramix/bin/panoramix
251
```
252
253
## Configuration Validation
254
255
The application includes configuration validation to ensure proper setup:
256
257
- Database connectivity testing
258
- Required configuration checks
259
- Authentication system validation
260
- File system permissions verification
261
262
This comprehensive configuration system allows Panoramix to be deployed in various environments with appropriate security, performance, and functionality settings.