Skip to content

Conditional v1.4.0 #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions conditional/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import os
import subprocess
from flask import Flask
from flask import redirect
from flask import Flask, redirect, request, render_template, g
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from csh_ldap import CSHLDAP
from raven import fetch_git_sha
from raven.contrib.flask import Sentry
from raven.exceptions import InvalidGitRepository
import structlog

app = Flask(__name__)

config = os.path.join(os.getcwd(), "config.py")
config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.py")

app.config.from_pyfile(config)
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

app.config["GIT_REVISION"] = subprocess.check_output(['git',
'rev-parse',
'--short',
'HEAD']).decode('utf-8').rstrip()
try:
app.config["GIT_REVISION"] = fetch_git_sha(app.config["ROOT_DIR"])[:7]
except (InvalidGitRepository, KeyError):
app.config["GIT_REVISION"] = "unknown"

db = SQLAlchemy(app)
migrate = Migrate(app, db)
logger = structlog.get_logger()
sentry = Sentry(app)

ldap = CSHLDAP(app.config['LDAP_BIND_DN'],
app.config['LDAP_BIND_PW'],
Expand Down Expand Up @@ -52,6 +56,7 @@
app.register_blueprint(slideshow_bp)
app.register_blueprint(cache_bp)

from conditional.util.ldap import ldap_get_member

@app.route('/<path:path>')
def static_proxy(path):
Expand All @@ -63,6 +68,42 @@ def static_proxy(path):
def default_route():
return redirect('/dashboard')

@app.errorhandler(404)
@app.errorhandler(500)
def route_errors(error):
data = dict()
username = request.headers.get('x-webauth-user')

# Handle the case where the header isn't present
if username is not None:
member = ldap_get_member(username)
data['username'] = member.uid
data['name'] = member.cn
else:
data['username'] = "unknown"
data['name'] = "Unknown"

# Figure out what kind of error was passed
if isinstance(error, int):
code = error
elif hasattr(error, 'code'):
code = error.code
else:
# Unhandled exception
code = 500

# Is this a 404?
if code == 404:
error_desc = "Page Not Found"
else:
error_desc = type(error).__name__

return render_template('errors.html',
error=error_desc,
error_code=code,
event_id=g.sentry_event_id,
public_dsn=sentry.client.get_public_dsn('https'),
**data), int(code)

@app.cli.command()
def zoo():
Expand Down
22 changes: 11 additions & 11 deletions conditional/blueprints/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_non_alumni_non_coop(internal=False):
for account in active_members:
if account.uid in coop_members:
# Members who are on co-op don't need to go to house meeting.
pass
continue

eligible_members.append(
{
Expand All @@ -91,8 +91,8 @@ def get_non_alumni_non_coop(internal=False):

if internal:
return eligible_members
else:
return jsonify({'members': eligible_members}), 200

return jsonify({'members': eligible_members}), 200


@attendance_bp.route('/attendance/cm_members')
Expand Down Expand Up @@ -314,15 +314,15 @@ def alter_house_attendance(uid, hid):
member_meeting.attendance_status = "Attended"
db.session.commit()
return jsonify({"success": True}), 200
else:
freshman_meeting = FreshmanHouseMeetingAttendance.query.filter(
FreshmanHouseMeetingAttendance.fid == uid,
FreshmanHouseMeetingAttendance.meeting_id == hid
).first()

freshman_meeting.attendance_status = "Attended"
db.session.commit()
return jsonify({"success": True}), 200
freshman_meeting = FreshmanHouseMeetingAttendance.query.filter(
FreshmanHouseMeetingAttendance.fid == uid,
FreshmanHouseMeetingAttendance.meeting_id == hid
).first()

freshman_meeting.attendance_status = "Attended"
db.session.commit()
return jsonify({"success": True}), 200


@attendance_bp.route('/attendance/alter/hm/<uid>/<hid>', methods=['POST'])
Expand Down
4 changes: 2 additions & 2 deletions conditional/blueprints/conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ def conditional_delete(cid):
db.session.flush()
db.session.commit()
return jsonify({"success": True}), 200
else:
return "Must be evals director to delete!", 401

return "Must be evals director to delete!", 401
25 changes: 15 additions & 10 deletions conditional/blueprints/intro_evals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from conditional.models.models import FreshmanCommitteeAttendance
from conditional.models.models import MemberCommitteeAttendance
from conditional.models.models import CommitteeMeeting
from conditional.models.models import FreshmanAccount
from conditional.models.models import FreshmanEvalData
from conditional.models.models import FreshmanHouseMeetingAttendance
Expand All @@ -33,11 +34,13 @@ def display_intro_evals(internal=False):
# get user data
def get_uid_cm_count(member_id):
return len([a for a in MemberCommitteeAttendance.query.filter(
MemberCommitteeAttendance.uid == member_id)])
MemberCommitteeAttendance.uid == member_id)
if CommitteeMeeting.query.filter(CommitteeMeeting.id == a.meeting_id).approved])

