def save_class(): raw_data = request.form details = httpagentparser.detect(request.headers.get("User-Agent")) details['operation'] = 'save_class' details['resolution'] = "%sx%s" % (raw_data.get( "screen-width", "?"), raw_data.get("screen-height", "?")) log_event(current_user.kerb, 'submit', details) data = {col: val.strip() for col, val in raw_data.items()} try: class_id = int(data.pop("class_id")) except Exception as err: msg = "Error getting class_id: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'update', status=-1, detail={ 'data': data, 'msg': msg }) if debug_mode(): raise flash_error(msg) return redirect(url_for("instructor")) current_user.acknowledge() try: flash_notify(current_user.update_class(class_id, data)) except Exception as err: msg = "Error updating class: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'update', status=-1, detail={ 'class_id': class_id, 'data': data, 'msg': msg }) if debug_mode(): raise flash_error(msg) return redirect(url_for("instructor"))
def activate(class_id): if not current_user.is_authenticated or not current_user.is_instructor: return redirect(url_for("index")) if not livesite() and current_user.stale_login: return redirect(url_for("logout")) current_user.acknowledge() try: flash_notify(current_user.activate(class_id)) except Exception as err: msg = "Error activing class {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'activate', status=-1, detail={ 'class_id': class_id, 'msg': msg }) if debug_mode(): raise flash_error(msg) return redirect(url_for("instructor"))
def acknoledge(): msgid = request.args.get('msgid') return current_user.acknowledge(msgid)
def save_student(): raw_data = request.form session["ctx"] = { x[4:]: raw_data[x] for x in raw_data if x.startswith("ctx-") } # return ctx-XXX values to if not 'submit' in session["ctx"]: flash_error( "Invalid operation, no submit value (please report this as a bug)." ) submit = [x for x in session["ctx"]["submit"].split(' ') if x] if not submit: flash_error( "Unrecognized submit value, no changes made (please report this as a bug)." ) return redirect(url_for("student")) if submit[0] == "cancel": flash_info("Changes discarded.") return redirect(url_for("student")) details = httpagentparser.detect(request.headers.get("User-Agent")) details['operation'] = submit[0] details['resolution'] = "%sx%s" % (raw_data.get( "screen-width", "?"), raw_data.get("screen-height", "?")) log_event(current_user.kerb, 'submit', details) if submit[0] == "save": # update the full_name supplied by Touchstone (in case this changes) if session.get("displayname", ""): current_user.full_name = session["displayname"] # treat the decision to save changes as acknowledgement of all unread messages current_user.acknowledge() if not save_changes(raw_data): if submit != "save": flash_error("The action you requested was not performed.") return redirect(url_for("student")) submit = submit[1:] if not submit: return redirect(url_for("student")) if submit[0] == "join": try: gid = int(submit[1]) flash_info(current_user.join(gid)) except Exception as err: msg = "Error joining group: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'join', status=-1, detail={ 'group_id': gid, 'msg': msg }) if debug_mode(): raise flash_error(msg) elif submit[0] == "leave": try: gid = int(submit[1]) flash_info(current_user.leave(gid)) except Exception as err: msg = "Error leaving group: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'leave', status=-1, detail={ 'group_id': gid, 'msg': msg }) if debug_mode(): raise flash_error(msg) elif submit[0] == "pool": try: cid = int(submit[1]) flash_info(current_user.pool(cid)) except Exception as err: msg = "Error adding you to the match pool: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'pool', status=-1, detail={ 'class_id': cid, 'msg': msg }) if debug_mode(): raise flash_error(msg) elif submit[0] == "unpool": try: cid = int(submit[1]) flash_info(current_user.unpool(cid)) except Exception as err: msg = "Error removing you from the match pool: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'unpool', status=-1, detail={ 'class_id': cid, 'msg': msg }) if debug_mode(): raise flash_error(msg) elif submit[0] == "matchasap": try: gid = int(submit[1]) flash_info(current_user.matchasap(gid)) except Exception as err: msg = "Error submitting match me asap request: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'matchasap', status=-1, detail={ 'group_id': gid, 'msg': msg }) if debug_mode(): raise flash_error(msg) elif submit[0] == "matchnow": try: gid = int(submit[1]) flash_info(current_user.matchnow(gid)) except Exception as err: msg = "Error submitting match me now request: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'matchnow', status=-1, detail={ 'group_id': gid, 'msg': msg }) if debug_mode(): raise flash_error(msg) elif submit[0] == "createprivate": try: cid = int(submit[1]) flash_info( current_user.create_group( cid, {k: raw_data.get(k, '').strip() for k in group_options}, public=False)) except Exception as err: msg = "Error creating private group: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'create', status=-1, detail={ 'class_id': cid, 'public': False, 'msg': msg }) if debug_mode(): raise flash_error(msg) elif submit[0] == "createpublic": try: cid = int(submit[1]) flash_info( current_user.create_group( cid, {k: raw_data.get(k, '').strip() for k in group_options}, public=True)) except Exception as err: msg = "Error creating public group: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'create', status=-1, detail={ 'class_id': cid, 'public': True, 'msg': msg }) if debug_mode(): raise flash_error(msg) elif submit[0] == "editgroup": try: gid = int(submit[1]) flash_info( current_user.edit_group( gid, {k: raw_data.get(k, '').strip() for k in group_options})) except Exception as err: msg = "Error editing group: {0}{1!r}".format( type(err).__name__, err.args) log_event(current_user.kerb, 'edit', status=-1, detail={ 'group_id': gid, 'public': True, 'msg': msg }) if debug_mode(): raise flash_error(msg) else: flash_error("Unrecognized submit command: " + submit[0]) return redirect(url_for("student"))