def add_monkey(): form = AddForm(request.form) if form.validate_on_submit(): monkey = Monkey(name=form.name.data, age=form.age.data, email=form.email.data, friends=[], bf=None) db.session.add(monkey) db.session.commit() flash(monkey.name + ' successfully added') return redirect(url_for('list_monkeys')) return render_template('add.html', form=form)
def add(): form = AddForm(csrf_enabled=False) if request.method == "POST" and form.validate_on_submit(): user = Data() print form.data code = user.add( form.data["firstname"], form.data["lastname"], form.data["number"], middlename=form.data["middlename"] ) return render_template("add.done.html", code=code, data=form.data) else: return render_template("add.html", form=form)
def add_pup(): form = AddForm() if form.validate_on_submit(): name = form.name.data new_pup = Puppy(name) db.session.add(new_pup) db.session.commit() return redirect(url_for('list_pup')) return render_template('add.html', form=form)
def home_todo(): form = AddForm() if form.validate_on_submit(): date = form.date.data new_date = Date(date) db.session.add(new_date) db.session.commit() return redirect(url_for('add_todo')) else: return render_template('home.html', form=form)
def add_character(): form = AddForm() if form.validate_on_submit(): name = form.p_name.data date = form.p_date.data new_char = Character(name, date) db.session.add(new_char) db.session.commit() return redirect(url_for('characters')) return render_template('add-character.html', form=form)
def add_kit(): form = AddForm() if form.validate_on_submit(): name = form.name.data new_kit = Kitten(name) # grabs the name of the user form User model db.session.add(new_kit) db.session.commit() return redirect(url_for('list_kit')) return render_template('add.html', form = form)
def add_student(): form = AddForm() if form.validate_on_submit(): name = form.name.data new_student = Student(name) db.session.add(new_student) db.session.commit() return redirect(url_for('list_student')) return render_template('add.html', form=form)
def menusetup(user): form = AddForm() available = [] localrepopath = settings.WORKING_DIR + user.nickname for sub in os.listdir(localrepopath): subpath = localrepopath + "/" + sub if os.path.isdir(subpath): available.extend([(sub,sub)]) available.extend(allsubdirectories(user, sub, "|-", localrepopath)) form.location.choices = available types = [("None","Other"), ("mkdir","Directory")] languages = Language.query.all() for lang in languages: types.extend([(lang.filetype,"." + lang.filetype)]) form.type.choices = types if request.form.get('bar', None) == 'Add': if form.validate_on_submit(): userlocation = form.location.data locationpath = settings.WORKING_DIR + user.nickname + "/" + userlocation if os.path.isdir(locationpath): filepath = locationpath + "/" + form.filename.data if form.type.data == "mkdir": if not os.path.isdir(filepath): p1 = subprocess.Popen(["sudo", "mkdir", filepath]) p1.wait() flash('New Directory Created', 'success') else: flash('Directory already exists', 'error') else: if not form.type.data == "None": filepath = filepath + "." + form.type.data if not os.path.exists(filepath): open(filepath, 'a').close() repository = userlocation.split("/")[0] myrepo = user.repos.filter_by(repourl= "/" + repository + "/" ).first() filename = form.filename.data if not form.type.data == "None": filename = form.filename.data + "." + form.type.data f = File(filename=filename, path=userlocation, type="txt", repo=myrepo) flash("Created file " + filename + " in " + userlocation, 'success') db.session.add(f) db.session.commit() else: flash('File or directory already exists', 'error') else: flash('Name of new file or directory must not have spaces or slashes', 'error') cleanprocess() return form
def add_tractor(): form = AddForm() if form.validate_on_submit(): name = form.name.data # Add new Tractor to database new_tractor = Tractor(name) db.session.add(new_tractor) db.session.commit() return redirect(url_for('list_tractor')) return render_template('add.html',form=form)
def add_pup(): form = AddForm() if form.validate_on_submit(): name = form.name.data flash(f"{name.capitalize()} has been added to the database!", category="success") new_pup = Puppy(name) db.session.add(new_pup) db.session.commit() return redirect(url_for('list_pup')) return render_template('add.html', form=form)
def add_book(): form = AddForm() if form.validate_on_submit(): title = form.title.data author = form.author.data price = form.price.data new_book = Books(title, author, price) db.session.add(new_book) db.session.commit() return redirect(url_for('book_list')) return render_template('add_book.html', form=form)
def index(): pages = Page.query.all() form = AddForm() if form.validate_on_submit(): page = form.page.data if validators.url(page): if requests.get(page).status_code == 200: new_page = Page(page) db.session.add(new_page) db.session.commit() return redirect(url_for('index')) return render_template('index.html', pages=pages, form=form)
def index(): form = AddForm() if form.validate_on_submit(): name = form.name.data new_Name = N2(name) db.session.add(new_Name) db.session.commit() return redirect(url_for('list')) return render_template('home.html', form=form)
def add_user(): form = AddForm() if form.validate_on_submit(): name = form.name.data email = form.email.data # Add new User to database new_user = User(name, email) db.session.add(new_user) db.session.commit() return redirect(url_for('list_user')) return render_template('add.html',form=form)
def add_item(): form = AddForm() if form.validate_on_submit(): name = form.name.data param1 = form.param1.data param2 = bool(form.param2.data) item = DBModel(name, param1, param2) db.session.add(item) db.session.commit() return redirect(url_for('list_items')) return render_template('add.html', form=form)
def add_pup(): form = AddForm() if form.validate_on_submit(): name = form.name.data age = form.age.data breed = form.breed.data colour = form.colour.data characteristics = form.characteristics.data new_pup = Puppy(name, age, breed, colour, characteristics) db.session.add(new_pup) db.session.commit() return redirect(url_for('list_pup')) return render_template('add.html', form=form)
def Add_form(): form = AddForm() if form.validate_on_submit(): Username = form.Username.data Password = form.Password.data Strength = form.Strength.data # Add new Puppy to database new_pup = Manager(Username,Password,Strength) db.session.add(new_pup) db.session.commit() return redirect(url_for('output')) return render_template('add.html',form=form)
def add_dog(): form = AddForm() if form.validate_on_submit(): name = form.name.data breed = form.breed.data color = form.color.data age = form.age.data mood = form.mood.data sex = form.sex.data new_dog = Dog(name, breed, color, age, mood, sex) db.session.add(new_dog) db.session.commit() return redirect(url_for('list_dog')) return render_template('add.html', form=form)
def add_todo(): form = AddForm() if form.validate_on_submit(): todoName = form.todoName.data duedate = form.duedate.data feedback = form.feedback.data new_todo = Todo(todoName, duedate, feedback) db.session.add(new_todo) db.session.commit() return redirect(url_for('list_todo')) else: return render_template('add.html', form=form)
def add_pup(): form = AddForm() if form.validate_on_submit(): name = form.name.data color = form.color.data breed = form.breed.data # Add new Puppy to database new_pup = Puppy(name, color, breed) db.session.add(new_pup) db.session.commit() return redirect(url_for('list_pup')) return render_template('add.html', form=form)
def add_movie(): form = AddForm(request.form) if form.validate_on_submit(): title = form.title.data premiere = form.premiere.data rate = int(form.rate.data) new_movie = Movie(title, premiere, rate) database.session.add(new_movie) database.session.commit() return redirect(url_for('list_movies')) return render_template('add.html', form=form)
def add(): form = AddForm() if form.validate_on_submit(): answers = form.answers.data question = Question(question=form.question, correct=answers[int(form.correct)]) question.save() for answer in answers: Answer(question_id=question.id, answer=answer) flash('Question added: {}'.format(form.question.data)) return redirect(url_for('question_list')) elif request.method == 'POST': flash_errors(form) return render_template('add.html', form=form, radio=list(form.correct))
def add_student(): form = AddForm() if form.validate_on_submit(): name = form.name.data sem = form.sem.data dept = form.dept.data st_phno = form.st_phno.data pa_phno = form.pa_phno.data new_stud = students(name, sem, dept, st_phno, pa_phno) db.session.add(new_stud) db.session.commit() return render_template('add.html', form=form)
def add_new_cafe(): form = AddForm() if form.validate_on_submit(): new_cafe = Cafe(name=form.name.data, map_url=form.name.data, img_url=form.name.data, location=form.name.data, has_sockets=form.name.data, has_toilet=form.name.data, has_wifi=form.name.data, can_take_calls=form.name.data, seats=form.name.data, coffee_price=form.name.data) db.session.add(new_cafe) db.session.commit() return redirect(url_for("get_all_cafes")) return render_template('add.html', form=form)
def add_emp(): form = AddForm() if form.validate_on_submit(): name = form.name.data team = form.team.data skills = form.skills.data learning_status = form.learning_status.data # Add new Emp to database new_emp = Emp(name, team, skills, learning_status) db.session.add(new_emp) db.session.commit() return redirect(url_for('list_emp')) return render_template('add.html', form=form)
def blog_add(): if request.method == "GET": return render_template("blog_add.html", form=AddForm()) if request.method == "POST": form = AddForm(request.form) if form.validate_on_submit(): create_time = str(datetime.fromtimestamp(int(time.time()))) new_blog = Blog(title=form.title.data, author=form.author.data, content=form.content.data, create_time=create_time) db.session.add(new_blog) db.session.commit() b = Blog.query.filter_by(create_time=create_time).first() return redirect(url_for('blog_id', bid=b.id)) else: return render_template("blog_add.html", form=form)
def book_ticket(): form = AddForm() global ticket_count ticket_count = ticket_count + 1 if form.validate_on_submit() and ticket_count <= 20: name = form.name.data phone = form.phone.data slot = form.slot.data customer = Customer(name, phone) db.session.add(customer) db.session.commit() ticket = Ticket(customer.id, slot) db.session.add(ticket) db.session.commit() return redirect(url_for('ticket_booked')) elif ticket_count > 20: return redirect(url_for('all_seat_booked')) return render_template('bookTicket.html', form=form)
def add_todo(): form = AddForm() if form.validate_on_submit(): todoName = form.todoName.data duedate = form.duedate.data feedback = form.feedback.data todos = Todo.query.all() now = datetime.today() nowDate = now.strftime('%Y-%m-%d') new_todo = Todo(todoName, duedate, feedback) db.session.add(new_todo) db.session.commit() return render_template('add.html', form=form, todos=todos, nowDate=nowDate) else: return render_template('add.html', form=form)
def index(): form = AddForm() if form.validate_on_submit(): email = form.email.data state = form.state.data city = form.city.data phonenumber = form.phonenumber.data new_member = Interestlist(email=email, state=state, city=city, phonenumber=phonenumber) db.session.add(new_member) db.session.commit() return redirect(url_for('thankyou')) return render_template('index.html', form=form)
def add_pet(): form = AddForm() if form.validate_on_submit(): # create owner owner_name = form.owner_name.data owner_email = form.owner_email.data owner_phone = form.owner_phone.data owner = Owner.query.filter_by(email=owner_email).first() if owner is None: owner = Owner(owner_name, owner_email, owner_phone) db.session.add(owner) db.session.commit() owner = Owner.query.filter_by(email=owner_email).first() # create pet pet_name = form.pet_name.data pet_type = form.pet_type.data pet_age = form.pet_age.data pet_info = form.additional.data pet = Pet(pet_name, pet_type, pet_age, pet_info, owner.id) id = Pet.query.order_by(Pet.id).all() if len(id) == 0: id = 1 else: id = id[-1].id + 1 if form.pet_pic.data: pic = add_profile_pic(form.pet_pic.data, id) else: pic = 'default.jpg' pet.pic = pic db.session.add_all([pet, owner]) db.session.commit() return redirect(url_for('list_pets')) return render_template('add_pet.html', form=form)
def add(): form = AddForm() if form.validate_on_submit(): print('validated') try: if form.status.data: status_text = "NAUGHTY" else: status_text = "NICE" db.insertPerson(form.username.data, form.name.data, status=status_text, status_description=form.status_description.data) return redirect(url_for('add')) except: print('excepted') flash('ERROR') return redirect(url_for('add')) else: print(form.errors) return render_template('add.html', title='Add', form=form)
def add(): form = AddForm() if form.validate_on_submit(): dream = Dream(name=form.name.data, description=form.description.data) db.session.add(dream) db.session.commit() return redirect(url_for('main.index')) return render_template('add.html', form=form) # @main.route('/add_all', methods = ['GET', 'POST']) # def add_all(): # import xml.etree.ElementTree as ET # from collections import OrderedDict as OrD # tree = ET.parse(current_app.config['XML_DREAMS']) # root = tree.getroot() # dreams = OrD() #ordered dictionary for getting last key added # to_database = {} # for page in root.findall('page'): # if int(page.attrib['number']) > 33 and (int(page.attrib['number']))<394 : # for text in page: # if int(text.attrib['font']) == 0: #font for description # last_key=list(dreams.items())[-1][0] #geting last key from dictionary # dreams[last_key].append(text.text) #and adding value to it # elif int(text.attrib['font']) == 6: #font for dream # for dream in text: # dreams[dream.text] = [] #addding new key - dream, to the dreams # for k,v in dreams.items(): #adding from ordered dictionary to unordered # to_database[k] = str(' '.join(v)) # try: # for k, v in to_database.items(): # dream = Dream(name = k, description = v) # db.session.add(dream) # db.session.commit() # return redirect(url_for('main.index')) # except: # return "Oops something went wrong"
def addItem(): """ Logged in user attempts to add an item :return: GET : Renders Add Item Form POST : Inserts added item to database and redirects user dashbiard page """ form = AddForm() if form.validate_on_submit(): item = Item(name=bleach.clean(form.name.data), description=bleach.clean(form.description.data), owner_id=int(current_user.get_id()), category_id=int(form.category.data)) db.session.add(item) db.session.commit() return redirect(url_for('main.dashboard')) return render_template('main/addItem.html', form=form)
def add(): bookname = None author = None sortedd = None introduction = None commentt = None score = None state = None if "s" not in session: return redirect(url_for("login")) form = AddForm() if form.validate_on_submit(): bookname = form.bookname.data author = form.author.data sortedd = form.sortedd.data introduction = form.introduction.data commentt = form.commentt.data score = form.score.data state = form.state.data # file1=open('1.txt','a') # file1.write(score.encode('utf-8')) # file1.close() # session['bookname_a']=bookname # print bookname+"=="+author+"=="+sortedd+"=="+introduction+"=="+comment+"=="+score+"=="+state if not bookname and not author: flash(u"请重新填写") form.bookname.data = "" form.author.data = "" form.sortedd.data = "" form.introduction.data = "" form.commentt.data = "" form.score.data = "" form.state.data = "" addbooklist = books_record( id="id", bookname=bookname, author=author, sortedd=sortedd, introduction=introduction, commentt=commentt, score=score, state=state, ) db.session.add(addbooklist) db.session.commit() return render_template( "add.html", form=form, bookname=bookname, author=author, sortedd=sortedd, introduction=introduction, commentt=commentt, score=score, state=state, )