Example #1
0
 def get_feedback(self, parser, user_id):
     self.add_pagination_args(parser)
     page, page_size = self.get_params('page', 'page_size')
     user = User.get(id=user_id)
     if not user:
         self.bad_request(errorcode.NOT_FOUND)
     q = StudyFeedback.query.filter_by(student_id=user_id)
     total = q.count()
     fbs = q.order_by(StudyFeedback.study_date.desc()).paginate(
         page, page_size).items
     items = []
     for fb in fbs:
         data = {
             'id': fb.id,
             'chinese_name': fb.chinese_name,
             'study_date': fb.study_date.strftime('%Y-%m-%d'),
             'class_time': fb.class_time,
             'leave_time': fb.study_time,
             'course_name': fb.course_name,
             'section': fb.section,
             'contents': fb.contents,
             'homework': fb.homework,
             'feedback': fb.feedback,
         }
         items.append(data)
     return {
         'page_total': page_total(total, page_size),
         'page': page,
         'items': items,
         'chinese_name': user.chinese_name,
     }
Example #2
0
 def get_list(self):
     parser = self.get_parser()
     self.add_pagination_args(parser)
     parser.add_argument('order_update_time', type=str, required=False, location='args', default='desc')
     page, page_size = self.get_params('page', 'page_size')
     if self.get_param('order_update_time') == 'desc':
         order_by = SuccessCase.update_time.desc()
     else:
         order_by = SuccessCase.update_time
     total, items = SuccessCase.get_all(page, page_size, order_by=order_by)
     datas = []
     for item in items:
         school = item.school if item.school else u'待定'
         data = {
             'id': item.id,
             'chinese_name': item.chinese_name,
             'school': school,
             'tag': item.tag,
             'update_time': item.update_time.strftime('%Y-%m-%d'),
         }
         datas.append(data)
     return {
         'page_total': page_total(total, page_size),
         'page': page,
         'items': datas,
     }
Example #3
0
 def get_students(self):
     parser = self.get_parser()
     self.add_pagination_args(parser)
     parser.add_argument('key',
                         type=StringParam.check,
                         required=False,
                         location='args',
                         min=0,
                         max=20)
     parser.add_argument('order_create_time',
                         type=str,
                         required=False,
                         location='args')
     parser.add_argument('order_update_time',
                         type=str,
                         required=False,
                         location='args')
     page, page_size, key = self.get_params('page', 'page_size', 'key')
     order_create_time = self.get_param('order_create_time')
     order_update_time = self.get_param('order_update_time')
     if order_create_time == 'desc':
         order_by = User.create_time.desc()
     elif order_create_time == 'asc':
         order_by = User.create_time
     elif order_update_time == 'desc':
         order_by = User.coursetb_update_time.desc()
     elif order_update_time:
         order_by = User.coursetb_update_time
     else:
         order_by = None
     total, users = user_datastore.get_users(RoleType.student,
                                             page,
                                             page_size,
                                             'enabled',
                                             key,
                                             order_by=order_by)
     items = []
     for user in users:
         count = CourseTable.query.filter_by(student_id=user.id).count()
         status = u'已创建' if count != 0 else u'未创建'
         data = {
             'id': user.id,
             'chinese_name': user.chinese_name,
             'course_name': user.student.course_name,
             'study_country': user.student.study_country,
             'location': user.student.location,
             'learn_range': user.student.learn_range,
             'phone': user.phone,
             'status': status,
             'create_time': user.create_time.strftime('%Y-%m-%d'),
             'update_time': user.coursetb_update_time.strftime('%Y-%m-%d'),
         }
         items.append(data)
     return {
         'page_total': page_total(total, page_size),
         'page': page,
         'items': items,
     }
