[web2py] Re: Visual Studio Code and debugging

2017-03-25 Thread Ty oc
You have 2 options, first is to optne the full web2py with applications 
directory and open web2py script and hit run (with internal console, 
external and so on should work)

Or setup remote debugging 
https://donjayamanne.github.io/pythonVSCodeDocs/docs/debugging_remote-debugging/

basically you need to install python -m pip install  ptvsd and then in for 
example db.py put the two lines

import ptvsd
ptvsd.enable_attach("my_secret", address = ('0.0.0.0', 3000))



and that will be it... Im just testing now, but I guess any of the two 
should work





El miércoles, 22 de marzo de 2017, 5:34:17 (UTC-6), Andrea Fae' escribió:
>
> I tried to use Visual Studio Code like IDE for debugging web2py programs.
>
> In the launch.json I inserted this:
> {
> "name": "Web2py",
> "type": "python",
> "request": "launch",
> "stopOnEntry": true,
> "pythonPath": "${config.python.pythonPath}",
> "program": "${workspaceRoot}/../../web2py.py",
> "args": [
> ], 
> "cwd": "${workspaceRoot}",
> "debugOptions": [
> "WaitOnAbnormalExit",
> "WaitOnNormalExit",
> "RedirectOutput"
> ]
> }
>
>
> I installed Python 0.6.0 extension from Don Jayamanne.
> But if I fix some breakpoints the program doesn't stop...why?
> I'd like to use Visual Studio Code to debug my web2py programs...
>
> Moreover, anyone knows if there is a free easy IDE to use as debugger for 
> web2py? Can I have any information?
>
> Thank you
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: A delete record button

2017-03-25 Thread 黄祥
i think you can use A callback or onclick with jQuery.post()
e.g. put it on views
{{=A(I(_class = 'glyphicon glyphicon-remove-sign'), callback = 
URL(link_callback, args = id) ) }}
or
{{=A(I(_class = 'glyphicon glyphicon-remove-sign'), _onclick = 
"jQuery.post('%s')" % URL(link_callback, args = id) ) }}

best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] A delete record button

2017-03-25 Thread r
So I have a comment system and I want to have a delete button to delete the 
linked review. If a user (admin) clicks on this button the review is 
deleted. I have read about using CRUD and SQLFORMS deletable, but I want 
this not as a form but as a button.

How would I do so?

Controller:
def view():
{some code for displaying some parts of page here}
rows = db(db.comment.id == request.vars.commentNumber).select()
return locals()

View:
{ some code for displaying page here}
{{for row in rows:}}
"{{=row.reviewsTitle}}" {{=row.date}}Delete
 {{=row.reviewsText}}
{{pass}}

Example of comment:
"Good work" 2017-02-25 Delete
descriptionhere
"I like itk" 2016-03-25 Delete
descriptionhere

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: put function on models or modules

2017-03-25 Thread 黄祥
i mean that callback function is called when i hit the default/user login 
screen
btw, your explaination about login_onfail is clear enough, but when compare 
to the 2nd example, i've bit confused :
assuming the login_onfail is the callback function and not executed when 
it's hit login screen (not login yet), so why _before_insert function is 
executed, when i call the controller (e.g. SQLFORM.grid(db.person) )? 
just call the controller, not add the record yet.
yes, the lazy_tables = True in models/db.py 

thanks and best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: Using Stripe's Checkout w/ web2py

2017-03-25 Thread Mathieu Clabaut
I use the attached modules/stripeform.py, which is mostly based upon the
contrib/stripe.py
It imports the python stripe module :
https://github.com/stripe/stripe-python.git

I use it like :

@auth.requires_login(otherwise=lambda: helper.flash(
T("You need to log in to extend your subscription")))def buy():
from stripeform import clean_stripe_session
clean_stripe_session() #To prevent reuse of idempotent uuid for
stripe transactions
form = SQLFORM.factory(
   # snipped …
)
form = form.process(keepvalues=True)
if form.accepted:
   # error logic
