Esempio n. 1
0
 def video_get(self, video_id):
     """
     GET LIST BY id
     """
     if video_id is None:
         return None
     try:
         video = Video.objects.get(id=video_id)
     except IntegrityError:
         print 'error'
     video_data = to_dict(video)
     segment_all = video.video_segments.all()
     video_data['segments'] = [to_dict(v) for v in segment_all]
     return video_data
Esempio n. 2
0
    def pic_get(self, pic_id):
        """
          GET LIST BY id
          """
        if pic_id is None:
            return None
        try:
            pic = BKPPic.objects.get(id=pic_id)
        except IntegrityError:
            print 'error'
        pic_data = to_dict(pic)
        segment_all = BKPTarget.objects.filter(bkp_pic_id=pic_id).all()
        pic_data['segments'] = [to_dict(v) for v in segment_all]

        return pic_data
Esempio n. 3
0
 def course_get(self, course_id):
     """
     GET LIST BY id
     """
     if course_id is None:
         return None
     try:
         course = Course.objects.get(id=course_id)
     except IntegrityError:
         print 'error'
     course_data = to_dict(course)
     course_unit = course.courseunit.all()
     course_data['course_unit'] = [{
         'unit_id':
         obj.unit.id,
         'unit_text':
         u'{}:{}:{}:{}'.format(
             obj.unit.id,
             UNIT_TYPE.getDesc(obj.unit.type),
             obj.unit.name,
             obj.unit.show_name,
         ),
         'seq':
         obj.seq,
     } for obj in course_unit]
     course_data['course_system'] = [{
         'id':
         course.course_system.id,
         'text':
         u'{}:{}'.format(
             course.course_system.id,
             course.course_system.name,
         ),
     }]
     return course_data
Esempio n. 4
0
 def build_obj_data(self, obj, fields):
     obj_data = {}
     obj_data = to_dict(obj, fields)
     if fields:
         for field in fields:
             fn_vfield = 'getval_{}'.format(field)
             fn_val = getattr(self, fn_vfield, None)
             if callable(fn_val):
                 pds = get_func_param_default(fn_val)
                 default_value = pds.get('default', '')
                 need_escape = pds.get('need_escape', True)
                 try:
                     fn_kwargs = {}
                     if 'default' in pds:
                         fn_kwargs['default'] = default_value
                     if 'need_escape' in pds:
                         fn_kwargs['need_escape'] = need_escape
                     v = fn_val(obj, **fn_kwargs)
                     if need_escape and isinstance(v, (str, unicode)):
                         v = escape(v)
                     obj_data[field] = v
                 except:
                     import traceback
                     traceback.print_exc()
                     print 'error'
                     obj_data[field] = default_value
     obj_data['pk'] = obj.id
     # for datatables
     obj_data['DT_RowId'] = u'row_{}'.format(obj.id)
     obj_data['DT_RowData'] = {'pk': unicode(obj.id)}
     return obj_data
Esempio n. 5
0
 def course_system_get(self, course_system_id):
     """
     GET LIST BY id
     """
     if course_system_id is None:
         return None
     try:
         course_system = CourseSystem.objects.get(id=course_system_id)
     except IntegrityError:
         print 'error'
     cooridinate_all = course_system.course_coordinate.all()
     course_system_data = to_dict(course_system)
     cooridinate_data = [to_dict(v) for v in cooridinate_all]
     print course_system_data
     course_system_data['coordinates'] = cooridinate_data
     return course_system_data
Esempio n. 6
0
 def get_teacher_by_mobile(cls, mobile):
     """
     GET LIST BY id
     """
     try:
         teacher = Teacher.objects.get(mobile=mobile)
         teacher_data = to_dict(teacher)
     except:
         print "NO teacher"
         try:
             from backend.student.models import Student
             student = Student.objects.get(mobile=mobile)
             teacher_data = to_dict(student)
         except:
             print "NO student"
             return {'name': ''}
     return teacher_data
Esempio n. 7
0
    def level_get(self, level_id):
        """
          GET LIST BY id
          """
        if level_id is None:
            return None

        level = BKPLevel.objects.get(id=level_id)
        pic_data = to_dict(level)
        segment_all = BKPRound.objects.filter(
            bkp_level_id=level_id).order_by('seq').all()
        pic_data['segments'] = [to_dict(v) for v in segment_all]
        for item in pic_data['segments']:
            try:
                r = BKPPic.objects.get(id=item['bkp_pic_id'])
                item['bkp_pic_name'] = r.name if r else '图片丢失'
            except:
                item['bkp_pic_name'] = '图片丢失'
        return pic_data
