Skip to content

Commit

Permalink
Member Submission of Attendance (#116)
Browse files Browse the repository at this point in the history
* Fix Eboard Check and Frsmn Migration

* Add Approved Field and Migration Titles

* Committee Meeting Submtn and Review

* Technical Seminar Atnd Smbtn

* Spelling is hard.

* Display Seminars on History Page
  • Loading branch information
mbillow committed Jan 25, 2017
1 parent 28d2288 commit 0a5fd32
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 49 deletions.
200 changes: 175 additions & 25 deletions conditional/blueprints/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,9 @@ def display_attendance_cm():
request_id=str(uuid.uuid4()))
log.info('frontend', action='display committee meeting attendance page')

user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)
if not ldap_is_eboard(account):
return redirect("/dashboard")

return render_template(request,
'attendance_cm.html',
username=user_name,
username=request.headers.get("x-webauth-user"),
date=datetime.now().strftime("%Y-%m-%d"))


Expand All @@ -145,14 +140,9 @@ def display_attendance_ts():
request_id=str(uuid.uuid4()))
log.info('frontend', action='display technical seminar attendance page')

user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)
if not ldap_is_eboard(account):
return redirect("/dashboard")

return render_template(request,
'attendance_ts.html',
username=user_name,
username=request.headers.get("x-webauth-user"),
date=datetime.now().strftime("%Y-%m-%d"))


Expand Down Expand Up @@ -182,9 +172,7 @@ def submit_committee_attendance():

user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)
if not ldap_is_eboard(account):
return "must be eboard", 403

approved = ldap_is_eboard(account)
post_data = request.get_json()

committee = post_data['committee']
Expand All @@ -193,7 +181,7 @@ def submit_committee_attendance():
timestamp = post_data['timestamp']

timestamp = datetime.strptime(timestamp, "%Y-%m-%d")
meeting = CommitteeMeeting(committee, timestamp)
meeting = CommitteeMeeting(committee, timestamp, approved)

db.session.add(meeting)
db.session.flush()
Expand Down Expand Up @@ -225,8 +213,7 @@ def submit_seminar_attendance():
user_name = request.headers.get('x-webauth-user')

account = ldap_get_member(user_name)
if not ldap_is_eboard(account):
return "must be eboard", 403
approved = ldap_is_eboard(account)

post_data = request.get_json()

Expand All @@ -236,7 +223,7 @@ def submit_seminar_attendance():
timestamp = post_data['timestamp']

timestamp = datetime.strptime(timestamp, "%Y-%m-%d")
seminar = TechnicalSeminar(seminar_name, timestamp)
seminar = TechnicalSeminar(seminar_name, timestamp, approved)

db.session.add(seminar)
db.session.flush()
Expand Down Expand Up @@ -395,6 +382,18 @@ def get_meeting_attendees(meeting_id):
FreshmanAccount.id == freshman).first().name)
return attendees

def get_seminar_attendees(meeting_id):
attendees = [ldap_get_member(a.uid).displayName for a in
MemberSeminarAttendance.query.filter(
MemberSeminarAttendance.seminar_id == meeting_id).all()]

for freshman in [a.fid for a in
FreshmanSeminarAttendance.query.filter(
FreshmanSeminarAttendance.seminar_id == meeting_id).all()]:
attendees.append(FreshmanAccount.query.filter(
FreshmanAccount.id == freshman).first().name)
return attendees

log = logger.new(user_name=request.headers.get("x-webauth-user"),
request_id=str(uuid.uuid4()))

