def editItem(id): """ Logged in User attempts to edit an item :param id: unique identifier of the item :return: GET : Renders Edit Item form POST: Adds item to database and redirects user """ item = Item.query.filter_by(id=id).first() # Abort if logged in user is not the owner of the page if int(current_user.get_id()) != item.owner_id: abort(403) form = EditForm(id=id, name=item.name, description=item.description) if form.validate_on_submit(): item.name = bleach.clean(form.name.data) item.description = bleach.clean(form.description.data) db.session.add(item) db.session.commit() return redirect(url_for('main.dashboard')) return render_template('main/editItem.html', form=form)
def edit_product(product_id): #view and edit a product if not g.user: return redirect('/') else: method = request.method product = Product.query.get(product_id) form = EditForm(obj=product) if form.validate_on_submit(): product.update_product(form) db.session.add(product) db.session.commit() return redirect(f'/{get_route()}/{product.id}') else: #prepare an image for display product.prepare_to_show() availability = 'Sold' if product.available: availability = 'Available' return render_template('admin-products-edit.html', product=product, form=form, route=get_route(), availability=availability)
def editusers(username): user = User.query.filter_by(username=username).first() form = EditForm() result = User.query.all() if form.validate_on_submit(): user.first_name = form.first_name.data user.last_name = form.last_name.data user.address = form.address.data user.city = form.city.data user.country = form.country.data user.birth_date = form.birth_date.data user.contact_num = form.contact_num.data user.description = form.description.data db.session.add(user) db.session.commit() flash("Your changes have been saved.") return render_template('admin/users.html', result=result) else: form.first_name.data = user.first_name form.last_name.data = user.last_name form.address.data = user.address form.city.data = user.city form.country.data = user.country form.birth_date.data = user.birth_date form.contact_num.data = user.contact_num form.description.data = user.description return render_template('admin/editusers.html', user=user, form=form)
def profile(): """Update profile for current user.""" # IMPLEMENT THIS if not g.user: flash("Access unauthorized.", "danger") return redirect("/") user = User.query.get_or_404(g.user.id) form = EditForm(obj=user) if form.validate_on_submit(): if User.authenticate(user.username, form.password.data): user.username = form.username.data, user.email = form.email.data, user.image_url = form.image_url.data or User.image_url.default.arg, user.header_image_url = form.header_image_url.data or User.image_url.default.arg, user.bio = form.bio.data user.location = form.location.data db.session.commit() return redirect(f"/users/{user.id}") else: flash("Incorrect Password.", "danger") return render_template("users/edit.html", user=user, form=form)
def edit(user_id): if user_id != current_user.id: return redirect(url_for("edit", user_id = current_user.id)) user = User.query.filter(User.id == user_id).first() form = EditForm() if form.validate_on_submit(): new_nickname = request.form.get("nickname") new_about = request.form.get("about") user.nickname = new_nickname user.about = new_about try: db.session.add(user) db.session.commit() except: flash("The DataBase Error") # return redirect(url_for('/edit/'+str(user_id))) flash("你的个人信息已经被更新!") return redirect(url_for("edit", user_id=user_id)) else: form.nickname.data = user.nickname form.about.data = user.about return render_template( "edit.html", form = form)
def editUsers(): form = EditForm() if form.add_more_component.data: form.component.append_entry(u'default value') if form.validate_on_submit(): user = Users.query.filter_by(username=form.username.data).first() if user is None: flash('No such user') return render_template('editUsers.html', form=form) status = user.edit(username=form.username.data, password=form.password.data, fullname=form.fullname.data, email = form.email.data, user_group= dict(form.user_choices).get(form.user_group.data), pillar=form.pillar.data, term=form.term.data, student_id=form.student_id.data, professor_id=form.professor_id.data, coursetable = form.coursetable.data, delete=form.delete.data) flash(status) return redirect(url_for('usersTable')) return render_template("editUsers.html", form=form)
def blog_detail_view_edit(time, username, comp_name): # conv c, conn = get_db() time = time.replace('-', '/') c.execute("SELECT * FROM Blog where time_=? and user_nm=? and comp_nm=?", [time, username, comp_name]) blog = c.fetchone() if blog: # Render a detailForm and show it. form = EditForm() form.content.data = blog['post'] if form.validate_on_submit(): if 'submit' in request.form: # get the new post new_post = request.form.get('content') print("What is the new post?", new_post) # commit it to the database c, conn = get_db() c.execute("UPDATE Blog \ SET post=? \ WHERE time_=? and user_nm=? and comp_nm=?", (new_post, time, username, comp_name)) conn.commit() return redirect(url_for('blog')) elif 'cancel_btn' in request.form: # if cancelling then just redirect back to the message board return redirect(url_for('blog')) else: # TODO: return 404 page return "Not found" return render_template('edit.html', form=form)
def index(): form = EditForm(csrf_enabled = False) if form.validate_on_submit(): return redirect('/solar') # Renders index.html. return render_template('index.html', form = form)
def edit_experience(id): my_experience = Experiencia.query.filter_by(id=id).first() form = EditForm(empresa=my_experience.empresa, puesto=my_experience.puesto, anyo_inicio=my_experience.anyo_inicio, anyo_salida=my_experience.anyo_salida) if request.method == 'POST': if form.validate_on_submit(): # Guardamos en la base de datos flash('Guardado bien', 'success') my_experience.empresa = request.form['empresa'] my_experience.puesto = request.form['puesto'] my_experience.anyo_inicio = request.form['anyo_inicio'] my_experience.anyo_salida = request.form['anyo_salida'] db.session.add(my_experience) try: db.session.commit() except: db.session.rollback() return redirect(url_for('index')) else: # Mostramos errores errores = form.errors.items() for campo, mensajes in errores: for mensaje in mensajes: flash(mensaje, 'danger') return render_template('items/edit.html', form=form, note=my_experience)
def edit(): form = EditForm(g.user.nickname) if request.method == 'POST': avatar_img_file = request.files[form.avatar_img.name] else: avatar_img_file = None if form.validate_on_submit(avatar_img_file): g.user.nickname = form.nickname.data g.user.about_me = form.about_me.data db.session.add(g.user) db.session.commit() if form.avatar_img.data: f = request.files[form.avatar_img.name] pic = Photo(fname = "", timestamp = datetime.utcnow(), owner = g.user) db.session.add(pic) db.session.commit() #try: pic.fname = (str(pic.id)+"."+f.filename.split(".")[-1]) f.save(os.path.join(UPLOAD_IMG_DIR, pic.fname)) g.user.set_avatar(pic) db.session.add(pic) db.session.add(g.user) db.session.commit() flash('Your changes have been saved.', 'info') return redirect(url_for('user', nickname=g.user.nickname)) else: form.nickname.data = g.user.nickname form.about_me.data = g.user.about_me return render_template('edit.html', form = form, user = g.user)
def index(): form = EditForm() if form.validate_on_submit(): uuid = gen_uuid() open('./notes/{}.txt'.format(uuid), 'w').write(form.content.data) return redirect('/' + uuid) return render_template('note/edit.html', form=form)
def editInfo(): form = EditForm() if form.validate_on_submit(): print(current_user.id, file=sys.stderr) about = form.about.data interests = form.interests.data location = form.location.data gender = form.gender.data i = db.getInfo(current_user.id) if (about == ""): about = i[0][0] if (interests == ""): interests = i[0][1] # if(location == ""): # location = i[0][2] # if(gender == ""): # gender = i[0][3] print(about, file=sys.stderr) print(interests, file=sys.stderr) db.editInfo(current_user.id, about, interests, location, gender) print(form.errors, file=sys.stderr) return redirect(url_for('profile')) print(form.errors, file=sys.stderr) pic = getProfPic(current_user.id) return render_template('editProfile.html', title='Edit', form=form, pic=pic)
def profile(): """Update profile for current user."""\ if not g.user: flash("Access unauthorized.", "danger") return redirect("/") form = EditForm(obj=g.user) if form.validate_on_submit(): user_authenticate = User.authenticate(g.user.username, form.password.data) if user_authenticate: g.user.username = form.username.data g.user.email = form.email.data g.user.image_url = form.image_url.data g.user.header_image_url = form.header_image_url.data g.user.bio = form.bio.data db.session.add(g.user) db.session.commit() return redirect(f'/users/{session[CURR_USER_KEY]}') else: form.username.errors = ['Invalid password'] return render_template('/users/edit.html', form=form) else: return render_template('/users/edit.html', form=form)
def edit(): form = EditForm() if form.validate_on_submit(): # Update fields using the submitted form g.user.about_me = form.about_me.data g.user.birthday = form.birthday.data g.user.emails = form.emails.data db.session.add(g.user) db.session.commit() flash('Saved Changes') return redirect(url_for('profile', nickname=g.user.nickname)) else: form.about_me = form.about_me form.birthday = form.birthday form.emails = form.emails print type(form.birthday) #print form.birthday.date().strftime('on %m/%d/%y') # print 'form %s' % (form.about_me.data) # print form.emails # print str(form.birthday.data) # t = parse(form.birthday.data) # print t.date().strftime('%d/%m/%y') flash('hey') return render_template('edit.html', form=form)
def edit(): form = EditForm() if form.validate_on_submit(): user_obj = g.user user_obj.blog_title = edit_property(user_obj.blog_title, form.blog_title.data) user_obj.email = edit_property(user_obj.email, form.email.data) if form.username.data: try: User.objects.get(username=form.username.data) form.username.errors.append('User Exist') except(DoesNotExist): user_obj.username = form.username.data if form.new.data and form.old.data: # so user wanted to change his password to if not user_obj.change_password(form.old.data, form.new.data): form.old.errors.append('Wrong password.') elif form.new.data or form.old.data: if form.new.data: form.new.errors.append('Input old password.') else: form.old.errors.append('Input new password.') user_obj.save() flash('Updated') return render_template('edit.html', form=form)
def edit_file(file_name): form = EditForm() if form.validate_on_submit(): file_name = form.title.data # print(file_name) try: with open("./files/" + file_name, "+r", encoding='utf8') as f: f.seek(0) f.truncate() f.write(form.content.data) except: with open("./files/" + file_name, "w", encoding='utf8') as f: f.seek(0) f.truncate() f.write(form.content.data) return redirect(url_for('view_file', file_name=file_name)) file_contents = "" with open("./files/" + file_name) as f: for line in f: file_contents += line # except: # pass form.title.data = file_name form.content.data = file_contents # print('HERE') # print(file_contents) text = Text_Table(file_contents) text.index_text(text.text) text.prepare_text() form.prepared.data = text form.trigrams.data = text.ngrams return render_template('doc.html', form=form, title=file_name)
def add_user_info(): form = EditForm() # Pre-populating the form if request.method == 'GET': extracted_info = { 'name': None, 'fname': None, 'pan': None, 'date': None } extracted_info.update(session['extracted_info']) form.name.data = extracted_info['name'] form.fname.data = extracted_info['fname'] form.pan.data = extracted_info['pan'] form.date.data = extracted_info['date'] if form.validate_on_submit(): # If user successfuly fills the information, his details will be saved. new_user = UserModel() form.populate_obj(new_user) new_user.save_to_db() return render_template('thanks.html') return render_template('user_form.html', form=form)
def edit_review(review_id): """ Edit review functionality """ review_to_edit = mongo.db.reviews.find_one({"_id": ObjectId(review_id)}) # Pass the existing review through to populate the form form = EditForm(**review_to_edit) if request.method == 'POST': if form.validate_on_submit(): # Add updated review to mongoDB updated_review = { "material_name": form.material_name.data, "brand": form.brand.data, "filament_name": form.filament_name.data, "author": session["user"], "rating": int(form.rating.data), "temperature": form.temperature.data, "finish": form.finish.data, "colour": form.colour.data, "review_text": form.review_text.data, "image_url": form.image_url.data, "cost": int(form.cost.data), "likes": 0 } mongo.db.reviews.update({"_id": ObjectId(review_id)}, updated_review) flash("Review successfully updated.") return redirect(url_for("profile", username=session["user"])) return render_template("edit_review.html", form=form, review_to_edit=review_to_edit)
def edit(username): """ Edit a smiley's data """ person = PeopleModel.get_by_key_name(username.lower()) if person and person.password: if 'username' in session and session['username'] == username: form = EditForm() if form.validate_on_submit(): if form.delete.data: person.delete() return redirect(url_for('home')) else: updated_person = PeopleModel( key_name = person.name, name = person.name, startdate = form.startdate.data, enddate = form.enddate.data, password = person.password ) updated_person.put() return redirect(url_for('home') + person.name.encode("utf-8")) startdate = person.startdate enddate = person.enddate return render_template('edit.html', name=username, form=form, startdate=startdate, enddate=enddate) else: return redirect(url_for('home')+username+'/auth') else: abort(404)
def user(nickname, page = 1): user = dq.find(User, ['nickname'], [nickname]).first() if user == None: flash('User ' + nickname +' does not exist!' ) return redirect(url_for('index')) #data borrow_records = g.user.borrow_history() lend_records = g.user.lend_history() friends = user.valid_friends() form = EditForm(g.user.nickname) if form.validate_on_submit(): dq.update(g.user, ['nickname', 'about_me'], [form.nickname.data, form.about_me.data]) flash('Your changes have been saved.') return redirect(url_for('user', nickname = nickname)) else: form.nickname.data = g.user.nickname form.about_me.data = g.user.about_me return render_template('user.html', form = form, user = user, borrow_records = borrow_records, lend_records = lend_records, friends = friends)
def edit_task(task_id): task = mongo.db.tasks.find_one_or_404({'_id': ObjectId(task_id)}) form = EditForm(request.form) if request.method == 'GET': form = EditForm(data=task) return render_template('edit_task.html', title='Edit task', task=task, form=form) if form.validate_on_submit(): task = mongo.db.tasks task.update_one({ '_id': ObjectId(task_id), }, { '$set': { 'name': request.form['name'], 'description': request.form['description'], 'due_day': request.form['due_day'], 'important': request.form.get('important'), } }) return redirect(url_for('all_tasks', title='New task has been added')) return render_template('edit_task.html', title='Edit task', task=task, form=form)
def editItem(id): """ Logged in User attempts to edit an item :param id: unique identifier of the item :return: GET : Renders Edit Item form POST: Adds item to database and redirects user """ item = Item.query.filter_by(id=id).first() # Abort if logged in user is not the owner of the page if int(current_user.get_id()) != item.owner_id: abort(403); form = EditForm(id=id, name=item.name, description=item.description) if form.validate_on_submit(): item.name = bleach.clean(form.name.data) item.description = bleach.clean(form.description.data) db.session.add(item) db.session.commit() return redirect(url_for('main.dashboard')) return render_template('main/editItem.html', form=form)
def edit(): form = EditForm() if not current_user.isadmin: return """STOP!""" user_id = request.args.get('id') user = User.query.filter_by(id=user_id).first() if (request.method == 'GET'): form.name.default = user.name form.password.default = user.password form.email.default = user.email form.process() return render_template('edit.html', form=form, user=user) else: if form.validate_on_submit(): name = request.form.get('name') password = request.form.get('password') user = User.query.filter_by(email=user.email).first() user.name = name user.password = password db.session.commit() flash('User saved!') current_user.is_active = True login_user(current_user) return render_template('edit.html', form=form, user=user) else: flash('<br>'.join(['<br>'.join(e) for e in form.errors.values()])) return render_template('edit.html', form=form, user=user)
def edit(post_id): user = g.user #Creating post before editinf if it's new if not Post.query.get(post_id): newpost(post_id) post = Post.query.get(post_id) if user != post.author: flash('Access denied') return redirect(url_for('index')) form = EditForm(post.title) if form.validate_on_submit(): #Check what button is pressed if 'save' in request.form: post = Post.query.get(post_id) post.title = form.title.data post.body = form.post.data post.timestamp = datetime.utcnow() db.session.add(post) db.session.commit() flash('CHANGES SAVED!!!') return redirect(url_for('index')) elif 'delete' in request.form: deletepost(post_id) return redirect(url_for('notes')) else: form.post.data = Post.query.get(post_id) form.title.data = Post.query.get(post_id).Title() return render_template('edit.html', form = form)
def passwd(): form = EditForm() if form.validate_on_submit() and check_qaptcha(): l = ldap.initialize(LDAP_SERVER) l.simple_bind_s(LDAP_BINDDN, LDAP_BINDPW) [(dn, attrs)] = l.search_s(people_basedn, ldap.SCOPE_ONELEVEL, '(uid=%s)' % (g.user.username), None) if dn: # if user exists passwd_list = attrs['userPassword'][0].split('$') if '{CRYPT}' + crypt.crypt(form.old_password.data, '$' + passwd_list[1] + '$' + passwd_list[2] + '$') == attrs['userPassword'][0]: # if passwd is right old = {'userPassword': attrs['userPassword']} new = {'userPassword': ['{CRYPT}' + crypt.crypt(form.new_password.data, '$6$%s$'%(''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(10)])))]} ldif = modlist.modifyModlist(old, new) l.modify_s(dn, ldif) logout_user() flash('Your password has been reset, please login now.') l.unbind_s() return redirect(url_for('login')) else: # if passwd is wrong flash('Password incorrect!') l.unbind_s() return render_template('passwd.html', form = form, user = g.user) else: flash("User doesn't exist, please login again.") l.unbind_s() return redirect(url_for('login')) return render_template('passwd.html', form = form, user = g.user)
def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data g.user.street = form.street.data g.user.number = form.number.data g.user.postcode = form.postcode.data g.user.city = form.city.data g.user.country = form.country.data g.user.bank_IBAN = form.bank_IBAN.data g.user.bank_BIC = form.bank_BIC.data g.user.phone = form.phone.data g.user.phone_2 = form.phone_2.data db.session.add(g.user) db.session.commit() flash('Your changes have been saved.') return redirect(url_for('user',nickname=g.user.nickname)) elif request.method != "POST": form.nickname.data = g.user.nickname form.street.data = g.user.street form.number.data = g.user.number form.postcode.data = g.user.postcode form.city.data = g.user.city form.country.data = g.user.country form.bank_IBAN.data = g.user.bank_IBAN form.bank_BIC.data = g.user.bank_BIC form.phone.data = g.user.phone form.phone_2.data = g.user.phone_2 return render_template('edit.html', form = form)
def exchanger(r): ex = db.session.query(models.Exchangers).filter_by(id=r).first() if not ex: abort(404) ex_data = [ex.name, ex.country, ex.description, ex.comments, ex.positives, ex.complains, ex.link, ex.id, ex.ownerId, ex.image, ex.dateOfCreation] badges = [] if ex.badges: badges = ex.badges.split(',') form = CommentForm() form1 = EditForm() comments = db.session.query(models.Comment).filter(models.Comment.exchangerId == r) comments = comments[::-1] recent = comments[:5] if form.validate_on_submit(): if len(form.review.data) > 5: if current_user.id == ex.ownerId: new_comment = models.Comment(review=str(form.review.data), type=str(form.type.data), userId=current_user.id, userName=current_user.name, exchangerId=r, byAdmin=1) else: new_comment = models.Comment(review=str(form.review.data), type=str(form.type.data), userId=current_user.id, userName=current_user.name, exchangerId=r, byAdmin=0) db.session.add(new_comment) # db.session.commit() if current_user.id != ex.ownerId: if form.type.data == 'Positive': ex.positives = ex.positives + 1 elif form.type.data == 'Complain': ex.complains = ex.complains + 1 else: ex.comments = ex.comments + 1 db.session.commit() return redirect('/exchanger/{}'.format(r)) ex = db.session.query(models.Exchangers).filter_by(id=r).first() if form1.validate_on_submit(): if form1.name.data: ex.name = form1.name.data if form1.url.data: ex.link = form1.url.data if form1.description.data: ex.description = form1.description.data # if form1.picURL.data: # ex.image = form1.picURL.data db.session.commit() return redirect('/exchanger/{}'.format(r)) return render_template('exchanger.html', ex_data=ex_data, form=form, comments=comments, recent=recent, form1=form1, badges=badges)
def edit_post(id): post = Post.query.filter_by(id=id).first_or_404() form = EditForm(obj=post) if form.validate_on_submit(): print "weee" form.populate_obj(post) db.session.commit() return redirect(url_for('manage')) return render_template('edit_post.html', form=form)
def edit(postid): form = EditForm() post = Post.query.get(postid) if form.validate_on_submit(): post.title = form.title.data post.category = form.category.data post.article = form.article.data db.session.commit() return redirect(url_for('homepage', nickname=current_user.username)) return render_template('edit.html', nickname=current_user.username, post=post, form=form)
def edit_note(noteid): form = EditForm() note = Note.query.get(noteid) if form.validate_on_submit(): note.body = form.body.data db.session.commit() flash("Your note is updated.") return redirect(url_for('index')) form.body.data = note.body return render_template("editnote.html", form=form)
def edit_url(id): form = EditForm(request.form) url_row = db.session.query(Locator).filter_by(id=id).first() if request.method == 'POST' and form.validate_on_submit(): url_row.title = form.title.data url_row.url = form.url.data url_row.groupname = form.groupname.data db.session.commit() return redirect(url_for('main')) return render_template('edit.jade', form=form, url=url_row)
def edit(id): edit_form = EditForm() #If it does not validate, it will return home without doing code. if not edit_form.validate_on_submit(): flash("Name or Description too Long") return redirect(url_for('home')) name = edit_form.name.data description = edit_form.description.data edit_backpack(id, name, description) return redirect('/')
def test(): addForm = ItemForm() delForm = DelForm() editForm = EditForm() itemsOfInterest = Item.query() #makes database if it doesn't exist... if len(itemsOfInterest.fetch(None)) == 0: mower = Item(id=str(uuid.uuid1()), item='Lawn Mower') eater = Item(id=str(uuid.uuid1()), item='Weed Eater') mower.addModel('Honda') mower.addModel('Black & Decker') eater.addModel('Torro') eater.addModel('Echo') print mower.item print eater.item mower.put() eater.put() itemsOfInterest = Item.query() print "The query length is " + str(len(itemsOfInterest.fetch(None))) if request.form.has_key("edit") and editForm.validate_on_submit( ): # If edit button press & something in edit box then... myItems = Item.query() # get item list for item in myItems: # find correct item print item print item.id if str(item.id) == str(editForm.id.data): # Get item item = item.key.get() # Change item to edit box data item.item = editForm.editItem.data # Save item item.put() flash('Item Edited!') return redirect(url_for('index')) elif request.form.has_key("delete") and delForm.validate_on_submit(): myItems = Item.query() for item in myItems: print item print item.id if str(item.id) == str(delForm.id.data): ndb.delete_multi([item.key]) flash('Item deleted!') return redirect(url_for('index')) elif request.form.has_key("add") and addForm.validate_on_submit(): newItem = Item(id=str(uuid.uuid1()), item=addForm.item.data) print("myUUID is " + newItem.id) newItem.put() flash('New item added!') return redirect(url_for('index')) return render_template('index.html', title='USI Help System', itemsOfInterest=itemsOfInterest, addForm=addForm, delForm=delForm, editForm=editForm)
def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data db.session.add(g.user) db.session.commit() flash('Your changes have been saved.') return redirect(url_for('edit')) elif request.method != "POST": form.nickname.data = g.user.nickname return render_template('edit.html', form=form)
def edit(): form = EditForm(request.form) if form.validate_on_submit(): g.user.about_me = form.about_me.data db.session.add(g.user) db.session.commit() flash(gettext('Your changes have been saved.')) return redirect(url_for('user', username=g.user.username)) else: form.about_me.data = g.user.about_me return render_template('edit.html', form=form)
def details(id): """GET and POST for displaying pet details and editing pet """ pet = Pet.get(id) form = EditForm(obj=pet) if (form.validate_on_submit()): EditForm.fill_pet(form, pet) db.session.commit() return redirect('/') return render_template('details.html', pet=pet, form=form)
def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data db.session.add(g.user) db.session.commit() flash('Ваши изменения были сохранены') return redirect(url_for('edit')) else: form.nickname.data = g.user.nickname return render_template('edit.html', form = form)
def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data g.user.about_me = form.about_me.data dboper.add_user(g.user) flash('Your changes have been saved.') return redirect(url_for('user', nickname = g.user.nickname)) else: form.nickname.data = g.user.nickname form.about_me.data = g.user.about_me return render_template('edit.html', form = form)
def edit(id): page, content = pm.get_page_and_content(id) if not page: abort(404) form = EditForm(body=content.text) if form.validate_on_submit(): pm.save_modified_page(page, content=form.body.data, commitMSG=form.commit_msg.data) pm.set_notification(page) flash(_('Page modified.'), 'success') return redirect(url_for('show', id=page.id)) return render_template("editor.html", form=form, title=_('edit')+page.title, flag="Modify")
def list(page=1): forms = EditForm(csrf_enabled=True) if forms.validate_on_submit(): add() todos = Todo.query.order_by(Todo.status).order_by( Todo.add_time.desc()).paginate(page, per_page=6) users = User.query.all() return render_template('list.html', todos=todos, users=users, roles=session['roles'], forms=forms)
def edit_doc(): #check if id is digit if request.args.get('id').isdigit(): form = EditForm(request.form) doc_id = request.args.get('id').encode('ascii', 'ignore') #get document document = db.session.query( Document, Submit).join(Submit).join(User).filter( or_( Submit.uid == session['uid'], current_user.role == 'Admin', and_(current_user.role == 'Agency_Admin', Document.agency == current_user.agency))).filter( Document.status == "publishing").filter( Document.id == doc_id).all() #check if it has multiple sections if document[0][0].common_id != None: results = db.session.query( Document, Section).outerjoin(Section).join(Submit).filter( Document.status == "publishing").filter(Document.common_id != None).filter( Document.common_id == document[0][0].common_id).all() else: results = document if request.method == 'GET': year = str(document[0][0].dateCreated.year) month = str(document[0][0].dateCreated.month) day = str(document[0][0].dateCreated.day) form = EditForm(request.form, type_=document[0][0].type, year=year, month=month, day=day, description=document[0][0].description, title=document[0][0].title, category=document[0][0].category) #update document elif form.validate_on_submit(): doc = Document.query.get(doc_id) doc.title = form.title.data doc.description = form.description.data doc.dateCreated = datetime.date(int(form.year.data), int(form.month.data), int(form.day.data)) doc.type = form.type_.data form.category.data = form.category.data.encode('ascii', 'ignore') if form.category.data != 'None': doc.category = form.category.data db.session.commit() return redirect(url_for('submitted_docs')) return render_template('edit_doc.html', form=form, results=results, current_user=current_user)
def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): #instead of checking POST, this includes validation g.user.nickname = form.nickname.data db.session.add(g.user) db.session.commit() flash('Your changes have been saved') return redirect(url_for('edit')) else: form.nickname.data = g.user.nickname return render_template('edit.html', form = form)
def edit(note_id): note_id = os.path.basename(note_id) note_path = './notes/{}.txt'.format(note_id) if os.path.isfile(note_path): form = EditForm() if form.validate_on_submit(): open(note_path, 'w').write(form.content.data) else: form.content.data = open(note_path).read() return render_template('note/edit.html', form=form) else: abort(404)
def edit(): user = g.current_user form = EditForm() if form.validate_on_submit(): text = form.text.data id = user["id"] cur = g.db.cursor(cursor_factory=psycopg2.extras.DictCursor) cur.execute('update users set about_me=%s where id=%s', (text, id)) g.db.commit() cur.close() return redirect(url_for('user', username=user["username"])) return render_template('edit.html', form=form)
def edit(): if not is_loggedin(): return redirect(url_for('login')) form=EditForm() if form.validate_on_submit(): g.user.about_me=form.about_me.data db.session.add(g.user) db.session.commit() return redirect(url_for('profile',account_name=g.user.account_name)) else: form.about_me.data=g.user.about_me return render_template('edit.html', form=form)
def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data g.user.about_me = form.about_me.data db.session.add(g.user) db.session.commit() flash("Your changes have been saved") return redirect(url_for('edit')) else: form.nickname.data = g.user.nickname form.about_me.data = g.user.about_me return render_template("edit.html", form=form)
def edit(): form = EditForm() if form.validate_on_submit(): g.user.first_name = form.first_name g.user.last_name = form.last_name g.user.about_user = form.about_user db.session.add(g.user) db.session.commit() flash('Your changes have been saved.') return redirect(url_for('edit')) else: form.about_me.data = g.user.about_user return render_template('edit.html', form=form)
def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data g.user.about_me = form.about_me.data db.session.add(g.user) db.session.commit() flash('Changes saved.') return redirect(url_for('user', nickname=g.user.nickname)) else: form.nickname.data = g.user.nickname form.about_me.data = g.user.about_me return render_template('edit.html', form=form)
def edit_profile(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data g.user.about_me = re.sub('<[A-Za-z\/][^>]*>', '', form.about_me.data) db.session.add(g.user) db.session.commit() flash('Zmiany zapisane.') return redirect(url_for('edit_profile')) else: form.nickname.data = g.user.nickname form.about_me.data = g.user.about_me return render_template('edit.html', form = form)
def edit(): e_form = EditForm() if e_form.validate_on_submit(): g.user.fname = e_form.fname.data g.user.bio = e_form.bio.data db.session.add(g.user) db.session.commit() flash('Your changes have been saved.', category="success") return redirect(url_for('user', user=g.user)) elif request.method != "POST": e_form.fname.data = g.user.fname e_form.bio.data = g.user.bio return render_template('edit.html', form=e_form)
def settings(): edit_form = EditForm(g.user.nickname) if edit_form.validate_on_submit(): dq.update(g.user, ['nickname', 'about_me'], [form.nickname.data, form.about_me.data]) flash('Your changes have been saved.') return redirect(url_for('user', nickname = g.user.nickname)) else: edit_form.nickname.data = g.user.nickname edit_form.about_me.data = g.user.about_me return render_template('settings.html', edit_form = edit_form, sina_url = url)
def xxx(id): form=EditForm() post=models.Post.query.filter_by(id=id).first_or_404() if form.validate_on_submit(): post.tilte=form.blogtilte.data post.body=form.blogbody.data try: db.session.add(post) db.session.commit() except Exception,e: db.session.rollback() flash('OK',request.args) return redirect(url_for('xxx',id=id))
def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data g.user.about_me = form.about_me.data db.session.add(g.user) db.session.commit() flash('Your changes have been saved.') return redirect(url_for('edit')) else: form.nickname.data = g.user.nickname ####very good. avoid user to type the form again!!! form.about_me.data = g.user.about_me ####very good. avoid user to type the form again!!! return render_template('edit.html', form = form)
def edit(nickname): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data g.user.about_me = form.about_me.data db.session.add(g.user) db.session.commit() flash('Your changes have been saved.') return redirect(url_for('user', nickname=nickname)) else: form.nickname.data = g.user.nickname form.about_me.data = g.user.about_me return render_template('edit.html', form=form)
def edit(): editform = EditForm(g.user.username) if editform.validate_on_submit(): g.user.username = editform.username.data g.user.about_me = editform.about_me.data db.session.add(g.user) db.session.commit() flash(gettext('Your changes have been saved.')) return redirect(url_for('edit')) else: editform.username.data = g.user.username editform.about_me.data = g.user.about_me return render_template('edit.html', user = g.user, editform=editform, passwordform = ChangePasswordForm())
def edit(): form = EditForm(request.form) if form.validate_on_submit(): g.user.name = form.name.data g.user.username = form.username.data db.session.add(g.user) db.session.commit() flash('Your changes have been saved.', 'success') return redirect(url_for('edit')) else: form.name.data = g.user.name form.username.data = g.user.username return render_template('edit.html', form=form)
def edit(): form = EditForm() if form.validate_on_submit(): g.user.nickname = form.nickname.data g.user.theme = form.themesong.data db.session.add(g.user) db.session.commit() flash('Your changes have been saved.') return redirect(url_for('edit')) else: form.nickname.data = g.user.nickname form.themesong.data = g.user.theme return render_template('edit.html', form = form)
def edit(): form=EditForm() if form.validate_on_submit(): title=form.blogtilte.data body=form.blogbody.data if body or title: post=models.Post(tilte=title,body=body,timestamp=datetime.utcnow(),author=g.user) try: db.session.add(post) db.session.commit() except Exception,e: db.session.rollback() flash('OK',request.args) return redirect('edit')