def insert_item(argv):
    '''Takes the system arguments as parameter and then inserts the item.

    Keyword arguments:
    argv -- An array of command line arguments passed to the program.
    '''
    if argv[2] == "school":
        school = School.create(name=argv[3])
        print "New school: " + str(School.get(School.name == argv[3]))
    elif argv[2] == "batch":
        batch = Batch.create(school=argv[3], name=argv[4])
        print "New batch: " + str(Batch.get(Batch.name == argv[4]))
    elif argv[2] == "student":
        print "New student:",
        if len(argv) > 6:
            student = Student.create(batch=argv[3],
                                     age=argv[4],
                                     last_name=argv[5],
                                     first_name=argv[6])
            print str(Student.get(Student.age == argv[4] and
                                  Student.last_name == argv[5] and
                                  Student.first_name == argv[6]))
        else:
            student = Student.create(batch=argv[3],
                                     age=argv[4],
                                     last_name=argv[5])
            print str(Student.get(Student.age == argv[4] and
                                  Student.last_name == argv[5]))
    elif argv[2] == "exercise":
        exercise = Exercise.create(student=argv[3],
                                   subject=argv[4],
                                   note=argv[5])
        print "New Exercise: " + str(exercise)
Ejemplo n.º 2
0
def create_instance_test():
    t1 = Teacher.create(name='t1')
    t2 = Teacher.create(name='t2')
    s1 = Student.create(name = 's1', teacher=t1)
    s2 = Student.create(name = 's2', teacher=t1)
    s3 = Student.create(name = 's3', teacher=t2)
    s4 = Student.create(name = 's4', teacher=t2)
Ejemplo n.º 3
0
def create_instance_test():
    t1 = Teacher.create(name='t1')
    t2 = Teacher.create(name='t2')
    s1 = Student.create(name='s1', teacher=t1)
    s2 = Student.create(name='s2', teacher=t1)
    s3 = Student.create(name='s3', teacher=t2)
    s4 = Student.create(name='s4', teacher=t2)
Ejemplo n.º 4
0
def register():
    data = dict(request.form.items())
    if data.get('username', None):
        Student.create(username=data.get('username', 'anonymous'),
                       name=data.get('name', 'Jane Doe'),
                       course=data.get('course', 'Python'),
                       age=data.get('age', 18))
    return render_template("register_student.html")
Ejemplo n.º 5
0
def create_student(name, drink_coffee, entrou, saiu):
    entrou = list(map(int, entrou.split('/')))
    entrou = datetime(entrou[2], entrou[1], entrou[0])
    saiu = list(map(int, saiu.split('/')))
    saiu = datetime(saiu[2], saiu[1], saiu[0])
    Student.create(name=name,
                   drink_coffee=drink_coffee,
                   entrou=entrou,
                   saiu=saiu,
                   email='')
Ejemplo n.º 6
0
def register():
    data = dict(request.form.items())
    if data.get('id', None):
        Student.create(
            id=data.get('id',1),
            title=data.get('title', 'python class was hard today'),
            date=data.get('Date', 12/7/9),
            
        )
    return render_template("register_student.html")
Ejemplo n.º 7
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('first_name', required=True)
     parser.add_argument('last_name', required=True)
     parser.add_argument('email', required=True)
     parser.add_argument('password', required=True)
     parser.add_argument('state',
                         default='NOT_VERIFIED'
                         if os.environ.get('TEST') is None else 'ACTIVE')
     student_args = parser.parse_args()
     if student_args.get('state') not in STUDENT_STATES:
         error_dict = {
             'error_message': f'Invalid state {student_args.get("state")}',
         }
         LOGGER.error(error_dict)
         return error_dict, 400
     try:
         return Student.create(**student_args)
     except IntegrityError as e:
         error_dict = {
             'error_message': e,
         }
         LOGGER.error(error_dict)
         return error_dict, 400
     except Exception as e:
         LOGGER.error(e)
