Пример #1
0
def parent_register_view(request):
	if request.method == "POST":
		username = request.POST['username']
		if not User.objects.filter(username = username).exists():
			return render(request, 'reg/parent_register.html', {'error':'Username or email already used, or passwords do not match'})
		u = User.objects.get(username = username)

		t = Parent(user=u)
		t.save()
		return redirect('home')
	else:
		if Student.objects.filter(user=request.user).count() > 0 or Teacher.objects.filter(user=request.user).count() > 0 or Parent.objects.filter(user=request.user).count() > 0:
			return redirect('home')

		return render(request, 'reg/parent_register.html')
Пример #2
0
    def test_mutually_referential(self):
        # Create a Parent
        q = Parent(name='Elizabeth')
        q.save()

        # Create some children
        c = q.child_set.create(name='Charles')
        e = q.child_set.create(name='Edward')

        # Set the best child
        # No assertion require here; if basic assignment and
        # deletion works, the test passes.
        q.bestchild = c
        q.save()
        q.delete()
Пример #3
0
def handle_parent():
    #----------------------------CREATE POST
    if request.method == 'POST':
        body = request.get_json()
        if body is None:
            return "The request body is null", 400
        if 'person_id' not in body:
            return "You need to specify the person_id", 400
        if 'father_id' not in body:
            return "You need to specify the father_id", 400
        if 'mother_id' not in body:
            return "You need to specify the mother_id", 400       
        
        relation = Parent()
        relation.own_id = body['person_id']
        relation.father_id = body['father_id']
        relation.mother_id = body['mother_id']
        relation.relativity ='person id: '+ str(body['person_id'])+' - '+'father id: '+str(body['father_id'])+' - '+'mother id: '+str(body['mother_id']) 

        verification = Parent.query.filter_by(own_id = body['person_id']).first()
        if verification is None:
            db.session.add(relation)
        elif relation.own_id == verification.own_id:
            return "This user already has a RELATION", 400
        else:
            db.session.add(relation)      
            
        db.session.commit()

        response_body = {"msg": "You POST a RELATION"}        

        return jsonify(response_body), 200
Пример #4
0
    def test_mutually_referential(self):
        # Create a Parent
        q = Parent(name='Elizabeth')
        q.save()

        # Create some children
        c = q.child_set.create(name='Charles')
        e = q.child_set.create(name='Edward')

        # Set the best child
        # No assertion require here; if basic assignment and
        # deletion works, the test passes.
        q.bestchild = c
        q.save()
        q.delete()
Пример #5
0
def parent_login():
    if request.form:
        login = request.form.get("login")
        password = request.form.get("password")
        parent = Parent.auth(login, password)

        if parent:
            session["auth"] = parent.id
            return {
                "id": parent.id,
                "name": parent.name,
                "surname": parent.surname,
                "login": parent.login,
                "password": parent.password,
                "position": parent.position,
                "child_id": parent.child__id
            }
        else:
            return "Неправильный логин или пароль"
Пример #6
0
    def post(self):
        args = parent_parser.parse_args()

        if 'id' not in args:
            highest = Parent.query.order_by(Parent.id).last()
            parent_id = highest + 1
        else:
            parent_id = args['id']

        parent = Parent(id=parent_id,
                        email=args['email'],
                        password=args['password'],
                        first_name=args['first_name'],
                        last_name=args['last_name'])

        # TODO: Search for child's name

        db.session.add(parent)
        db.session.commit()

        return parent, 201
Пример #7
0
 def test_object_creation(self):
     Third.objects.create(id='3', name='An example')
     parent = Parent(name='fred')
     parent.save()
     Child.objects.create(name='bam-bam', parent=parent)
Пример #8
0
 def test_object_creation(self):
     Third.objects.create(id='3', name='An example')
     parent = Parent(name='fred')
     parent.save()
     Child.objects.create(name='bam-bam', parent=parent)