def get_fid_cm_count(member_id):
return len([a for a in FreshmanCommitteeAttendance.query.filter(
FreshmanCommitteeAttendance.fid == member_id)])
FreshmanCommitteeAttendance.fid == member_id)
if CommitteeMeeting.query.filter(CommitteeMeeting.id == a.meeting_id).approved])

user_name = None
if not internal:
Expand Down Expand Up @@ -88,7 +91,8 @@ def get_fid_cm_count(member_id):
[s.name for s in TechnicalSeminar.query.filter(
TechnicalSeminar.id.in_(
[a.seminar_id for a in FreshmanSeminarAttendance.query.filter(
FreshmanSeminarAttendance.fid == fid.id)]
FreshmanSeminarAttendance.fid == fid.id)
if TechnicalSeminar.query.filter(TechnicalSeminar.id == a.seminar_id).approved]
))
],
'social_events': '',
Expand Down Expand Up @@ -141,7 +145,8 @@ def get_fid_cm_count(member_id):
[s.name for s in TechnicalSeminar.query.filter(
TechnicalSeminar.id.in_(
[a.seminar_id for a in MemberSeminarAttendance.query.filter(
MemberSeminarAttendance.uid == uid)]
MemberSeminarAttendance.uid == uid)
if TechnicalSeminar.query.filter(TechnicalSeminar.id == a.seminar_id).approved]
))
],
'social_events': freshman_data.social_events,
Expand All @@ -160,9 +165,9 @@ def get_fid_cm_count(member_id):

if internal:
return ie_members
else:
# return names in 'first last (username)' format
return render_template(request,
'intro_evals.html',
username=user_name,
members=ie_members)

# return names in 'first last (username)' format
return render_template(request,
'intro_evals.html',
username=user_name,
members=ie_members)
5 changes: 3 additions & 2 deletions conditional/blueprints/intro_evals_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from conditional.models.models import FreshmanEvalData
from conditional.models.models import EvalSettings
from conditional.util.ldap import ldap_is_intromember
from conditional.util.ldap import ldap_get_member
from conditional.util.flask import render_template

from conditional import db
Expand All @@ -23,8 +24,8 @@ def display_intro_evals_form():

# get user data
user_name = request.headers.get('x-webauth-user')

if not ldap_is_intromember(user_name):
account = ldap_get_member(user_name)
if not ldap_is_intromember(account):
return redirect("/dashboard")
eval_data = FreshmanEvalData.query.filter(
FreshmanEvalData.uid == user_name).first()
Expand Down
4 changes: 2 additions & 2 deletions conditional/blueprints/major_project_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ def major_project_delete(pid):
db.session.flush()
db.session.commit()
return jsonify({"success": True}), 200
else:
return "Must be project owner to delete!", 401

return "Must be project owner to delete!", 401
14 changes: 7 additions & 7 deletions conditional/blueprints/member_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ def get_hm_date(hm_id):
'missed_hm': hms_missed,
'user': 'eval'
}), 200
else:
return jsonify(
{
'name': account.cn,
'active_member': ldap_is_active(account),
'user': 'financial'
}), 200

return jsonify(
{
'name': account.cn,
'active_member': ldap_is_active(account),
'user': 'financial'
}), 200


@member_management_bp.route('/manage/user/<fid>', methods=['DELETE'])
Expand Down
22 changes: 16 additions & 6 deletions conditional/blueprints/spring_evals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from conditional.util.ldap import ldap_get_active_members

from conditional.models.models import MemberCommitteeAttendance
from conditional.models.models import CommitteeMeeting
from conditional.models.models import MemberHouseMeetingAttendance
from conditional.models.models import MajorProject
from conditional.models.models import HouseMeeting
Expand All @@ -28,7 +29,8 @@ def display_spring_evals(internal=False):

def get_cm_count(member_id):
return len([a for a in MemberCommitteeAttendance.query.filter(
MemberCommitteeAttendance.uid == member_id)])
MemberCommitteeAttendance.uid == member_id)
if CommitteeMeeting.query.filter(CommitteeMeeting.id == a.meeting_id).approved])

