예제 #1
0
def registration_student_view(request):
    if request.method == 'POST':
        serializer = RegisterationSerializer(data=request.data)
        serializer2 = CreateStudent(data=request.data)
        data = {}
        if serializer.is_valid():
            if serializer2.is_valid():
                user = serializer.save()
                data['respone'] = 'Successful registrated a new user'
                data['email'] = user.email
                data['username'] = user.username
                data['role'] = user.role
                data['address'] = user.address
                data['phone'] = user.phone_number
                data['birth_date'] = user.birth_date
                token = Token.objects.get(user=user).key
                data['token'] = token
                username = user.username
                student = serializer2.save(username)
                data['uni_code'] = student.uni_code
                data['grade'] = student.grade
                data['level'] = student.level
            else:
                data = serializer2.errors
        else:
            data = serializer.errors
        return Response(data)
예제 #2
0
def registration_parent_view(request):
    if request.method == 'POST':
        serializer = RegisterationSerializer(data=request.data)
        serializer2 = CreateParent(data=request.data)
        data = {}
        # status = 0
        if serializer.is_valid():
            user = serializer.save()
            data['respone'] = 'Successful registrated a new user'
            data['email'] = user.email
            data['username'] = user.username
            data['role'] = user.role
            data['address'] = user.address
            data['phone'] = user.phone_number
            data['birth_date'] = user.birth_date
            token = Token.objects.get(user=user).key
            data['token'] = token
            if serializer2.is_valid():
                username = user.username
                author = get_or_none(User, username=username)
                if username:
                    # check that unicode is exist in database
                    masters = HeadMaster.objects.all()
                    listMaster = []
                    for master in masters:
                        listMaster.append(master.uni_code)
                    
                    if serializer2.uni_code not in listMaster:
                        data['uni_code'] = 'unicode dose not exist'
                        confirmUser = serializer2.cofirm_user
                        userWhichSaved = User.objects.get(username=confirmUser)
                        if userWhichSaved:
                            userWhichSaved.delete()
                        else:
                            data['user'] = '******'
                    else:
                        parent = serializer2.save(user=author)
                        data['uni_code'] = parent.uni_code
                    # status = 201
                else:
                    data['responseUser'] = '******'
                    # status = 404
            else:
                data['responseStudent'] = 'error in validation'
                # status = 400
        else:
            if data:
                data += serializer.errors
            else:
                data = serializer.errors
        return Response(data)
예제 #3
0
def registration_headmaster_view(request):

    if request.method == 'POST':
        serializer = RegisterationSerializer(data=request.data)
        serializer2 = CreateHeadMaster(data=request.data)
        data = {}
        # status = 0
        if serializer.is_valid():
            user = serializer.save()
            data['respone'] = 'Successful registrated a new user'
            data['email'] = user.email
            data['username'] = user.username
            data['role'] = user.role
            data['address'] = user.address
            data['phone'] = user.phone_number
            data['birth_date'] = user.birth_date
            token = Token.objects.get(user=user).key
            data['token'] = token
            if serializer2.is_valid():
                username = user.username
                author = get_or_none(User, username=username)
                if username:
                    headmaster = serializer2.save(user=author)
                    data['uni_code'] = headmaster.uni_code
                    data['educationalType'] = headmaster.educational_type
                    data['level'] = headmaster.educational_level
                    # status = 201
                else:
                    data['responseUser'] = '******'
                    # status = 404
            else:
                data['responseHeadMaster'] = 'error in validation'
                # status = 400
        else:
            if data:
                data += serializer.errors
            else:
                data = serializer.errors
        return Response(data)
예제 #4
0
def registration_headmaster_view(request):
    if request.method == 'POST':
        serializer = RegisterationSerializer(data=request.data)
        serializer2 = CreateHeadMaster(data=request.data)
        data = {}
        if serializer.is_valid() and serializer2.is_valid():
            user = serializer.save()
            data['respone'] = 'Successful registrated a new user'
            data['email'] = user.email
            data['username'] = user.username
            data['role'] = user.role
            data['address'] = user.address
            data['phone'] = user.phone_number
            data['birth_date'] = user.birth_date
            token = Token.objects.get(user=user).key
            data['token'] = token
            headmaster = serializer2.save(user=user)
            data['uni_code'] = headmaster.uni_code
            data['educationalType'] = headmaster.educational_type
        else:
            data = serializer.errors
            data += serializer2.errors
        return Response(data)