else:
session.buyvars = form.vars
redirect(URL('pay'))
elif form.errors: # pragma: no branch
response.flash = T('form has errors')
return dict(form=form)
@auth.requires_login(otherwise=lambda: helper.flash(
T("You need to log in to extend your subscription")))def pay():
if not session.buyvars:
redirect(URL('buy'))
from stripeform import StripeForm
total = # TODO calculate total from session.buyvars content
cart_form = TABLE(# snipped : table displaying what is buyed (from
session.buyvars
  )
payment_id = db.payments.insert(amount=total)
form = StripeForm(
pk=STRIPE_PUBLISHABLE_KEY,
sk=STRIPE_SECRET_KEY,
amount=total,  # (amount is in cents)
currency='eur',
currency_symbol='€',
description="…",
more = { 'metadata': {'payment_id':payment_id}}
).process()

if form.accepted:
pi = form.response
from datetime import datetime
import pytz
db.payments[payment_id]= dict(…) # Update db with buyed items
if necessary
session.flash = T("Thank you!")
redirect(URL(c='default', f='index'))
elif form.errors: # pragma: no branch
response.flash = form.response.errors
del db.payments[payment_id]
return dict(cart_form=cart_form, form=form)

And the views for pay looks like:

{{extend 'layout.html'}}

   
  {{=T("Payment")}}
  
 {{=T("Cart Content")}}
 
{{=cart_form}}
 
  
  
 {{=form}}
  
…

On Thu, Mar 23, 2017 at 8:47 PM Joe Barnhart joe.barnh...@gmail.com
 wrote:

I use Stripe all the time.  My sites (web2py and rails) have charged over
> $10M thru stripe so I'd have to say it works pretty well.
>
> My favorite way to use it is to use their Javascript pop-up box, which
> prevents any CC info from even getting into my server logs.  I actually
> started using it before the stripe.py contrib, so I haven't used the
> contrib library very much.
>
> I'll look over the question here and post later when I have a minute.
>
> --- Joe B.
>
>
> On Tuesday, March 21, 2017 at 8:19:21 PM UTC-7, Scott Hunter wrote:
>
> Has anyone been able to use Stripe's Checkout with web2py?  If so, how did
> you do it?  I'm having trouble getting the token it generates back.
>
> - Scott
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
​

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import logging
import urllib
from hashlib import sha1

import gluon.contrib.simplejson
from gluon.storage import Storage
from gluon.html import DIV, A, P, XML, INPUT

import stripe


logger = logging.getLogger("web2py.app.foundit.stripeform")
logger.setLevel(logging.DEBUG)

def clean_stripe_session():

from gluon import current
current.session.stripe_uuid = None