user_name = None
if not internal:
Expand Down Expand Up @@ -87,6 +89,14 @@ def get_cm_count(member_id):
MajorProject.uid == uid)]
}
member['major_projects_len'] = len(member['major_projects'])
member['major_project_passed'] = [
{
'name': p.name,
'status': p.status,
'description': p.description
} for p in MajorProject.query.filter(MajorProject.uid == uid)
if p.status == "Passed"]
member['major_projects_passed_len'] = len(member['major_projects_passed'])
member['major_project_passed'] = False
for mp in member['major_projects']:
if mp['status'] == "Passed":
Expand All @@ -103,8 +113,8 @@ def get_cm_count(member_id):
# return names in 'first last (username)' format
if internal:
return sp_members
else:
return render_template(request,
'spring_evals.html',
username=user_name,
members=sp_members)

return render_template(request,
'spring_evals.html',
username=user_name,
members=sp_members)
10 changes: 8 additions & 2 deletions conditional/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@
{% block body %}
{% endblock %}
{% else %}
<div class="container main">
<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-remove-sign"></span> Site Lockdown: Evaluations in progress. Please check back later.</div>
<div class="container main error-page align-center">
<div class="col-xs-12">
<img src="/static/images/material_lock.svg" alt="Attention!">
<h1>Congratulations or I'm Sorry...</h1>
<h2>We cannot reveal the results of your evaluation!</h2>
<h3>Evaluations underway:</h3>
<p>Conditional is in Lockdown</p>
</div>
</div>
{% endif %}

Expand Down
19 changes: 19 additions & 0 deletions conditional/templates/errors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "nav.html" %}
{% block title %}Error {{ error_code }}{% endblock %}
{% block body %}
<div class="container main error-page align-center">
<div class="col-xs-12">
<img src="/static/images/material_attention.svg" alt="Attention!">
<h1>Congratulations or I'm Sorry...</h1>
<h2>Something has gone terribly wrong!</h2>
<h3>{{ error }}</h3>
{% if event_id %}
<p>The error identifier is: {{ event_id }}</p>
{% endif %}
</div>
{% if event_id %}
<button type="button" class="btn btn-primary" data-module="errorReport" data-event="{{ event_id }}">Report this Error</button>
{% endif %}
</div>

{% endblock %}
4 changes: 2 additions & 2 deletions conditional/templates/intro_evals.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ <h6 class="eval-uid">{{ m['uid'] }}</h6>
<div class="text-center">
{% if m['signatures_missed'] == 0 %}
<div class="eval-info-label">
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>Sigantures Missed
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>Signatures Missed
<span class="eval-info-number">{{ m['signatures_missed'] }}</span>
</div>
{% elif m['signatures_missed'] > 0 %}
<div class="eval-info-label">
<span class="glyphicon glyphicon-remove-sign red eval-info-status"></span>Sigantures Missed
<span class="glyphicon glyphicon-remove-sign red eval-info-status"></span>Signatures Missed
<span class="eval-info-number">{{ m['signatures_missed'] }}</span>
</div>
{% else %}
Expand Down
8 changes: 5 additions & 3 deletions conditional/templates/major_project_submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ <h3 class="page-title">Major Project Form</h3>
<div class="panel-body">
<div class="form-group label-floating is-empty">
<label class="control-label" for="name">Project Name</label>
<input class="form-control" id="name" name="name" type="text" maxlength="64">
<input class="form-control" id="name" name="name" type="text" maxlength="64"
placeholder="A clever name for your project, sometimes people will come up with an acronym.">
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body" style="padding-top:20px;">
<div class="form-group label-floating is-empty">
<label class="control-label" for="description">Description</label>
<textarea name="description" class="form-control" rows="3" id="description"></textarea>
<textarea name="description" class="form-control" rows="3" id="description"
placeholder="A 'two liner' description of what your project is. If you have source materials like a GitHub repo publicly available, it's also useful to include links to them."></textarea>
</div>
</div>
</div>
Expand Down Expand Up @@ -79,7 +81,7 @@ <h5 style="padding:15px 20px;float:right"><span class="glyphicon glyphicon-hourg
{% endif %}
</div>
<button class="btn-expand-panel" role="button" data-toggle="collapse" href="#evalsCollapse-{{p['id']}}" aria-expanded="false" aria-controls="evalsCollapse-{{p['id']}}"><span class="glyphicon glyphicon glyphicon-menu-down"></span></button>
<div class="collapse" id="evalsCollapse-{{p['id']}}">
<div class="collapse major-project-desc" id="evalsCollapse-{{p['id']}}">
{{p['description']}}
</div>
</div>
Expand Down
Loading