Ejemplo n.º 8
0
    def test_create_2(self):
        test_student_1 = {
            'first_name': 'test_1',
            'last_name': 'test_1',
            'email': '*****@*****.**',
            'password': '******',
            'state': 'TEST',
        }
        test_student_2 = {
            'first_name': 'test_2',
            'last_name': 'test_2',
            'email': '*****@*****.**',
            'password': '******',
            'state': 'TEST',
        }
        return_result_1 = Student.create(**test_student_1)
        self.assertEqual(test_student_1.get('first_name'),
                         return_result_1.first_name)
        self.assertEqual(test_student_1.get('last_name'),
                         return_result_1.last_name)
        self.assertEqual(test_student_1.get('email'), return_result_1.email)
        self.assertEqual(test_student_1.get('password'),
                         return_result_1.password)
        return_result_2 = Student.create(**test_student_2)
        self.assertEqual(test_student_2.get('first_name'),
                         return_result_2.first_name)
        self.assertEqual(test_student_2.get('last_name'),
                         return_result_2.last_name)
        self.assertEqual(test_student_2.get('email'), return_result_2.email)
        self.assertEqual(test_student_2.get('password'),
                         return_result_2.password)

        get_result_1 = Student.get(id=return_result_1.id)
        self.assertEqual(test_student_1.get('first_name'),
                         get_result_1.first_name)
        self.assertEqual(test_student_1.get('last_name'),
                         get_result_1.last_name)
        self.assertEqual(test_student_1.get('email'), get_result_1.email)
        self.assertEqual(test_student_1.get('password'), get_result_1.password)

        get_result_2 = Student.get(id=return_result_2.id)
        self.assertEqual(test_student_2.get('first_name'),
                         get_result_2.first_name)
        self.assertEqual(test_student_2.get('last_name'),
                         get_result_2.last_name)
        self.assertEqual(test_student_2.get('email'), get_result_2.email)
        self.assertEqual(test_student_2.get('password'), get_result_2.password)
Ejemplo n.º 9
0
def create_student(student_name):
    """Create new student"""

    checked_in = False
    new_student = Student.create(
        student_name=student_name, checked_in=checked_in)
    new_student.save()
    cprint("Created new student:", 'green', 'on_grey')
    cprint("\tId: {0}\n\tName: {1}".format(
        new_student.id, new_student.student_name), 'cyan')
def change_batch(argv):
    '''Takes the system arguments as parameter. argv[2] is id of the student to
    change, argv[3] is the batch to change the student to.

    Keyword arguments:
    argv -- An array of command line arguments passed to the program.
    '''
    student_found = False
    batch_found = False
    for student in Student.select():
        if str(student.id) == str(argv[2]):
            student_found = True
    for batch in Batch.select():
        if str(batch.id) == str(argv[3]):
            batch_found = True
    if student_found is False:
        print "Student not found"
        return
    if batch_found is False:
        print "Batch not found"
        return

    for student in Student.select():
        if str(student.id) == str(argv[2]):
            if str(student.batch.id) == str(argv[3]):
                student_found = True
                print student,
                print "already in " + str(student.batch)
            else:
                '''If the student is not already in the batch, then reassign.'''
                tmp_id = student.id
                tmp_age = student.age
                tmp_first_name = student.first_name
                tmp_last_name = student.last_name

                d = Student.delete().where(Student.id == tmp_id)
                d.execute()
                new = Student.create(id=tmp_id,
                                     batch=argv[3],
                                     age=tmp_age,
                                     last_name=tmp_last_name,
                                     first_name=tmp_first_name)

                print student,
                print "has been move to",
                print new.batch
Ejemplo n.º 11
0
    def test_create_1(self):
        test_student_1 = {
            'first_name': 'test',
            'last_name': 'test',
            'email': '*****@*****.**',
            'password': '******',
            'state': 'TEST',
        }
        return_result = Student.create(**test_student_1)
        self.assertEqual(test_student_1.get('first_name'),
                         return_result.first_name)
        self.assertEqual(test_student_1.get('last_name'),
                         return_result.last_name)
        self.assertEqual(test_student_1.get('email'), return_result.email)
        self.assertEqual(test_student_1.get('password'),
                         return_result.password)

        get_result = Student.get(id=return_result.id)
        self.assertEqual(test_student_1.get('first_name'),
                         get_result.first_name)
        self.assertEqual(test_student_1.get('last_name'), get_result.last_name)
        self.assertEqual(test_student_1.get('email'), get_result.email)
        self.assertEqual(test_student_1.get('password'), get_result.password)
Ejemplo n.º 12
0
try:
    Student.create_table()
except peewee.OpertationalError:
    pass



if sys.argv[2] == :
    School.create(name= argv[3])
    print New school: School: self.name, self.id
elif:
    argv[2] == "batch"
    Batch.create(school= array[3], name= argv[4])
    print New batch: Batch: self.school, self.name
elif:
    argv[2] == "user"
    User.create(first_name = argv[3], last_name = argv[4], age = argv[5])
    print New user: User: self.first_name, self.last_name, self.age
else:
    Student.create(age = argv[3], last_name = argv[4], first_name = argv[5])
    print New student: Student: self.age, self.last_name, self.first_name







# if sys.argv[2] == model name in lowercase: