Пример #1
0
def add_4(request):
    teacher=Teacher(
    id=2,
    tea_name="张老师"
    )
    teacher.save()
    return HttpResponse("添加成功")
Пример #2
0
def create_teacher_user():
    base_user = User.objects.create_user(email="*****@*****.**",
                                         password="******")
    base_user.teacher_status = True

    teacher = Teacher(name='test teacher',
                      department='CD',
                      phone=9828127640,
                      user=base_user)
    return teacher
Пример #3
0
    def setUp(self):
        self.student_a = Student(
            first_name="Tiffany",
            last_name="Jeruto",
            date_of_birth=datetime.date(2000, 6, 24),
            registration_number="254016",
            Email="*****@*****.**",
            phone_number="0789647745",
            place_of_residence="Rongai",
            guardian_phone="0789567484",
            id_number=345378625,
            date_joined=datetime.date.today(),
        )

        self.student_b = Student(
            first_name="Clay",
            last_name="Jensen",
            date_of_birth=datetime.date(1999, 7, 25),
            registration_number="254017",
            Email="*****@*****.**",
            phone_number="0789765945",
            place_of_residence="Roysambu",
            guardian_phone="0780007684",
            id_number=3453734789,
            date_joined=datetime.date.today(),
        )

        self.python = Course(name="Python",
                             duration_in_months=10,
                             Course_number="1001",
                             description="Django and Flask frameworks")

        self.javascript = Course(
            name="Javascript",
            duration_in_months=10,
            Course_number="1002",
            description="Vanilla javascript and frameworks")

        self.hardware = Course(name="Hardware",
                               duration_in_months=10,
                               Course_number="1003",
                               description=" Product design using Fusion 360")

        self.teacher = Teacher(first_name="James",
                               last_name="Mwai",
                               place_of_residence="Kilimani",
                               phone_number="0723456786",
                               Email="*****@*****.**",
                               id_number=3128956743,
                               profession="Google Expert",
                               registration_number="2344",
                               date_joined=datetime.date.today())
Пример #4
0
    def setUp(self):
        self.student_a = Student.objects.create(
            first_name="Joan",
            last_name="Aluka",
            date_of_birth=datetime.date(2000, 7, 10),
            registration_number="123",
            email="*****@*****.**",
            phone_number="0718149079",
            place_of_residence="Nairobi",
            guardian_phone="12334",
            id_number=1234,
            date_joined=datetime.date.today(),
        )

        self.student_b = Student.objects.create(
            first_name="Joan",
            last_name="Aluka",
            date_of_birth=datetime.date(2000, 7, 10),
            registration_number="123",
            email="*****@*****.**",
            phone_number="0718149079",
            place_of_residence="Nairobi",
            guardian_phone="12334",
            id_number=1234,
            date_joined=datetime.date.today(),
        )

        self.python = Course.objects.create(name="python",
                                            duration_in_months=6,
                                            course_number="5",
                                            description="python")
        self.javaScript = Course.objects.create(name="javaScript",
                                                duration_in_months=6,
                                                course_number="5",
                                                description="react js")
        self.hardware = Course.objects.create(name="hardware",
                                              duration_in_months=6,
                                              course_number="5",
                                              description="product design")

        self.teacher = Teacher(
            first_name="Joan",
            last_name="Aluka",
            date_of_birth=datetime.date(2000, 7, 10),
            registration_no="123",
            email="*****@*****.**",
            phone_number="0718149079",
            place_of_residence="Nairobi",
            id_number=1234,
            profession="Frontend developer",
        )
Пример #5
0
	def setUp(self):
		self.student_a=Student(first_name=Joy,
			last_name=Wahome,
			date_of_birth=datetime.date(1998,8,25),
			registration_number=123,
			place_of_residence=Nairobi,
			phone_number=123456789,
			[email protected],
			guardian_phone=12345,
			id_number=1111111,
			date_joined=datetime.date.today(),)

		self.student_b=Student(first_name=Ivy,
			last_name=Wahome,
			date_of_birth=datetime.date(1996,5,24),
			registration_number=1234,
			place_of_residence=Nairobi,
			phone_number=123456789,
			[email protected],
			guardian_phone=123456,
			id_number=2222222,
			date_joined=datetime.date.today(),)

		self.python=Course(name=python,
			duration_in_months=10,
			course_number=1,
			description=Learn to code in Python,)

		self.javascript=Course(name=javascript,
			duration_in_months=10,
			course_number=2,
			description=Learn to code in JS,)

		self.hardware=Course(name=hardware,
			duration_in_months=10,
			course_number=3,
			description=Learn to build hardware,)

		self.teacher=Teacher(first_name=James,
			last_name=Mwai,
			date_of_birth=datetime.date(1998,8,25),
			registration_no=123,
			place_of_residence=Nairobi,
			phone_number=123456789,
			[email protected],
			id_number=1111111,
			profession=Consultant,)
Пример #6
0
def managerTeach(request):
    if request.method == 'GET':
        return render(request, 'manager/teachdashboard.html')
    else:
        email = request.POST.get('email')
        name = request.POST.get('name')
        password = getRandomPassword()
        user = Account(email=email,
                       password=make_password(password),
                       is_teacher=True,
                       is_manager=False)
        user.save()
        msg = f'{name}, Your Account is created successfully, to log into your account \n please use \n email: {email} \n password : {password}'
        Mail(subject='Account Created', message=msg, recipient_list=[email])
        teacher = Teacher(name=name, user_id=user.id)
        teacher.save()
        messages.success(
            request, "Account created successfully please do check your email")
        return redirect('managerTeach')