Пример #9
0
    def test_fk_assignment_and_related_object_cache(self):
        # Tests of ForeignKey assignment and the related-object cache (see #6886).

        p = Parent.objects.create(name="Parent")
        c = Child.objects.create(name="Child", parent=p)

        # Look up the object again so that we get a "fresh" object.
        c = Child.objects.get(name="Child")
        p = c.parent

        # Accessing the related object again returns the exactly same object.
        self.assertTrue(c.parent is p)

        # But if we kill the cache, we get a new object.
        del c._parent_cache
        self.assertFalse(c.parent is p)

        # Assigning a new object results in that object getting cached immediately.
        p2 = Parent.objects.create(name="Parent 2")
        c.parent = p2
        self.assertTrue(c.parent is p2)

        # Assigning None succeeds if field is null=True.
        p.bestchild = None
        self.assertTrue(p.bestchild is None)

        # bestchild should still be None after saving.
        p.save()
        self.assertTrue(p.bestchild is None)

        # bestchild should still be None after fetching the object again.
        p = Parent.objects.get(name="Parent")
        self.assertTrue(p.bestchild is None)

        # Assigning None fails: Child.parent is null=False.
        self.assertRaises(ValueError, setattr, c, "parent", None)

        # You also can't assign an object of the wrong type here
        self.assertRaises(ValueError, setattr, c, "parent",
                          First(id=1, second=1))

        # Nor can you explicitly assign None to Child.parent during object
        # creation (regression for #9649).
        self.assertRaises(ValueError, Child, name='xyzzy', parent=None)
        self.assertRaises(ValueError,
                          Child.objects.create,
                          name='xyzzy',
                          parent=None)

        # Creation using keyword argument should cache the related object.
        p = Parent.objects.get(name="Parent")
        c = Child(parent=p)
        self.assertTrue(c.parent is p)

        # Creation using keyword argument and unsaved related instance (#8070).
        p = Parent()
        c = Child(parent=p)
        self.assertTrue(c.parent is p)

        # Creation using attname keyword argument and an id will cause the
        # related object to be fetched.
        p = Parent.objects.get(name="Parent")
        c = Child(parent_id=p.id)
        self.assertFalse(c.parent is p)
        self.assertEqual(c.parent, p)
Пример #10
0
def register():
    if request.form:
        login = request.form.get("login")
        password = request.form.get("password")
        name = request.form.get("name")
        surname = request.form.get("surname")
        position = request.form.get("position")

        if position == "Teacher":
            teacher = Teacher.auth(login, password)

            if teacher:
                return json.dumps({'resultCode': 1})

            email = request.form.get("email")
            phone = request.form.get("phone")
            qualification = request.form.get("qualification")

            teacher = Teacher(login, password, name, surname, qualification,
                              phone, email, False)
            teacher.save()

            session["auth"] = teacher.id

            return json.dumps({
                'resultCode': 0,
                'data': {
                    'userId': teacher.id,
                    'login': login,
                    'password': password,
                    'position': position,
                    'name': name,
                    'surname': surname,
                    'email ': email,
                    'phone ': phone,
                    'qualification ': qualification
                }
            })

        elif position == "Pupil":
            pupil = Pupil.auth(login, password)

            print(pupil)

            if pupil:
                return json.dumps({'resultCode': 1})

            clas = request.form.get('clas')
            pupil = Pupil(name, surname, login, password, clas)
            pupil.save()

            school_class = SchoolClass.get_class_by_name(clas)
            school_class.add_student(pupil.id)

            session["auth"] = pupil.id

            return json.dumps({
                'resultCode': 0,
                'data': {
                    'userId': pupil.id,
                    'login': login,
                    'password': password,
                    'position': position,
                    'name': name,
                    'surname': surname,
                    'clas': clas
                }
            })

        elif position == "Parent":
            parent = Parent.auth(login, password)

            if parent:
                return json.dumps({'resultCode': 1})

            child_id = request.form.get("child_id")
            parent = Parent(name, surname, child_id, login, password)
            parent.save()

            session["auth"] = parent.id

            return json.dumps({
                'resultCode': 0,
                'data': {
                    'userId': parent.id,
                    'login': login,
                    'password': password,
                    'position': position,
                    'name': name,
                    'surname': surname,
                    'child_id': child_id
                }
            })

        else:
            return json.dumps({'resultCode': 1})