[Flask] Creating table only if its not created for user already

Anonymous Coder anonymouscodar at gmail.com
Wed Mar 8 03:25:06 EST 2017


Thanks for the recommendation and I am going to read and practice it
thoroughly.

I apologise to bother you all on and off and will make sure to go through
it line by line.

Thanks again.

On Tue, Mar 7, 2017 at 10:48 PM, Anthony Ford <ford.anthonyj at gmail.com>
wrote:

> I totally second the sentiment that the docs are good, as well as the book.
>
> Definitely take a few days or more to set down and work through some of
> the Flask & Flask-SQLAlchemy tutorials. Without that, you'll have a much
> harder time getting things going.
>
>
>
> Anthony Ford,
> KF5IBN,
> ford.anthonyj at gmail.com
>
> On Tue, Mar 7, 2017 at 3:56 PM, Corey Boyle <coreybrett at gmail.com> wrote:
>
>> FWIW, I think the official documentation is actually quite good.
>>
>> I also highly recommend the following book.
>>
>> http://a.co/0zFaCVl
>>
>> Pause whatever project you are currently working on (because your code
>> is probably a mess), and work through this book chapter by chapter.
>>
>> On Tue, Mar 7, 2017 at 12:30 PM, Anonymous Coder
>> <anonymouscodar at gmail.com> wrote:
>> > Thanks for help but all I am trying to do here is create a udemy clone
>> with
>> > some changes I would like my solution to have. Its not a job I am doing
>> it
>> > for myself. I like python and that's why I chose Flask.
>> >
>> > For your comment above, official documentation sucks that's why I have
>> no
>> > other option as this is my very first project.
>> > Thanks for help though, I will try it.
>> >
>> > Cheers.
>> >
>> > On Tue, Mar 7, 2017 at 4:21 PM, Ziirish <ziirish at ziirish.info> wrote:
>> >>
>> >> It would be better if you showed us some of your tries and/or error
>> >> messages.
>> >> Regarding the latest emails you sent it looks like you want us to do
>> your
>> >> job...
>> >>
>> >> Anyway, the "if" you are looking for is probably something like:
>> >>
>> >>
>> >>     package = Package.query.filter_by(
>> >>         student_id=student_id, stripe_id = customer.id,
>> >>         student_email=request.form['stripeEmail'], is_active=True,
>> >>         package_type='yearlyrec', subscription_id=subscription.id
>> >>     ).first()
>> >>
>> >>     if not package:
>> >>         package = Package(...)
>> >>         dbase.session.add(package)
>> >>         dbase.session.commit()
>> >>
>> >>
>> >>
>> >> * On Tuesday, March 07, 2017 at 04:01 PM +0000, Anonymous Coder
>> >> <anonymouscodar at gmail.com> wrote:
>> >> > I was trying to find a way to process/commit a model table for view
>> only
>> >> > if
>> >> > it doesn't exists already. But I couldn't find the way to do it. I
>> tried
>> >> > if/else but it doesn't create model at all if I try it that way.
>> >> > Following
>> >> > is view and I need to create sqlalchymy table only if it doesn't
>> exist
>> >> > alrady.
>> >> >
>> >> > @app.route('/yearlychargedrec', methods=['GET', 'POST'])
>> >> > def yearly_charged_rec():
>> >> >     if not user_authorized():
>> >> >         return redirect('/')
>> >> >
>> >> >     current_package = Package.query.all()
>> >> >
>> >> >     if request.method == 'POST':
>> >> >         data = get_profile_data(session['auth_token'])
>> >> >         profile_data = data['StudentProfile']
>> >> >         student =
>> >> > get_profile_data(session['auth_token'])['StudentProfile']
>> >> >
>> >> >         stripe_token = request.form['stripeToken']
>> >> >         email = request.form['stripeEmail']
>> >> >         customer = stripe.Customer.create(
>> >> >             email=email,
>> >> >             source=request.form['stripeToken']
>> >> >         )
>> >> >         try:
>> >> >             subscription = stripe.Subscription.create(
>> >> >                 customer=customer.id,
>> >> >                 plan="yearlyrec",
>> >> >             )
>> >> >             student_id = profile_data.id
>> >> >             student.stripe_customer_id = customer.id
>> >> >             student.stripe_subscription_id = subscription.id
>> >> >
>> >> >             package = Package(
>> >> >                 student_id=student_id,
>> >> >                 stripe_id = customer.id,
>> >> >                 student_email=request.form['stripeEmail'],
>> >> >                 is_active=True,
>> >> >                 package_type='yearlyrec',
>> >> >                 subscription_id=subscription.id
>> >> >             )
>> >> >             dbase.session.add(package)
>> >> >             dbase.session.commit()
>> >> >
>> >> >         except stripe.error.CardError as e:
>> >> >             body = e.json_body
>> >> >             err = body['error']
>> >> >
>> >> >     return render_template('/profile/charge/monthlycharge.html',
>> >> > current_package=current_package)
>> >> >
>> >> > Please advise.
>> >
>> >
>> >
>> > _______________________________________________
>> > Flask mailing list
>> > Flask at python.org
>> > https://mail.python.org/mailman/listinfo/flask
>> >
>> _______________________________________________
>> Flask mailing list
>> Flask at python.org
>> https://mail.python.org/mailman/listinfo/flask
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20170308/b530439b/attachment.html>


More information about the Flask mailing list