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)
def add_school(): # Start with no errors and no fields errors = None fields = None # Store user id from session to associate school with user user_id = session['user_id'] if request.method == 'POST': fields = {'name': request.form['name'], 'url': request.form['url']} # Validate form submission by checking no empty fields errors = check_no_blanks(fields=fields) if not errors: # Check that school name does not already exist # TODO: this check needs to check by case insensitive if School.get_by_name(fields['name']): errors['name_exists'] = True else: school = School.create(name=fields['name'], url=fields['url'], user_id=user_id) flash('School created') return redirect(url_for('view_school', id=school.id)) return render_template('add_school.html', fields=fields, errors=errors)
pass try: User.create_table() except peewee.OpertationalError: pass 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