コード例 #1
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)})
コード例 #2
0
def get_lesson_name(request):
    ret = datetimeutil.get_term_from_date_range(request)
    if isinstance(ret, (str, unicode)):
        return create_failure_dict(msg=ret)
    q = models.LessonSchedule.objects.filter(class_uuid__grade__term=ret)
    q = q.values_list('lesson_name__name', flat=True)
    if not q.exists():
        q = models.LessonName.objects.filter(school=ret.school)
        q = q.values_list('name', flat=True)
    records = [{'name': i} for i in set(q)]
    return create_success_dict(data={'lesson_name': records})
コード例 #3
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)
コード例 #4
0
def classes1(request, *args, **kwargs):
    computerclass_need = request.GET.get('computerclass_need', False)
    only_computerclass = request.GET.get('only_computerclass', False)
    school_year = request.GET.get('school_year', None)
    term_type = request.GET.get('term_type', None)
    start_date = request.GET.get('start_date', None)
    end_date = request.GET.get('end_date', None)
    no_cache = request.GET.get('no_cache', False)
    c = cache.get('classes')
    if c and not no_cache:
        data = json.loads(c)
    elif start_date and end_date:
        t = get_term_from_date_range(request)
        if isinstance(t, (models.Term, models.NewTerm)):
            terms = [
                t,
            ]
        else:
            terms = models.Term.objects.none()
    else:
        school_uuid = request.GET.get('school')
        if school_uuid:
            school = models.Group.objects.get(uuid=school_uuid,
                                              group_type='school')
        else:
            school = models.Group.objects.filter(group_type='school')
        if school_year and term_type and school:
            terms = models.Term.objects.filter(school_year=school_year,
                                               term_type=term_type,
                                               school=school)
        else:
            terms = models.Term.get_current_term_list(school)
        q = models.Class.objects.filter(grade__term__in=terms)
        if only_computerclass == 'true':  # 仅需要电脑教室的联动信息
            q = q.filter(grade__number=13)
        elif computerclass_need != 'true':  # 仅需要普通年级班级的联动信息
            q = q.exclude(grade__number=13)
        q = q.order_by().values('name', 'grade__name').distinct()
        data = model_list_to_dict(q)
        cache.set('classes', json.dumps(data), get_timeout('classes', None))

    return create_success_dict(data=data)