Example #4
0
 def get_student(self, parser):
     self.add_pagination_args(parser)
     page, page_size = self.get_params('page', 'page_size')
     parser.add_argument('key',
                         type=unicode,
                         required=False,
                         location='args')
     parser.add_argument('order_create_time',
                         type=str,
                         required=False,
                         location='args',
                         default='desc')
     if self.get_param('order_create_time') == 'desc':
         order_by = User.create_time.desc()
     else:
         order_by = User.create_time
     total, users = user_datastore.get_users(RoleType.student,
                                             page,
                                             page_size,
                                             'enabled',
                                             self.get_param('key'),
                                             order_by=order_by)
     items = []
     for user in users:
         q = StudyFeedback.query.filter_by(student_id=user.id)
         count = q.count()
         fbs = q.order_by(StudyFeedback.study_date.desc()).paginate(1,
                                                                    1).items
         update_time = fbs[0].update_time.strftime(
             '%Y-%m-%d') if count != 0 else '-'
         data = {
             'id': user.id,
             'chinese_name': user.chinese_name,
             'course_name': user.student.course_name,
             'school': user.student.school,
             'location': user.student.location,
             'learn_range': user.student.learn_range,
             'phone': user.phone,
             'create_time': user.create_time.strftime('%Y-%m-%d'),
             'update_time': update_time,
             'count': count,
         }
         items.append(data)
     return {
         'page_total': page_total(total, page_size),
         'page': page,
         'items': items,
     }
Example #5
0
 def get_course_apply(self):
     parser = self.get_parser()
     self.add_pagination_args(parser)
     page, page_size = self.get_params('page', 'page_size')
     total, items = CourseApply.get_all(page, page_size)
     datas = []
     for item in items:
         data = {
             'id': item.id,
             'phone': item.phone,
             'name': item.name,
             'teacher': item.teacher,
             'create_time': item.create_time.strftime('%Y-%m-%d %H:%M:%S'),
         }
         datas.append(data)
     return {
         'page': page,
         'page_total': page_total(total, page_size),
         'items': datas,
     }
Example #6
0
            total = 1
            items = [case]
        else:
            total, items = SuccessCase.get_all(page, page_size, tag)
        datas = []
        for item in items:
            school = item.school if item.school else u'待定'
            data = {
                'id': item.id,
                'chinese_name': item.chinese_name,
                'school': school,
                'tag': item.tag,
                'test1': item.test1,
                'test2': item.test2,
                'test3': item.test3,
                'score1': item.score1,
                'score2': item.score2,
                'score3': item.score3,
                'feeling': item.feeling,
                'comment': item.comment,
                'update_time': item.update_time.strftime('%Y-%m-%d'),
            }
            datas.append(data)
        return {
            'page_total': page_total(total, page_size),
            'page': page,
            'total': total,
            'items': datas,
        }

Example #7
0
 def get_users(self, role_name, status):
     parser = self.get_parser()
     self.add_pagination_args(parser)
     parser.add_argument('key',
                         type=StringParam.check,
                         required=False,
                         location='args',
                         min=0,
                         max=20)
     parser.add_argument('order_update_time',
                         type=str,
                         required=False,
                         location='args',
                         default='desc')
     parser.add_argument('show',
                         type=str,
                         required=False,
                         location='args',
                         default='false')
     page, page_size, key = self.get_params('page', 'page_size', 'key')
     show = self.get_param('show') == 'true'
     if self.get_param('order_update_time') == 'desc':
         order_by = User.update_time.desc()
     else:
         order_by = User.update_time
     total, users = user_datastore.get_users(role_name, page, page_size,
                                             status, key, show, order_by)
     items = []
     if role_name == RoleType.teacher:
         for user in users:
             phone = user.phone if len(user.phone) != 32 else ''
             info = {
                 'id': user.id,
                 'chinese_name': user.chinese_name,
                 'english_name': user.english_name,
                 'graduated': user.teacher.graduated,
                 'major': user.teacher.major,
                 'country': user.teacher.country,
                 'phone': phone,
                 'introduce': user.teacher.introduce,
                 'success_case': user.teacher.success_case,
                 'feature': user.teacher.feature,
                 'update_time':
                 user.update_time.strftime('%Y-%m-%d %H:%M:%S'),
             }
             items.append(info)
     else:
         if not current_user.has_role(RoleType.admin):
             self.unauthorized(errorcode.UNAUTHORIZED)
         for user in users:
             info = {
                 'id': user.id,
                 'chinese_name': user.chinese_name,
                 'sexual': user.student.sexual,
                 'age': user.student.age,
                 'school': user.student.school,
                 'location': user.student.location,
                 'course_name': user.student.course_name,
                 'phone': user.phone,
                 'update_time':
                 user.update_time.strftime('%Y-%m-%d %H:%M:%S'),
             }
             items.append(info)
     return {
         'page_total': page_total(total, page_size),
         'page': page,
         'items': items,
     }