|
1 | 1 | import os
|
2 | 2 | import subprocess
|
| 3 | +from datetime import datetime |
3 | 4 | from flask import Flask, redirect, request, render_template, g
|
4 | 5 | from flask_sqlalchemy import SQLAlchemy
|
5 | 6 | from flask_migrate import Migrate
|
|
16 | 17 | app.config.from_pyfile(config)
|
17 | 18 | app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
18 | 19 |
|
19 |
| -try: |
20 |
| - app.config["GIT_REVISION"] = fetch_git_sha(app.config["ROOT_DIR"])[:7] |
21 |
| -except (InvalidGitRepository, KeyError): |
22 |
| - app.config["GIT_REVISION"] = "unknown" |
| 20 | +app.config["GIT_REVISION"] = subprocess.check_output(['git', |
| 21 | + 'rev-parse', |
| 22 | + '--short', |
| 23 | + 'HEAD']).decode('utf-8').rstrip() |
| 24 | + |
23 | 25 |
|
24 | 26 | db = SQLAlchemy(app)
|
25 | 27 | migrate = Migrate(app, db)
|
26 |
| -logger = structlog.get_logger() |
27 | 28 | sentry = Sentry(app)
|
28 | 29 |
|
29 | 30 | ldap = CSHLDAP(app.config['LDAP_BIND_DN'],
|
30 | 31 | app.config['LDAP_BIND_PW'],
|
31 | 32 | ro=app.config['LDAP_RO'])
|
32 | 33 |
|
| 34 | +def start_of_year(): |
| 35 | + start = datetime(datetime.today().year, 6, 1) |
| 36 | + if datetime.today() < start: |
| 37 | + start = datetime(datetime.today().year-1, 6, 1) |
| 38 | + return start |
| 39 | + |
33 | 40 | # pylint: disable=C0413
|
| 41 | +from conditional.models.models import UserLog |
| 42 | + |
| 43 | +# Configure Logging |
| 44 | +def request_processor(logger, log_method, event_dict): # pylint: disable=unused-argument, redefined-outer-name |
| 45 | + if 'request' in event_dict: |
| 46 | + flask_request = event_dict['request'] |
| 47 | + event_dict['user'] = flask_request.headers.get("x-webauth-user") |
| 48 | + event_dict['ip'] = flask_request.remote_addr |
| 49 | + event_dict['method'] = flask_request.method |
| 50 | + event_dict['blueprint'] = flask_request.blueprint |
| 51 | + event_dict['path'] = flask_request.full_path |
| 52 | + return event_dict |
| 53 | + |
| 54 | + |
| 55 | +def database_processor(logger, log_method, event_dict): # pylint: disable=unused-argument, redefined-outer-name |
| 56 | + if 'request' in event_dict: |
| 57 | + if event_dict['method'] != 'GET': |
| 58 | + log = UserLog( |
| 59 | + ipaddr=event_dict['ip'], |
| 60 | + user=event_dict['user'], |
| 61 | + method=event_dict['method'], |
| 62 | + blueprint=event_dict['blueprint'], |
| 63 | + path=event_dict['path'], |
| 64 | + description=event_dict['event'] |
| 65 | + ) |
| 66 | + db.session.add(log) |
| 67 | + db.session.flush() |
| 68 | + db.session.commit() |
| 69 | + del event_dict['request'] |
| 70 | + return event_dict |
| 71 | + |
| 72 | +structlog.configure(processors=[ |
| 73 | + request_processor, |
| 74 | + database_processor, |
| 75 | + structlog.processors.KeyValueRenderer() |
| 76 | + ]) |
| 77 | + |
| 78 | +logger = structlog.get_logger() |
| 79 | + |
34 | 80 |
|
35 |
| -from conditional.blueprints.dashboard import dashboard_bp |
| 81 | +from conditional.blueprints.dashboard import dashboard_bp # pylint: disable=ungrouped-imports |
36 | 82 | from conditional.blueprints.attendance import attendance_bp
|
37 | 83 | from conditional.blueprints.major_project_submission import major_project_bp
|
38 | 84 | from conditional.blueprints.intro_evals import intro_evals_bp
|
|
43 | 89 | from conditional.blueprints.member_management import member_management_bp
|
44 | 90 | from conditional.blueprints.slideshow import slideshow_bp
|
45 | 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 |
46 | 94 |
|
47 | 95 | app.register_blueprint(dashboard_bp)
|
48 | 96 | app.register_blueprint(attendance_bp)
|
|
55 | 103 | app.register_blueprint(member_management_bp)
|
56 | 104 | app.register_blueprint(slideshow_bp)
|
57 | 105 | app.register_blueprint(cache_bp)
|
| 106 | +app.register_blueprint(co_op_bp) |
| 107 | +app.register_blueprint(log_bp) |
58 | 108 |
|
59 | 109 | from conditional.util.ldap import ldap_get_member
|
60 | 110 |
|
|
0 commit comments