Esempio n. 8
0
 def backendgroup_get(self, backendgroup_id):
     """
     GET LIST BY id
     """
     if backendgroup_id is None:
         return None
     try:
         backendgroup = BackendGroup.objects.get(id=backendgroup_id)
     except IntegrityError:
         print 'error'
     backendgroup_data = to_dict(backendgroup)
     return backendgroup_data
Esempio n. 9
0
 def simple_get(self, simple_id):
     """
     GET LIST BY id
     """
     if simple_id is None:
         return None
     try:
         simple = Simple.objects.get(id=simple_id)
     except IntegrityError:
         print 'error'
     simple_data = to_dict(simple)
     return simple_data
Esempio n. 10
0
 def teacherversion_get(self, teacherversion_id):
     """
     GET LIST BY id
     """
     if teacherversion_id is None:
         return None
     try:
         teacherversion = TeacherVersion.objects.get(id=teacherversion_id)
     except IntegrityError:
         print 'error'
     teacherversion_data = to_dict(teacherversion)
     return teacherversion_data
Esempio n. 11
0
 def class_get(self, class_id):
     """
     GET LIST BY id
     """
     if class_id is None:
         return None
     try:
         classes = Class.objects.get(id=class_id)
     except IntegrityError:
         print 'error'
     class_data = to_dict(classes)
     class_data['start_time'] = getformattime(
         class_data['start_time']) if class_data['start_time'] else ''
     class_data['course_system_name'] = classes.course_system.name
     class_data['course_rate'] = classes.classess.filter(
         course_status=2).count()
     class_data['progress'] = '%s/%s' % (
         class_data['course_rate'], classes.course_system.courses.count())
     class_data['teacher_name'] = classes.teacher.name
     class_data['students'] = [to_dict(s) for s in classes.students.all()]
     return class_data
Esempio n. 12
0
 def unit_get(self, unit_id):
     """
     GET LIST BY id
     """
     if unit_id is None:
         return None
     try:
         unit = Unit.objects.get(id=unit_id)
     except IntegrityError:
         print 'error'
     unit_data = to_dict(unit)
     return unit_data
Esempio n. 13
0
    def score_get(self, score_id):
        """
          GET LIST BY id
          """
        if score_id is None:
            return None
        try:
            score = ScoreEnjoy.objects.get(id=score_id)
        except IntegrityError:
            print 'error'
        score_data = to_dict(score)

        return score_data
Esempio n. 14
0
 def institution_get(self, institution_id):
     """
     GET LIST BY id
     """
     if institution_id is None:
         return None
     try:
         institution = Institution.objects.get(id=institution_id)
     except IntegrityError:
         print 'error'
     institution_data = to_dict(institution)
     institution_data['province'] = {
         'id': institution.city.province.id,
         'text': institution.city.province.name,
     }
     institution_data['city_name'] = institution.city.name
     return institution_data
Esempio n. 15
0
 def teacher_get(self, teacher_id):
     """
     GET LIST BY id
     """
     if teacher_id is None:
         return None
     try:
         teacher = Teacher.objects.get(id=teacher_id)
     except IntegrityError:
         raise IntegrityError
     teacher_data = to_dict(teacher)
     teacher_data['province'] = {
         'id': teacher.city.province.id,
         'text': teacher.city.province.name,
     } if getattr(teacher, 'city', '') else {}
     teacher_data['city_name'] = teacher.city.name if getattr(teacher, 'city', '') else ''
     return teacher_data
Esempio n. 16
0
 def user_get(cls, admin_id):
     """
     GET LIST BY id
     """
     if admin_id is None:
         return None
     try:
         admin = Admin.objects.get(user_id=admin_id)
     except IntegrityError:
         print 'error'
     admin_data = to_dict(admin)
     user_data = {
         'username': admin.user.username,
         'password': admin.user.password,
         'belong_groups': [1]
     }
     admin_data.update(user_data)
     return admin_data
Esempio n. 17
0
 def score_get(self, score_id):
     """
     GET LIST BY id
     """
     if score_id is None:
         return None
     try:
         qnyd_score = QnydScore.objects.get(id=score_id)
     except IntegrityError:
         print 'error'
     qnyd_score_data = to_dict(qnyd_score)
     qnyd_score_data['music_office'] = [
         self.get_dict_score(getattr(qnyd_score, 'staff1_score', '')),
         self.get_dict_score(getattr(qnyd_score, 'staff2_score', '')),
         self.get_dict_score(getattr(qnyd_score, 'staff3_score', '')),
         self.get_dict_score(getattr(qnyd_score, 'whole_score', ''))
     ]
     print qnyd_score_data
     return qnyd_score_data