class Stripe:
"""
Use in WEB2PY (guaranteed PCI compliant)

def pay():
from gluon.contrib.stripe import StripeForm
form = StripeForm(
pk=STRIPE_PUBLISHABLE_KEY,
sk=STRIPE_SECRET_KEY,
amount=150, # $1.5 (amount is in cents)
description="Nothing").process()
if form.accepted:
payment_id = form.response['id']
redirect(URL('thank_you'))
elif form.errors:
redirect(URL('pay_error'))
return dict(form=form)

Low level API:

key=''
d = Stripe(key).charge(
   amount=100, # 1 dollar
   currency='usd',
   description='test charge')
print d
   

[web2py] Re: put function on models or modules

2017-03-25 Thread Anthony
What do you mean by the word "loaded"? Are you expected these functions to 
be executed? They are callback functions that are only executed in 
particular cases. For example, login_onfail will only be executed upon a 
failed login attempt. A table's on_define will be executed when it is fully 
defined (not when initially created if lazy tables are enabled), but 
_before_insert will only be executed when you actually try to insert a 
record.

Anthony

On Saturday, March 25, 2017 at 9:07:20 AM UTC-4, 黄祥 wrote:
>
> just curious what happen when i put function def or lambda on models when 
> running web2py with profiler
> *e.g. 1*
> *models/db.py*
> # login onfail create new record on auth_event
> def login_onfail(form):
> username = request.vars.username
> row = db((db.auth_user.username == username ) ).iterselect(cache = 
> cache_db, 
>   cacheable = True).first()
> if row is not None:
> test_event.onfail_event(row.id, row.username)
>
> auth.settings.login_onfail.append(login_onfail)
>
> why this is not loaded when hit defaults/user (not trying to login yet) 
> (checked during running snakeviz) ?
>
> *e.g. 2*
> *models/db.py*
> def before_insert_person(f):
> if f['auth_user']:
> query_auth_user = (db.auth_user.id == f['auth_user'] )
> row_auth_user = db(query_auth_user).iterselect(cache = (cache.ram, 3600), 
>   cacheable = True).first()
> f['username'] = row_auth_user.username
> f['first_name'] = row_auth_user.first_name
> f['last_name'] = row_auth_user.last_name
> f['email'] = row_auth_user.email
>
> def on_define_person(table): 
> #table._before_insert.append(test_define_table.before_insert_person)
> table._before_insert.append(before_insert_person)
>
> db.define_table('person', 
> Field('is_auth', 'boolean'),
> Field('auth_user', 'reference auth_user'), 
> Field('username'), 
> Field('first_name'), 
> Field('last_name'), 
> Field('email', 'list:string'), 
> on_define = on_define_person, 
> format = lambda r: '%s %s' % (r.first_name, r.last_name) )
>
> when checked during running snakeviz :
> 1. why before_insert_person is loaded when put it on models, and not 
> loaded when put it on modules?
> 2. why on_define is loaded whether put it on models or modules?
>
> any idea or explaination about that?
>
> thanks and best regards,
> stifan
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: web2pyslices

2017-03-25 Thread Marlysson Silva
Awesome.  This is in github?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] put function on models or modules

2017-03-25 Thread 黄祥
just curious what happen when i put function def or lambda on models when 
running web2py with profiler
*e.g. 1*
*models/db.py*
# login onfail create new record on auth_event
def login_onfail(form):
username = request.vars.username
row = db((db.auth_user.username == username ) ).iterselect(cache = 
cache_db, 
  cacheable = True).first()
if row is not None:
test_event.onfail_event(row.id, row.username)

auth.settings.login_onfail.append(login_onfail)

why this is not loaded when hit defaults/user (not trying to login yet) 
(checked during running snakeviz) ?

*e.g. 2*
*models/db.py*
def before_insert_person(f):
if f['auth_user']:
query_auth_user = (db.auth_user.id == f['auth_user'] )
row_auth_user = db(query_auth_user).iterselect(cache = (cache.ram, 3600), 
  cacheable = True).first()
f['username'] = row_auth_user.username
f['first_name'] = row_auth_user.first_name
f['last_name'] = row_auth_user.last_name
f['email'] = row_auth_user.email

def on_define_person(table): 
#table._before_insert.append(test_define_table.before_insert_person)
table._before_insert.append(before_insert_person)

db.define_table('person', 
Field('is_auth', 'boolean'),
Field('auth_user', 'reference auth_user'), 
Field('username'), 
Field('first_name'), 
Field('last_name'), 
Field('email', 'list:string'), 
on_define = on_define_person, 
format = lambda r: '%s %s' % (r.first_name, r.last_name) )

when checked during running snakeviz :
1. why before_insert_person is loaded when put it on models, and not loaded 
when put it on modules?
2. why on_define is loaded whether put it on models or modules?

any idea or explaination about that?

thanks and best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Should html input helpers inject a newline in value param

2017-03-25 Thread 'Yan Wong' via web2py-users
When using the web2py TEXTAREA html helper, I was caught out when 
displaying text that has an initial newline. This is incorrectly displayed 
when setting e.g. TEXTAREA(value="\n\nhello"), since the HTML 4 spec 
(http://www.w3.org/TR/WD-html40-970917/struct/text.html) says "A line break 
occurring immediately following a start tag must be ignored, as must a line 
break occurring immediately before an end tag.". There is some discussion 
of this WRT html 5 in a RoR issue: https://github.com/rails/rails/issues/393

Should web2py inject a newline into the html output between textarea tags 
in this case? It seems from the spec that it should also inject a trailing 
one, but I can't get this to work.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.