Expand All @@ -409,20 +408,46 @@ def get_meeting_attendees(meeting_id):
offset = 0 if int(page) == 1 else ((int(page)-1)*10)
limit = int(page)*10
all_cm = [{"id": m.id,
"directorship": m.committee,
"name": m.committee,
"dt_obj": m.timestamp,
"date": m.timestamp.strftime("%a %m/%d/%Y"),
"attendees": get_meeting_attendees(m.id)
} for m in CommitteeMeeting.query.all()]
c_meetings = sorted(all_cm, key=lambda k: k['dt_obj'], reverse=True)[offset:limit]
"attendees": get_meeting_attendees(m.id),
"type": "cm"
} for m in CommitteeMeeting.query.filter(
CommitteeMeeting.approved).all()]
all_ts = [{"id": m.id,
"name": m.name,
"dt_obj": m.timestamp,
"date": m.timestamp.strftime("%a %m/%d/%Y"),
"attendees": get_seminar_attendees(m.id),
"type": "ts"
} for m in TechnicalSeminar.query.filter(
TechnicalSeminar.approved).all()]
pend_cm = [{"id": m.id,
"name": m.committee,
"dt_obj": m.timestamp,
"date": m.timestamp.strftime("%a %m/%d/%Y"),
"attendees": get_meeting_attendees(m.id)
} for m in CommitteeMeeting.query.filter(
CommitteeMeeting.approved == False).all()] # pylint: disable=singleton-comparison
pend_ts = [{"id": m.id,
"name": m.name,
"dt_obj": m.timestamp,
"date": m.timestamp.strftime("%a %m/%d/%Y"),
"attendees": get_seminar_attendees(m.id)
} for m in TechnicalSeminar.query.filter(
TechnicalSeminar.approved == False).all()] # pylint: disable=singleton-comparison
all_meetings = sorted((all_cm + all_ts), key=lambda k: k['dt_obj'], reverse=True)[offset:limit]
if len(all_cm) % 10 != 0:
total_pages = (int(len(all_cm) / 10) + 1)
else:
total_pages = (int(len(all_cm) / 10))
return render_template(request,
'attendance_history.html',
username=user_name,
history=c_meetings,
history=all_meetings,
pending_cm=pend_cm,
pending_ts=pend_ts,
num_pages=total_pages,
current_page=int(page))

Expand Down Expand Up @@ -459,8 +484,83 @@ def alter_committee_attendance(cid):
db.session.commit()
return jsonify({"success": True}), 200


@attendance_bp.route('/attendance/alter/ts/<sid>', methods=['POST'])
def alter_seminar_attendance(sid):
log = logger.new(user_name=request.headers.get("x-webauth-user"),
request_id=str(uuid.uuid4()))
log.info('api', action='edit technical seminar attendance')

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

account = ldap_get_member(user_name)
if not ldap_is_eboard(account):
return "must be eboard", 403

post_data = request.get_json()
meeting_id = sid
m_attendees = post_data['members']
f_attendees = post_data['freshmen']

FreshmanSeminarAttendance.query.filter(
FreshmanSeminarAttendance.seminar_id == meeting_id).delete()

MemberSeminarAttendance.query.filter(
MemberSeminarAttendance.seminar_id == meeting_id).delete()

for m in m_attendees:
db.session.add(MemberSeminarAttendance(m, meeting_id))

for f in f_attendees:
db.session.add(FreshmanSeminarAttendance(f, meeting_id))

db.session.flush()
db.session.commit()
return jsonify({"success": True}), 200


@attendance_bp.route('/attendance/ts/<sid>', methods=['GET', 'DELETE'])
def get_cm_attendees(sid):
if request.method == 'GET':
attendees = [{"value": a.uid,
"display": ldap_get_member(a.uid).displayName
} for a in
MemberSeminarAttendance.query.filter(
MemberSeminarAttendance.seminar_id == sid).all()]

for freshman in [{"value": a.fid,
"display": FreshmanAccount.query.filter(FreshmanAccount.id == a.fid).first().name
} for a in FreshmanSeminarAttendance.query.filter(
FreshmanSeminarAttendance.seminar_id == sid).all()]:
attendees.append(freshman)
return jsonify({"attendees": attendees}), 200

elif request.method == 'DELETE':
log = logger.new(user_name=request.headers.get("x-webauth-user"),
request_id=str(uuid.uuid4()))
log.info('api', action='delete technical seminar')

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

account = ldap_get_member(user_name)
if not ldap_is_eboard(account):
return "must be eboard", 403

FreshmanSeminarAttendance.query.filter(
FreshmanSeminarAttendance.seminar_id == sid).delete()
MemberSeminarAttendance.query.filter(
MemberSeminarAttendance.seminar_id == sid).delete()
TechnicalSeminar.query.filter(
TechnicalSeminar.id == sid).delete()

db.session.flush()
db.session.commit()

