def edit_bookmark(bookmark_id): bookmark = Bookmark.query.get_or_404(bookmark_id) if current_user != bookmark.user: abort(403) form = BookmarkForm(obj=bookmark) if form.validate_on_submit(): form.populate_obj(bookmark) db.session.commit() flash("Stored %s" % bookmark.description) return redirect(url_for('user',username=current_user.username)) return render_template('edit.html',form=form,title='Edit Bookmark')
def edit_bookmark(bookmark_id): bookmark = Bookmark.query.get_or_404(bookmark_id) if current_user != bookmark.user: abort(403) form = BookmarkForm(obj=bookmark) if form.validate_on_submit(): form.populate_obj(bookmark) db.session.commit() flash("Stored '{}'".format(bookmark.description)) return redirect(url_for('user', username=current_user.username)) return render_template('bookmark_form.html', form=form, title="Edit Trip")
def edit(self, bookmark_id): if not users.get_current_user(): webapp2.abort(401) bookmark = db.get(db.Key.from_path('Bookmark', int(bookmark_id))) form = BookmarkForm(self.get_locale(), self.request.POST, bookmark) if self.request.POST and form.validate(): form.populate_obj(bookmark) bookmark.date = datetime.now() bookmark.put() return self.redirect('/bookmark/list') self.render_template('form.html', {'title': _('Bookmark'), 'form': form, 'name': 'bookmark', 'id': bookmark.key().id()})
def editUrl(bookmarkid): bookmark = bookmarkDB.query.get(bookmarkid) form = BookmarkForm(obj=bookmark) if form.validate_on_submit(): form.populate_obj(bookmark) db.session.commit() flash("Successfully edited the bookmark") return redirect(url_for("user", userid=current_user.id)) return render_template('addUrlForm.html', form=form, user=current_user, title="Edit bookmark")
def edit_bookmark(id): b = g.user.bid(id) form = BookmarkForm(obj=b) if not b: abort(403) if form.validate_on_submit(): form.populate_obj(b) b.updated = datetime.utcnow() db.session.add(b) db.session.commit() flash('Bookmark %s updated' % (form.title.data), category='info') return redirect(url_for('index')) return render_template('edit.html', title='Edit', form=form)
def edit_bookmark(id): b = g.user.bid(id) form = BookmarkForm(obj=b) if not b: abort(403) if form.validate_on_submit(): form.populate_obj(b) b.updated = datetime.utcnow() db.session.add(b) db.session.commit() flash("Bookmark %s updated" % (form.title.data), category="info") return redirect(url_for("index")) return render_template("edit.html", title="Edit", form=form)
def edit_bookmark(bookmark_id): bookmark = Bookmark.query.get_or_404(bookmark_id) if current_user != bookmark.user: abort(403) form = BookmarkForm(obj=bookmark) if form.validate_on_submit(): form.populate_obj(bookmark) db.session.commit() flash('Your bookmark was saved succesfully') return redirect(url_for('main.user', username=current_user.username)) return render_template('bookmark_form.html', form=form, title='Edit Bookmark')
def edit_bookmark(bookmark_id): bookmark = models.Bookmark.query.get_or_404(bookmark_id) print(type(bookmark)) if current_user != bookmark.user: abort(403) form = BookmarkForm(obj=bookmark) if form.validate_on_submit(): form.populate_obj(bookmark) db.session.commit() flash('Stored {}'.format(bookmark.description), "success") return redirect(url_for('user', username=current_user.username)) return render_template('bookmark_form.html', form=form, title='Edit Bookmark')
def edit_bookmark(bookmark_id): bookmark = Bookmark.query.get_or_404(bookmark_id) if current_user != bookmark.user: abort(403) form = BookmarkForm( obj=bookmark ) # On a GET request, the fields are empty and the form variables are also empty. On a POST request, the variables are full. This will likely only work because the action was "", as that means it referring to a still available form to read the values of if form.validate_on_submit( ): # This line also checks to make sure the method is not GET form.populate_obj(bookmark) db.session.commit() flash("Stored '{}'".format(bookmark.description)) return redirect(url_for('user', username=current_user.username)) return render_template( 'bookmark_form.html', form=form, title="Edit Bookmark" ) # form=form is sent because the template is actually using the form to populate the DOM with form fields
def new_bookmark(): form = BookmarkForm() if form.validate_on_submit(): b = Bookmark() form.populate_obj(b) b.owner_id = g.user.id b.created = datetime.utcnow() b.tags = " ".join([t.strip() for t in form.tags.data.strip().split(",")]).lower() b.clicks = 0 if not form.title.data: soup = BSoup(urlopen(form.url.data)) b.title = soup.title.string db.session.add(b) db.session.commit() flash("New bookmark %s added" % (b.title), category="info") return redirect(url_for("index")) return render_template("new.html", title="New", form=form)
def new_bookmark(): form = BookmarkForm() if form.validate_on_submit(): b = Bookmark() form.populate_obj(b) b.owner_id = g.user.id b.created = datetime.utcnow() b.tags = ' '.join( [t.strip() for t in form.tags.data.strip().split(',')])\ .lower() b.clicks = 0 if not form.title.data: soup = BSoup(urlopen(form.url.data)) b.title = soup.title.string db.session.add(b) db.session.commit() flash('New bookmark %s added' % (b.title), category='info') return redirect(url_for('index')) return render_template('new.html', title='New', form=form)