def new_quote(): quote_form = QuoteForm() if quote_form.validate_on_submit(): quote_tmp = Quote(who=quote_form.who.data, date=quote_form.date.data, cost=quote_form.cost.data, pmargin=quote_form.pmargin.data, sell_price=quote_form.sell_price.data) tmp_slist = json.loads(quote_form.s_list.data) for service in tmp_slist: quote_tmp.service_list.append( Service(name=service['name'], cost=service['price'])) db.session.add(quote_tmp) db.session.commit() flash("Orçamento inserido.", "success") return redirect(url_for("home")) return render_template('new_quote.html', title="Novo orçamento", form=quote_form, today=datetime.datetime.now().date())
def quote_update(id): quote = db.quote_select_by_id(id) form = QuoteForm(quote_id=id, quote_body=quote['body'], quote_source=quote['source']) if form.validate_on_submit(): if form.quote_submit.data: response = db.quote_update_one(form.quote_body.data, form.quote_source.data, id) if response: flash(response, 'error') else: flash('Successful UPDATE', 'message') return redirect(url_for('quote_update', id=id)) elif form.quote_delete.data: response = db.quote_delete_one(id) if response: flash(response, 'error') else: flash('Successful DELETE', 'message') return redirect(url_for('quote')) return render_template('form_quote_update.html', form=form, quote=quote)
def register(request): # A HTTP POST? if request.method == 'POST': form = QuoteForm(request.POST) # Have we been provided with a valid form? if form.is_valid(): human = True # Save the new category to the database. new_quote = form.save(commit=True) # Now call the index() view. # The user will be shown the homepage. return show_msg(request, str(new_quote.id)) else: # The supplied form contained errors - just print them to the terminal. print form.errors else: # If the request was not a POST, display the form to enter details. form = QuoteForm() return render(request, 'add.html', { 'page_title': 'Contacts', 'form': form, })
def newQuote(): form = QuoteForm() if form.validate_on_submit(): quote = Quote(body=form.quote.data, user_id=g.user.id) db.session.add(quote) db.session.commit() flash('Qoute saved') return redirect(url_for('index')) return render_template('newQuote.html', title='New Quote', form=form)
def quote_new(): form = QuoteForm() if form.validate_on_submit(): db.quote_insert_one(form.quote_body.data, form.quote_source.data) flash('Successful INSERT', 'message') return redirect(url_for('quote_new')) flash_validation_errors(form) return render_template('form_quote_new.html', form=form)
def new_quotes(): if not g.poet: flash('you must be logged in to create a quote!') return redirect('/') form = QuoteForm() if form.validate_on_submit(): quote = Quote(content=form.content.data, poet_id=g.poet.id) db.session.add(quote) db.session.commit() return redirect(f'/account?f=own') else: return render_template('quotes/new.html', form=form)
def verify_honeypot_value_QuoteForm(request, field_name): """ Verify that request.POST[field_name] is a valid honeypot. Ensures that the field exists and passes verification according to HONEYPOT_VERIFIER. """ verifier = getattr(settings, 'HONEYPOT_VERIFIER', honeypot_equals) dictToReturn = {} if request.method == 'POST': field = field_name or settings.HONEYPOT_FIELD_NAME if field not in request.POST or not verifier(request.POST[field]): resp = render_to_string('honeypot/honeypot_error.html', {'fieldname': field}) form = QuoteForm(request.POST) if form.is_valid(): dictToReturn['form'] = form msg = EmailMultiAlternatives("Support Request - FROM PLCPART", form.getEmailBody(), fromEmail, [to_spamEmail]) msg.attach_alternative(render_to_response('surplusEmail.html', dictToReturn), 'text/html') msg.send() return HttpResponseBadRequest(resp)
def quotepage(): # !IMPORTANT! # only allow access to the quotepage if the user selected a movie from "homepage" or they just searched for # a quote using "quotepage" # if post data is submitted to this route, check it if request.method == 'POST': # check to see if form data under the name of 'movieName' and 'quote' was submitted if request.form.get('movieID') and request.form.get('quote'): movieID = request.form.get('movieID') movie = Movie.query.get(movieID) movieName = movie.title quoteRequest = request.form.get('quote') # form for submitting a different quote request (search bar, essentially) form = QuoteForm(movieID=movieID) # do db stuff here... # the db query results using "quoteRequest" quoteResults = Timestamp.query.filter( and_(Timestamp.movieid == movieID, Timestamp.subtitle.like("%" + quoteRequest + "%"))).all() # stores selection forms for all of the quote results the db returns quoteForms = [] for result in quoteResults: quoteForms.append( [result.subtitle, SelectQuoteForm(quoteID=result.uid)]) if quoteForms == []: msg = 'Sorry, we couldn\'t find anything. Perhaps try searching again' return render_template('quote.html', title='Quote', movieName='movieName', form=form, quoteRequest=quoteRequest, msg=msg) return render_template('quote.html', title='Quote', movieName=movieName, form=form, quoteRequest=quoteRequest, quoteForms=quoteForms) # if form data under the names of 'movieName' and 'quote' were not both submitted, check to see if # just 'movieName' data was submitted (ie just came from "homepage") elif request.form.get('movieID'): movieID = request.form.get('movieID') movie = Movie.query.get(movieID) movieName = movie.title # form for submitting a quote request (search bar, essentially) form = QuoteForm(movieID=movieID) return render_template('quote.html', title='Quote', form=form, movieName=movieName) # redirect the user if they didn't select a movie from "homepage" or search for a quote on "quotepage" # (ie no correct post data submitted) return redirect(url_for('homepage'))