return jsonify({"success": True}), 200


@attendance_bp.route('/attendance/cm/<cid>', methods=['GET', 'DELETE'])
def get_cm_attendees(cid):
def get_ts_attendees(cid):
if request.method == 'GET':
attendees = [{"value": a.uid,
"display": ldap_get_member(a.uid).displayName
Expand All @@ -476,6 +576,16 @@ def get_cm_attendees(cid):
return jsonify({"attendees": attendees}), 200

elif request.method == 'DELETE':
log = logger.new(user_name=request.headers.get("x-webauth-user"),
request_id=str(uuid.uuid4()))
log.info('api', action='delete committee meeting')

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

account = ldap_get_member(user_name)
if not ldap_is_eboard(account):
return "must be eboard", 403

FreshmanCommitteeAttendance.query.filter(
FreshmanCommitteeAttendance.meeting_id == cid).delete()
MemberCommitteeAttendance.query.filter(
Expand All @@ -487,3 +597,43 @@ def get_cm_attendees(cid):
db.session.commit()

return jsonify({"success": True}), 200


@attendance_bp.route('/attendance/cm/<cid>/approve', methods=['POST'])
def approve_cm(cid):
log = logger.new(user_name=request.headers.get("x-webauth-user"),
request_id=str(uuid.uuid4()))
log.info('api', action='approve committee meeting attendance')

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

account = ldap_get_member(user_name)
if not ldap_is_eboard(account):
return "must be eboard", 403

CommitteeMeeting.query.filter(
CommitteeMeeting.id == cid).first().approved = True
db.session.flush()
db.session.commit()

return jsonify({"success": True}), 200


@attendance_bp.route('/attendance/ts/<sid>/approve', methods=['POST'])
def approve_ts(sid):
log = logger.new(user_name=request.headers.get("x-webauth-user"),
request_id=str(uuid.uuid4()))
log.info('api', action='approve committee meeting attendance')

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

account = ldap_get_member(user_name)
if not ldap_is_eboard(account):
return "must be eboard", 403

TechnicalSeminar.query.filter(
TechnicalSeminar.id == sid).first().approved = True
db.session.flush()
db.session.commit()

return jsonify({"success": True}), 200
3 changes: 2 additions & 1 deletion conditional/blueprints/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def display_dashboard():
c_meetings = [m.meeting_id for m in
MemberCommitteeAttendance.query.filter(
MemberCommitteeAttendance.uid == member.uid
)]
) if CommitteeMeeting.query.filter(
CommitteeMeeting.id == m.meeting_id).first().approved]
spring['committee_meetings'] = len(c_meetings)
h_meetings = [(m.meeting_id, m.attendance_status) for m in
MemberHouseMeetingAttendance.query.filter(
Expand Down
3 changes: 2 additions & 1 deletion conditional/blueprints/member_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ def member_management_upgrade_user():
db.session.add(OnFloorStatusAssigned(uid, datetime.now()))

if acct.room_number:
ldap_set_roomnumber(uid, acct.room_number)
new_account = ldap_get_member(uid)
ldap_set_roomnumber(new_account, acct.room_number)

db.session.delete(acct)

Expand Down
8 changes: 6 additions & 2 deletions conditional/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ class CommitteeMeeting(db.Model):
'R&D', 'House Improvements', 'Financial', 'Chairman', name="committees_enum"),
nullable=False)
timestamp = Column(DateTime, nullable=False)
approved = Column(Boolean, nullable=False)
active = Column(Boolean)

def __init__(self, committee, timestamp):
def __init__(self, committee, timestamp, approved):
self.committee = committee
self.timestamp = timestamp
self.approved = approved
self.active = True


Expand Down Expand Up @@ -91,11 +93,13 @@ class TechnicalSeminar(db.Model):
id = Column(Integer, primary_key=True)
name = Column(String(128), nullable=False)
timestamp = Column(DateTime, nullable=False)
approved = Column(Boolean, nullable=False)
active = Column(Boolean)

def __init__(self, name, timestamp):
def __init__(self, name, timestamp, approved):
self.name = name
self.timestamp = timestamp
self.approved = approved
self.active = True


Expand Down
Loading

0 comments on commit 0a5fd32

Please sign in to comment.