Help tying up loose ends on my payment system integration (Stripe/Django) [LONG]
**OMG;TIWTL;DR;FU (OMG, this is way too long, didn't read, F you): Can someone please help me work through the design/architecture of my payment system with Stripe? I think I have most of the pieces to the puzzle but I'm not sure how they fit together.**
-----------------------------
**Long Version:**
Hi there,
I'm going to try to make this as detailed but also as concise as possible. I am trying to tie up the loose ends on the Stripe subscription/recurring payment system for my web app before taking it live and I think I just need some help understanding exactly what the whole process should look like from a bird's eye view. If you've successfully integrated Stripe with Django before it will definitely help a lot in understanding the questions I have and your ability to provide answers. Ok, so here we go!
My current start to finish workflow from new user registration to payment is as follows, and this all works (though there are likely unforeseen bugs and holes in it, so please feel free to call them out):
**User Registration:**
- User uses standard django-registration form to register, an activation email is sent, and user clicks link in activation email to activate their account.
- Upon new user registration the following happens:
- A new user profile is created including a few extra fields that extend the default user model through a OneToOneField link
- A user PlanProfile is created, initializing them to the free plan, initializing the boolean premium_user field to False, and giving them a default "NA" value for stripeID and subscriptionID (These will be the stripe customer ID and subscription ID once they join a paid plan. Without a paid plan there is no need for them)
**Joining a Paid Plan:**
- Customer navigates to /plans/ and selects a payment plan
- Depending on which button they click (simple pricing tables), the appropriate StripeCheckout handler is configured and called via Javascript, and the form data (CC token, email address, name, plan type, etc) is submitted to the payment processing view /plans/processpayment/
- Payment processing view checks the user's plan profile to see if they have an existing Stripe customer ID **and** existing Stripe subscription ID. They **should** have both, or neither (at this point).
- If they do **NOT** have both (i.e. they are a new customer):
- A new Stripe customer is created, assuming there are no card/form validation errors
- A new subscription for that customer is created (assuming same)
- Assuming no errors from Stripe:
- The user's plan profile is updated, setting the premium_user field to True, and the stripeID and subID fields to the customer and subscription IDs returned from Stripe, respectively.
- The user is redirected to the post payment view saying thanks, reflecting their new subscription, confirmation email is sent from Stripe with a copy of their invoice
- If they **DO** have both (i.e. they are already a customer):
- Payment processing view uses the subscription ID from the user's plan profile to get the customer ID from that Stripe subscription within Stripe
- Payment processing view uses the customer ID from the user's plan profile to get the subscription ID from that Stripe customer object within Stripe
- Payment processing view compares the customer ID and subscription ID returned in the Stripe objects with the local customer and subscription IDs and makes sure they are the same (this confirms that we're working with the right customer and the right subscription, I think!), and makes sure that the customer has an active subscription by checking that the length of the subscriptions.data list is not 0.
- If **ANY** of the above is not true (e.g. customer doesn't have an active sub, or there is a conflict between the Stripe object IDs and the local customer/sub IDs):
- FAIL and return the user to the post payment view with an error that something is wro
**OMG;TIWTL;DR;FU (OMG, this is way too long, didn't read, F you): Can someone please help me work through the design/architecture of my payment system with Stripe? I think I have most of the pieces to the puzzle but I'm not sure how they fit together.**
-----------------------------
**Long Version:**
Hi there,
I'm going to try to make this as detailed but also as concise as possible. I am trying to tie up the loose ends on the Stripe subscription/recurring payment system for my web app before taking it live and I think I just need some help understanding exactly what the whole process should look like from a bird's eye view. If you've successfully integrated Stripe with Django before it will definitely help a lot in understanding the questions I have and your ability to provide answers. Ok, so here we go!
My current start to finish workflow from new user registration to payment is as follows, and this all works (though there are likely unforeseen bugs and holes in it, so please feel free to call them out):
**User Registration:**
- User uses standard django-registration form to register, an activation email is sent, and user clicks link in activation email to activate their account.
- Upon new user registration the following happens:
- A new user profile is created including a few extra fields that extend the default user model through a OneToOneField link
- A user PlanProfile is created, initializing them to the free plan, initializing the boolean premium_user field to False, and giving them a default "NA" value for stripeID and subscriptionID (These will be the stripe customer ID and subscription ID once they join a paid plan. Without a paid plan there is no need for them)
**Joining a Paid Plan:**
- Customer navigates to /plans/ and selects a payment plan
- Depending on which button they click (simple pricing tables), the appropriate StripeCheckout handler is configured and called via Javascript, and the form data (CC token, email address, name, plan type, etc) is submitted to the payment processing view /plans/processpayment/
- Payment processing view checks the user's plan profile to see if they have an existing Stripe customer ID **and** existing Stripe subscription ID. They **should** have both, or neither (at this point).
- If they do **NOT** have both (i.e. they are a new customer):
- A new Stripe customer is created, assuming there are no card/form validation errors
- A new subscription for that customer is created (assuming same)
- Assuming no errors from Stripe:
- The user's plan profile is updated, setting the premium_user field to True, and the stripeID and subID fields to the customer and subscription IDs returned from Stripe, respectively.
- The user is redirected to the post payment view saying thanks, reflecting their new subscription, confirmation email is sent from Stripe with a copy of their invoice
- If they **DO** have both (i.e. they are already a customer):
- Payment processing view uses the subscription ID from the user's plan profile to get the customer ID from that Stripe subscription within Stripe
- Payment processing view uses the customer ID from the user's plan profile to get the subscription ID from that Stripe customer object within Stripe
- Payment processing view compares the customer ID and subscription ID returned in the Stripe objects with the local customer and subscription IDs and makes sure they are the same (this confirms that we're working with the right customer and the right subscription, I think!), and makes sure that the customer has an active subscription by checking that the length of the subscriptions.data list is not 0.
- If **ANY** of the above is not true (e.g. customer doesn't have an active sub, or there is a conflict between the Stripe object IDs and the local customer/sub IDs):
- FAIL and return the user to the post payment view with an error that something is wro
ng. Make no changes to the account.
- If **ALL** of the above are true:
- Retrieve the customer from Stripe using the local customer ID
- Update the customer's name, email, and CC token with the new data from the form
- Create a new subscription with the new plan the user is signing up for and save the ID of it returned from Stripe, assuming no errors on the Stripe end (card errors, etc)
- Delete the customer's old subscription in Stripe, using the local subscription ID to look it up
- Again, assuming no errors from Stripe:
- The user's plan profile is updated, setting the premium_user field to True, and the stripeID and subID fields to the customer and subscription IDs (in this case the one we saved earlier) returned from Stripe, respectively.
- The user is redirected to the post payment view saying thanks, reflecting their new subscription, confirmation email is sent from Stripe with a copy of their invoice
So it **seems** like that all works. However, all that does is handle creating new subscriptions and (sort of) changing plans. The reason I say (sort of) with changing plans is that the changing plan logic is not good because it doesn't handle proration/refunds if a customer cancels in the middle of a plan period, price changes between plans, or if a customer just wants to cancel their plan entirely and go back to free. So I decided what I think I should do is, if a customer wants to change plans, they must first cancel their current one and then join the new one. This would essentially force them to delete their subscription, get a refund, wipe out both their local AND remote Stripe customer and subscription IDs, and then start fresh as a "new" customer. So on that venture, I decided to write a payment cancellation view. This is where I'm getting sort of lost.
It's easy enough to just pull the local customer ID from the database, confirm that it returns a valid Stripe object, get the subscription ID out of that object and then delete that subscription. Upon doing that a customer.subscription.deleted webhook event would be sent to my webhook view (which also works, BTW, though it doesn't currently do anything) which I feel like I can use somehow. Also, when I create a new subscription, or when a new charge is made on an existing subscription, there are various webhooks sent such as (in no particular order):
- customer.created
- customer.card.created
- charge.succeeded (or failed)
- invoice.created
- invoice.payment_succeeded (or failed)
- customer.subscription.created
- customer.updated
- *probably others along the way*
So if you've made it this far, I guess what I want to know is, how the hell do I tie this all together? I feel like I have the right pieces to the puzzle, and I've assembled the border, but the middle pieces are still all strewn about the table waiting to be put together. I think it would be best if we just leave the discussion open-ended rather than asking specific questions since it's tough for me to come up with any specific questions without really knowing what I need to know. So I guess I am looking for some discussion/help with how to structure the whole process. For example:
- How can I handle an existing subscription that gets charged the regular monthly payment? What should I do in the database?
- How should I handle cancelled subscriptions? Calculate refunds via webhooks and then issue a refund via the cancellation view, or code the webhook view to issue a refund whenever it receives a subscription.deleted event, or something else?
- Should my payment processing view interact with my webhooks at all, and if so, how? In other words does the error handling I'm doign already seem ok, or should I be using the webhooks to verify that stuff happened correctly on the Stripe end before making changes to the database, and if so, how can I halt the payment processing view along the way and check that various webhooks are coming in as expected? The webhook view is sort of an event listener so cu
- If **ALL** of the above are true:
- Retrieve the customer from Stripe using the local customer ID
- Update the customer's name, email, and CC token with the new data from the form
- Create a new subscription with the new plan the user is signing up for and save the ID of it returned from Stripe, assuming no errors on the Stripe end (card errors, etc)
- Delete the customer's old subscription in Stripe, using the local subscription ID to look it up
- Again, assuming no errors from Stripe:
- The user's plan profile is updated, setting the premium_user field to True, and the stripeID and subID fields to the customer and subscription IDs (in this case the one we saved earlier) returned from Stripe, respectively.
- The user is redirected to the post payment view saying thanks, reflecting their new subscription, confirmation email is sent from Stripe with a copy of their invoice
So it **seems** like that all works. However, all that does is handle creating new subscriptions and (sort of) changing plans. The reason I say (sort of) with changing plans is that the changing plan logic is not good because it doesn't handle proration/refunds if a customer cancels in the middle of a plan period, price changes between plans, or if a customer just wants to cancel their plan entirely and go back to free. So I decided what I think I should do is, if a customer wants to change plans, they must first cancel their current one and then join the new one. This would essentially force them to delete their subscription, get a refund, wipe out both their local AND remote Stripe customer and subscription IDs, and then start fresh as a "new" customer. So on that venture, I decided to write a payment cancellation view. This is where I'm getting sort of lost.
It's easy enough to just pull the local customer ID from the database, confirm that it returns a valid Stripe object, get the subscription ID out of that object and then delete that subscription. Upon doing that a customer.subscription.deleted webhook event would be sent to my webhook view (which also works, BTW, though it doesn't currently do anything) which I feel like I can use somehow. Also, when I create a new subscription, or when a new charge is made on an existing subscription, there are various webhooks sent such as (in no particular order):
- customer.created
- customer.card.created
- charge.succeeded (or failed)
- invoice.created
- invoice.payment_succeeded (or failed)
- customer.subscription.created
- customer.updated
- *probably others along the way*
So if you've made it this far, I guess what I want to know is, how the hell do I tie this all together? I feel like I have the right pieces to the puzzle, and I've assembled the border, but the middle pieces are still all strewn about the table waiting to be put together. I think it would be best if we just leave the discussion open-ended rather than asking specific questions since it's tough for me to come up with any specific questions without really knowing what I need to know. So I guess I am looking for some discussion/help with how to structure the whole process. For example:
- How can I handle an existing subscription that gets charged the regular monthly payment? What should I do in the database?
- How should I handle cancelled subscriptions? Calculate refunds via webhooks and then issue a refund via the cancellation view, or code the webhook view to issue a refund whenever it receives a subscription.deleted event, or something else?
- Should my payment processing view interact with my webhooks at all, and if so, how? In other words does the error handling I'm doign already seem ok, or should I be using the webhooks to verify that stuff happened correctly on the Stripe end before making changes to the database, and if so, how can I halt the payment processing view along the way and check that various webhooks are coming in as expected? The webhook view is sort of an event listener so cu
rrently it doesn't have any interaction with the payment processing view.
I'm sure more questions will come up along the way but if anyone has dealt with building this type of integration before I would greatly appreciate some guidance! I'm not really looking for specific answers with code but more of a general answer to the question "how the hell should all of this fit together so I don't destroy my database or charge my customers incorrectly?"
Whew, ok I'm done now. Let me know if you have any questions and THANK YOU!!!!
/r/django
https://redd.it/705dwa
I'm sure more questions will come up along the way but if anyone has dealt with building this type of integration before I would greatly appreciate some guidance! I'm not really looking for specific answers with code but more of a general answer to the question "how the hell should all of this fit together so I don't destroy my database or charge my customers incorrectly?"
Whew, ok I'm done now. Let me know if you have any questions and THANK YOU!!!!
/r/django
https://redd.it/705dwa
reddit
Help tying up loose ends on my payment system... • r/django
**OMG;TIWTL;DR;FU (OMG, this is way too long, didn't read, F you): Can someone please help me work through the design/architecture of my payment...
Those working in Machine Learning/Data Science in Europe, what are your salaries?
It would be great if we have more machine learning developers/ data scientists in [this survey](https://docs.google.com/forms/d/e/1FAIpQLScTh14SV6qbMvGrGz5-XQz0aGp04j5M4P_4ciaSOXsTBfzvGA/viewform) pulished in [HN](https://news.ycombinator.com/item?id=15088840) :)
/r/MachineLearning
https://redd.it/701j70
It would be great if we have more machine learning developers/ data scientists in [this survey](https://docs.google.com/forms/d/e/1FAIpQLScTh14SV6qbMvGrGz5-XQz0aGp04j5M4P_4ciaSOXsTBfzvGA/viewform) pulished in [HN](https://news.ycombinator.com/item?id=15088840) :)
/r/MachineLearning
https://redd.it/701j70
Google Docs
Developers Salaries
I am having problems estimating how much a developer actually earns in the European market. Seeing all those US salaries make me dizzy, but I know that is another universe, especially the Silicon Valley. I thought it would be great gather some numbers about…
Having some trouble with OCR, excel, scanned documents, and Adobe acrobat. Was directed here from r/excel.
We have these stacks of "tickets" (there are thousands of them) that are printed similarly to a receipt at a gas station. Sometimes there's handwriting in there between printed text that screws up the character recognition in Adobe acrobat pro. Adobe seems to have trouble even deciphering the printed ink text that is perfect.
The problem gets worse, the tickets aren't printed in an excel friendly format really. The are all the same format though and they are batch scanned in so theres probably 40-50 at least in each batch (pdf).
I need all this data in excel so I can check it for errors and discrepancies. I don't know the best way to do this (they were entering by hand before). Do I need a vba macro in excel or JavaScript in adobe? I think the best thing to do is to try to get the extract data I need from the specific areas of each type data only instead of using OCR on the whole ticket.
I also exported the whole tickets to Word and the OCR seemed to work better for that transfer for some reason. I thought it might be easier to transfer the data from word to excel instead of acrobat to excel.
If there are any other subs to post this to that might be helpful, I'd like to know. If I don't figure a way to do this soon I'll have type each ticket into excel by hand. Ill die from inefficiency.
I'm not an experienced programmer so something very complecated will not be easy for me. Thanks in advance.
Original post below.
https://www.reddit.com/r/excel/comments/7076lh/i_need_to_extract_data_from_scanned_pdfs_in_to
/r/Python
https://redd.it/707bxb
We have these stacks of "tickets" (there are thousands of them) that are printed similarly to a receipt at a gas station. Sometimes there's handwriting in there between printed text that screws up the character recognition in Adobe acrobat pro. Adobe seems to have trouble even deciphering the printed ink text that is perfect.
The problem gets worse, the tickets aren't printed in an excel friendly format really. The are all the same format though and they are batch scanned in so theres probably 40-50 at least in each batch (pdf).
I need all this data in excel so I can check it for errors and discrepancies. I don't know the best way to do this (they were entering by hand before). Do I need a vba macro in excel or JavaScript in adobe? I think the best thing to do is to try to get the extract data I need from the specific areas of each type data only instead of using OCR on the whole ticket.
I also exported the whole tickets to Word and the OCR seemed to work better for that transfer for some reason. I thought it might be easier to transfer the data from word to excel instead of acrobat to excel.
If there are any other subs to post this to that might be helpful, I'd like to know. If I don't figure a way to do this soon I'll have type each ticket into excel by hand. Ill die from inefficiency.
I'm not an experienced programmer so something very complecated will not be easy for me. Thanks in advance.
Original post below.
https://www.reddit.com/r/excel/comments/7076lh/i_need_to_extract_data_from_scanned_pdfs_in_to
/r/Python
https://redd.it/707bxb
reddit
I need to extract data from scanned pdfs in to excel... • r/excel
We have these stacks of "tickets" (there are thousands of them) that are printed similarly to a receipt at a gas station. Sometimes there's...
Loop like a native: while, for, iterators, generators
https://nedbatchelder.com/text/iter.html
/r/Python
https://redd.it/707e2p
https://nedbatchelder.com/text/iter.html
/r/Python
https://redd.it/707e2p
reddit
Loop like a native: while, for, iterators, generators • r/Python
11 points and 4 comments so far on reddit
PSA - Malicious software libraries in the official Python package repository (xpost /r/netsec)
http://www.nbu.gov.sk/skcsirt-sa-20170909-pypi/
/r/Python
https://redd.it/709vch
http://www.nbu.gov.sk/skcsirt-sa-20170909-pypi/
/r/Python
https://redd.it/709vch
Anyone have a high res version of the XKCD Python Antigravity Image?
Randall Munroe is giving a talk here in a couple of weeks and I'd like to get him to sign a copy.
https://xkcd.com/353/
I can't see it available to buy in the XKCD store. Can anyone please link me to a high res version?
/r/Python
https://redd.it/70a9n8
Randall Munroe is giving a talk here in a couple of weeks and I'd like to get him to sign a copy.
https://xkcd.com/353/
I can't see it available to buy in the XKCD store. Can anyone please link me to a high res version?
/r/Python
https://redd.it/70a9n8
xkcd
Python
Getting users to update or create
I seem to have got myself confused this morning, like one of those days you begin to question how to spell a simple word you should know well. Anyway...
What's the best way to handle users eg updating an address vs creating a new one?
This current app will have lots of other models tied to the user's address (services etc....), we want to be able to let them update their current address (eg fill in missing details or correct a mistake) or create a new address eg when they move house (or add an additional property).
From a users point of view they shouldn't have to care whether they are updating their current address or creating a new one (moving house) they just want to change their address.
What's the best way to handle this?
Debating if it should just be a single form which in the view uses create_or_update and then checks whatever is the unique property of the address?
Additionally what's the best way to have a unique property on an address?
I originally had `unique_together(house_name_or_number, postcode)` but it's better to have separate fields for `house_name` and `house_number`but now not sure how to create a unique identifier now they are separate? (eg to prevent adding properties that already exist).
/r/django
https://redd.it/708m2q
I seem to have got myself confused this morning, like one of those days you begin to question how to spell a simple word you should know well. Anyway...
What's the best way to handle users eg updating an address vs creating a new one?
This current app will have lots of other models tied to the user's address (services etc....), we want to be able to let them update their current address (eg fill in missing details or correct a mistake) or create a new address eg when they move house (or add an additional property).
From a users point of view they shouldn't have to care whether they are updating their current address or creating a new one (moving house) they just want to change their address.
What's the best way to handle this?
Debating if it should just be a single form which in the view uses create_or_update and then checks whatever is the unique property of the address?
Additionally what's the best way to have a unique property on an address?
I originally had `unique_together(house_name_or_number, postcode)` but it's better to have separate fields for `house_name` and `house_number`but now not sure how to create a unique identifier now they are separate? (eg to prevent adding properties that already exist).
/r/django
https://redd.it/708m2q
reddit
Getting users to update or create • r/django
I seem to have got myself confused this morning, like one of those days you begin to question how to spell a simple word you should know well. ...
Adding a "better" switch statement to Python (by abusing metaclasses)
https://github.com/tetrapus/switchcase
/r/Python
https://redd.it/70ax60
https://github.com/tetrapus/switchcase
/r/Python
https://redd.it/70ax60
GitHub
tetrapus/switchcase
switchcase - A "better" switch statement for Python
Learning jquery/ajax to develop frontend over django - advice from full-stack developers?
Hey guys,
I've been learning django for 2 months now, and learnt a crapload already. I'm developing my webapp while learning, and now I'd like to learn enough jquery/ajax to implement some basic stuff like better looking user forms, save buttons and opening pages on modals (I think that's how it's called).
But honestly, I'm intimidated by jquery, mainly by ajax, from what I've dug into so far. And there doesn't seem to be such a linear way to learn things like with django. Or it's because I'm starting.
I like to skip steps and go straight to the action, which sometimes is fine and sometimes makes things harder. My question is: should I learn jquery in a regular fashion, and if yes, from which resources?
/r/django
https://redd.it/70dhzc
Hey guys,
I've been learning django for 2 months now, and learnt a crapload already. I'm developing my webapp while learning, and now I'd like to learn enough jquery/ajax to implement some basic stuff like better looking user forms, save buttons and opening pages on modals (I think that's how it's called).
But honestly, I'm intimidated by jquery, mainly by ajax, from what I've dug into so far. And there doesn't seem to be such a linear way to learn things like with django. Or it's because I'm starting.
I like to skip steps and go straight to the action, which sometimes is fine and sometimes makes things harder. My question is: should I learn jquery in a regular fashion, and if yes, from which resources?
/r/django
https://redd.it/70dhzc
reddit
Learning jquery/ajax to develop frontend over django -... • r/django
Hey guys, I've been learning django for 2 months now, and learnt a crapload already. I'm developing my webapp while learning, and now I'd like to...
[AF]Setting up a version controlled build environment for several developers to access/build locally/push to live
Title mostly says it all, I want to set up a version controlled directory in which my flask app lives. I then want to be able to have all my developers use svn or git (my version control of choice still up in the air) to be able to sync that directory onto any machine they feel like working on. Within this app I want to have some kind of "build environment" (that's what I think it's called at least). At the end of the day I need something similar to Make like how I've seen 'make clean' to remove any artifacts 'make dev' to spin up a local webserver of the app and install the needed virtual env with required packages and finally a 'make install' that pushes it out to the production server and restarts apache.
Obviously make can do this, however after talking with an older coworker who lives and breathes by make, he had mentioned that it was totally overkill for what I am trying to do and that there are other more elegant solutions designed specifically for this process.
I have been searching over the past week to try and find some information about standard practices and basically what my options are to do this, but I can't find much of anything useful and I think it's because the term "build environment" may not be exactly the search I need.
If anyone can help point me in the right direction I would be greatly appreciative!
/r/flask
https://redd.it/70a95d
Title mostly says it all, I want to set up a version controlled directory in which my flask app lives. I then want to be able to have all my developers use svn or git (my version control of choice still up in the air) to be able to sync that directory onto any machine they feel like working on. Within this app I want to have some kind of "build environment" (that's what I think it's called at least). At the end of the day I need something similar to Make like how I've seen 'make clean' to remove any artifacts 'make dev' to spin up a local webserver of the app and install the needed virtual env with required packages and finally a 'make install' that pushes it out to the production server and restarts apache.
Obviously make can do this, however after talking with an older coworker who lives and breathes by make, he had mentioned that it was totally overkill for what I am trying to do and that there are other more elegant solutions designed specifically for this process.
I have been searching over the past week to try and find some information about standard practices and basically what my options are to do this, but I can't find much of anything useful and I think it's because the term "build environment" may not be exactly the search I need.
If anyone can help point me in the right direction I would be greatly appreciative!
/r/flask
https://redd.it/70a95d
reddit
[AF]Setting up a version controlled build environment... • r/flask
Title mostly says it all, I want to set up a version controlled directory in which my flask app lives. I then want to be able to have all my...
Its ok if I just replace SQLite settings with my Postgresql DB in a blank project?
Hi, Im struggling with this, the thing is everytime you create a Django project the settings by default works with SQLite. I have Postgresql locally and I just want to avoid using SQLite.
What I do is remove the SQLite settings by default and replace them with the ones I have with my local DB in Postgresql, but its so hard to setup my website on Heroku after doing this since it doesnt show up after typing heroku open.
I set everything else fine, I mean, I might be missing something of course but I avoid to setup few things that you usually do if you want SQLite for a local DB and Postgres in Server. There is no documentation about removing SQLite completely, what I see in many many tutorials and other sites, its that SQLite should be used for your local DB which is the thing I want to avoid and use Postgresql instead, locally and in a server(heroku). Seriously, its hilarious that there is not a single post about creating a django project and get rid of SQLite, I actually might do a post about it since nobody has done this before it seems lol.
Any tips? Sorry, Im kinda new to this, but really want to get rid of this issues to fully start working with Django.
/r/django
https://redd.it/70e3az
Hi, Im struggling with this, the thing is everytime you create a Django project the settings by default works with SQLite. I have Postgresql locally and I just want to avoid using SQLite.
What I do is remove the SQLite settings by default and replace them with the ones I have with my local DB in Postgresql, but its so hard to setup my website on Heroku after doing this since it doesnt show up after typing heroku open.
I set everything else fine, I mean, I might be missing something of course but I avoid to setup few things that you usually do if you want SQLite for a local DB and Postgres in Server. There is no documentation about removing SQLite completely, what I see in many many tutorials and other sites, its that SQLite should be used for your local DB which is the thing I want to avoid and use Postgresql instead, locally and in a server(heroku). Seriously, its hilarious that there is not a single post about creating a django project and get rid of SQLite, I actually might do a post about it since nobody has done this before it seems lol.
Any tips? Sorry, Im kinda new to this, but really want to get rid of this issues to fully start working with Django.
/r/django
https://redd.it/70e3az
reddit
Its ok if I just replace SQLite settings with my... • r/django
Hi, Im struggling with this, the thing is everytime you create a Django project the settings by default works with SQLite. I have Postgresql...
Jupyter Notebook 5.1.0 Released
https://groups.google.com/forum/#!topic/jupyter/jZu-4fhF1ss
/r/IPython
https://redd.it/70gs36
https://groups.google.com/forum/#!topic/jupyter/jZu-4fhF1ss
/r/IPython
https://redd.it/70gs36
Manipulating single bit values in python for compression?
Hi.
I have been reading about compression and decided to implement the Huffman coding for simple strings.
I have been able to write a program which does implement the algorithm by generating Huffman codes using strings of 0s and 1s. However, the problem with this is that this doesn't actually result in any compression as I am just representing Huffman codes as strings of 8 bit characters and not as the n-bit values they represent eg '010' is 8*3 bits in size instead of 3 bits (010) in size I would like.
My question is, is there a way to manipulate integers in python so I am working with just raw 1s and 0s instead of having to manipulate values as integers are represented this way in python? Or as python has arbitrary integer length, is this automatically done? Or does python just not allow this level of bit manipulation?
Any help is appreciated
/r/Python
https://redd.it/70hb4o
Hi.
I have been reading about compression and decided to implement the Huffman coding for simple strings.
I have been able to write a program which does implement the algorithm by generating Huffman codes using strings of 0s and 1s. However, the problem with this is that this doesn't actually result in any compression as I am just representing Huffman codes as strings of 8 bit characters and not as the n-bit values they represent eg '010' is 8*3 bits in size instead of 3 bits (010) in size I would like.
My question is, is there a way to manipulate integers in python so I am working with just raw 1s and 0s instead of having to manipulate values as integers are represented this way in python? Or as python has arbitrary integer length, is this automatically done? Or does python just not allow this level of bit manipulation?
Any help is appreciated
/r/Python
https://redd.it/70hb4o
reddit
Manipulating single bit values in python for compression? • r/Python
Hi. I have been reading about compression and decided to implement the Huffman coding for simple strings. I have been able to write a program...
List comprehension help
Can someone recommend a good blog post or videos to learn this concept. Thank you
/r/Python
https://redd.it/70hybi
Can someone recommend a good blog post or videos to learn this concept. Thank you
/r/Python
https://redd.it/70hybi
reddit
List comprehension help • r/Python
Can someone recommend a good blog post or videos to learn this concept. Thank you
[AF] Flask-Bootstrap + WTForms Layout Issue
Having some trouble with the layout of customized SelectMultipleField.
Here is what I'm seeing:
[Checkbox Form](https://image.ibb.co/bCJwZQ/Screen_Shot_2017_09_16_at_7_42_32_AM.png)
Need to figure out how to:
-Have the checkboxes not run into other form fields
-Remove the box outline from checkbox field
This seems to be a common way to create checkboxes in WTForms, but I haven't been able to find anyone having the same problem. Not sure if I should be looking to modify my code, the Bootstrap CSS files, or something else.
Here is the form code:
class CheckBox(SelectMultipleField):
widget=widgets.ListWidget(prefix_label=True)
option_widget=widgets.CheckboxInput()
class NumberForm(Form):
data = CheckBox(label='Choose an option', choices=data_choices)
email = TextField('What is your email?', validators=[Required()])
submit = SubmitField('Submit')
---
Here is how the form is called in the HTML template:
{% import "bootstrap/wtf.html" as wtf %}
...
{{ wtf.quick_form(form) }}
---
Can provide more detail if necessary, but wanted to keep it simple. Any help is much appreciated. Thanks
/r/flask
https://redd.it/70hbqy
Having some trouble with the layout of customized SelectMultipleField.
Here is what I'm seeing:
[Checkbox Form](https://image.ibb.co/bCJwZQ/Screen_Shot_2017_09_16_at_7_42_32_AM.png)
Need to figure out how to:
-Have the checkboxes not run into other form fields
-Remove the box outline from checkbox field
This seems to be a common way to create checkboxes in WTForms, but I haven't been able to find anyone having the same problem. Not sure if I should be looking to modify my code, the Bootstrap CSS files, or something else.
Here is the form code:
class CheckBox(SelectMultipleField):
widget=widgets.ListWidget(prefix_label=True)
option_widget=widgets.CheckboxInput()
class NumberForm(Form):
data = CheckBox(label='Choose an option', choices=data_choices)
email = TextField('What is your email?', validators=[Required()])
submit = SubmitField('Submit')
---
Here is how the form is called in the HTML template:
{% import "bootstrap/wtf.html" as wtf %}
...
{{ wtf.quick_form(form) }}
---
Can provide more detail if necessary, but wanted to keep it simple. Any help is much appreciated. Thanks
/r/flask
https://redd.it/70hbqy
Flask-APScheduler, does anyone have experience with using this? I keep running into an error.
Bascially, I start my app the first time, it runs, then I shut it down and start it again and I get a error:
apscheduler.jobstores.base.ConflictingIdError: 'Job identifier (job1) conflicts with an existing job'
It has to do with APscheduler trying to create the same jobid every time I run the app, but I am not sure how to fix this error.
Link to [SO](https://stackoverflow.com/questions/46242710/flask-apscheduler-conflicting-job-error) post.
/r/flask
https://redd.it/70byje
Bascially, I start my app the first time, it runs, then I shut it down and start it again and I get a error:
apscheduler.jobstores.base.ConflictingIdError: 'Job identifier (job1) conflicts with an existing job'
It has to do with APscheduler trying to create the same jobid every time I run the app, but I am not sure how to fix this error.
Link to [SO](https://stackoverflow.com/questions/46242710/flask-apscheduler-conflicting-job-error) post.
/r/flask
https://redd.it/70byje
Stack Overflow
Flask_APScheduler conflicting job error?
Not sure how to store a job on a database. Whenever I run my flask app it runs the first time and then when I shutdown the server and restart the app I get the error:
sqlalchemy.exc.IntegrityErro...
sqlalchemy.exc.IntegrityErro...
Django model design help
Hello,
I have a web app which I'm planning to monetize soon and I'm looking for a little guidance setting up the models. The payment system is Stripe. My current models are as follows:
**UserProfile (truncated for brevity):**
class UserProfile(models.Model):
yrs_experience = (
#Choices...
)
tradingstyles = (
#Choices...
)
analysisstyles = (
#Choices...
)
instruments = (
#Choices...
)
user = models.OneToOneField(User, on_delete=models.CASCADE)
location = models.CharField(max_length=30, blank=True)
birthdate = models.DateField(null=True, blank=True)
trading_style = models.CharField(max_length=30, choices=tradingstyles, default='NS')
analysis_style = models.CharField(max_length=30, choices=analysisstyles, default='NS')
instrument = models.CharField(max_length=30, choices=instruments, default='NS')
experience = models.CharField(max_length=10, choices=yrs_experience, default='NS')
def __str__(self): # __unicode__ for Python 2
return self.user.username
**PlanProfile (truncated for brevity):**
class PlanProfile(models.Model):
plans = (
#Choices...
)
user = models.OneToOneField(User, on_delete=models.CASCADE)
stripe_id = models.CharField(max_length=30, default='NA')
sub_id = models.CharField(max_length=30, default='NA')
is_premium = models.BooleanField(default=False)
plan_type = models.CharField(max_length=15, choices=plans, default='FREE')
def __str__(self): # __unicode__ for Python 2
return self.user.username
Currently when a customer signs up for a paid plan, the PlanProfile is updated to reflect the customer ID and subscription ID returned from Stripe, as well as setting the premium flag to true and setting their plan type so that I can manage access control within the views (via a few custom decorators). When a customer wishes to change plans, I currently have it set up so that they have to cancel their current one and then sign up for the new one. This works fine but on the Stripe end I'm executing it by deleting the subscription and the customer and setting the IDs in my DB back to 'NA' so when they sign up again it just makes a new call to Stripe and makes a new customer and subscription and then updates the DB again with the new IDs. Again that works great BUT when I delete the customer I lose their payment history, old invoices, old charges, old subscription history, etc. So, I'd like to get around that by adding a couple models to my own database and also I plan to implement an upgrade/downgrade system with Stripe as well as an alternative to cancelling/rejoining. Either way I'd like to keep the customer's payment history in my own database just for completeness so I'm looking for a little guidance with how I should build the additional models. The components I am guessing I'll want to keep from Stripe are:
- Invoices (which contain a customer ID, subscription ID, charge ID and invoice ID)
- Charges (I just want the charge ID so I have a record of past charges I guess)
- Subscriptions/subscription history for each customer(?) (Each one has an ID, and I can either change plans within the same ID or delete/recreate the subscription with a new ID/new plan in Stripe)
- Refunds (Issued if a customer cancels the sub before expiration, and is identified by a refund ID)
**Constraints:**
- Each customer can only have one subscription at a time
- Each charge is unique to a specific invoice
- An invoice may (not sure?) have multiple charges
- A subscription ID is unique to only one customer
- A charge is unique to a specific customer
- A refund is unique to a specific charge
- Possibly others I'm not thinking of...
So, I'm not a database designer and I'm not sure if/how I should design this. I'm trying to figure out which tables/models I need, e.g. a subscriptions table, a charges table, an invoices table, etc. I most likely don't need them all and would like to keep it as simple as possible. So, any insight on how you would do it?
Thanks!
/r/django
https://redd.it/70h6bo
Hello,
I have a web app which I'm planning to monetize soon and I'm looking for a little guidance setting up the models. The payment system is Stripe. My current models are as follows:
**UserProfile (truncated for brevity):**
class UserProfile(models.Model):
yrs_experience = (
#Choices...
)
tradingstyles = (
#Choices...
)
analysisstyles = (
#Choices...
)
instruments = (
#Choices...
)
user = models.OneToOneField(User, on_delete=models.CASCADE)
location = models.CharField(max_length=30, blank=True)
birthdate = models.DateField(null=True, blank=True)
trading_style = models.CharField(max_length=30, choices=tradingstyles, default='NS')
analysis_style = models.CharField(max_length=30, choices=analysisstyles, default='NS')
instrument = models.CharField(max_length=30, choices=instruments, default='NS')
experience = models.CharField(max_length=10, choices=yrs_experience, default='NS')
def __str__(self): # __unicode__ for Python 2
return self.user.username
**PlanProfile (truncated for brevity):**
class PlanProfile(models.Model):
plans = (
#Choices...
)
user = models.OneToOneField(User, on_delete=models.CASCADE)
stripe_id = models.CharField(max_length=30, default='NA')
sub_id = models.CharField(max_length=30, default='NA')
is_premium = models.BooleanField(default=False)
plan_type = models.CharField(max_length=15, choices=plans, default='FREE')
def __str__(self): # __unicode__ for Python 2
return self.user.username
Currently when a customer signs up for a paid plan, the PlanProfile is updated to reflect the customer ID and subscription ID returned from Stripe, as well as setting the premium flag to true and setting their plan type so that I can manage access control within the views (via a few custom decorators). When a customer wishes to change plans, I currently have it set up so that they have to cancel their current one and then sign up for the new one. This works fine but on the Stripe end I'm executing it by deleting the subscription and the customer and setting the IDs in my DB back to 'NA' so when they sign up again it just makes a new call to Stripe and makes a new customer and subscription and then updates the DB again with the new IDs. Again that works great BUT when I delete the customer I lose their payment history, old invoices, old charges, old subscription history, etc. So, I'd like to get around that by adding a couple models to my own database and also I plan to implement an upgrade/downgrade system with Stripe as well as an alternative to cancelling/rejoining. Either way I'd like to keep the customer's payment history in my own database just for completeness so I'm looking for a little guidance with how I should build the additional models. The components I am guessing I'll want to keep from Stripe are:
- Invoices (which contain a customer ID, subscription ID, charge ID and invoice ID)
- Charges (I just want the charge ID so I have a record of past charges I guess)
- Subscriptions/subscription history for each customer(?) (Each one has an ID, and I can either change plans within the same ID or delete/recreate the subscription with a new ID/new plan in Stripe)
- Refunds (Issued if a customer cancels the sub before expiration, and is identified by a refund ID)
**Constraints:**
- Each customer can only have one subscription at a time
- Each charge is unique to a specific invoice
- An invoice may (not sure?) have multiple charges
- A subscription ID is unique to only one customer
- A charge is unique to a specific customer
- A refund is unique to a specific charge
- Possibly others I'm not thinking of...
So, I'm not a database designer and I'm not sure if/how I should design this. I'm trying to figure out which tables/models I need, e.g. a subscriptions table, a charges table, an invoices table, etc. I most likely don't need them all and would like to keep it as simple as possible. So, any insight on how you would do it?
Thanks!
/r/django
https://redd.it/70h6bo
reddit
Django model design help • r/django
Hello, I have a web app which I'm planning to monetize soon and I'm looking for a little guidance setting up the models. The payment system is...