Пример #7
0
def manager_teacherview(request):
    if request.method == 'GET':
        return render(request, 'manager/manager_teacherview.html')
    else:
        email = request.POST.get('email')
        name = request.POST.get('name')
        contact = request.POST['contact']
        password = randomPassword()
        user = Account(email=email,
                       password=make_password(password),
                       is_teacher=True,
                       is_manager=False,
                       is_student=False)
        user.save()
        msg = f'{name}, your account is created successfully \n use the following credential to login \n email:{email} \n password:{password}'
        Mail(subject='Account created', message=msg, recipient_list=[email])
        teacher = Teacher(name=name, contact=contact, user_id=user.id)
        teacher.save()
        messages.add_message(request, messages.SUCCESS,
                             'Teacher Account is created successfully')
        return redirect('manager_teacherview')
 def post(self, request, *args, **kwargs):
     email = request.POST.get('email')
     name = request.POST.get('name')
     password_ = randomPassword()
     try:
         user = Account(email=email,
                        password=make_password(password_),
                        is_teacher=True)
         user.save()
         msg = f'{name}, Your account is created Please use the following credential to login into your account \n Email: {email} \n password: {password_}'
         Mail(subject="Account Creation",
              message=msg,
              recipient_list=[
                  email,
              ])
         teacher = Teacher(name=name, user_id=user.id)
         teacher.save()
         messages.add_message(request, messages.SUCCESS,
                              'Teacher Account is created successfully')
         return redirect(reverse_lazy('manage_teacher'))
     except Exception as e:
         messages.add_message(request, messages.ERROR, str(e))
         return redirect('manage_teacher')
Пример #9
0
    def post(self, request, format='json'):
        serializer = UserSerializer(data=request.data)
        if serializer.is_valid():
            #print("Valid")
            user = serializer.save()
            if user:
                if request.data["isStudent"] == 1:
                    new_student = Student(
                        user=user, contact_no=request.data["contact_no"])
                    new_student.save()
                elif request.data["isStudent"] == 0:
                    new_teacher = Teacher(
                        user=user, contact_no=request.data["contact_no"])
                    new_teacher.save()
                else:
                    return Response(serializer.errors,
                                    status=status.HTTP_400_BAD_REQUEST)

                token = Token.objects.create(user=user)
                json = serializer.data
                json['token'] = token.key
                return Response(json, status=status.HTTP_201_CREATED)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #10
0
    try:
        classes = Classes.objects.get(name=classes)
    except:
        print("+++++++++++------we dont find this %r" % classes, end="||")
        newclass = Classes()
        newclass.name = classes
        newclass.save()
        #continue
        classes = newclass
    #teacher
    try:
        teacher = User.objects.get(username=teacher)
        try:
            teacher = Teacher.objects.get(teacher=teacher)
        except:
            newteacher = Teacher()
            newteacher.teacher = teacher
            newteacher.save()
            teacher = newteacher
    except:
        a = User.objects.create_user(teacher, "*****@*****.**", "jtdxjwk")
        newteacher = Teacher()
        newteacher.teacher = a
        newteacher.is_teacher = True
        newteacher.save()
        teacher = newteacher
        print("we have save a new user %r" % teacher, end="||")

    from course.models import Course
    try:
        course = Course.objects.get(name=course)
Пример #11
0
    def create(self, request, *args, **kwargs):
        check_token = pd_adm_token(request)
        if check_token:
            return check_token

        # 用户名
        user_name = request.data.get('user_name')
        # 手机号
        phone_number = request.data.get("phone_number")
        # 密码
        password = request.data.get("password")
        # 角色
        role = request.data.get('role')
        # 真实姓名
        name = request.data.get('name')

        if not (role == 0 or role == 1 or role == 2):
            return response_success_200(code=STATUS_PARAMETER_ERROR,
                                        message="role的取值为(0, 1, 2)")

        if not pd_phone_number(phone_number):
            message = "手机号格式错误"
            return response_success_200(code=STATUS_PHONE_NUMBER_DUPLICATE,
                                        message=message)

        if check_user_name(user_name):
            message = "用户名已存在"
            return response_success_200(code=STATUS_USER_NAME_DUPLICATE,
                                        message=message)
        if check_phone_number(phone_number):
            message = "该手机号已被注册"
            return response_success_200(code=STATUS_PHONE_NUMBER_DUPLICATE,
                                        message=message)

        # 创建用户详情 并获得他的id
        user_details_id = UserDetails.objects.create(name=name).id

        # 加密
        request.data["password"] = my_encode(password)
        request.data['user_details'] = user_details_id
        request.data['token'] = "-1"

        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)

        # 创建角色信息
        user_id = serializer.data['id']
        if role == 0:
            save_teacher = Teacher(user_id=user_id)
            save_teacher.save()
        elif role == 1:
            save_student = Student(user_id=user_id)
            save_student.save()
        elif role == 2:
            save_parent = Parent(user_id=user_id)
            save_parent.save()
        else:
            message = "角色不存在"
            return response_success_200(status=STATUS_CODE_ERROR,
                                        message=message)
        # data = serializer.data
        print(f'数据是:{serializer.data}')
        return response_success_200(code=STATUS_200_SUCCESS,
                                    data=serializer.data,
                                    headers=headers)
Пример #12
0
def addTeacher(request):
    teacher_name = request.POST.get('tname', '')
    t = Teacher(teacher_name=teacher_name)
    t.save()
    # request.session['name_teacher'] = teacher_name
    return render_to_response('teacher/teacherAdded.html')