1
+ # pylint: disable=wrong-import-order
2
+ from ._version import __version__
3
+
1
4
import os
2
- import subprocess
3
5
from datetime import datetime
6
+
7
+ import structlog
8
+ from csh_ldap import CSHLDAP
4
9
from flask import Flask , redirect , request , render_template , g
5
- from flask_sqlalchemy import SQLAlchemy
6
10
from flask_migrate import Migrate
7
- from csh_ldap import CSHLDAP
8
- from raven import fetch_git_sha
11
+ from flask_sqlalchemy import SQLAlchemy
9
12
from raven .contrib .flask import Sentry
10
- from raven . exceptions import InvalidGitRepository
11
- import structlog
13
+
14
+ from conditional import config
12
15
13
16
app = Flask (__name__ )
14
17
15
- config = os .path .join (app .config .get ('ROOT_DIR' , os .getcwd ()), "config.py" )
18
+ app .config .from_object (config )
19
+ if os .path .exists (os .path .join (os .getcwd (), "config.py" )):
20
+ app .config .from_pyfile (os .path .join (os .getcwd (), "config.py" ))
16
21
17
- app .config .from_pyfile (config )
18
22
app .config ["SQLALCHEMY_TRACK_MODIFICATIONS" ] = False
19
23
20
- app .config ["GIT_REVISION" ] = subprocess .check_output (['git' ,
21
- 'rev-parse' ,
22
- '--short' ,
23
- 'HEAD' ]).decode ('utf-8' ).rstrip ()
24
-
25
-
26
24
db = SQLAlchemy (app )
27
25
migrate = Migrate (app , db )
28
26
sentry = Sentry (app )
31
29
app .config ['LDAP_BIND_PW' ],
32
30
ro = app .config ['LDAP_RO' ])
33
31
32
+
34
33
def start_of_year ():
35
34
start = datetime (datetime .today ().year , 6 , 1 )
36
35
if datetime .today () < start :
37
- start = datetime (datetime .today ().year - 1 , 6 , 1 )
36
+ start = datetime (datetime .today ().year - 1 , 6 , 1 )
38
37
return start
39
38
39
+
40
40
# pylint: disable=C0413
41
- from conditional .models .models import UserLog
41
+ from .models .models import UserLog
42
+
42
43
43
44
# Configure Logging
44
- def request_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
45
+ def request_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
45
46
if 'request' in event_dict :
46
47
flask_request = event_dict ['request' ]
47
48
event_dict ['user' ] = flask_request .headers .get ("x-webauth-user" )
@@ -52,7 +53,7 @@ def request_processor(logger, log_method, event_dict): # pylint: disable=unused-
52
53
return event_dict
53
54
54
55
55
- def database_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
56
+ def database_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
56
57
if 'request' in event_dict :
57
58
if event_dict ['method' ] != 'GET' :
58
59
log = UserLog (
@@ -62,35 +63,35 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unused
62
63
blueprint = event_dict ['blueprint' ],
63
64
path = event_dict ['path' ],
64
65
description = event_dict ['event' ]
65
- )
66
+ )
66
67
db .session .add (log )
67
68
db .session .flush ()
68
69
db .session .commit ()
69
70
del event_dict ['request' ]
70
71
return event_dict
71
72
73
+
72
74
structlog .configure (processors = [
73
75
request_processor ,
74
76
database_processor ,
75
77
structlog .processors .KeyValueRenderer ()
76
- ])
78
+ ])
77
79
78
80
logger = structlog .get_logger ()
79
81
80
-
81
- from conditional .blueprints .dashboard import dashboard_bp # pylint: disable=ungrouped-imports
82
- from conditional .blueprints .attendance import attendance_bp
83
- from conditional .blueprints .major_project_submission import major_project_bp
84
- from conditional .blueprints .intro_evals import intro_evals_bp
85
- from conditional .blueprints .intro_evals_form import intro_evals_form_bp
86
- from conditional .blueprints .housing import housing_bp
87
- from conditional .blueprints .spring_evals import spring_evals_bp
88
- from conditional .blueprints .conditional import conditionals_bp
89
- from conditional .blueprints .member_management import member_management_bp
90
- from conditional .blueprints .slideshow import slideshow_bp
91
- from conditional .blueprints .cache_management import cache_bp
92
- from conditional .blueprints .co_op import co_op_bp
93
- from conditional .blueprints .logs import log_bp
82
+ from .blueprints .dashboard import dashboard_bp # pylint: disable=ungrouped-imports
83
+ from .blueprints .attendance import attendance_bp
84
+ from .blueprints .major_project_submission import major_project_bp
85
+ from .blueprints .intro_evals import intro_evals_bp
86
+ from .blueprints .intro_evals_form import intro_evals_form_bp
87
+ from .blueprints .housing import housing_bp
88
+ from .blueprints .spring_evals import spring_evals_bp
89
+ from .blueprints .conditional import conditionals_bp
90
+ from .blueprints .member_management import member_management_bp
91
+ from .blueprints .slideshow import slideshow_bp
92
+ from .blueprints .cache_management import cache_bp
93
+ from .blueprints .co_op import co_op_bp
94
+ from .blueprints .logs import log_bp
94
95
95
96
app .register_blueprint (dashboard_bp )
96
97
app .register_blueprint (attendance_bp )
@@ -106,7 +107,8 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unused
106
107
app .register_blueprint (co_op_bp )
107
108
app .register_blueprint (log_bp )
108
109
109
- from conditional .util .ldap import ldap_get_member
110
+ from .util .ldap import ldap_get_member
111
+
110
112
111
113
@app .route ('/<path:path>' )
112
114
def static_proxy (path ):
@@ -118,6 +120,7 @@ def static_proxy(path):
118
120
def default_route ():
119
121
return redirect ('/dashboard' )
120
122
123
+
121
124
@app .errorhandler (404 )
122
125
@app .errorhandler (500 )
123
126
def route_errors (error ):
@@ -149,15 +152,17 @@ def route_errors(error):
149
152
error_desc = type (error ).__name__
150
153
151
154
return render_template ('errors.html' ,
152
- error = error_desc ,
153
- error_code = code ,
154
- event_id = g .sentry_event_id ,
155
- public_dsn = sentry .client .get_public_dsn ('https' ),
156
- ** data ), int (code )
155
+ error = error_desc ,
156
+ error_code = code ,
157
+ event_id = g .sentry_event_id ,
158
+ public_dsn = sentry .client .get_public_dsn ('https' ),
159
+ ** data ), int (code )
160
+
157
161
158
162
@app .cli .command ()
159
163
def zoo ():
160
164
from conditional .models .migrate import free_the_zoo
161
165
free_the_zoo (app .config ['ZOO_DATABASE_URI' ])
162
166
167
+
163
168
logger .info ('conditional started' )
0 commit comments