Ejemplo n.º 1
0
 def get(user):
     k = 'group-%s' % user.uuid
     v = cache.get(k)
     if v:
         data = cPickle.loads(v)
         data['cache'] = 'hit'
         return data
     data = {'group': [], 'grade': [], 'cache': 'miss'}
     server_type = models.Setting.getvalue('server_type')
     q = models.Group.objects.all()
     if server_type != 'school':
         if not is_admin(user):
             q = q.filter(uuid__in=user.permitted_groups.all())
     else:
         school = models.Group.objects.filter(group_type='school')
         terms = models.Term.get_current_term_list(school)
         grades = models.Grade.objects.filter(term__in=terms)
         grades = grades.values('uuid', 'name', 'term__school__uuid')
         data['grade'] = model_list_to_dict(grades)
     q = q.values('uuid', 'name', 'group_type', 'parent__uuid')
     data['group'] = model_list_to_dict(q)
     for d in data['group']:
         py = pypinyin.pinyin(d['name'], pypinyin.FIRST_LETTER)
         d['first_letter'] = ''.join([i[0] for i in py])
         py = ' '.join(pypinyin.lazy_pinyin(d['name'], pypinyin.TONE2))
         d['pinyin'] = py
     cache.set(k, cPickle.dumps(data, cPickle.HIGHEST_PROTOCOL),
               get_timeout(k, None))
     return data
Ejemplo n.º 2
0
def info(request, *args, **kwargs):
    d = {}
    # 缓存使用状况
    d['classes_last_active_time'] = cache.get('classes_last_active_time')
    d['classes'] = cache.get('classes')
    # 数据库状态
    q = models.Setting.objects.all()
    d['setting'] = model_list_to_dict(q)
    if models.Setting.getvalue('server_type') == 'school':
        q = models.Group.objects.all()
        d['group'] = model_list_to_dict(q)
    q = models.SyncLog.objects.count()
    d['synclog_count'] = q
    return create_success_dict(data=d)
Ejemplo n.º 3
0
def list_current(request, *args, **kwargs):
    school_uuid = request.GET.get('school_uuid')
    donot_pagination = request.GET.get('donot_pagination', False)
    q = models.LessonName.objects.filter(deleted=False)
    if school_uuid:
        q = q.filter(school__uuid=school_uuid)
    if models.Setting.getvalue('server_type') == 'school':
        q = q.values('uuid', 'name', 'types')
    else:
        q = q.order_by().values('name').distinct()

    order_lst = [
        u'',
        u'小学',
        u'小学,初中',
        u'小学,高中',
        u'小学,初中,高中',
        u'初中',
        u'初中,高中',
        u'高中',
    ]
    if len(q):
        q = list(q)
        q.sort(key=lambda d: len(d['name']))
        q.sort(key=lambda d: d.has_key('types') and d['types'] in order_lst and
               order_lst.index(d['types']) or -1)

    if donot_pagination == 'true':
        return create_success_dict(
            data={
                'records': model_list_to_dict(q),
                'page': 1,
                'page_size': len(q),
                'record_count': len(q),
                'page_count': 1,
            })

    page_info = get_page_info(request)
    page_data = db_utils.pagination(q, **page_info)

    return create_success_dict(
        data={
            'records': model_list_to_dict(page_data['records']),
            'page': page_data['page_num'],
            'page_size': page_data['page_size'],
            'record_count': page_data['record_count'],
            'page_count': page_data['page_count'],
        })
