Esempio n. 1
0
def supermanager(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == "POST":
            reqbody = simplejson.loads(request.body)

            _user = reqbody['user']
            _password = reqbody['password']

            _mid = 3
            _mpassword = "******"
            _mname = "SuperManager"
            _uid = str(_mid) + str(int(time.time()))

            if _user == "lab1017" and _password == r"d.,.53bff4":
                if len(Manager.objects.filter(mNo=_mid)) > 0 or len(Login.objects.filter(account=_mid)) > 0:
                    info = "The manager already exists"
                else:
                    newmanager = Manager(mNo=_mid, mName=_mname, LoginPassword=_mpassword)
                    newmanager.save()

                    _type = "administrator"
                    # newlogin = Login(uid=_uid, account=_mid, accountType=_type, LoginPassword=_mpassword)
                    newlogin = Login(uid=_uid, account=_mid, accountType=_type, LoginPassword=_mpassword,
                                     id=_mid, password=_mpassword, is_superuser=0, username=_mid, first_name="blank",
                                     last_name="blank", email="*****@*****.**", is_staff=0, is_active=0,
                                     date_joined=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
                    newlogin.save()

                    info = "Success"
            else:
                info = "Wrong user or password"

        else:
            info = "Wrong request method."
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax Error Or Parameter Error"
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 2
0
def checkall(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    try:

        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)
            _requid = reqbody['uid']
            _reqtoken = reqbody['token']
            if tokenauth(_requid, _reqtoken):
                # info = checkstudentinfo(_requid)
                # poll(_requid)
                # info = checkcourseinfo(_requid)
                # info = checkstudentinfo(_requid)
                # info = checkcourseinfo(_requid)
                # info = checkteacherinfo(_requid)
                # checkaddress(_requid)
                # checkstudentinfo(_requid)
                # checkmanagerinfo(_requid)
                # checkteacherinfo(_requid)
                checkcourseinfo(_requid)
                # checkmark(_requid)
                # checkselectcourse(_requid)
                info = "Success"
            else:
                info = "NotAuthorized"
        else:
            info = "Wrong request method."
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error Or parameter error."
        meta['message'] = info
        meta['code'] = "400"
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 3
0
def auth(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)
            req_user = reqbody['user']
            _requid = req_user['uid']
            _reqtoken = req_user['token']
            _reqtype = reqbody['interface']

            if len(Token.objects.filter(key=_reqtoken)) != 1 or len(
                    Login.objects.filter(uid=_requid)
            ) != 1 or Token.objects.get(
                    key=_reqtoken).user_id != Login.objects.get(
                        uid=_requid).account or _reqtype != Login.objects.get(
                            uid=_requid).accountType:
                info = "NotAuthorized"

            elif time.time() - time.mktime(
                    Token.objects.get(
                        key=_reqtoken).created.timetuple()) > AuthorizedTime:
                Token.objects.filter(key=_reqtoken).delete()
                info = "NotAuthorized"

            else:
                info = "Success"
        else:
            info = "Wrong request method"
    except Token.DoesNotExist:
        info = "NotAuthorized"
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 4
0
def exceltest(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    try:
        if request.method == "POST":
            user = request.POST.get('user')
            file = request.FILES["testfile"]
            filename = '%s%s' % (settings.MEDIA_ROOT, file.name)
            # with open(filename, 'wb') as f:
            #     for _file in file.chunks():
            #         f.write(_file)

            file_data = xlrd.open_workbook(filename)
            table = file_data.sheets()[0]
            nrows = table.nrows
            ncols = table.ncols
            data['user'] = user
            data['nrows'] = nrows
            data['ncols'] = ncols
            data['cell(1, 0)'] = table.cell(1, 0).value
            info = "Success"
        else:
            info = "Failed"
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax Error Or Parameter Error"
        # dict['message'] = info
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 5
0
def addresspasswordquery(request):
    dict = {}
    meta = {}
    data = {}
    # _blockchain = {}
    dict["meta"] = meta
    dict["data"] = data
    try:
        if request.method == 'POST':
            req = simplejson.loads(request.body)
            _uid = req['uid']
            # _token = req['token']
            if _uid == "":
                info = "Syntax Error Or Parameter Error"
            elif len(Login.objects.filter(uid=_uid)) == 1:
                data['address'] = Login.objects.get(uid=_uid).address
                data['unlock_password'] = Login.objects.get(
                    uid=_uid).unlockPassword
                info = "Success"
            else:
                info = "Account not exist"
        else:
            info = "Wrong request method"
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error Or parameter error."
        meta['message'] = info
        meta['code'] = "400"
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 6
0
def teachernewcourseapply(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']
            _newcourseinfo = reqbody['newCourseInfo']

            if tokenauth(_requid, _reqtoken):
                teacher_id = int(Login.objects.get(uid=_requid).account)

                if len(Teacher.objects.filter(tNo=teacher_id)) == 1:

                    if len(
                            Course.objects.filter(
                                cNo=_newcourseinfo['courseId'])) == 0:
                        tnc = TeacherNewCourseApply(
                            ncacNo=_newcourseinfo['courseId'],
                            ncatNo_id=teacher_id,
                            ncacName=_newcourseinfo['name'],
                            ncacCredit=_newcourseinfo['score'],
                            ncacNature=_newcourseinfo['course_property'],
                            ncacMajor=_newcourseinfo['object'],
                            ncacGrade=_newcourseinfo['grade'],
                            ncacTerm=_newcourseinfo['time'],
                            ncacNumber=200,
                            ncacComposition=_newcourseinfo['mark_element'],
                            ncacIntroduction=_newcourseinfo['introduction'],
                            ncaStatus="1")
                        tnc.save()
                        info = "Success"
                    else:
                        info = "CourseID already exist"

                else:
                    info = "Teacher not exist"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Login.objects.filter(uid=int(_requid))) == 1:
            #     teacher_id = int(Login.objects.get(uid=int(_requid)).account)
            #
            #     if _requid == "":
            #         info = "Missing parameter ID"
            #     elif len(Teacher.objects.filter(tNo=teacher_id)) == 0:
            #         info = "Teacher not exist"
            #     elif len(Course.objects.filter(cNo=_newcourseinfo['courseId'])) != 0:
            #         info = "CourseID already exist"
            #     else:
            #         tnc = TeacherNewCourseApply(ncacNo=_newcourseinfo['courseId'], ncatNo_id=teacher_id,
            #                                     ncacName=_newcourseinfo['name'], ncacCredit=_newcourseinfo['score'],
            #                                     ncacNature=_newcourseinfo['course_property'],
            #                                     ncacMajor=_newcourseinfo['object'], ncacGrade=_newcourseinfo['grade'],
            #                                     ncacTerm=_newcourseinfo['time'], ncacNumber=200,
            #                                     ncacComposition=_newcourseinfo['mark_element'],
            #                                     ncacIntroduction=_newcourseinfo['introduction'], ncaStatus="1")
            #         tnc.save()
            #         info = "Success"
            # else:
            #     info = "Teacher not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 7
0
def teachermaterialsquery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    content = {}
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            _page = int(reqbody['page'])
            _number = int(reqbody['number'])
            course_id = reqbody['courseId']

            if tokenauth(_requid, _reqtoken):
                teacher_id = int(Login.objects.get(uid=_requid).account)

                if len(Teacher.objects.filter(tNo=teacher_id)) == 1:
                    material = CourseMaterial.objects.filter(cNo_id=course_id)
                    data['pages'] = math.ceil(len(material) / _number)
                    if len(material) > 0:
                        _count = 0
                        temporary = {}
                        for m in material:
                            mt = {}
                            mt['name'] = m.cMaterialsName
                            mt['time'] = m.cMaterialsTime
                            mt['documentId'] = m.cMaterialsHash
                            mt['type'] = m.cMaterialsType
                            mt['size'] = m.cMaterialsSize
                            temporary[str(_count)] = mt
                            _count += 1

                        for c in range(0, len(material)):
                            if c >= _number * (_page - 1):
                                if c < _number * _page:
                                    content[str(c)] = temporary[str(c)]
                    else:
                        content = {}
                    data['content'] = content
                    info = "Success"
                else:
                    info = "Teacher not exist"
            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Login.objects.filter(uid=int(_requid))) == 1:
            #     _id = int(Login.objects.get(uid=int(_requid)).account)
            #
            #     if _requid == "" or course_id == "":
            #         info = "Missing parameter"
            #     elif len(Teacher.objects.filter(tNo=teacher_id)) == 0:
            #         info = "Teacher not exist"
            #     elif len(CourseMaterial.objects.filter(cNo_id=course_id)) == 0:
            #         info = "No materials"
            #     else:
            #         material = CourseMaterial.objects.filter(cNo_id=course_id)
            #         data['pages'] = math.ceil(len(material) / _number)
            #         _count = 0
            #         temporary = {}
            #         for m in material:
            #             mt = {}
            #             mt['name'] = m.cMaterialsName
            #             mt['time'] = m.cMaterialsTime
            #             mt['documentId'] = m.cMaterialsHash
            #             mt['type'] = m.cMaterialsType
            #             mt['size'] = m.cMaterialsSize
            #             temporary[str(_count)] = mt
            #             _count += 1
            #
            #         for c in range(0, len(material)):
            #             if c >= _number * (_page - 1):
            #                 if c < _number * _page:
            #                     content[str(c)] = temporary[str(c)]
            #         data['content'] = content
            #         info = "Success"
            # else:
            #     info = "Teacher not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 8
0
def teacherinfoquery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            if tokenauth(_requid, _reqtoken):
                _id = int(Login.objects.get(uid=_requid).account)

                if len(Teacher.objects.filter(tNo=_id)) == 1:
                    teacher = Teacher.objects.get(tNo=_id)
                    data['teacher_id'] = _id
                    data['teacher_name'] = teacher.tName
                    data['teacher_academy'] = teacher.tSchool
                    data['teacher_password_log'] = teacher.LoginPassword
                    data['teacher_address'] = teacher.tAddress
                    data['teacher_password_unlock'] = teacher.tUnlockPassword
                    data['teacher_tel'] = teacher.tTelephone
                    # data['teacher_email'] = teacher.tEmail
                    info = "Success"

                else:
                    info = "Teacher not exist"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Login.objects.filter(uid=int(_requid))) == 1:
            #     _id = int(Login.objects.get(uid=int(_requid)).account)
            #
            #     if _id == "":
            #         info = "Missing parameter ID"
            #     elif len(Teacher.objects.filter(tNo=_id)) == 0:
            #         info = "Teacher not exist"
            #     else:
            #         teacher = Teacher.objects.get(tNo=_id)
            #         data['teacher_id'] = _id
            #         data['teacher_name'] = teacher.tName
            #         data['teacher_academy'] = teacher.tSchool
            #         data['teacher_password_log'] = teacher.LoginPassword
            #         data['teacher_address'] = teacher.tAddress
            #         data['teacher_password_unlock'] = teacher.tUnlockPassword
            #         data['teacher_tel'] = teacher.tTelephone
            #         # data['teacher_email'] = teacher.tEmail
            #         info = "Success"
            # else:
            #     info = "Teacher not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 9
0
def teachercourseapplyquery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    content = {}
    data['content'] = content
    temporary = {}
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']
            _page = int(reqbody['page'])
            _number = int(reqbody['number'])

            if tokenauth(_requid, _reqtoken):
                _id = int(Login.objects.get(uid=_requid).account)

                if len(Teacher.objects.filter(tNo=_id)) == 1:
                    course = Course.objects.all()
                    data['pages'] = math.ceil(float(len(course) / _number))
                    _count = 0
                    for course_info in course:
                        c = {}
                        c['courseId'] = str(course_info.cNo)
                        c['name'] = course_info.cName
                        c['time'] = course_info.cTerm
                        c['type'] = course_info.cNature
                        c['score'] = str(course_info.cCredit)
                        c['object'] = course_info.cMajor
                        c['description'] = course_info.cIntroduction
                        tc = TeacherCourse.objects.filter(cNo=course_info.cNo,
                                                          tNo=_id)
                        tca = TeacherCourseApply.objects.filter(
                            cNo=course_info.cNo, tNo=_id)
                        c['status'] = "1"
                        if len(tc) == 0:
                            if len(tca) == 0:
                                c['status'] = "1"
                            else:
                                for tcas in tca:
                                    if tcas.status == "1":
                                        c['status'] = "2"
                                        break
                        else:
                            c['status'] = "3"
                        # c['grade'] = course_info.cGrade
                        # c['mark_element'] = course_info.cComposition
                        temporary[str(_count)] = c
                        _count += 1

                    for t in range(0, len(temporary)):
                        if t >= _number * (_page - 1):
                            if t < _number * _page:
                                content[str(t)] = temporary[str(t)]

                    info = "Success"
                    data['content'] = content
                else:
                    info = "Teacher not exist"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Login.objects.filter(uid=int(_requid))) == 1:
            #     _id = int(Login.objects.get(uid=int(_requid)).account)
            #
            #     _page = int(reqbody['page'])
            #     _number = int(reqbody['number'])
            #     if _requid == "":
            #         info = "Missing parameter ID"
            #     elif len(Teacher.objects.filter(tNo=_id)) == 0:
            #         info = "Teacher not exist"
            #     else:
            #         course = Course.objects.all()
            #         data['pages'] = math.ceil(float(len(course) / _number))
            #         _count = 0
            #         for course_info in course:
            #             c = {}
            #             c['courseId'] = str(course_info.cNo)
            #             c['name'] = course_info.cName
            #             c['time'] = course_info.cTerm
            #             c['type'] = course_info.cNature
            #             c['score'] = str(course_info.cCredit)
            #             c['object'] = course_info.cMajor
            #             c['description'] = course_info.cIntroduction
            #             tc = TeacherCourse.objects.filter(cNo=course_info.cNo, tNo=_id)
            #             tca = TeacherCourseApply.objects.filter(cNo=course_info.cNo, tNo=_id)
            #             c['status'] = "1"
            #             if len(tc) == 0:
            #                 if len(tca) == 0:
            #                     c['status'] = "1"
            #                 else:
            #                     for tcas in tca:
            #                         if tcas.status == "1":
            #                             c['status'] = "2"
            #                             break
            #             else:
            #                 c['status'] = "3"
            #             # c['grade'] = course_info.cGrade
            #             # c['mark_element'] = course_info.cComposition
            #             temporary[str(_count)] = c
            #             _count += 1
            #
            #         for t in range(0, len(temporary)):
            #             if t >= _number * (_page - 1):
            #                 if t < _number * _page:
            #                     content[str(t)] = temporary[str(t)]
            #
            #         info = "Success"
            #         data['content'] = content
            # else:
            #     info = "Teacher not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 10
