I'm using this code to assign data to some variables if a form doesn't validate. This is some logic I'll be using a lot in my script. I want to create a function so that the else portion of this statement is stored in a function, so that I can just call it rather than pasting these lines each time.
if form.validate_on_submit():
do something
else:
brand_title=form.brand_title.data or ''
carrier_format=form.carrier_format.data or ''
recording_artist=form.recording_artist.data or ''
producer=form.producer.data or ''
session=form.session.data or ''
tx_date=form.tx_date.data or ''
network=form.network.data or ''
programme_number=form.programme_number.data or ''
start_time_1=form.start_time_1.data or ''
I've created a function like so:
def variables():
brand_title=form.brand_title.data or ''
carrier_format=form.carrier_format.data or ''
recording_artist=form.recording_artist.data or ''
producer=form.producer.data or ''
session=form.session.data or ''
tx_date=form.tx_date.data or ''
network=form.network.data or ''
programme_number=form.programme_number.data or ''
start_time_1=form.start_time_1.data or ''
But how do I return the variables so that calling the function mirrors typing each line out (as in else section in the first section of code). I've read that simply returning each variable like so:
return (brand_title. carrier_format, recording_artist, producer, session, tx_date, network, programme_number, start_time_1)
would create a tuple, which doesn't seem like the correct option for my needs.
form- what methods does it support?WTForm?form.datadict and return that to wherever it's needed... then access it viacopy_of_form_data.get('session', '')