Apply a discount code and delete it from the Django session, if it exists [on hold]

Multi tool use
Multi tool use











up vote
0
down vote

favorite












This piece of code is placed at the end of my checkout process. Once the user paid successfully, I want to check at the end, if there a discount code was used. If so, I want to remove the discount code session. When the user goes back to the event/product page, he has to type in the discount again, in case he wants to use it.



Is there a better way to first check for the session, and then delete it?



# If set, delete discount cookie
discount_code_session_name = 'discount_code_' + str(
self.order_items_dict['event'].pk
)
discount_code_session = request.session.get(discount_code_session_name, None)
if discount_code_session:
del request.session[discount_code_session_name]









share|improve this question















put on hold as off-topic by Mathias Ettinger, Graipher, alecxe, Malachi yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mathias Ettinger, Graipher, alecxe, Malachi

If this question can be reworded to fit the rules in the help center, please edit the question.













  • with suppress(KeyError): del request.session[discount_code_session_name]. But this question is so stripped of context that I’m voting to close it as off-topic.
    – Mathias Ettinger
    2 days ago










  • You mean I should have posted more of my code, what's around it?
    – Jon Programmer
    2 days ago






  • 4




    Yes. It helps getting the bigger picture. Right now you're retrieving the session information name from a dict we know nothing about. Maybe changing this bit could avoid suppressing the session altogether… Who knows?
    – Mathias Ettinger
    2 days ago










  • Please see the related meta posts here and there.
    – Mathias Ettinger
    2 days ago










  • I tried to explain it better in what context I use it (see edit). I will also check the links you posted, thank you.
    – Jon Programmer
    2 days ago

















up vote
0
down vote

favorite












This piece of code is placed at the end of my checkout process. Once the user paid successfully, I want to check at the end, if there a discount code was used. If so, I want to remove the discount code session. When the user goes back to the event/product page, he has to type in the discount again, in case he wants to use it.



Is there a better way to first check for the session, and then delete it?



# If set, delete discount cookie
discount_code_session_name = 'discount_code_' + str(
self.order_items_dict['event'].pk
)
discount_code_session = request.session.get(discount_code_session_name, None)
if discount_code_session:
del request.session[discount_code_session_name]









share|improve this question















put on hold as off-topic by Mathias Ettinger, Graipher, alecxe, Malachi yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mathias Ettinger, Graipher, alecxe, Malachi

If this question can be reworded to fit the rules in the help center, please edit the question.













  • with suppress(KeyError): del request.session[discount_code_session_name]. But this question is so stripped of context that I’m voting to close it as off-topic.
    – Mathias Ettinger
    2 days ago










  • You mean I should have posted more of my code, what's around it?
    – Jon Programmer
    2 days ago






  • 4




    Yes. It helps getting the bigger picture. Right now you're retrieving the session information name from a dict we know nothing about. Maybe changing this bit could avoid suppressing the session altogether… Who knows?
    – Mathias Ettinger
    2 days ago










  • Please see the related meta posts here and there.
    – Mathias Ettinger
    2 days ago










  • I tried to explain it better in what context I use it (see edit). I will also check the links you posted, thank you.
    – Jon Programmer
    2 days ago















up vote
0
down vote

favorite









up vote
0
down vote

favorite











This piece of code is placed at the end of my checkout process. Once the user paid successfully, I want to check at the end, if there a discount code was used. If so, I want to remove the discount code session. When the user goes back to the event/product page, he has to type in the discount again, in case he wants to use it.



Is there a better way to first check for the session, and then delete it?



# If set, delete discount cookie
discount_code_session_name = 'discount_code_' + str(
self.order_items_dict['event'].pk
)
discount_code_session = request.session.get(discount_code_session_name, None)
if discount_code_session:
del request.session[discount_code_session_name]









share|improve this question















This piece of code is placed at the end of my checkout process. Once the user paid successfully, I want to check at the end, if there a discount code was used. If so, I want to remove the discount code session. When the user goes back to the event/product page, he has to type in the discount again, in case he wants to use it.