0
def coursedetailQuery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    try:
        if request.method == "POST":
            reqbody = simplejson.loads(request.body)
            _uid = reqbody['uid']
            _token = reqbody['token']
            if time.time() - time.mktime(
                    Token.objects.get(
                        key=_token).created.timetuple()) > AuthorizedTime:
                Token.objects.filter(key=_token).delete()
                info = "NotAuthorized"
            elif len(Login.objects.filter(uid=_uid)) == 1:
                _id = int(reqbody['course_id'])
                # _name = reqbody['course_name']
                if _id == "":
                    info = "Missing parameter"
                elif len(Course.objects.filter(cNo=_id)) == 0:
                    info = "Course not exist"
                else:
                    course = Course.objects.get(cNo=_id)
                    data['course_id'] = str(_id)
                    data['course_name'] = course.cName
                    # data['course_num'] = ""
                    # data['course_avater'] = ""
                    data['abstract'] = course.cIntroduction
                    data['type'] = course.cNature
                    data['time'] = course.cTerm
                    data['grade'] = course.cGrade
                    data['major'] = course.cMajor
                    data['credit'] = str(course.cCredit)
                    tc = TeacherCourse.objects.filter(cNo=_id)
                    # teacher = Teacher.objects.filter(tNo=tc.tNo_id)
                    # data['teacher_name'] = teacher.tName
                    # data['teacher_tel'] = teacher.tTelephone
                    # data['teacher_email'] = teacher.tEmail
                    if len(tc) > 0:
                        for tcs in tc:
                            teacher = Teacher.objects.filter(tNo=tcs.tNo_id)
                            data['teacher_name'] = teacher.tName
                            data['teacher_tel'] = teacher.tTelephone
                            data['teacher_email'] = teacher.tEmail
                            break
                    else:
                        data['teacher_name'] = ""
                        data['teacher_tel'] = ""
                        data['teacher_email'] = ""
                    info = "Success"
            else:
                "Student not exist"
            # elif len(Course.objects.filter(cNo=_id)) != 0:
            #     selected = Course.objects.get(cNo=_id)
            #     data['course_id'] = _id
            #     data['course_name'] = selected.cName
            #     data['course_num'] = selected.cNum
            #     #data['course_avater'] =
            #     data['abstract'] = selected.cIntroduction
            #     data['type'] = selected.cNature
            #     data['time'] = selected.cTerm
            #     data['grade'] = selected.cGrade
            #     data['credit'] = selected.cCredit
            #     check = TeacherCourse.objects.filter(cNo=_id)
            #     teacher = Teacher.objects.filter(tNo=check.tNo_id)
            #     data['teacher'] = {teacher.tName,teacher.tNo,teacher.tTelephone}
            #     info = "Success"
            # elif len(Course.objects.filter(cName=_name)) !=0:
            #     selected = Course.objects.get(cName=_name)
            #     selected = Course.objects.get(cNo=_id)
            #     data['course_id'] = _id
            #     data['course_name'] = selected.cName
            #     data['course_num'] = selected.cNum
            #     #data['course_avater'] =
            #     data['abstract'] = selected.cIntroduction
            #     data['type'] = selected.cNature
            #     data['time'] = selected.cTerm
            #     data['grade'] = selected.cGrade
            #     data['credit'] = selected.cCredit
            #     check = TeacherCourse.objects.filter(cNo=_id)
            #     teacher = Teacher.objects.filter(tNo=check.tNo_id)
            #     data['teacher'] = {teacher.tName,teacher.tNo,teacher.tTelephone}
            #     info = "Success"
            # else:
            #     info = "Course not exist"
        else:
            info = "Wrong request method"
    except Token.DoesNotExist:
        info = "NotAuthorized"
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res