Ejemplo n.º 4
0
def grade_class(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(msg=failure)

        f = ClassFormSet(request.POST)
        if f.is_valid():
            # 删除旧数据进行全新安装
            cursor = connection.cursor()
            cursor.execute('DELETE FROM `Class`')
            cursor.execute('DELETE FROM `Grade`')
            for i in f.forms:
                i.save()
            install_step = models.Setting.objects.get(name='install_step')
            install_step.value = request.POST['install_step']
            install_step.save()
            return create_success_dict(msg='安装成功!')

        return create_failure_dict(msg='安装失败!', errors=f.errors)

    elif request.method == 'GET':
        if models.Setting.getvalue('installed') == 'True':
            return HttpResponseRedirect('/')

        q = models.Class.objects.all().values('grade__name', 'name')
        return create_success_dict(data=model_list_to_dict(q))
Ejemplo n.º 5
0
def get_lesson_period(request):
    ret = datetimeutil.get_term_from_date_range(request)
    if isinstance(ret, (str, unicode)):
        return create_failure_dict(msg=ret)
    q = models.LessonPeriod.objects.filter(term=ret)
    q = q.values('uuid', 'sequence')
    return create_success_dict(data={'lesson_period': model_list_to_dict(q)})
Ejemplo n.º 6
0
def lesson_list(request):
    #pk = request.GET.get('id')
    grade_name = request.GET.get('grade_name', '')
    term_uuid = request.GET.get('term_uuid', '')
    try:
        t = models.NewTerm.objects.get(uuid=term_uuid)
    except:
        return create_failure_dict(msg='错误的学年学期')

    # 保存syllabusgrade
    try:
        obj, c = models.SyllabusGrade.objects.get_or_create(
            school_year=t.school_year,
            term_type=t.term_type,
            grade_name=grade_name,
            defaults={'in_use': False})
    except:
        return create_failure_dict(msg='错误的班级信息')

    q = models.SyllabusGradeLesson.objects.filter(syllabus_grade=obj)
    q = q.values()

    return create_success_dict(
        data={
            'records': model_list_to_dict(q),
            'host': 'http://oebbt-cover.qiniudn.com',
            'RESOURCE_PLATFORM_HOST': constants.RESOURCE_PLATFORM_HOST
        })
Ejemplo n.º 7
0
    def get_teachers_lessons(class_uuid):
        q = models.LessonTeacher.objects.filter(class_uuid=class_uuid)
        q = q.values('teacher__uuid', 'teacher__name', 'lesson_name__name')
        ret = model_list_to_dict(q)
        return ret

        key = 'simplecache_lesson_teacher_%s' % class_uuid.uuid
        c = cache.get(key)
        if c:
            ret = json.loads(c)
        else:
            q = models.LessonTeacher.objects.filter(class_uuid=class_uuid)
            q = q.values('teacher__uuid', 'teacher__name', 'lesson_name__name')
            ret = model_list_to_dict(q)
            cache.set(key, json.dumps(ret), get_timeout(key, None))
        return ret
Ejemplo n.º 8
0
 def update_class_weekday(grade_name, class_name, weekday):
     '''
     lessonschedule-class-week: [
         {
             'lesson_name__name': 'fdsfds',
             'lesson_period__sequence': 1,
             'lesson_period__start_time': 'hh:mm:ss',
             'lesson_period__end_time': 'hh:mm:ss',
         },
         {...}, {...},
     ]
     '''
     try:
         term = models.Term.get_current_term_list()[0]
     except:
         return
     try:
         c = models.Class.objects.get(grade__term=term,
                                      grade__name=grade_name,
                                      name=class_name)
     except:
         return
     q = models.LessonSchedule.objects.all()
     q = q.filter(class_uuid=c, weekday=weekday)
     k = 'lessonschedule-%s-%s' % (c.uuid, weekday)
     cache.delete(k)
     q = q.filter(weekday=weekday).values('uuid', 'lesson_name__name',
                                          'lesson_period__uuid',
                                          'lesson_period__sequence',
                                          'lesson_period__start_time',
                                          'lesson_period__end_time')
     q = q.order_by('lesson_period__sequence')
     v = json.dumps(model_list_to_dict(q), cls=RevisedDjangoJSONEncoder)
     cache.set(k, v, get_timeout(k, 60 * 60 * 24))
Ejemplo n.º 9
0
def force_index_query(page_info):
    timelog = []
    timelog.append({'start': str(datetime.datetime.now())})
    sql = '''SELECT uuid, province_name, city_name,
             country_name, town_name, school_name, grade_name,
             class_name, teacher_name, lesson_period_sequence,
             lesson_name, created_at
             FROM TeacherLoginLog
             FORCE INDEX (TeacherLoginLog_96511a37)
             ORDER BY created_at DESC
             LIMIT %s OFFSET %s'''
    limit = page_info['page_size']
    offset = limit * (page_info['page_num'] - 1)
    q = models.TeacherLoginLog.objects.raw(sql, [limit, offset])
    timelog.append({'1': str(datetime.datetime.now())})

    count = models.TeacherLoginLog.objects.count()
    timelog.append({'2': str(datetime.datetime.now())})
    records = model_list_to_dict(q)
    timelog.append({'3': str(datetime.datetime.now())})
    if page_info['page_num'] != 1:
        records = format_record.activity_logged_in_force_index(records)
        timelog.append({'4': str(datetime.datetime.now())})
    data = {
        'records': records,
        'page': 1,
        'page_size': 25,
        'record_count': count,
        'page_count': (count + 25) / 25,
        'timelog': timelog,
    }
    timelog.append({'end': str(datetime.datetime.now())})
    return data
Ejemplo n.º 10
0
def group_get_children(request):
    if request.method == 'GET':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(msg=failure)
        province_name = request.GET.get('province_name')
        city_name = request.GET.get('city_name')
        country_name = request.GET.get('country_name')
        q = None
        if province_name and city_name and country_name:
            q = models.GroupTB.objects.filter(parent__name=country_name,
                                              parent__parent__name=city_name)
            q = q.filter(parent__parent__parent__name=province_name)
            q = q.values('name')
        elif province_name and city_name:
            q = models.GroupTB.objects.filter(parent__name=city_name)
            q = q.filter(parent__parent__name=province_name)
            q = q.values('name')
        elif province_name:
            q = models.GroupTB.objects.filter(parent__name=province_name)
            q = q.values('name')
        else:
            q = models.GroupTB.objects.filter(parent_id__isnull=True)
            q = q.values('name')
        return create_success_dict(data={'children': model_list_to_dict(q)})
Ejemplo n.º 11
0
def get_unreported(request, *args, **kwargs):
    """客户端获取未申报的电脑教室列表"""
    if models.Setting.getvalue('server_type') != 'school':
        return create_failure_dict()
    term = models.Term.get_current_term_list()
    if not term:
        return create_failure_dict(msg='当前时间不在任何学期内')
    t = term[0]
    cc = models.ComputerClass.objects.filter(class_bind_to__grade__term=t)
    if cc.exists():
        uuids = models.ClassMacV2.objects.all().values_list('class_uuid',
                                                            flat=True)
        cc = cc.exclude(class_bind_to__in=uuids).order_by(
            'class_bind_to__name',
            'class_bind_to__number').values_list('class_bind_to',
                                                 'class_bind_to__name',
                                                 'class_bind_to__number',
                                                 'class_bind_to__grade__uuid',
                                                 flat=False)
        data = map(
            lambda c: {
                'uuid': c[0],
                'name': c[1],
                'number': c[2],
                'grade_uuid': c[3]
            }, cc)
        return create_success_dict(data=data, term=model_list_to_dict(term))
    return create_success_dict(data=[])
Ejemplo n.º 12
0
 def _update(uu):
     key = 'simplecache_lesson_teacher_%s' % uu
     cache.delete(key)
     q = models.LessonTeacher.objects.filter(class_uuid=uu)
     q = q.values('teacher__uuid', 'teacher__name', 'lesson_name__name')
     ret = model_list_to_dict(q)
     cache.set(key, json.dumps(ret), get_timeout(key, None))
Ejemplo n.º 13
0
def list_current_class(request, *args, **kwargs):
    page_info = get_page_info(request)
    school_uuid = request.GET.get('school_uuid')

    q = models.LessonName.objects.filter(deleted=False)
    if school_uuid:
        q = q.filter(school__uuid=school_uuid)
    # MH:filter if class is selected
    # MH:return q.filter if lesson_name is exist
    try:
        class_uuid = request.GET.get('class_uuid')
        if class_uuid:
            c = models.LessonSchedule.objects.filter(deleted=False)
            lesson_name = c.filter(
                class_uuid=class_uuid).values('lesson_name_uuid')
            if lesson_name:
                q = q.filter(lesson_name__uuid__in=lesson_name)
    except:
        pass
    if models.Setting.getvalue('server_type') == 'school':
        #q = q.values('uuid', 'name')
        q = q.values('uuid', 'name', 'types')
    else:
        q = q.order_by().values('name').distinct()
    page_data = db_utils.pagination(q, **page_info)

    return create_success_dict(
        data={
            'records': model_list_to_dict(page_data['records']),
            'page': page_data['page_num'],
            'page_size': page_data['page_size'],
            'record_count': page_data['record_count'],
            'page_count': page_data['page_count'],
        })
Ejemplo n.º 14
0
def content_list(request):
    pk = request.GET.get('id')
    q = models.SyllabusGradeLessonContent.objects.filter(
        syllabus_grade_lesson=pk)
    q = q.values().order_by('seq', 'subseq')
    q = format_record.syllabus_content_list(q)
    return create_success_dict(data={'records': model_list_to_dict(q)})
Ejemplo n.º 15
0
def term(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(msg=failure)

        f = TermFormSet(request.POST)
        if f.is_valid():
            models.Term.objects.all().delete()  # 删除旧数据进行全新安装
            for i in f.forms:
                i.save()
            install_step = models.Setting.objects.get(name='install_step')
            install_step.value = request.POST['install_step']
            install_step.save()
            return create_success_dict(msg='安装成功!')

        return create_failure_dict(msg='安装失败!', errors=f.errors)

    elif request.method == "GET":
        if models.Setting.getvalue('installed') == 'True':
            return HttpResponseRedirect('/')

        q = models.Term.objects.all().values('term_type', 'start_date',
                                             'end_date', 'school_year')
        return create_success_dict(data=model_list_to_dict(q))
Ejemplo n.º 16
0
def lesson_name(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(failure)

        f = LessonNameFormSet(request.POST)
        if f.is_valid():
            models.LessonName.objects.all().delete()  # 删除旧数据进行全新安装
            school = models.Group.objects.get(group_type='school')
            for i in f.forms:
                obj = i.save(commit=False)
                obj.school = school
                obj.save()
            install_step = models.Setting.objects.get(name='install_step')
            install_step.value = request.POST['install_step']
            install_step.save()
            return create_success_dict(msg='安装成功!')

        return create_failure_dict(msg='安装失败!', errors=f.errors)
    elif request.method == 'GET':
        if models.Setting.getvalue('installed') == 'True':
            return HttpResponseRedirect('/')

        q = models.LessonName.objects.all().values('name')
        return create_success_dict(data=model_list_to_dict(q))
Ejemplo n.º 17
0
def import_from(request, *args, **kwargs):
    if request.method == 'POST':
        f = TermUploadForm(request.POST, request.FILES)
        if f.is_valid():
            terms = f.save()
            return create_success_dict(data=model_list_to_dict(terms))

        return create_failure_dict(msg='导入学年学期失败!', errors=f.errors)
Ejemplo n.º 18
0
def get_devicemodel_by_assettype(request, *args, **kwargs):
    uu = request.GET.get('uuid')
    try:
        q = models.Asset.objects.filter(asset_type__uuid=uu)
        q = q.values('device_model').distinct()
        return create_success_dict(data={'records': model_list_to_dict(q)})
    except:
        logger.exception('')
Ejemplo n.º 19
0
def verify(request, *args, **kwargs):
    if request.method == 'POST':
        f = LessonNameUploadVerifyForm(request.POST, request.FILES)
        if f.is_valid():
            objs = f.save()
            return create_success_dict(data=model_list_to_dict(objs))

        return create_failure_dict(msg='验证学校开课课程失败!', errors=f.errors)
Ejemplo n.º 20
0
def import_from(request, *args, **kwargs):
    if request.method == 'POST':
        f = LessonNameUploadForm(request.POST, request.FILES)
        if f.is_valid():
            lesson_names = f.save()
            return create_success_dict(data=model_list_to_dict(lesson_names))

        return create_failure_dict(msg='导入学校开课课程失败!', errors=f.errors)
Ejemplo n.º 21
0
def list_current(request, *args, **kwargs):
    page_info = get_page_info(request)
    school_year = request.GET.get('school_year')
    term_type = request.GET.get('term_type')
    # terms = models.Term.get_current_term_list()
    terms = models.Term.objects.filter(deleted=False)
    q = models.LessonPeriod.objects.filter(term__in=terms)
    if models.Setting.getvalue('server_type') != 'school':
        q = q.order_by().values('sequence').distinct()
        return create_success_dict(data={'records': model_list_to_dict(q)})
    else:
        if not is_admin(request.current_user):
            if not request.current_user.role:
                return create_failure_dict(status='permission_denied',
                                           msg='您没有权限访问当前功能!')
            count = request.current_user.role.roleprivilege_set
            count = count.filter(privilege='system_lesson_period').count()
            if count == 0:
                return create_failure_dict(status='permission_denied',
                                           msg='您没有权限访问当前功能!')

    if school_year:
        q = q.filter(school_year=school_year)
    if term_type:
        q = q.filter(term_type=term_type)
    q = q.values('uuid', 'term__school_year', 'term__term_type', 'sequence',
                 'start_time', 'end_time')
    page_data = db_utils.pagination(q, **page_info)
    data = {
        'records': model_list_to_dict(page_data['records']),
        'page': page_data['page_num'],
        'page_size': page_data['page_size'],
        'record_count': page_data['record_count'],
        'page_count': page_data['page_count'],
    }
    try:
        term = models.Term.get_current_term_list()[0]
        max_sequence = models.LessonPeriod.objects.filter(term=term)
        max_sequence = max_sequence.aggregate(Max('sequence'))
        # print max_sequence
        data['max_sequence'] = max_sequence['sequence__max']
    except:
        pass

    return create_success_dict(data=data)
Ejemplo n.º 22
0
def courseware_list(request):
    pk = request.GET.get('id')
    teacherloginlog_uuids = models.TeacherLoginLogLessonContent.objects.filter(
        lessoncontent=pk).values_list('teacherloginlog', flat=True)
    q = models.TeacherLoginLogCourseWare.objects.filter(
        teacherloginlog__in=teacherloginlog_uuids)
    q = q.values('courseware__title', 'courseware__qiniu_url').distinct()

    return create_success_dict(data={'records': model_list_to_dict(q)})
Ejemplo n.º 23
0
def get_grade_class(request):
    ret = datetimeutil.get_term_from_date_range(request)
    computerclass_need = request.GET.get('computerclass_need', False)
    only_computerclass = request.GET.get('only_computerclass', False)
    if isinstance(ret, (str, unicode)):
        return create_failure_dict(msg=ret)
    grades = models.Grade.objects.filter(term=ret)
    if only_computerclass == 'true':  # 仅需要电脑教室的联动信息
        grades = grades.filter(number=13)
    elif computerclass_need != 'true':  # 仅需要普通年级班级的联动信息
        grades = grades.exclude(number=13)

    classes = models.Class.objects.filter(grade__in=grades)
    data = {
        'grade': model_list_to_dict(grades.values('uuid', 'name')),
        'class': model_list_to_dict(classes.values('uuid', 'name', 'grade'))
    }
    return create_success_dict(data=data)
Ejemplo n.º 24
0
def verify(request, *args, **kwargs):
    if request.method == 'POST':
        f = LessonTeacherUploadVerifyForm(request.POST, request.FILES)
        if f.is_valid():
            objs = f.save()
            return create_success_dict(
                data={'records': model_list_to_dict(objs)})

        return create_failure_dict(msg='验证班级课程授课老师失败!', errors=f.errors)
Ejemplo n.º 25
0
def verify(request, *args, **kwargs):
    if request.method == 'POST':
        try:
            f = TeacherUploadVerifyForm(request.POST, request.FILES)
            if f.is_valid():
                objs = f.save()
                return create_success_dict(data=model_list_to_dict(objs))
            return create_failure_dict(msg='验证教职人员基础信息失败!', errors=f.errors)
        except:
            traceback.print_exc()
Ejemplo n.º 26
0
def list_current(request, *args, **kwargs):
    uuid = request.GET.get('uuid')
    q = models.LessonSchedule.objects.all()
    q = q.filter(class_uuid__grade__term__deleted=False)
    if uuid:
        q = q.filter(class_uuid=uuid)
    q = q.values('uuid', 'class_uuid', 'lesson_period__uuid',
                 'lesson_period__sequence', 'lesson_period__start_time',
                 'lesson_period__end_time', 'weekday', 'lesson_name__name')
    return create_success_dict(data={'records': model_list_to_dict(q)})
Ejemplo n.º 27
0
 def get():
     key = 'simplecache_resource'
     c = cache.get(key)
     if c:
         ret = json.loads(c)
     else:
         q = models.Resource.objects.values('resource_from').distinct()
         ret = model_list_to_dict(q)
         cache.set(key, json.dumps(ret), get_timeout(key, None))
     return ret
Ejemplo n.º 28
0
def grade_list(request):
    uu = request.GET.get('uuid')
    try:
        t = models.NewTerm.objects.get(uuid=uu)
    except:
        return create_failure_dict(msg='错误的uuid')
    q = models.SyllabusGrade.objects.filter(school_year=t.school_year,
                                            term_type=t.term_type)
    q = q.values('id', 'grade_name', 'in_use')
    return create_success_dict(data={'records': model_list_to_dict(q)})
Ejemplo n.º 29
0
def lesson_teacher_import(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(msg=failure)
        f = LessonTeacherUploadForm(request.POST, request.FILES)
        if f.is_valid():
            objs = f.save()
            return create_success_dict(data=model_list_to_dict(objs))

        return create_failure_dict(msg='导入班级课程授课老师失败!', errors=f.errors)
Ejemplo n.º 30
0
def grade_class_import(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(msg=failure)
        f = ClassUploadForm(request.POST, request.FILES)
        if f.is_valid():
            classes = f.save()
            return create_success_dict(data=model_list_to_dict(classes))

        return create_failure_dict(msg='导入学校年级班级失败!', errors=f.errors)