Is there a better way to first check for the session, and then delete it?



# If set, delete discount cookie
discount_code_session_name = 'discount_code_' + str(
self.order_items_dict['event'].pk
)
discount_code_session = request.session.get(discount_code_session_name, None)
if discount_code_session:
del request.session[discount_code_session_name]






python django session






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









200_success

127k15148411




127k15148411










asked 2 days ago









Jon Programmer

1073




1073




put on hold as off-topic by Mathias Ettinger, Graipher, alecxe, Malachi yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mathias Ettinger, Graipher, alecxe, Malachi

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Mathias Ettinger, Graipher, alecxe, Malachi yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mathias Ettinger, Graipher, alecxe, Malachi

If this question can be reworded to fit the rules in the help center, please edit the question.












  • with suppress(KeyError): del request.session[discount_code_session_name]. But this question is so stripped of context that I’m voting to close it as off-topic.
    – Mathias Ettinger
    2 days ago










  • You mean I should have posted more of my code, what's around it?
    – Jon Programmer
    2 days ago






  • 4




    Yes. It helps getting the bigger picture. Right now you're retrieving the session information name from a dict we know nothing about. Maybe changing this bit could avoid suppressing the session altogether… Who knows?
    – Mathias Ettinger
    2 days ago










  • Please see the related meta posts here and there.
    – Mathias Ettinger
    2 days ago










  • I tried to explain it better in what context I use it (see edit). I will also check the links you posted, thank you.
    – Jon Programmer
    2 days ago




















  • with suppress(KeyError): del request.session[discount_code_session_name]. But this question is so stripped of context that I’m voting to close it as off-topic.
    – Mathias Ettinger
    2 days ago










  • You mean I should have posted more of my code, what's around it?
    – Jon Programmer
    2 days ago






  • 4




    Yes. It helps getting the bigger picture. Right now you're retrieving the session information name from a dict we know nothing about. Maybe changing this bit could avoid suppressing the session altogether… Who knows?
    – Mathias Ettinger
    2 days ago










  • Please see the related meta posts here and there.
    – Mathias Ettinger
    2 days ago










  • I tried to explain it better in what context I use it (see edit). I will also check the links you posted, thank you.
    – Jon Programmer
    2 days ago


















with suppress(KeyError): del request.session[discount_code_session_name]. But this question is so stripped of context that I’m voting to close it as off-topic.
– Mathias Ettinger
2 days ago




with suppress(KeyError): del request.session[discount_code_session_name]. But this question is so stripped of context that I’m voting to close it as off-topic.
– Mathias Ettinger
2 days ago












You mean I should have posted more of my code, what's around it?
– Jon Programmer
2 days ago




You mean I should have posted more of my code, what's around it?
– Jon Programmer
2 days ago




4




4




Yes. It helps getting the bigger picture. Right now you're retrieving the session information name from a dict we know nothing about. Maybe changing this bit could avoid suppressing the session altogether… Who knows?
– Mathias Ettinger
2 days ago




Yes. It helps getting the bigger picture. Right now you're retrieving the session information name from a dict we know nothing about. Maybe changing this bit could avoid suppressing the session altogether… Who knows?
– Mathias Ettinger
2 days ago












Please see the related meta posts here and there.
– Mathias Ettinger
2 days ago




Please see the related meta posts here and there.
– Mathias Ettinger
2 days ago












I tried to explain it better in what context I use it (see edit). I will also check the links you posted, thank you.
– Jon Programmer
2 days ago






I tried to explain it better in what context I use it (see edit). I will also check the links you posted, thank you.
– Jon Programmer
2 days ago

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

fMCW9WTJ hL XBhzG0ZCg1Zr4MufiDis90NeGTug,83my w51XfrrTp5YWxLALAs jmXTw 4,kzDlNWCaj5
NZZEDOkxiRGrVLn,ZgTyV XLxOfArl,Djf1,Znfsg

Popular posts from this blog

Orthoptera

Ellipse (mathématiques)

Quarter-circle Tiles