def get(self, type_): # 对课程进行选择 class_arg_parser_helper(self.parser, location=("args", )) # 在query字符中写上需要的数据量 self.parser.add_argument("count", type=int, required=True, location=("args", )) args = self.parser.parse_args() class_id = str(args['start_year']) + "_" + str( args["end_year"]) + "_" + str(args['semester']) + "_" + str( args['number']) lesson = query_class_by_class_id(class_id) if lesson is None: return jsonify(ERROR="No such class") # 课程表的主键 id_ = lesson.id if type_ == self.HOMEWORK: # 根据参数返回相应数据 all_homework = get_homework(id_, args['count']) count = len(all_homework) if count == 0: return jsonify(ERROR="no homework") return jsonify(count=count, homework=list( map(lambda x: x.to_dict(), all_homework))) elif type_ == self.DISCUSSION: # 返回讨论信息 # 暂时限制返回的全球吹水数量 message_count = args['count'] if message_count == 400: message_count = 100 all_discussions = get_discussion(id_, message_count) count = len(all_discussions) if count == 0: return jsonify(ERROR="no discussion") class_number = int(args['number']) if class_number == 0: # 全球吹水的话 notifications = notification_manager.get_notification() if notifications is not None: return jsonify(latest=notifications, count=count, discussions=list( map(lambda x: x.to_dict(), all_discussions))) return jsonify(count=count, discussions=list( map(lambda x: x.to_dict(), all_discussions))) else: abort(404)
def get(self, type_): # 对课程进行选择 class_arg_parser_helper(self.parser, location=("args", )) # 在query字符中写上需要的数据量 self.parser.add_argument("count", type=int, required=True, location=("args", )) args = self.parser.parse_args() class_id = str(args['start_year']) + "_" + str(args["end_year"]) + "_" + str(args['semester']) + "_" + str(args['number']) lesson = query_class_by_class_id(class_id) if lesson is None: return jsonify(ERROR="No such class") # 课程表的主键 id_ = lesson.id if type_ == self.HOMEWORK: # 根据参数返回相应数据 all_homework = get_homework(id_, args['count']) count = len(all_homework) if count == 0: return jsonify(ERROR="no homework") return jsonify(count=count, homework=list(map(lambda x: x.to_dict(), all_homework))) elif type_ == self.DISCUSSION: # 返回讨论信息 # 暂时限制返回的全球吹水数量 message_count = args['count'] if message_count == 400: message_count = 100 all_discussions = get_discussion(id_, message_count) count = len(all_discussions) if count == 0: return jsonify(ERROR="no discussion") class_number = int(args['number']) if class_number == 0: # 全球吹水的话 notifications = notification_manager.get_notification() if notifications is not None: return jsonify(latest=notifications, count=count, discussions=list(map(lambda x: x.to_dict(), all_discussions))) return jsonify(count=count, discussions=list(map(lambda x: x.to_dict(), all_discussions))) else: abort(404)
def get(self): obj = notification_manager.get_notification() if obj is not None: return jsonify(latest=obj) else: return jsonify(ERROR="no any notifications")