def save_bookmark(request, bookmark_id=False): if request.is_ajax: return ajax_save_bookmark(request, bookmark_id) form = BookmarkForm() bookmark = get_object_or_None(Bookmark, pk=bookmark_id) if bookmark: form = BookmarkForm(instance=bookmark) if not request.user.is_authenticated() or ( not request.user.is_staff and (bookmark.note.author == request.user)): return HttpResponseRedirect(reverse(list, args=(note.id, ))) if request.method == "POST": if bookmark: form = BookmarkForm(request.POST, instance=bookmark) else: form = BookmarkForm(request.POST) if form.is_valid(): if not bookmark: bookmark = Bookmark() bookmark.save() if 'text' in form.cleaned_data: bookmark.text = form.cleaned_data['text'] if 'chart' in form.cleaned_data: bookmark.chart = form.cleaned_data['chart'] if 'tags' in form.cleaned_data: bookmark.tags = form.cleaned_data['tags'] if 'note' in form.cleaned_data: bookmark.note = form.cleaned_data['note'] bookmark.save() return HttpResponseRedirect( reverse(save_bookmark, kwargs={ "bookmark_id": bookmark.id, })) return render_to_response('notes/form_page.html', {'form': form}, context_instance=RequestContext(request))
def add_bookmark(request): """ This view serves and validates a bookmark form. If requested via ajax it also returns the drop bookmark form to replace the add bookmark form. """ if request.method == "POST": form = BookmarkForm(user=request.user, data=request.POST) if form.is_valid(): bookmark = form.save() if not request.is_ajax(): messages.success(request, 'Bookmark added') if request.POST.get('next'): return HttpResponseRedirect(request.POST.get('next')) return HttpResponse('Added') return render_to_response( 'admin_tools/menu/remove_bookmark_form.html', RequestContext(request, { 'bookmark': bookmark, 'url': bookmark.url, })) else: form = BookmarkForm(user=request.user) return render_to_response( 'admin_tools/menu/form.html', RequestContext(request, { 'form': form, 'title': 'Add Bookmark', }))
def add_bookmark(request): """ This view serves and validates a bookmark form. If requested via ajax it also returns the drop bookmark form to replace the add bookmark form. """ if request.method == "POST": form = BookmarkForm(user=request.user, data=request.POST) if form.is_valid(): bookmark = form.save() if not request.is_ajax(): request.user.message_set.create(message='Bookmark added') if request.POST.get('next'): return HttpResponseRedirect(request.POST.get('next')) return HttpResponse('Added') return TemplateResponse( request, 'client_admin/menu/remove_bookmark_form.html', context={ 'bookmark': bookmark, 'url': bookmark.url, }) else: form = BookmarkForm(user=request.user) return TemplateResponse(request, 'client_admin/menu/form.html', context={ 'form': form, 'title': 'Add Bookmark', })
def create(request): if request.method == 'POST': # If the form has been submitted... form = BookmarkForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass bookmark = form.save() return HttpResponseRedirect( reverse('bookmark_index')) # Redirect after POST else: form = BookmarkForm() # An unbound form return render_to_response('create.html', RequestContext(request, { 'form': form, }))
def edit_bookmark(id): """ Edit a bookmark """ add_bookmark = False bookmark = Bookmark.query.get_or_404(id) form = BookmarkForm(obj=bookmark) if form.validate_on_submit(): bookmark.name = form.name.data bookmark.url = form.url.data bookmark.description = form.description.data db.session.commit() flash('You have successfully edited the bookmark.') # redirect to the bookmarks page return redirect(url_for('profile.list_bookmarks')) form.description.data = bookmark.description form.url.data = bookmark.url form.name.data = bookmark.name return render_template('profile/bookmarks/bookmark.html', action="Edit", add_bookmark=add_bookmark, form=form, bookmark=bookmark, title="Edit Bookmark")
def add(): user = Users("Debabrata", "Patnaik") form = BookmarkForm() form.userform.data = user.getfullname()[:3] # if request.method == "POST": # url = request.form["url"] # user = request.form.get("user","Deb") # store_bookmarks(url, user) # app.logger.debug("Stored URL: " + url) # flash("Stored URL: " + url) # return redirect(url_for('index')) # return render_template("add.html") if form.validate_on_submit(): print form.url.data, form.description.data try: print form.userform except Exception, exc: print exc url = form.url.data description = form.description.data user = form.userform.data store_bookmarks(url, user, description) app.logger.debug("Stored URL: " + url) flash("Stored URL: {}".format(url)) return redirect(url_for("index"))
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data destination = form.destination.data outbound_date = form.outbound_date.data outbound_time = form.outbound_time.data inbound_date = form.inbound_date.data inbound_time = form.inbound_time.data tags = form.tags.data bm = Bookmark(user=current_user, url=url, description=description, destination=destination, tags=tags, outbound_date=outbound_date, outbound_time=outbound_time, inbound_date=inbound_date, inbound_time=inbound_time) db.session.add(bm) db.session.commit() flash("Stored trip '{}'".format(description)) return redirect(url_for('index')) return render_template('bookmark_form.html', form=form, title="Add a Trip")
def add_bookmark(): """ Add a bookmark to the database """ add_bookmark = True form = BookmarkForm() if form.validate_on_submit(): bookmark = Bookmark(name=form.name.data, url=form.url.data, description=form.description.data, user_id=current_user.id) try: # add bookmark to the database db.session.add(bookmark) db.session.commit() flash('You have successfully added a new bookmark.') except: # in case bookmark name already exists flash('Error: bookmark name already exists.') # redirect to bookmarks page return redirect(url_for('profile.list_bookmarks')) # load bookmark template return render_template('profile/bookmarks/bookmark.html', action="Add", add_bookmark=add_bookmark, form=form, title="Add Bookmark")
def add(): form = BookmarkForm() if form.validate_on_submit(): url, description = form.url.data, form.description.data store_bookmark(url, description) flash(f"stored url: {url}") return redirect(url_for('index')) return render_template('add.html', form=form)
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data store_bookmark(url, description) flash("Stored bookmark '{}'".format(description)) return redirect(url_for('index')) return render_template('add.html', form=form)
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data store_bookmark(url, description) flash("You have successfully bookmarked {}".format(url)) return redirect(url_for('index')) return render_template('add.html', form=form)
def update(request, bookmark_id): try: bookmark = Bookmark.objects.get(id=bookmark_id) except Bookmark.DoesNotExist: raise Http404 if request.method == 'POST': # If the form has been submitted... form = BookmarkForm(request.POST, instance=bookmark) if form.is_valid(): # All validation rules pass bookmark = form.save() return HttpResponseRedirect( reverse('bookmark_index')) # Redirect after POST else: form = BookmarkForm(instance=bookmark) return render_to_response('update.html', RequestContext(request, { 'form': form, }))
def my_bookmark(request, template_name='bookmark/my_bookmark.html'): form = BookmarkForm() file_form = FileForm() return render_to_response( template_name, RequestContext(request, { 'form': form, 'file_form': file_form, 'active': 'my_bookmark' }))
def add(): form = BookmarkForm() # If method=GET OR form-content is invalid, then... if form.validate_on_submit(): url = form.url.data description = form.description.data store_bookmark(url, description) flash("Stored bookmark '{}'".format(url)) return redirect(url_for('index')) return render_template('add.html', form=form)
def edit_bookmark(request, id): bookmark = get_object_or_404(Bookmark, id=id) if request.method == "POST": form = BookmarkForm(user=request.user, data=request.POST, instance=bookmark) if form.is_valid(): form.save() if not request.is_ajax(): request.user.message_set.create(message='Bookmark updated') if request.POST.get('next'): return HttpResponseRedirect(request.POST.get('next')) return HttpResponse('Saved') else: form = BookmarkForm(user=request.user, instance=bookmark) return direct_to_template(request, 'admin_tools/menu/form.html', { 'form': form, 'title': 'Edit Bookmark', })
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data store_bookmark(url, description) flash(f'Stored {description}') app.logger.debug(f'Stored {url} as {description}') return redirect(url_for('index')) return render_template('add.html', form=form)
def add(): form = BookmarkForm() if form.validate_on_submit(): url = request.form['url'] bm = Bookmark(user=current_user, url=url) db.session.add(bm) db.session.commit() application.logger.debug('URL:' + url) flash("Stored url: {}".format(url)) return redirect(url_for('return_200')) return render_template('add.html', form=form)
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data #url = request.form['url'] #getting data from 'form' dictionary(works with request reference) store_bookmark(url, description) flash('Bookmark saved: {}'.format(description)) #app.logger.debug('stored url:' + url) return redirect(url_for('index')) return render_template('add.html', form=form)
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data bm = models.Bookmark(url=url, description=description) db.session.add(bm) db.session.commit() flash("Stored '{}'".format(description)) return redirect(url_for('index')) return render_template('add.html', form=form)
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description=form.description.data store_bookmark(url,description) # app.logger.debug('stored url %s' % url) flash("Stored bookmark '{}'".format(description)) return redirect(url_for('index')) return render_template('add.html',Text="1232",form=form)
def add(): form = BookmarkForm() # 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 url = form.url.data description = form.description.data bm = models.Bookmark(user=logged_in_user(), url=url, description=description) db.session.add(bm) db.session.commit() flash("Stored '{}'".format(description)) return redirect(url_for('index')) return render_template('add.html', form=form) # form=form is sent because the template is actually using the form to populate the DOM with form fields
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 add(): form = BookmarkForm() if form.validate_on_submit(): db.session.add( Bookmark(user=logged_in_user(), url=form.obj.data, description=form.description.data)) db.session.commit() flash("Stored description {}".format(form.description.data)) return redirect(url_for('index')) return render_template('add.html', form=form)
def add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data bm = Bookmark(user=logged_in_user(), url=url, description=description) db.session.add(bm) db.session.commit() flash("Stored bookmak '{}'.".format(description)) return redirect(url_for("index")) return render_template("add.html", form=form)
def add(): form = BookmarkForm() if form.validate_on_submit(): # url = request.form['url'] # store_bookmark(url) url = form.url.data description = form.description.data store_bookmark(url, description) flash("please find below list of URLs.") flash("Bookmark is :- '{}'".format(url)) return redirect(url_for('hello')) return render_template('Add.html', form=form)
def add_bookmark(): form = BookmarkForm() # checks http request and form if form.validate_on_submit(): url = form.url.data description = form.description.data bm = Bookmark(url=url, description=description) db.session.add(bm) db.session.commit() flash(f"stored bookmark: {url}") return redirect(url_for('index')) return render_template('add.html', form=form)
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(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(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 add(): form = BookmarkForm() if form.validate_on_submit(): url = form.url.data description = form.description.data bm = Bookmark(url=url, description=description, user=current_user) db.session.add(bm) db.session.commit() flash('Stored bookmark: {}'.format(url)) return redirect(url_for('index')) return render_template('bookmark_form.html', form=form, title='Add Bookmark')