def text(short_question, methods=['GET']): """Return all comments of a given type (e.g. general comments).""" # Unpack arguments # Only allow 'en' and 'fr' to be passed to app lang = 'fr' if request.args.get('lang', None) == 'fr' else 'en' short_question = fields.QUESTION_DICT.get(short_question, None) course_code = request.args.get('course_code', '').upper() department_code = request.args.get('department_code', '').upper() fiscal_year = request.args.get('fiscal_year', '') stars = request.args.get('stars', '') limit = request.args.get('limit', '') offset = request.args.get('offset', '0') # Mandatory arguments if short_question is None: return _invalid_args('Invalid question type.') if not department_code: return _missing_args(missing=['department_code']) if not limit: return _missing_args(missing=['limit']) # Ensure args 'limit' and 'offset' are both integers if not limit.isdigit() or not offset.isdigit(): return _invalid_args('Invalid limit and/or offset.') # Run query and return as JSON results = queries.load_comments(short_question, course_code, lang, fiscal_year, department_code, stars, limit, offset) if not results: return _valid_get(list()) results = [_make_dict(tup, lang) for tup in results] results_processed = _valid_get(results) return results_processed
def offering_counts(): # Only allow 'en' and 'fr' to be passed to app lang = 'fr' if request.args.get('lang', None) == 'fr' else 'en' # User must pass at least date_1 date_1 = request.args.get('date_1', None) if not date_1: return _missing_args(missing=['date_1']) # If date_2 not specified, simply assume a 1-day range date_2 = request.args.get('date_2', None) if not date_2: date_2 = date_1 # If exclude_cancelled is true, exclude 'Cancelled - Normal' from # permitted values for offering_status exclude_cancelled = request.args.get('exclude_cancelled', 'false') offering_status = [ 'Delivered - Normal', 'Open - Normal', 'Open - Normal' ] if exclude_cancelled == 'true' else [ 'Cancelled - Normal', 'Delivered - Normal', 'Open - Normal' ] # Optional course_code = request.args.get('course_code', '').upper() instructor_name = request.args.get('instructor_name', '') business_line = request.args.get('business_line', '') clients_only = request.args.get('clients_only', 'false') # Run query and return as JSON results = queries.load_offering_counts(date_1, date_2, offering_status, course_code, instructor_name, business_line, clients_only, lang) results_processed = _valid_get(results) return results_processed
def remove_mandatory_course(): # Unpack arguments data = request.json department_code = data.get('department_code', None) course_code = data.get('course_code', None) if not department_code: return _missing_args(missing=['department_code']) if not course_code: return _missing_args(missing=['course_code']) try: queries.remove_mandatory_course(department_code, course_code) except Exception as e: return _invalid_delete() else: return _valid_delete()
def add_mandatory_course(): # Unpack arguments data = request.json department_code = data.get('department_code', None) course_code = data.get('course_code', None) if not department_code: return _missing_args(missing=['department_code']) if not course_code: return _missing_args(missing=['course_code']) try: queries.add_mandatory_course(department_code, course_code) # If IntegrityError i.e. course entry already exists, return status 'OK' except IntegrityError: return _valid_post() except Exception as e: return _invalid_post() else: return _valid_post()
def training_locations(): # Only allow 'en' and 'fr' to be passed to app lang = 'fr' if request.args.get('lang', None) == 'fr' else 'en' # Unpack arguments department_code = request.args.get('department_code', '').upper() if not department_code: return _missing_args(missing=['department_code']) # Run query and return as JSON results = queries.load_training_locations(lang, department_code) results_processed = _valid_get(results) return results_processed
def get_mandatory_courses(): """Return list of all active courses and if the given department considers them mandatory for its employees. """ # Only allow 'en' and 'fr' to be passed to app lang = 'fr' if request.args.get('lang', None) == 'fr' else 'en' # Unpack arguments department_code = request.args.get('department_code', '').upper() if not department_code: return _missing_args(missing=['department_code']) # Run query and return as JSON results = queries.load_mandatory_courses(lang, department_code) results_processed = _valid_get(results) return results_processed
def course_codes(short_question, methods=['GET']): """Return list of course codes that match criteria.""" # Unpack arguments short_question = fields.QUESTION_DICT.get(short_question, None) department_code = request.args.get('department_code', '').upper() fiscal_year = request.args.get('fiscal_year', '') # Mandatory arguments if short_question is None: return _invalid_args('Invalid question type.') if not department_code: return _missing_args(missing=['department_code']) results = queries.load_course_codes(short_question, fiscal_year, department_code) results_processed = _valid_get(results) return results_processed
def counts(short_question, methods=['GET']): """Return number of comments of a given type (e.g. general comments).""" # Unpack arguments short_question = fields.QUESTION_DICT.get(short_question, None) course_code = request.args.get('course_code', '').upper() department_code = request.args.get('department_code', '').upper() fiscal_year = request.args.get('fiscal_year', '') # Mandatory arguments if short_question is None: return _invalid_args('Invalid question type.') if not department_code: return _missing_args(missing=['department_code']) results = queries.load_counts(short_question, course_code, fiscal_year, department_code) results_processed = _valid_get(results) return results_processed