Esempio n. 18
0
 def student_get(self, student_id):
     """
     GET LIST BY id
     """
     if student_id is None:
         return None
     try:
         studentes = Student.objects.get(id=student_id)
     except IntegrityError:
         print 'error'
     student_data = to_dict(studentes)
     count_result = self.get_count_num(student_id)
     student_data['create_time'] = getformattime(
         student_data['create_time']) if student_data['create_time'] else ''
     student_data['course_nums'] = count_result[0][0]
     student_data['game_bkp_level'] = count_result[1][0]
     student_data['game_bkp_coin_num'] = count_result[1][1]
     student_data['game_ballon_level'] = '%s/%s' % (count_result[2][0],
                                                    count_result[2][1])
     student_data['game_ballon_coin_num'] = count_result[2][2]
     return student_data
Esempio n. 19
0
    def section_get(self, section_id, type):
        """
        GET LIST BY id
        """
        if section_id is None:
            return None
        section_model = SECTION_TYPE_MODEL[int(type)]
        try:
            section = section_model.objects.get(id=section_id)
        except IntegrityError:
            print 'error'
        section_data = to_dict(section)
        video_options = []
        video_segment_options = []
        score_options = []
        score_segment_options = []
        game_options = []
        socres = []
        score_enjoys = []
        if isinstance(section, SECTION_TYPE_MODEL[1]) or isinstance(
                section, SECTION_TYPE_MODEL[2]):
            video_options.append({
                'id':
                section.video.id,
                'text':
                u'{}:{}:{}'.format(
                    section.video.id,
                    VIDEO_TYPE.getDesc(section.video.type),
                    section.video.name,
                ),
            })
            video_segment_options.append({
                'id':
                section.video_segment.id,
                'text':
                u'{}:{}'.format(
                    section.video_segment.id,
                    section.video_segment.label,
                ),
            }) if section.video_segment else ''
            section_data['video_segment'] = 2
        if isinstance(section, SECTION_TYPE_MODEL[2]):
            score_options.append({
                'id':
                section.score.id,
                'text':
                u'{}:{}:{}'.format(
                    section.score.id,
                    MUSIC_CATEGORY_TYPE.getDesc(section.score.music_category),
                    section.score.name,
                ),
            })

            score_segment_options.append({
                'id':
                section.score_segment.id,
                'text':
                u'{}:{}'.format(
                    section.score_segment.id,
                    section.score_segment.label,
                ),
            })
        if isinstance(section, SECTION_TYPE_MODEL[3]):
            score_options.append({
                'id':
                section.score.id,
                'text':
                u'{}:{}:{}'.format(
                    section.score.id,
                    MUSIC_CATEGORY_TYPE.getDesc(section.score.music_category),
                    section.score.name,
                ),
            })
        if isinstance(section, SECTION_TYPE_MODEL[4]):
            scores = section.sections.all()
            score_enjoyset = section.mc_sections.all()
            socres = [{
                'score_id':
                obj.score.id,
                'score_text':
                u'{}:{}:{}'.format(
                    obj.score.id,
                    MUSIC_CATEGORY_TYPE.getDesc(obj.score.music_category),
                    obj.score.name,
                ),
                'keyboard':
                obj.keyboard,
                'star_num':
                str(obj.star_num),
                'times':
                obj.times,
                'tempo':
                obj.tempo,
            } for obj in scores]
            score_enjoys = [{
                'score_id':
                obj.score_enjoy.id,
                'score_text':
                u'{}:{}'.format(
                    obj.score_enjoy.id,
                    obj.score_enjoy.name,
                ),
            } for obj in score_enjoyset]
        if isinstance(section, SECTION_TYPE_MODEL[5]):
            from .enumtype import GAME_TYPE
            query_set_all = BalloonSubLevel if int(
                section.type) == GAME_TYPE.YYQQ else BKPLevel
            game = query_set_all.objects.get(id=section.level_id)
            game_options.append({
                'id': game.id,
                'text': u'{}:{}'.format(
                    game.id,
                    game.name,
                ),
            })
        section_data['video_options'] = video_options
        section_data['video_segment_options'] = video_segment_options
        section_data['score_options'] = score_options
        section_data['score_segment_options'] = score_segment_options
        section_data['game_options'] = game_options
        section_data['scores'] = socres
        section_data['score_enjoys'] = score_enjoys
        return section_data
Esempio n. 20
0
    def target_by_id(self, target_id=None):
        if not target_id:
            return

        target = BKPTarget.objects.filter(id=target_id).all()[0]
        return to_dict(target)
Esempio n. 21
0
 def get_all_pics(cls):
     pics = []
     entrys = BKPPic.objects.all()
     return [to_dict(k) for k in entrys]