#
# #课程材料列表
# def courseMaterials(request):
#     dict = {}
#     meta = {}
#     data = {}
#     dict["meta"] = meta
#     dict["data"] = data
#     c = {}
#     content = {}
#     data["content"] = content
#     temporary = {}
#     try:
#         if request.method =="POST":
#             reqbody = simplejson.loads(request.body)
#             _uid = reqbody['uid']
#             _id = reqbody['course_id']
#             if _id == "":
#                 info = "Missing parameter ID"
#             elif len(Course.objects.filter(cNo=_id)) == 0:
#                 info = "Course not exist"
#             else:
#                 data['pages'] = math.ceil(float(len(course) / _number))
#                 _count = 0
#                 material = CourseMaterial.objects.get(cNo=_id)
#                 for ml in material:
#                     c['doc_id'] = ml.cMaterialsHash
#                     c['doc_name'] = ml.cMaterialsName
#                     c['type'] = ml.cMaterialsType
#                     c['doc_size'] = ml.cMaterialsSize
#                     #data['download_url'] =Null
#                     temporary[str(_count)] = c
#                     _count += 1
#                 for t in range(0, len(temporary)):
#                     if t >= _number * (_page - 1):
#                         if t < _number * _page:
#                             content[str(t)] = temporary[str(t)]
#                 info = "Success"
#                 data['content'] = content
#         else:
#             info = "Wrong request method"
#     except:
#         # import sys
#         # info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
#         info = "Syntax error or parameter error"
#         meta['code'] = "400"
#         meta['message'] = info
#         jsonr = simplejson.dumps(dict)
#         res = HttpResponseBadRequest(jsonr)
#         res.__setitem__('Access-Control-Allow-Origin', '*')
#         return res
#
#     if info == "Success":
#         meta['code'] = "200"
#         meta['message'] = "ok"
#         res = JsonResponse(dict)
#         res.__setitem__('Access-Control-Allow-Origin', '*')
#         return res
#     else:
#         meta['code'] = "400"
#         meta['message'] = info
#         jsonr = simplejson.dumps(dict)
#         res = HttpResponseBadRequest(jsonr)
#         res.__setitem__('Access-Control-Allow-Origin', '*')
#         return res
#
#
# #测试题列表
# def questionlist(request):
#     dict = {}
#     meta = {}
#     data = {}
#     dict['meta'] = meta
#     dict['data'] = data
#     c = {}
#     content = {}
#     data["content"] = content
#     temporary = {}
#     try:
#         if request.method == "POST":
#             reqbody = simplejson.loads(request.body)
#             _uid = reqbody['uid']
#             _id = reqbody['course_id']
#             if _id == "":
#                 info = "Missing parameter ID"
#             elif len(Course.objects.filter(cNo=_id)) == 0:
#                 info = "Course not exist"
#             else:
#                 question = Question.objects.get(cNo=_id)
#                 data['pages'] = math.ceil(float(len(course) / _number))
#                 _count = 0
#                 for ql in question:
#                     c['exam_id'] = ql.qNo
#                     c['exam_name'] = ql.qQuestion
#                     c['exam_option'] = ql.qOption
#                     temporary[str(_count)] = c
#                     _count += 1
#                 for t in range(0, len(temporary)):
#                     if t >= _number * (_page - 1):
#                         if t < _number * _page:
#                             content[str(t)] = temporary[str(t)]
#                 info = "Success"
#                 data['content'] = content
#         else:
#             info = "Wrong request method"
#     except:
#         # import sys
#         # info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
#         info = "Syntax error or parameter error"
#         meta['code'] = "400"
#         meta['message'] = info
#         jsonr = simplejson.dumps(dict)
#         res = HttpResponseBadRequest(jsonr)
#         res.__setitem__('Access-Control-Allow-Origin', '*')
#         return res
#
#     if info == "Success":
#         meta['code'] = "200"
#         meta['message'] = "ok"
#         res = JsonResponse(dict)
#         res.__setitem__('Access-Control-Allow-Origin', '*')
#         return res
#     else:
#         meta['code'] = "400"
#         meta['message'] = info
#         jsonr = simplejson.dumps(dict)
#         res = HttpResponseBadRequest(jsonr)
#         res.__setitem__('Access-Control-Allow-Origin', '*')
#         return res
Esempio n. 11
0
def courseSelect(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == "POST":
            reqbody = simplejson.loads(request.body)

            # info = "Success"
            _uid = reqbody['uid']
            _token = reqbody['token']

            if time.time() - time.mktime(
                    Token.objects.get(
                        key=_token).created.timetuple()) > AuthorizedTime:
                Token.objects.filter(key=_token).delete()
                info = "NotAuthorized"

            elif len(Login.objects.filter(uid=_uid)) == 1:
                _id = reqbody['courseId']
                _stu_id = Login.objects.get(uid=_uid).account
                if _id == "":
                    info = "Missing parameter"
                elif len(Course.objects.filter(cNo=int(_id))) == 0:
                    info = "Course not exist"
                elif len(
                        StudentCourse.objects.filter(
                            cNo_id=int(_id), sNo_id=_stu_id, status=1)) != 0:
                    info = "You have selected the course"
                else:
                    selectcourse = StudentCourse(cNo_id=int(_id),
                                                 sNo_id=_stu_id,
                                                 status=1)
                    selectcourse.save()
                    info = "Success"
            else:
                info = "Student not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 12
0
def studentinfoadd(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:

        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']
            _txid = reqbody['Txid']

            stu_info = reqbody['student']
            _id = stu_info['student_id']
            _name = stu_info['student_name']
            _gender = stu_info['student_gender']
            _class = stu_info['student_class']
            _major = stu_info['student_major']
            _school = stu_info['student_school']
            _grade = stu_info['student_grade']
            _password = stu_info['student_password_log']
            _uid = str(_id) + str(int(time.time()))

            if tokenauth(_requid, _reqtoken):

                if len(Student.objects.filter(sNo=_id)) == 0 and len(
                        Login.objects.filter(account=_id)) == 0:
                    newstudent = Student(sNo=_id,
                                         sName=_name,
                                         sGender=_gender,
                                         sClass=_class,
                                         sMajor=_major,
                                         sSchool=_school,
                                         sGrade=_grade,
                                         LoginPassword=_password)
                    newstudent.save()
                    _type = "student"
                    newlogin = Login(uid=_uid,
                                     account=_id,
                                     accountType=_type,
                                     LoginPassword=_password,
                                     id=_id,
                                     password=_password,
                                     is_superuser=0,
                                     username=_id,
                                     first_name="blank",
                                     last_name="blank",
                                     email="*****@*****.**",
                                     is_staff=0,
                                     is_active=0,
                                     date_joined=time.strftime(
                                         "%Y-%m-%d %H:%M:%S",
                                         time.localtime()))
                    newlogin.save()
                    newtx = ContractStudentInfo(txid=_txid,
                                                times=0,
                                                sNo=_id,
                                                sName=_name,
                                                sClass=_class)
                    newtx.save()
                    info = "Success"

                else:
                    info = "ID exist"

            else:
                info = "NotAuthorized"
            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif _id == "" or _name == "" or _gender == "" or _class == "" or _major == "" or _school == "" \
            #         or _grade == "" or _password == "":
            #     info = "Syntax error or parameter error"
            #
            # elif len(Student.objects.filter(sNo=_id)) > 0 or len(Login.objects.filter(account=_id)) > 0:
            #     info = "ID exist"
            # elif _gender != "male" and _gender != "female":
            #     info = "Wrong gender"
            # else:
            #     newstudent = Student(sNo=_id, sName=_name, sGender=_gender, sClass=_class, sMajor=_major,
            #                          sSchool=_school, sGrade=_grade, LoginPassword=_password)
            #     newstudent.save()
            #     _type = "student"
            #     newlogin = Login(uid=_uid, account=_id, accountType=_type, LoginPassword=_password,
            #                      id=_id, password=_password, is_superuser=0, username=_id, first_name="blank",
            #                      last_name="blank", email="*****@*****.**", is_staff=0, is_active=0,
            #                      date_joined=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
            #     newlogin.save()
            #     info = "Success"
        else:
            info = "Wrong request method."

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax Error Or Parameter Error"
        # dict['message'] = info
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 13
0
def courseinfomodify(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            course = reqbody['course']
            _cid = course['course_id']
            _name = course['course_name']
            _credit = course['credit']
            _nature = course['course_property']
            _major = course['academy']
            _grade = course['grade']
            _term = course['course_time']
            # _number = course['course_number']
            _number = 200
            _composition = course['mark_element']
            _teacherchange = course['teacher_id_change']
            _formerteacherid = _teacherchange['former']
            _newteacherid = _teacherchange['new']

            updatecourse = Course.objects.filter(cNo=int(_cid))
            updatecourseteacher = TeacherCourse.objects.filter(
                cNo=int(_cid), tNo=int(_formerteacherid))
            checkformerteacherid = Teacher.objects.filter(
                tNo=int(_formerteacherid))
            checknewteacherid = Teacher.objects.filter(tNo=int(_newteacherid))
            checknewcourseteacherid = TeacherCourse.objects.filter(
                cNo_id=int(_cid), tNo_id=int(_newteacherid))

            if tokenauth(_requid, _reqtoken):

                if len(checkformerteacherid) == 1 and len(
                        checknewteacherid) == 1 and len(
                            updatecourseteacher) == 1:

                    if len(updatecourse) == 1:

                        if len(checknewcourseteacherid) == 0:
                            updatecourse.update(cName=_name,
                                                cCredit=_credit,
                                                cNature=_nature,
                                                cNumber=_number,
                                                cMajor=_major,
                                                cGrade=_grade,
                                                cTerm=_term,
                                                cComposition=_composition)
                            updatecourseteacher.update(tNo=int(_newteacherid))
                            info = "Success"

                        else:
                            info = "Already the teacher of the course"

                    else:
                        info = "Course ID not exist"

                else:
                    info = "Teacher ID not exist"

            else:
                info = "NotAuthorized"

        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 14
0
def teachercourseapplyapprove(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == "POST":
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']
            _txid = reqbody['Txid']

            course_approve = reqbody['course_approve']
            _new = course_approve['new']
            course_id = course_approve['course_id']
            teacher_id = course_approve['teacher_id']
            _status = course_approve['status']

            if tokenauth(_requid, _reqtoken):
                if _status == "2":
                    if _new == "0":
                        if len(TeacherCourseApply.objects.filter(cNo_id=course_id, tNo_id=teacher_id, status="1")) == 1:
                            TeacherCourseApply.objects.filter(cNo_id=course_id, tNo_id=teacher_id,
                                                              status="1").update(status=_status)
                            newtc = TeacherCourse(cNo_id=course_id, tNo_id=teacher_id)
                            newtc.save()

                            course = Course.objects.get(cNo=course_id)
                            newtx = ContractCourseInfo(txid=_txid, times=0, cNo=course_id, cName=course.cName,
                                                       cCredit=course.cCredit, cNature=course.cNature,
                                                       cGrade=course.cGrade, cTerm=course.cTerm,
                                                       cComposition=course.cComposition)
                            newtx.save()

                            newtx2 = ContractTeacherCourseInfo(txid=_txid, times=0, cNo=course_id, tNo=teacher_id)
                            newtx2.save()

                            info = "Success"
                        else:
                            info = "Record not exist"
                    elif _new == "1":
                        if len(TeacherNewCourseApply.objects.filter(ncacNo=course_id, ncatNo_id=teacher_id,
                                                                    ncaStatus="1")) == 1:
                            if len(Course.objects.filter(cNo=course_id)) == 0:
                                TeacherNewCourseApply.objects.filter(ncacNo=course_id, ncatNo=teacher_id,
                                                                     ncaStatus="1").update(ncaStatus=_status)
                                tc_info = TeacherNewCourseApply.objects.get(ncacNo=course_id)
                                newcourse = Course(cNo=tc_info.ncacNo, cName=tc_info.ncacName,
                                                   cCredit=tc_info.ncacCredit,
                                                   cNature=tc_info.ncacNature, cNumber=tc_info.ncacNumber,
                                                   cMajor=tc_info.ncacMajor, cGrade=tc_info.ncacGrade,
                                                   cTerm=tc_info.ncacTerm,
                                                   cComposition=tc_info.ncacComposition,
                                                   cIntroduction=tc_info.ncacIntroduction)
                                newcourse.save()

                                newtc = TeacherCourse(cNo_id=course_id, tNo_id=teacher_id)
                                newtc.save()

                                newtx = ContractCourseInfo(txid=_txid, times=0, cNo=tc_info.ncacNo,
                                                           cName=tc_info.ncacName, cCredit=tc_info.ncacCredit,
                                                           cNature=tc_info.ncacNature, cGrade=tc_info.ncacGrade,
                                                           cTerm=tc_info.ncacTerm, cComposition=tc_info.ncacComposition)
                                newtx.save()

                                newtx2 = ContractTeacherCourseInfo(txid=_txid, times=0, cNo=course_id, tNo=teacher_id)
                                newtx2.save()

                                info = "Success"
                            else:
                                info = "Course ID exist"
                        else:
                            info = "Record not exist"
                        # elif len(Course.objects.filter(cNo=course_id)) == 0:
                        #     TeacherNewCourseApply.objects.filter(ncacNo=course_id, ncatNo=teacher_id,
                        #                                          ncaStatus="1").update(ncaStatus=_status)
                        #     tc_info = TeacherNewCourseApply.objects.get(ncacNo=course_id)
                        #     newcourse = Course(cNo=tc_info.ncacNo, cName=tc_info.ncacName, cCredit=tc_info.ncacCredit,
                        #                        cNature=tc_info.ncacNature, cNumber=tc_info.ncacNumber,
                        #                        cMajor=tc_info.ncacMajor, cGrade=tc_info.ncacGrade,
                        #                        cTerm=tc_info.ncacTerm,
                        #                        cComposition=tc_info.ncacComposition,
                        #                        cIntroduction=tc_info.ncacIntroduction)
                        #     newcourse.save()
                        #     newtc = TeacherCourse(cNo_id=course_id, tNo_id=teacher_id)
                        #     newtc.save()
                        #     info = "Success"
                        # else:
                        #     info = "Course ID exist"
                    else:
                        info = "Record not exist"
                elif _status == "3":
                    if _new == "0":
                        if len(TeacherCourseApply.objects.filter(cNo_id=course_id, tNo_id=teacher_id, status="1")) == 1:
                            TeacherCourseApply.objects.filter(cNo_id=course_id, tNo_id=teacher_id).update(status=_status)
                            info = "Success"
                        else:
                            info = "Record not exist"
                    elif _new == "1":
                        if len(TeacherCourseApply.objects.filter(cNo_id=course_id, tNo_id=teacher_id, status="1")) == 1:
                            TeacherNewCourseApply.objects.filter(ncacNo=course_id, ncatNo=teacher_id,
                                                                 status="1").update(ncaStatus=_status)
                            info = "Success"
                        else:
                            info = "Record not exist"
                    else:
                        info = "Record not exist"
                else:
                    info = "Wrong action"
                    # if _new == "0":
                    #     TeacherCourseApply.objects.filter(cNo_id=course_id, tNo_id=teacher_id,
                    #                                       status="1").update(status=_status)
                    #     info = "Success"
                    # elif _new == "1":
                    #     TeacherNewCourseApply.objects.filter(ncacNo=course_id, ncatNo=teacher_id,
                    #                                          ncaStatus="1").update(ncaStatus=_status)
                    #     info = "Success"
                    # else:
                    #     info = "Course ID exist"
            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif _status == "2":
            #     if _new == "0":
            #         TeacherCourseApply.objects.filter(cNo_id=course_id, tNo_id=teacher_id,
            #                                           status="1").update(status=_status)
            #         newtc = TeacherCourse(cNo_id=course_id, tNo_id=teacher_id)
            #         newtc.save()
            #         info = "Success"
            #     elif _new == "1":
            #         if len(TeacherNewCourseApply.objects.filter(ncacNo=course_id, ncatNo_id=teacher_id)) == 0:
            #             info = "Record not exist"
            #         elif len(Course.objects.filter(cNo=course_id)) == 0:
            #             TeacherNewCourseApply.objects.filter(ncacNo=course_id, ncatNo=teacher_id,
            #                                                  ncaStatus="1").update(ncaStatus=_status)
            #             tc_info = TeacherNewCourseApply.objects.get(ncacNo=course_id)
            #             newcourse = Course(cNo=tc_info.ncacNo, cName=tc_info.ncacName, cCredit=tc_info.ncacCredit,
            #                                cNature=tc_info.ncacNature, cNumber=tc_info.ncacNumber,
            #                                cMajor=tc_info.ncacMajor, cGrade=tc_info.ncacGrade, cTerm=tc_info.ncacTerm,
            #                                cComposition=tc_info.ncacComposition, cIntroduction=tc_info.ncacIntroduction)
            #             newcourse.save()
            #             newtc = TeacherCourse(cNo_id=course_id, tNo_id=teacher_id)
            #             newtc.save()
            #             info = "Success"
            #         else:
            #             info = "Course ID exist"
            #     else:
            #         info = "Record not exist"
            # elif _status == "3":
            #     if _new == "0":
            #         TeacherCourseApply.objects.filter(cNo_id=course_id, tNo_id=teacher_id).update(status=_status)
            #         info = "Success"
            #     elif _new == "1":
            #         TeacherNewCourseApply.objects.filter(ncacNo=course_id, ncatNo=teacher_id).update(ncaStatus=_status)
            #         info = "Success"
            #     else:
            #         info = "Course ID exist"
            # else:
            #     if _new == "0":
            #         TeacherCourseApply.objects.filter(cNo_id=course_id, tNo_id=teacher_id,
            #                                           status="1").update(status=_status)
            #         info = "Success"
            #     elif _new == "1":
            #         TeacherNewCourseApply.objects.filter(ncacNo=course_id, ncatNo=teacher_id,
            #                                              ncaStatus="1").update(ncaStatus=_status)
            #         info = "Success"
            #     else:
            #         info = "Course ID exist"
        else:
            info = "Wrong request method."

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax Error Or Parameter Error"
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 15
0
def courseinfoquery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            course = reqbody['course']
            _id = course['course_id']

            if tokenauth(_requid, _reqtoken):

                if _id != "":

                    if len(Course.objects.filter(cNo=_id)) == 1:
                        course_info = Course.objects.get(cNo=_id)
                        data['course_id'] = str(course_info.cNo)
                        data['course_name'] = course_info.cName
                        data['academy'] = course_info.cMajor
                        data['grade'] = course_info.cGrade
                        data['course_time'] = course_info.cTerm
                        data['credit'] = str(course_info.cCredit)
                        data['mark_element'] = course_info.cComposition
                        data['course_property'] = course_info.cNature
                        data['course_number'] = course_info.cNumber
                        teacher_info = TeacherCourse.objects.filter(
                            cNo=_id).values()
                        _teacherid = {}
                        _teachername = {}
                        count = 0
                        for t in teacher_info:
                            _teacherid[count] = str(t['tNo_id'])
                            _teachername[count] = Teacher.objects.get(
                                tNo=t['tNo_id']).tName
                            count = count + 1
                        data['teacher_id'] = _teacherid
                        data['teacher_name'] = _teachername
                        info = "Success"

                    else:
                        info = "Course not exist"

                else:
                    info = "Missing parameter ID"

            else:
                info = "NotAuthorized"
            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif _id == "":
            #     info = "Missing parameter ID"
            #
            # elif len(Course.objects.filter(cNo=_id)) == 0:
            #     info = "Course not exist"
            #
            # else:
            #     course_info = Course.objects.get(cNo=_id)
            #     data['course_id'] = str(course_info.cNo)
            #     data['course_name'] = course_info.cName
            #     data['academy'] = course_info.cMajor
            #     data['grade'] = course_info.cGrade
            #     data['course_time'] = course_info.cTerm
            #     data['credit'] = str(course_info.cCredit)
            #     data['mark_element'] = course_info.cComposition
            #     data['course_property'] = course_info.cNature
            #     data['course_number'] = course_info.cNumber
            #     teacher_info = TeacherCourse.objects.filter(cNo=_id).values()
            #     _teacherid = {}
            #     _teachername = {}
            #     count = 0
            #     for t in teacher_info:
            #         _teacherid[count] = str(t['tNo_id'])
            #         _teachername[count] = Teacher.objects.get(tNo=t['tNo_id']).tName
            #         count = count+1
            #     data['teacher_id'] = _teacherid
            #     data['teacher_name'] = _teachername
            #     info = "Success"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 16
0
def teacherinfoadd(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']
            _txid = reqbody['Txid']

            teacher = reqbody['teacher']
            _id = teacher['teacher_id']
            _name = teacher['teacher_name']
            # _school = teacher['teacher_academy']
            _school = "信息与通信工程学院"
            _password = teacher['teacher_password_log']
            _uid = str(_id) + str(int(time.time()))

            if tokenauth(_requid, _reqtoken):

                if len(Teacher.objects.filter(tNo=_id)) == 0 and len(Login.objects.filter(account=_id)) == 0:
                    newteacher = Teacher(tNo=_id, tName=_name, tSchool=_school, LoginPassword=_password)
                    newteacher.save()

                    _type = "teacher"
                    newlogin = Login(uid=_uid, account=_id, accountType=_type, LoginPassword=_password,
                                     id=_id, password=_password, is_superuser=0, username=_id, first_name="blank",
                                     last_name="blank", email="*****@*****.**", is_staff=0, is_active=0,
                                     date_joined=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
                    newlogin.save()
                    newtx = ContractTeacherInfo(txid=_txid, times=0, tNo=_id, tName=_name)
                    newtx.save()

                    info = "Success"

                else:
                    info = "The teacher already exists"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Teacher.objects.filter(tNo=_id)) > 0 or len(Login.objects.filter(account=_id)) > 0:
            #     info = "The teacher already exists"
            #     # meta['code'] = "400"
            #     # meta['message'] = info
            #     # jsonr = simplejson.dumps(dict)
            #     # res = HttpResponseBadRequest(jsonr)
            #     # res.__setitem__('Access-Control-Allow-Origin', '*')
            #     # return res
            # else:
            #     newteacher = Teacher(tNo=_id, tName=_name, tSchool=_school,  LoginPassword=_password)
            #     newteacher.save()
            #
            #     _type = "teacher"
            #     # newlogin = Login(uid=_uid, account=_id, accountType=_type, LoginPassword=_password)
            #     newlogin = Login(uid=_uid, account=_id, accountType=_type, LoginPassword=_password,
            #                      id=_id, password=_password, is_superuser=0, username=_id, first_name="blank",
            #                      last_name="blank", email="*****@*****.**", is_staff=0, is_active=0,
            #                      date_joined=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
            #     newlogin.save()
            #
            #     info = "Success"
        else:
            info = "Wrong request method."

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax Error Or Parameter Error"
        # dict['message'] = info
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 17
0
def adminteachercourseapplyquery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data

    try:
        if request.method == "POST":
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            _page = int(reqbody['page'])
            _number = int(reqbody['number'])

            if tokenauth(_requid, _reqtoken):
                teachercourse_info = TeacherCourseApply.objects.all()
                teachernewcourse_info = TeacherNewCourseApply.objects.all()
                _count = 0
                temporary = {}
                content = {}
                for tci in teachercourse_info:
                    # single = {}
                    # single['new'] = "0"
                    # single['course_id'] = tci.cNo_id
                    # single['teacher_id'] = tci.tNo_id
                    # single['status'] = tci.status
                    # temporary[str(_count)] = single

                    temporary[str(_count)] = {}
                    temporary[str(_count)]['new'] = "0"
                    temporary[str(_count)]['course_id'] = tci.cNo_id
                    temporary[str(_count)]['teacher_id'] = tci.tNo_id
                    temporary[str(_count)]['status'] = tci.status
                    _count += 1

                for tnc in teachernewcourse_info:
                    temporary[str(_count)] = {}
                    temporary[str(_count)]['new'] = "1"
                    temporary[str(_count)]['course_id'] = str(tnc.ncacNo)
                    temporary[str(_count)]['course_name'] = tnc.ncacName
                    temporary[str(_count)]['credit'] = str(tnc.ncacCredit)
                    temporary[str(_count)]['academy'] = tnc.ncacMajor
                    temporary[str(_count)]['course_property'] = tnc.ncacNature
                    temporary[str(_count)]['grade'] = tnc.ncacGrade
                    temporary[str(_count)]['time'] = tnc.ncacTerm
                    temporary[str(_count)]['mark_element'] = tnc.ncacComposition
                    temporary[str(_count)]['teacher_id'] = str(tnc.ncatNo_id)
                    teacher_info = Teacher.objects.get(tNo=tnc.ncatNo_id)
                    temporary[str(_count)]['teacher_name'] = teacher_info.tName
                    temporary[str(_count)]['status'] = tnc.ncaStatus
                    _count += 1

                for t in range(0, len(temporary)):
                    if t >= _number * (_page - 1):
                        if t < _number * _page:
                            tt = {}
                            tt['new'] = temporary[str(t)]['new']
                            if temporary[str(t)]['new'] == "0":
                                _course_id = temporary[str(t)]['course_id']
                                _teacher_id = temporary[str(t)]['teacher_id']
                                course_info = Course.objects.get(cNo=_course_id)
                                teacher_info = Teacher.objects.get(tNo=_teacher_id)
                                tt['course_id'] = str(_course_id)
                                tt['course_name'] = course_info.cName
                                tt['credit'] = str(course_info.cCredit)
                                tt['academy'] = course_info.cMajor
                                tt['course_property'] = course_info.cNature
                                tt['grade'] = course_info.cGrade
                                tt['time'] = course_info.cTerm
                                tt['mark_element'] = course_info.cComposition
                                tt['teacher_id'] = str(_teacher_id)
                                tt['teacher_name'] = teacher_info.tName
                                tt['status'] = temporary[str(t)]['status']
                            else:
                                tt['course_id'] = temporary[str(t)]['course_id']
                                tt['course_name'] = temporary[str(t)]['course_name']
                                tt['credit'] = temporary[str(t)]['credit']
                                tt['academy'] = temporary[str(t)]['academy']
                                tt['course_property'] = temporary[str(t)]['course_property']
                                tt['grade'] = temporary[str(t)]['grade']
                                tt['time'] = temporary[str(t)]['time']
                                tt['mark_element'] = temporary[str(t)]['mark_element']
                                tt['teacher_id'] = temporary[str(t)]['teacher_id']
                                tt['teacher_name'] = temporary[str(t)]['teacher_name']
                                tt['status'] = temporary[str(t)]['status']
                            content[str(t % _number)] = tt

                data['content'] = content
                data['pages'] = len(temporary) // _number + 1
                info = "Success"
            else:
                info = "NotAuthorized"
            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # else:
            #     teachercourse_info = TeacherCourseApply.objects.all()
            #     teachernewcourse_info = TeacherNewCourseApply.objects.all()
            #     _count = 0
            #     temporary = {}
            #     content = {}
            #     for tci in teachercourse_info:
            #         # single = {}
            #         # single['new'] = "0"
            #         # single['course_id'] = tci.cNo_id
            #         # single['teacher_id'] = tci.tNo_id
            #         # single['status'] = tci.status
            #         # temporary[str(_count)] = single
            #
            #         temporary[str(_count)] = {}
            #         temporary[str(_count)]['new'] = "0"
            #         temporary[str(_count)]['course_id'] = tci.cNo_id
            #         temporary[str(_count)]['teacher_id'] = tci.tNo_id
            #         temporary[str(_count)]['status'] = tci.status
            #         _count += 1
            #
            #     for tnc in teachernewcourse_info:
            #         temporary[str(_count)] = {}
            #         temporary[str(_count)]['new'] = "1"
            #         temporary[str(_count)]['course_id'] = str(tnc.ncacNo)
            #         temporary[str(_count)]['course_name'] = tnc.ncacName
            #         temporary[str(_count)]['credit'] = str(tnc.ncacCredit)
            #         temporary[str(_count)]['academy'] = tnc.ncacMajor
            #         temporary[str(_count)]['course_property'] = tnc.ncacNature
            #         temporary[str(_count)]['grade'] = tnc.ncacGrade
            #         temporary[str(_count)]['time'] = tnc.ncacTerm
            #         temporary[str(_count)]['mark_element'] = tnc.ncacComposition
            #         temporary[str(_count)]['teacher_id'] = str(tnc.ncatNo_id)
            #         teacher_info = Teacher.objects.get(tNo=tnc.ncatNo_id)
            #         temporary[str(_count)]['teacher_name'] = teacher_info.tName
            #         temporary[str(_count)]['status'] = tnc.ncaStatus
            #         _count += 1
            #
            #     for t in range(0, len(temporary)):
            #         if t >= _number*(_page - 1):
            #             if t < _number*_page:
            #                 tt = {}
            #                 tt['new'] = temporary[str(t)]['new']
            #                 if temporary[str(t)]['new'] == "0":
            #                     _course_id = temporary[str(t)]['course_id']
            #                     _teacher_id = temporary[str(t)]['teacher_id']
            #                     course_info = Course.objects.get(cNo=_course_id)
            #                     teacher_info = Teacher.objects.get(tNo=_teacher_id)
            #                     tt['course_id'] = str(_course_id)
            #                     tt['course_name'] = course_info.cName
            #                     tt['credit'] = str(course_info.cCredit)
            #                     tt['academy'] = course_info.cMajor
            #                     tt['course_property'] = course_info.cNature
            #                     tt['grade'] = course_info.cGrade
            #                     tt['time'] = course_info.cTerm
            #                     tt['mark_element'] = course_info.cComposition
            #                     tt['teacher_id'] = str(_teacher_id)
            #                     tt['teacher_name'] = teacher_info.tName
            #                     tt['status'] = temporary[str(t)]['status']
            #                 else:
            #                     tt['course_id'] = temporary[str(t)]['course_id']
            #                     tt['course_name'] = temporary[str(t)]['course_name']
            #                     tt['credit'] = temporary[str(t)]['credit']
            #                     tt['academy'] = temporary[str(t)]['academy']
            #                     tt['course_property'] = temporary[str(t)]['course_property']
            #                     tt['grade'] = temporary[str(t)]['grade']
            #                     tt['time'] = temporary[str(t)]['time']
            #                     tt['mark_element'] = temporary[str(t)]['mark_element']
            #                     tt['teacher_id'] = temporary[str(t)]['teacher_id']
            #                     tt['teacher_name'] = temporary[str(t)]['teacher_name']
            #                     tt['status'] = temporary[str(t)]['status']
            #                 content[t] = tt
            #     data['content'] = content
            #     data['pages'] = len(temporary) // _number + 1
            #     info = "Success"
        else:
            info = "Wrong request method."

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax Error Or Parameter Error"
        # dict['message'] = info
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 18
0
def teacherinfomodify(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            teacher = reqbody['teacher']
            _id = teacher['teacher_id']
            _name = teacher['teacher_name']
            # _school = teacher['teacher_academy']
            _school = "信息与通信工程学院"
            _password = teacher['teacher_password_log']
            _address = teacher['teacher_address']
            _unlockpassword = teacher['teacher_password_unlock']

            updateteacher = Teacher.objects.filter(tNo=_id)
            checkid = Login.objects.filter(account=_id)
            checkaddress = Login.objects.filter(address=_address)

            if tokenauth(_requid, _reqtoken):
                if len(checkid) == 1 and len(updateteacher) == 1:
                    if len(checkaddress) == 1 or (len(checkaddress) == 1 and Login.objects.get(account=_id).address == _address):
                        updateteacher.update(tName=_name, tSchool=_school, LoginPassword=_password, tAddress=_address,
                                             tUnlockPassword=_unlockpassword)
                        checkid.update(LoginPassword=_password, address=_address, unlockPassword=_unlockpassword)
                        info = "Success"
                    else:
                        info = "Address already exist"
                else:
                    info = "Teacher ID dose not exist"
            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(checkid) == 0 or len(updateteacher) == 0:
            #     info = "Teacher ID dose not exist"
            #
            # elif len(checkaddress) > 0 and Login.objects.get(account=_id).address != _address:
            #     info = "Address already exist"
            #
            # else:
            #     updateteacher.update(tName=_name, tSchool=_school, LoginPassword=_password, tAddress=_address,
            #                          tUnlockPassword=_unlockpassword)
            #     checkid.update(LoginPassword=_password, address=_address, unlockPassword=_unlockpassword)
            #     info = "Success"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 19
0
def teachermaterialdelete(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']
            _file_hash = reqbody['file_hash']
            course_id = int(reqbody['courseId'])

            if tokenauth(_requid, _reqtoken):
                teacher_id = int(Login.objects.get(uid=_requid).account)

                if len(Teacher.objects.filter(tNo=teacher_id)) == 1:

                    if len(
                            CourseMaterial.objects.filter(
                                cNo_id=course_id,
                                cMaterialsHash=_file_hash)) == 1:
                        mdelete = CourseMaterial.objects.get(
                            cNo_id=course_id, cMaterialsHash=_file_hash)
                        mdelete.delete()
                        info = "Success"
                    else:
                        info = "File not exist"

                else:
                    info = "Teacher not exist"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Login.objects.filter(uid=int(_requid))) == 1:
            #     teacher_id = int(Login.objects.get(uid=int(_requid)).account)
            #     _hash = reqbody['documentId']
            #     if _requid == "":
            #         info = "Missing parameter ID"
            #     elif len(Teacher.objects.filter(tNo=teacher_id)) == 0:
            #         info = "Teacher not exist"
            #     elif len(CourseMaterial.objects.filter(cNo_id=course_id, cMaterialsHash=_hash)) == 0:
            #         info = "Document not exist"
            #     else:
            #         mdelete = CourseMaterial.objects.get(cNo_id=course_id, cMaterialsHash=_hash)
            #         mdelete.delete()
            #         info = "Success"
            # else:
            #     info = "Teacher not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 20
0
def studentinfomodify(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)
            _requid = reqbody['uid']
            _reqtoken = reqbody['token']
            stu_info = reqbody['student']
            _id = stu_info['student_id']
            _name = stu_info['student_name']
            _gender = stu_info['student_gender']
            _class = stu_info['student_class']
            _major = stu_info['student_major']
            _school = stu_info['student_school']
            _grade = stu_info['student_grade']
            _password = stu_info['student_password_log']
            _address = stu_info['student_address']
            _unlockpassword = stu_info['student_password_unlock']

            updatestudent = Student.objects.filter(sNo=_id)
            checkid = Login.objects.filter(account=_id)
            checkaddress = Login.objects.filter(address=_address)

            if tokenauth(_requid, _reqtoken):

                if len(checkid) == 1 and len(updatestudent) == 1:

                    if len(checkaddress) == 0 or (
                            len(checkaddress) == 1 and Login.objects.get(
                                account=_id).address == _address):
                        updatestudent.update(sName=_name,
                                             sGender=_gender,
                                             sClass=_class,
                                             sMajor=_major,
                                             sSchool=_school,
                                             sGrade=_grade,
                                             LoginPassword=_password,
                                             sAddress=_address,
                                             sUnlockPassword=_unlockpassword)
                        checkid.update(LoginPassword=_password,
                                       address=_address,
                                       unlockPassword=_unlockpassword)
                        info = "Success"

                    else:
                        info = "Address already exist"

                else:
                    info = "Student ID not exist"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(checkid) == 0 or len(updatestudent) == 0:
            #     info = "Student ID not exist"
            #
            # elif len(checkaddress) > 0 and Login.objects.get(account=_id).address != _address:
            #     info = "Address already exist"
            #
            # else:
            #     updatestudent.update(sName=_name, sGender=_gender, sClass=_class,  sMajor=_major, sSchool=_school,
            #                          sGrade=_grade, LoginPassword=_password, sAddress=_address,
            #                          sUnlockPassword=_unlockpassword)
            #     checkid.update(LoginPassword=_password, address=_address, unlockPassword=_unlockpassword)
            #     info = "Success"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        # import sys
        # info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 21
0
def teachercoursestudentquery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    content = {}
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            _course_id = reqbody['courseId']
            _page = int(reqbody['page'])
            _number = int(reqbody['number'])

            if tokenauth(_requid, _reqtoken):
                teacher_id = int(Login.objects.get(uid=int(_requid)).account)

                if len(Teacher.objects.filter(tNo=teacher_id)) == 1:

                    if len(Course.objects.filter(cNo=_course_id)) == 1:

                        if len(
                                TeacherCourse.objects.filter(
                                    tNo_id=teacher_id,
                                    cNo_id=_course_id)) == 1:
                            students = StudentCourse.objects.filter(
                                cNo_id=_course_id, status=1)
                            data['pages'] = math.ceil(
                                float(len(students) / _number))
                            if len(students) > 0:
                                _count = 0
                                temporary = {}
                                for s in students:
                                    st = {}
                                    st['name'] = Student.objects.get(
                                        sNo=s.sNo_id).sName
                                    st['studentId'] = s.sNo_id
                                    temporary[str(_count)] = st
                                    _count += 1

                                for c in range(0, len(students)):
                                    if c >= _number * (_page - 1):
                                        if c < _number * _page:
                                            content[str(c)] = temporary[str(c)]

                            else:
                                content = {}

                            data['content'] = content
                            info = "Success"
                        else:
                            info = "You are not the teacher of this course"
                    else:
                        info = "Course not exist"
                else:
                    info = "Teacher not exist"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Login.objects.filter(uid=int(_requid))) == 1:
            #     teacher_id = int(Login.objects.get(uid=int(_requid)).account)
            #
            #     if _requid == "":
            #         info = "Missing parameter ID"
            #     elif len(Teacher.objects.filter(tNo=teacher_id)) == 0:
            #         info = "Teacher not exist"
            #     elif len(Course.objects.filter(cNo=_course_id)) == 0:
            #         info = "Course not exist"
            #     elif len(TeacherCourse.objects.filter(tNo_id=teacher_id, cNo_id=_course_id)) == 0:
            #         info = "You are not the teacher of this course"
            #     else:
            #         students = StudentCourse.objects.filter(cNo_id=_course_id, status=1)
            #         data['pages'] = math.ceil(float(len(students) / _number))
            #         _count = 0
            #         temporary = {}
            #         for s in students:
            #             st = {}
            #             st['name'] = Student.objects.get(sNo=s.sNo_id).sName
            #             st['studentId'] = s.sNo_id
            #             temporary[str(_count)] = st
            #             _count += 1
            #
            #         for c in range(0, len(students)):
            #             if c >= _number * (_page - 1):
            #                 if c < _number * _page:
            #                     content[str(c)] = temporary[str(c)]
            #         data['content'] = content
            #         info = "Success"
            # else:
            #     info = "Teacher not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 22
0
def courseinfoadd(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            course = reqbody['course']
            _id = course['course_id']
            _name = course['course_name']
            _major = course['academy']
            _grade = course['grade']
            _term = course['course_time']
            _credit = course['credit']
            _composition = course['mark_element']
            _nature = course['course_property']
            # _number = course['course_number']
            _number = 200

            if tokenauth(_requid, _reqtoken):

                if len(Course.objects.filter(cNo=_id)) == 0:
                    newcourse = Course(cNo=_id,
                                       cName=_name,
                                       cCredit=_credit,
                                       cNature=_nature,
                                       cNumber=_number,
                                       cMajor=_major,
                                       cGrade=_grade,
                                       cTerm=_term,
                                       cComposition=_composition)
                    newcourse.save()
                    info = "Success"

                else:
                    info = "ID exist"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Course.objects.filter(cNo=_id)) > 0:
            #     info = "ID exist"
            #     # meta['code'] = "400"
            #     # meta['message'] = info
            #     # jsonr = simplejson.dumps(dict)
            #     # res = HttpResponseBadRequest(jsonr)
            #     # res.__setitem__('Access-Control-Allow-Origin', '*')
            #     # return res
            # else:
            #     newcourse = Course(cNo=_id, cName=_name, cCredit=_credit, cNature=_nature, cNumber=_number,
            #                        cMajor=_major, cGrade=_grade, cTerm=_term, cComposition=_composition)
            #     newcourse.save()
            #     info = "Success"
        else:
            info = "Wrong request method."

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax Error Or Parameter Error"
        # dict['message'] = info
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 23
0
def teachersubmitmark(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == "POST":
            reqbody = simplejson.loads(request.body)
            _uid = reqbody['uid']
            _txid = reqbody['Txid']
            _token = reqbody['token']
            _mark = reqbody['studentGrade']
            _cid = reqbody['courseId']
            _sid = reqbody['studentId']

            if tokenauth(_uid, _token):
                _tid = Login.objects.get(uid=_uid).account
                if len(Teacher.objects.filter(tNo=int(_tid))) == 1:
                    if len(Course.objects.filter(cNo=int(_cid))) == 1:
                        if len(Student.objects.filter(sNo=int(_sid))) == 1:
                            if len(
                                    TeacherCourse.objects.filter(
                                        cNo=int(_cid), tNo=int(_tid))) == 1:
                                if len(
                                        StudentCourse.objects.filter(
                                            sNo=int(_sid),
                                            cNo=int(_cid))) == 1:
                                    contractsubmitmark = ContractMark(
                                        txid=_txid,
                                        times=0,
                                        tNo=int(_tid),
                                        cNo=int(_cid),
                                        sNo=int(_sid),
                                        mark=_mark)
                                    contractsubmitmark.save()
                                    info = "Success"
                                else:
                                    info = "The student does not select this course"
                            else:
                                info = "You are not the teacher of this course"
                        else:
                            info = "Student not exist"
                    else:
                        info = "Course not exist"
                else:
                    info = "Teacher not exist"
            else:
                info = "NotAuthorized"
            # if time.time() - time.mktime(Token.objects.get(key=_token).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_token).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Login.objects.filter(uid=_uid)) == 1:
            #     _cid = reqbody['courseId']
            #     _sid = reqbody['studentId']
            #     _tid = Login.objects.get(uid=_uid).account
            #     if _cid == "" or _sid == "":
            #         info = "Missing parameter"
            #     elif len(Course.objects.filter(cNo=int(_cid))) == 0:
            #         info = "Course not exist"
            #     elif len(Student.objects.filter(sNo=int(_sid))) == 0:
            #         info = "Student not exist"
            #     elif len(TeacherCourse.objects.filter(cNo=int(_cid), tNo=int(_tid))) == 0:
            #         info = "You are not the teacher of this course"
            #     elif len(StudentCourse.objects.filter(sNo=int(_sid), cNo=int(_cid))) == 0:
            #         info = "the student not select this course"
            #     else:
            #         contractsubmitmark = ContractMark(txid=_txid, times=0, tNo=int(_tid), cNo=int(_cid), sNo=int(_sid),
            #                                           mark=_mark)
            #         contractsubmitmark.save()
            #         info = "Success"
            # else:
            #     info = "Teacher not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 24
0
def hpr(request):
    global result
    if request.method == 'POST':
        received_json_data = json.loads(request.body)
        script = received_json_data["script"]
        state = received_json_data["state"]

        state_keys = list(state.keys())
        state_values = list(state.values())

        for i in range(len(state_keys)):
            state_keys[i] = 'scope_' + state_keys[i] + ' = ' + str(
                state_values[i])

        variables = '\n'.join(state_keys)

        # запрещенные библиотеки и оператор import для запрета импортирования модулей внутри
        taboos = [
            '__render', 'HttpResponseRedirect', 'JsonResponse', 'PostForm',
            '__reverse', 'import', 'stderr', 'HttpResponseBadRequest'
        ]
        flag = True

        for taboo in taboos:
            if taboo in script or taboo in variables:
                flag = False
                break

        exception_flag = False

        if flag:
            ''' Выполнение кода, если не исползуется ничего из taboos '''
            try:
                exec(variables, globals())
                exec(script, globals())
                state['result'] = result
            except ValueError:
                status = '400: Bad Request'
                result = 'ValueError'
                response = HttpResponseBadRequest(result, status=400)
                response.__setitem__(header='status', value=status)
                return response
            except SyntaxError:
                status = '400: Bad Request'
                result = 'SyntaxError'
                response = HttpResponseBadRequest(result, status=400)
                response.__setitem__(header='status', value=status)
                return response
            except NameError:
                status = '400: Bad Request'
                result = 'NameError'
                response = HttpResponseBadRequest(result, status=400)
                response.__setitem__(header='status', value=status)
                return response
            except ZeroDivisionError:
                status = '400: Bad Request'
                result = 'ZeroDivisionError'
                response = HttpResponseBadRequest(result, status=400)
                response.__setitem__(header='status', value=status)
                return response
            except MemoryError:
                status = '400: Bad Request'
                result = 'MemoryError'
                response = HttpResponseBadRequest(result, status=400)
                response.__setitem__(header='status', value=status)
                return response
            except ModuleNotFoundError:
                status = '400: Bad Request'
                result = 'ModuleNotFoundError'
                response = HttpResponseBadRequest(result, status=400)
                response.__setitem__(header='status', value=status)
                return response

        else:
            script = None
            variables = None
            result = "AcceptError: using unavailable expression"
            state['result'] = result

        return JsonResponse(
            {
                "script": script,
                "result_variables": variables,
                "state": state,
            },
            safe=False)
    else:
        return __render(request, 'pyinjs/handling_post_request.html')
Esempio n. 25
0
def studentinfoquery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)
            _requid = reqbody['uid']
            _reqtoken = reqbody['token']
            stu = reqbody['student']
            _id = stu['student_id']

            if tokenauth(_requid, _reqtoken):

                if len(Student.objects.filter(sNo=_id)) == 1:
                    stu_info = Student.objects.get(sNo=_id)
                    data['student_id'] = _id
                    data['student_name'] = stu_info.sName
                    data['student_gender'] = stu_info.sGender
                    data['student_class'] = stu_info.sClass
                    data['student_major'] = stu_info.sMajor
                    data['student_school'] = stu_info.sSchool
                    data['student_grade'] = stu_info.sGrade
                    data['student_password_log'] = stu_info.LoginPassword
                    data['student_address'] = stu_info.sAddress
                    data['student_password_unlock'] = stu_info.sUnlockPassword
                    data['student_tel'] = stu_info.sTelephone
                    data['student_email'] = stu_info.sEmail
                    info = "Success"

                else:
                    info = "Student not exist"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif _id == "":
            #     info = "Missing parameter ID"
            #
            # elif len(Student.objects.filter(sNo=_id)) == 0:
            #     info = "Student not exist"
            #
            # else:
            #     stu_info = Student.objects.get(sNo=_id)
            #     data['student_id'] = _id
            #     data['student_name'] = stu_info.sName
            #     data['student_gender'] = stu_info.sGender
            #     data['student_class'] = stu_info.sClass
            #     data['student_major'] = stu_info.sMajor
            #     data['student_school'] = stu_info.sSchool
            #     data['student_grade'] = stu_info.sGrade
            #     data['student_password_log'] = stu_info.LoginPassword
            #     data['student_address'] = stu_info.sAddress
            #     data['student_password_unlock'] = stu_info.sUnlockPassword
            #     data['student_tel'] = stu_info.sTelephone
            #     data['student_email'] = stu_info.sEmail
            #     info = "Success"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 26
0
def teachercoursequery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            if tokenauth(_requid, _reqtoken):
                _id = int(Login.objects.get(uid=int(_requid)).account)

                if len(Teacher.objects.filter(tNo=_id)) == 1:
                    teachercourse = TeacherCourse.objects.filter(tNo=_id)
                    _count = 0
                    for tc in teachercourse:
                        c = {}
                        course_info = Course.objects.get(cNo=tc.cNo_id)
                        c['courseId'] = tc.cNo_id
                        c['name'] = course_info.cName
                        c['time'] = course_info.cTerm
                        c['type'] = course_info.cNature
                        c['score'] = course_info.cCredit
                        c['object'] = course_info.cMajor
                        c['description'] = course_info.cIntroduction
                        # c['grade'] = course_info.cGrade
                        # c['mark_element'] = course_info.cComposition
                        data[str(_count)] = c
                        _count += 1
                    info = "Success"
                else:
                    info = "Teacher not exist"
            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Login.objects.filter(uid=int(_requid))) == 1:
            #     _id = int(Login.objects.get(uid=int(_requid)).account)
            #
            #     if _requid == "":
            #         info = "Missing parameter ID"
            #     elif len(Teacher.objects.filter(tNo=_id)) == 0:
            #         info = "Teacher not exist"
            #     else:
            #         teachercourse = TeacherCourse.objects.filter(tNo=_id)
            #         _count = 0
            #         for tc in teachercourse:
            #             c = {}
            #             course_info = Course.objects.get(cNo=tc.cNo_id)
            #             c['courseId'] = tc.cNo_id
            #             c['name'] = course_info.cName
            #             c['time'] = course_info.cTerm
            #             c['type'] = course_info.cNature
            #             c['score'] = course_info.cCredit
            #             c['object'] = course_info.cMajor
            #             c['description'] = course_info.cIntroduction
            #             # c['grade'] = course_info.cGrade
            #             # c['mark_element'] = course_info.cComposition
            #             data[str(_count)] = c
            #             _count += 1
            #         info = "Success"
            # else:
            #     info = "Teacher not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 27
0
def addresspasswordsent(request):
    dict = {}
    meta = {}
    data = {}
    # _blockchain = {}
    dict["meta"] = meta
    dict["data"] = data
    try:
        w3 = Web3(HTTPProvider("http://localhost:8545"))
        contract_instance = w3.eth.contract(contract_abi, contract_address, ContractFactoryClass=ConciseContract)
        if request.method == 'POST':
            req = simplejson.loads(request.body)
            _uid = req['uid']
            # _timestamp = req['timestamp']
            _blockchain = req['block_chain']
            _address = _blockchain['address']
            _password = _blockchain['password_unlock']
            super_manager_uid = Login.objects.get(account=3).uid

            r = str(math.floor(random.random() * 10 ** 10))
            r.zfill(10)
            _txid = '%s%s%s' % (super_manager_uid, str(int(time.time())), str(r))

            # _txid = super_manager_uid + _timestamp

            if _uid == "" or _address == "" or _password == "":
                info = "Syntax Error Or Parameter Error"
            elif len(Login.objects.filter(uid=_uid)) == 1:
                check = Login.objects.get(uid=_uid)
                if check.address is None and check.unlockPassword is None:
                    Login.objects.filter(uid=_uid).update(address=_address, unlockPassword=_password)
                    data['type'] = check.accountType
                    _accounttype = check.accountType
                    _account = check.account
                    if _accounttype == "student":
                        if len(Student.objects.filter(sNo=_account)) == 1:
                            Student.objects.filter(sNo=_account).update(sAddress=_address, sUnlockPassword=_password)
                            contract_instance.addAccount(_txid, 0, _account, _address,
                                                         transact={'from': super_manager_address, 'gas': 400000})
                            w3.eth.sendTransaction({'from': super_manager_address, 'to': _address, 'value': amount,
                                                    'gas': 400000})
                            new_tx = ContractAddress(txid=_txid, times=0, accountType=0, account=_account,
                                                     address=_address)
                            new_tx.save()
                            info = "Success"
                        else:
                            info = "Account does not exist"
                    elif _accounttype == "teacher":
                        if len(Teacher.objects.filter(tNo=_account)) == 1:
                            Teacher.objects.filter(tNo=_account).update(tAddress=_address, tUnlockPassword=_password)
                            contract_instance.addAccount(_txid, 1, _account, _address,
                                                         transact={'from': super_manager_address, 'gas': 400000})
                            new_tx = ContractAddress(txid=_txid, times=0, accountType=1, account=_account,
                                                     address=_address)
                            new_tx.save()
                            info = "Success"
                        else:
                            info = "Account does not exist"
                    elif _accounttype == "administrator":
                        if len(Manager.objects.filter(mNo=_account)) == 1:
                            Manager.objects.filter(mNo=_account).update(mAddress=_address, mUnlockPassword=_password)
                            contract_instance.addAccount(_txid, 2, _account, _address,
                                                         transact={'from': super_manager_address, 'gas': 400000})
                            new_tx = ContractAddress(txid=_txid, times=0, accountType=2, account=_account,
                                                     address=_address)
                            new_tx.save()
                            info = "Success"
                        else:
                            info = "Account does not exist"
                    else:
                        info = "Wrong type. Please notify the administrator."
                else:
                    info = "Address and password already exist"
            else:
                info = "ID not exist"
        else:
            info = "Wrong request method."
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error Or parameter error."
        meta['message'] = info
        meta['code'] = "400"
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 28
0
def teachercourseapplysubmit(request):
    dict = {}
    meta = {}
    dict["meta"] = meta
    try:
        if request.method == 'POST':
            reqbody = simplejson.loads(request.body)

            _requid = reqbody['uid']
            _reqtoken = reqbody['token']

            course_id = int(reqbody['courseId'])

            if tokenauth(_requid, _reqtoken):
                teacher_id = int(Login.objects.get(uid=int(_requid)).account)

                if len(Teacher.objects.filter(tNo=teacher_id)) == 1:

                    if len(
                            TeacherCourse.objects.filter(cNo=course_id,
                                                         tNo=teacher_id)) == 0:

                        if len(
                                TeacherCourseApply.objects.filter(
                                    cNo=course_id, tNo=teacher_id,
                                    status="1")) == 0:
                            newapplication = TeacherCourseApply(
                                cNo_id=course_id,
                                tNo_id=teacher_id,
                                status="1")
                            newapplication.save()
                            info = "Success"
                        else:
                            info = "You have already submitted the application"

                    else:
                        info = "You are already the teacher of this course"

                else:
                    info = "Teacher not exist"

            else:
                info = "NotAuthorized"

            # if time.time() - time.mktime(Token.objects.get(key=_reqtoken).created.timetuple()) > AuthorizedTime:
            #     Token.objects.filter(key=_reqtoken).delete()
            #     info = "NotAuthorized"
            #
            # elif len(Login.objects.filter(uid=int(_requid))) == 1:
            #     teacher_id = int(Login.objects.get(uid=int(_requid)).account)
            #
            #     if _requid == "":
            #         info = "Missing parameter ID"
            #     elif len(Teacher.objects.filter(tNo=teacher_id)) == 0:
            #         info = "Teacher not exist"
            #     elif len(TeacherCourse.objects.filter(cNo=course_id, tNo=teacher_id)) != 0:
            #         info = "You are already the teacher of this course"
            #     elif len(TeacherCourseApply.objects.filter(cNo=course_id, tNo=teacher_id, status="1")) != 0:
            #         info = "You have already submitted the application"
            #     else:
            #         newapplication = TeacherCourseApply(cNo_id=course_id, tNo_id=teacher_id, status="1")
            #         newapplication.save()
            #         info = "Success"
            # else:
            #     info = "Teacher not exist"
        else:
            info = "Wrong request method"

    except Token.DoesNotExist:
        info = "NotAuthorized"

    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 29
0
def login(request):
    dict = {}
    meta = {}
    data = {}
    _blockchain = {}
    dict["meta"] = meta
    dict["data"] = data
    try:
        if request.method == 'POST':
            req = simplejson.loads(request.body)
            user = req['user']
            _account = user['account']
            _password = user['password']
            if _account == "" or _password == "":
                info = "Syntax Error Or Parameter Error"
                # return HttpResponseForbidden(info)
            elif len(Login.objects.filter(account=_account)) == 1:
                check = Login.objects.get(account=_account)
                if check.LoginPassword == _password:
                    _accounttype = check.accountType
                    data['type'] = _accounttype
                    data['uid'] = check.uid
                    if len(Token.objects.filter(user_id=check.account)) == 1:
                        Token.objects.filter(user_id=check.account).delete()
                    newtoken = Token.objects.create(user=check)
                    data['token'] = newtoken.key

                    if check.address is None and check.unlockPassword is None:
                    # if str(check.address) == "" and str(check.unlockPassword) == "":
                        data['address_exist'] = "0"
                        # info = "Success"
                        if _accounttype == "student":
                            if len(Student.objects.filter(sNo=_account)) == 1:
                                data['name'] = Student.objects.get(sNo=_account).sName
                                info = "Success"
                            else:
                                data['name'] = ""
                                info = "Account does not exist"
                        elif _accounttype == "teacher":
                            if len(Teacher.objects.filter(tNo=_account)) == 1:
                                data['name'] = Teacher.objects.get(tNo=_account).tName
                                info = "Success"
                            else:
                                data['name'] = ""
                                info = "Account does not exist"
                        elif _accounttype == "administrator":
                            if len(Manager.objects.filter(mNo=_account)) == 1:
                                data['name'] = Manager.objects.get(mNo=_account).mName
                                info = "Success"
                            else:
                                data['name'] = ""
                                info = "Account does not exist"
                        else:
                            info = "Wrong type. Please notify the administrator."
                        # data['name'] = _name
                    else:
                        if _accounttype == "student":
                            if len(Student.objects.filter(sNo=_account)) == 1:
                                data['name'] = Student.objects.get(sNo=_account).sName
                                info = "Success"
                            else:
                                data['name'] = ""
                                info = "Account does not exist"
                        elif _accounttype == "teacher":
                            if len(Teacher.objects.filter(tNo=_account)) == 1:
                                data['name'] = Teacher.objects.get(tNo=_account).tName
                                info = "Success"
                            else:
                                data['name'] = ""
                                info = "Account does not exist"
                        elif _accounttype == "administrator":
                            if len(Manager.objects.filter(mNo=_account)) == 1:
                                data['name'] = Manager.objects.get(mNo=_account).mName
                                info = "Success"
                            else:
                                data['name'] = ""
                                info = "Account does not exist"
                        else:
                            info = "Wrong type. Please notify the administrator."
                        data['address_exist'] = "1"
                        _blockchain['address'] = check.address
                        _blockchain['password_unlock'] = check.unlockPassword
                    data['blockchain'] = _blockchain

                else:
                    info = "Wrong password."
            else:
                info = "Account does not exist"
        else:
            info = "Wrong request method."
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error Or parameter error."
        meta['message'] = info
        meta['code'] = "400"
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        dict['data'] = {}
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
Esempio n. 30
0
def stuinfoquery(request):
    dict = {}
    meta = {}
    data = {}
    dict["meta"] = meta
    dict["data"] = data

    try:
        if request.method == "POST":
            reqbody = simplejson.loads(request.body)
            #stu = reqbody['student']
            _token = reqbody['token']
            _uid = reqbody['uid']
            if time.time() - time.mktime(
                    Token.objects.get(
                        key=_token).created.timetuple()) > AuthorizedTime:
                Token.objects.filter(key=_token).delete()
                info = "NotAuthorized"
            elif len(Login.objects.filter(uid=_uid)) == 1:
                _login = Login.objects.get(uid=_uid)
                _id = int(_login.account)
                if _id == "":
                    info = "Missing parameter ID"
                elif len(Student.objects.filter(sNo=_id)) == 0:
                    info = "Student not exist"
                else:
                    stu_info = Student.objects.get(sNo=_id)
                    data['id'] = _id
                    data['name'] = stu_info.sName
                    data['gender'] = stu_info.sGender
                    data['class'] = stu_info.sClass
                    data['major'] = stu_info.sMajor
                    data['school'] = stu_info.sSchool
                    data['grade'] = stu_info.sGrade
                    data['tel'] = stu_info.sTelephone
                    data['email'] = stu_info.sEmail
                    data['type'] = _login.accountType
                    info = "Success"
            else:
                info = "Student not exist"
            # else:
            #     info = "Wrong accounttype,please notify administrator"

        else:
            info = "Wrong request method"
    except Token.DoesNotExist:
        info = "NotAuthorized"
    except:
        import sys
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        # info = "Syntax error or parameter error"
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res

    if info == "Success":
        meta['code'] = "200"
        meta['message'] = "ok"
        res = JsonResponse(dict)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res
    else:
        meta['code'] = "400"
        meta['message'] = info
        jsonr = simplejson.dumps(dict)
        res = HttpResponseBadRequest(jsonr)
        res.__setitem__('Access-Control-Allow-Origin', '*')
        return res