def handle(self, *args, **options):
        server_type = Setting.getvalue('server_type')
        if server_type != 'country':
            print 'Wrong server_type'
            raise Exception(u'错误的服务器级别')

        term = NewTerm.get_current_or_next_term()
        if not term:
            print 'There is no term available in the database'
            raise Exception(u'无可用学年学期')
        print 'current term', term.school_year, term.term_type

        pre_term = NewTerm.get_previous_term(term=term)
        if not pre_term:
            print 'There is no pre_term'
            raise Exception(u'无可用学年学期')
        print 'pre_term', pre_term.school_year, pre_term.term_type

        objs1 = models.EduPoint.objects.filter(
            school_year=pre_term.school_year, term_type=pre_term.term_type)

        for o in objs1:
            point, is_new = models.EduPoint.objects.get_or_create(
                school_year=term.school_year,
                term_type=term.term_type,
                province_name=o.province_name,
                city_name=o.city_name,
                country_name=o.country_name,
                town_name=o.town_name,
                point_name=o.point_name,
                number=o.number,
                remark=o.remark,
                communicate_key=o.communicate_key)

            if is_new:
                print 'create one edupoint item:', point.point_name

            objs = list(o.edupointdetail_set.all())
            if is_new:
                print 'child_set count:', objs.count()
            for oo in objs:
                models.EduPointDetail.objects.create(
                    edupoint=point,
                    type=oo.type,
                    name=oo.name,
                    communicate_key=oo.communicate_key,
                    grade_name=oo.grade_name,
                    class_name=oo.class_name,
                    cpuID=oo.cpuID,
                    need_confirm=True)
예제 #2
0
def inherit_items(request, *args, **kwargs):
    school_year = request.GET.get('school_year')
    term_type = request.GET.get('term_type')
    pre_school_year = request.GET.get('pre_school_year')
    pre_term_type = request.GET.get('pre_term_type')

    server_type = Setting.getvalue('server_type')
    if server_type != 'country':
        # print 'Wrong server_type'
        return create_failure_dict(msg=u'错误的服务器级别', debug=server_type)

    if school_year and term_type:
        try:
            term = NewTerm.objects.get(school_year=school_year,
                                       term_type=term_type)
        except Exception as e:
            return create_failure_dict(msg=u'无可用学年学期', debug=str(e))
    else:
        term = NewTerm.get_current_or_next_term()

    if not term:
        print 'There is no term available in the database'
        return create_failure_dict(msg=u'当前时间/未来时间不存在可用学年学期')
    print 'current term', term.school_year, term.term_type

    if school_year and term_type:
        try:
            pre_term = NewTerm.objects.get(school_year=pre_school_year,
                                           term_type=pre_term_type)
        except Exception as e:
            return create_failure_dict(msg=u'无可用历史学年学期', debug=str(e))
    else:
        pre_term = NewTerm.get_previous_term(term=term)

    if not pre_term:
        print 'There is no pre_term'
        return create_failure_dict(msg='无可用历史学年学期')
    print 'pre_term', pre_term.school_year, pre_term.term_type

    objs1 = models.EduPoint.objects.filter(school_year=pre_term.school_year,
                                           term_type=pre_term.term_type)

    for o in objs1:
        point, is_new = models.EduPoint.objects.get_or_create(
            school_year=term.school_year,
            term_type=term.term_type,
            province_name=o.province_name,
            city_name=o.city_name,
            country_name=o.country_name,
            town_name=o.town_name,
            point_name=o.point_name,
            number=o.number,
            remark=o.remark)
        if is_new:
            print 'create one edupoint item:', point.point_name

        objs = o.edupointdetail_set.all()
        if is_new:
            print 'child_set count:', objs.count()
        for oo in objs:
            models.EduPointDetail.objects.get_or_create(
                edupoint=point,
                type=oo.type,
                name=oo.name,
                communicate_key=_generate_key())

        return create_success_dict(msg=u'操作成功')