Skip to content

Commit 51108e9

Browse files
authored
Merge pull request #139 from ComputerScienceHouse/develop
Conditional 1.5.0
2 parents 586a56d + 57d4402 commit 51108e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1411
-361
lines changed

conditional/__init__.py

+56-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import subprocess
3+
from datetime import datetime
34
from flask import Flask, redirect, request, render_template, g
45
from flask_sqlalchemy import SQLAlchemy
56
from flask_migrate import Migrate
@@ -16,23 +17,68 @@
1617
app.config.from_pyfile(config)
1718
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
1819

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+
2325

2426
db = SQLAlchemy(app)
2527
migrate = Migrate(app, db)
26-
logger = structlog.get_logger()
2728
sentry = Sentry(app)
2829

2930
ldap = CSHLDAP(app.config['LDAP_BIND_DN'],
3031
app.config['LDAP_BIND_PW'],
3132
ro=app.config['LDAP_RO'])
3233

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+
3340
# 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+
3480

35-
from conditional.blueprints.dashboard import dashboard_bp
81+
from conditional.blueprints.dashboard import dashboard_bp # pylint: disable=ungrouped-imports
3682
from conditional.blueprints.attendance import attendance_bp
3783
from conditional.blueprints.major_project_submission import major_project_bp
3884
from conditional.blueprints.intro_evals import intro_evals_bp
@@ -43,6 +89,8 @@
4389
from conditional.blueprints.member_management import member_management_bp
4490
from conditional.blueprints.slideshow import slideshow_bp
4591
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
4694

4795
app.register_blueprint(dashboard_bp)
4896
app.register_blueprint(attendance_bp)
@@ -55,6 +103,8 @@
55103
app.register_blueprint(member_management_bp)
56104
app.register_blueprint(slideshow_bp)
57105
app.register_blueprint(cache_bp)
106+
app.register_blueprint(co_op_bp)
107+
app.register_blueprint(log_bp)
58108

59109
from conditional.util.ldap import ldap_get_member
60110

0 commit comments

Comments
 (0)