Returning back all the fields and not the fields selected












1















I have a web page with list of 5 fields. I am trying to generate output depending on the fields selected by the user.



Here is the code I currently have in place that works fine.



fields = {field: value for field, value in form.data.items() if
value != None or value != 'csrf_token'}
print(fields)
## This prints out a list of all fields

o =
for a in fields:
if a is not None:
o.append(a)
print(o)

p = o[:-1]
print(p)


output = sample_function(*p)


The problem I am having is irrespective of which fields are selected, the output is the same (it returns back all fields irrespective of whether they are selected or not).



Could anyone advise as to where am I going wrong with this. Thanks.



Update:



@app.route('/index', methods=['GET','POST'])
def sample_function():
form = SampleForm()
if form.validate_on_submit():
store_id = form.store_id.data
store_name = form.store_name.data
location_id = form.location_id.data
store_type = form.store_type.data
store_location = form.store_location.data

fields = {field: value for field, value in form.data.items() if
value != None or value != 'csrf_token'}
print(fields)
## This prints out a list of all fields

o =
for a in fields:
if a is not None:
o.append(a)
print(o)

p = o[:-1]
print(p)


output = sample_function(*p)


Function that runs the query:



def sample_function(*field_names):
cursor = conn.cursor()
cursor.execute('select {} from table.format(', '.join(str(field) for field in field_names)))









share|improve this question

























  • Hi there, if value != None or key != 'None' or key != 'csrf_token' the or here is redundant. Any key will pass the checks. Did you mean to use and?

    – TrebuchetMS
    Nov 23 '18 at 14:05











  • @TrebuchetMS it was a typo I entered key != None twice.. I have edited the post

    – dark horse
    Nov 23 '18 at 14:33











  • @TrebuchetMS the problem still exists though..

    – dark horse
    Nov 23 '18 at 14:35











  • In that first comment, I've merely pointed out what I think was unintentional. Looking at your question, I'm still confused how your fields are selected by the user and how that ties in with the code you've shown. Please elaborate...?

    – TrebuchetMS
    Nov 23 '18 at 14:40











  • @TrebuchetMS as mentioned in my initial post, I have a web page with 5 fields(check boxes). As a user I can select any of the fields. Based on the user input, an excel get generated with the fields selected.. If all the check boxes are selected, the excel gets generated. However if I uncheck one of the checkboxes, it still returns the same output with all columns.. I have updated my initial post the complete form with the SQL that gets executed on submission..

    – dark horse
    Nov 23 '18 at 14:48
















1















I have a web page with list of 5 fields. I am trying to generate output depending on the fields selected by the user.



Here is the code I currently have in place that works fine.



fields = {field: value for field, value in form.data.items() if
value != None or value != 'csrf_token'}
print(fields)
## This prints out a list of all fields

o =
for a in fields:
if a is not None:
o.append(a)
print(o)

p = o[:-1]
print(p)


output = sample_function(*p)


The problem I am having is irrespective of which fields are selected, the output is the same (it returns back all fields irrespective of whether they are selected or not).



Could anyone advise as to where am I going wrong with this. Thanks.



Update:



@app.route('/index', methods=['GET','POST'])
def sample_function():
form = SampleForm()
if form.validate_on_submit():
store_id = form.store_id.data
store_name = form.store_name.data
location_id = form.location_id.data
store_type = form.store_type.data
store_location = form.store_location.data

fields = {field: value for field, value in form.data.items() if
value != None or value != 'csrf_token'}
print(fields)
## This prints out a list of all fields

o =
for a in fields:
if a is not None:
o.append(a)
print(o)

p = o[:-1]
print(p)


output = sample_function(*p)


Function that runs the query:



def sample_function(*field_names):
cursor = conn.cursor()
cursor.execute('select {} from table.format(', '.join(str(field) for field in field_names)))









share|improve this question

























  • Hi there, if value != None or key != 'None' or key != 'csrf_token' the or here is redundant. Any key will pass the checks. Did you mean to use and?

    – TrebuchetMS
    Nov 23 '18 at 14:05











  • @TrebuchetMS it was a typo I entered key != None twice.. I have edited the post

    – dark horse
    Nov 23 '18 at 14:33











  • @TrebuchetMS the problem still exists though..

    – dark horse
    Nov 23 '18 at 14:35











  • In that first comment, I've merely pointed out what I think was unintentional. Looking at your question, I'm still confused how your fields are selected by the user and how that ties in with the code you've shown. Please elaborate...?

    – TrebuchetMS
    Nov 23 '18 at 14:40











  • @TrebuchetMS as mentioned in my initial post, I have a web page with 5 fields(check boxes). As a user I can select any of the fields. Based on the user input, an excel get generated with the fields selected.. If all the check boxes are selected, the excel gets generated. However if I uncheck one of the checkboxes, it still returns the same output with all columns.. I have updated my initial post the complete form with the SQL that gets executed on submission..

    – dark horse
    Nov 23 '18 at 14:48














1












1








1








I have a web page with list of 5 fields. I am trying to generate output depending on the fields selected by the user.



Here is the code I currently have in place that works fine.



fields = {field: value for field, value in form.data.items() if
value != None or value != 'csrf_token'}
print(fields)
## This prints out a list of all fields

o =
for a in fields:
if a is not None:
o.append(a)
print(o)

p = o[:-1]
print(p)


output = sample_function(*p)


The problem I am having is irrespective of which fields are selected, the output is the same (it returns back all fields irrespective of whether they are selected or not).



Could anyone advise as to where am I going wrong with this. Thanks.



Update:



@app.route('/index', methods=['GET','POST'])
def sample_function():
form = SampleForm()
if form.validate_on_submit():
store_id = form.store_id.data
store_name = form.store_name.data
location_id = form.location_id.data
store_type = form.store_type.data
store_location = form.store_location.data

fields = {field: value for field, value in form.data.items() if
value != None or value != 'csrf_token'}
print(fields)
## This prints out a list of all fields

o =
for a in fields:
if a is not None:
o.append(a)
print(o)

p = o[:-1]
print(p)


output = sample_function(*p)


Function that runs the query:



def sample_function(*field_names):
cursor = conn.cursor()
cursor.execute('select {} from table.format(', '.join(str(field) for field in field_names)))









share|improve this question
















I have a web page with list of 5 fields. I am trying to generate output depending on the fields selected by the user.



Here is the code I currently have in place that works fine.



fields = {field: value for field, value in form.data.items() if
value != None or value != 'csrf_token'}
print(fields)
## This prints out a list of all fields

o =
for a in fields:
if a is not None:
o.append(a)
print(o)

p = o[:-1]
print(p)


output = sample_function(*p)


The problem I am having is irrespective of which fields are selected, the output is the same (it returns back all fields irrespective of whether they are selected or not).



Could anyone advise as to where am I going wrong with this. Thanks.



Update:



@app.route('/index', methods=['GET','POST'])
def sample_function():
form = SampleForm()
if form.validate_on_submit():
store_id = form.store_id.data
store_name = form.store_name.data
location_id = form.location_id.data
store_type = form.store_type.data
store_location = form.store_location.data

fields = {field: value for field, value in form.data.items() if
value != None or value != 'csrf_token'}
print(fields)
## This prints out a list of all fields

o =
for a in fields:
if a is not None:
o.append(a)
print(o)

p = o[:-1]
print(p)


output = sample_function(*p)


Function that runs the query:



def sample_function(*field_names):
cursor = conn.cursor()
cursor.execute('select {} from table.format(', '.join(str(field) for field in field_names)))






python python-3.x flask






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 16:14







dark horse

















asked Nov 23 '18 at 11:44









dark horsedark horse

15110




15110













  • Hi there, if value != None or key != 'None' or key != 'csrf_token' the or here is redundant. Any key will pass the checks. Did you mean to use and?

    – TrebuchetMS
    Nov 23 '18 at 14:05











  • @TrebuchetMS it was a typo I entered key != None twice.. I have edited the post

    – dark horse
    Nov 23 '18 at 14:33











  • @TrebuchetMS the problem still exists though..

    – dark horse
    Nov 23 '18 at 14:35











  • In that first comment, I've merely pointed out what I think was unintentional. Looking at your question, I'm still confused how your fields are selected by the user and how that ties in with the code you've shown. Please elaborate...?

    – TrebuchetMS
    Nov 23 '18 at 14:40











  • @TrebuchetMS as mentioned in my initial post, I have a web page with 5 fields(check boxes). As a user I can select any of the fields. Based on the user input, an excel get generated with the fields selected.. If all the check boxes are selected, the excel gets generated. However if I uncheck one of the checkboxes, it still returns the same output with all columns.. I have updated my initial post the complete form with the SQL that gets executed on submission..

    – dark horse
    Nov 23 '18 at 14:48



















  • Hi there, if value != None or key != 'None' or key != 'csrf_token' the or here is redundant. Any key will pass the checks. Did you mean to use and?

    – TrebuchetMS
    Nov 23 '18 at 14:05











  • @TrebuchetMS it was a typo I entered key != None twice.. I have edited the post

    – dark horse
    Nov 23 '18 at 14:33











  • @TrebuchetMS the problem still exists though..

    – dark horse
    Nov 23 '18 at 14:35











  • In that first comment, I've merely pointed out what I think was unintentional. Looking at your question, I'm still confused how your fields are selected by the user and how that ties in with the code you've shown. Please elaborate...?

    – TrebuchetMS
    Nov 23 '18 at 14:40











  • @TrebuchetMS as mentioned in my initial post, I have a web page with 5 fields(check boxes). As a user I can select any of the fields. Based on the user input, an excel get generated with the fields selected.. If all the check boxes are selected, the excel gets generated. However if I uncheck one of the checkboxes, it still returns the same output with all columns.. I have updated my initial post the complete form with the SQL that gets executed on submission..

    – dark horse
    Nov 23 '18 at 14:48

















Hi there, if value != None or key != 'None' or key != 'csrf_token' the or here is redundant. Any key will pass the checks. Did you mean to use and?

– TrebuchetMS
Nov 23 '18 at 14:05





Hi there, if value != None or key != 'None' or key != 'csrf_token' the or here is redundant. Any key will pass the checks. Did you mean to use and?

– TrebuchetMS
Nov 23 '18 at 14:05













@TrebuchetMS it was a typo I entered key != None twice.. I have edited the post

– dark horse
Nov 23 '18 at 14:33





@TrebuchetMS it was a typo I entered key != None twice.. I have edited the post

– dark horse
Nov 23 '18 at 14:33













@TrebuchetMS the problem still exists though..

– dark horse
Nov 23 '18 at 14:35





@TrebuchetMS the problem still exists though..

– dark horse
Nov 23 '18 at 14:35













In that first comment, I've merely pointed out what I think was unintentional. Looking at your question, I'm still confused how your fields are selected by the user and how that ties in with the code you've shown. Please elaborate...?

– TrebuchetMS
Nov 23 '18 at 14:40





In that first comment, I've merely pointed out what I think was unintentional. Looking at your question, I'm still confused how your fields are selected by the user and how that ties in with the code you've shown. Please elaborate...?

– TrebuchetMS
Nov 23 '18 at 14:40













@TrebuchetMS as mentioned in my initial post, I have a web page with 5 fields(check boxes). As a user I can select any of the fields. Based on the user input, an excel get generated with the fields selected.. If all the check boxes are selected, the excel gets generated. However if I uncheck one of the checkboxes, it still returns the same output with all columns.. I have updated my initial post the complete form with the SQL that gets executed on submission..

– dark horse
Nov 23 '18 at 14:48





@TrebuchetMS as mentioned in my initial post, I have a web page with 5 fields(check boxes). As a user I can select any of the fields. Based on the user input, an excel get generated with the fields selected.. If all the check boxes are selected, the excel gets generated. However if I uncheck one of the checkboxes, it still returns the same output with all columns.. I have updated my initial post the complete form with the SQL that gets executed on submission..

– dark horse
Nov 23 '18 at 14:48












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446088%2freturning-back-all-the-fields-and-not-the-fields-selected%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446088%2freturning-back-all-the-fields-and-not-the-fields-selected%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'