[web2py] In praise of the lowly "nested_select"

2018-08-02 Thread Joe Barnhart
How did I not know about this gem earlier?

I've been resorting to executesql() for my heavy joins-within-joins queries 
because, well, I thought I had to.  The select join syntax doesn't do 
nested joins directly and I'd never heard of nested_select.

Wow, what a great tool!  I just make my sub-join its own select, make an 
alias for it (required to use it with "on") and then put it in another 
query.  It is a thing of beauty.  (Well, maybe I have low standards of 
beauty!)

This result is the equivalent of a very complex executesql() query:

def gettimes(self, mid, eid, stage):
assert mid and eid and stage
db = current.db
dbt,dbc,dbs,dbei,dbts,dbti = 
db.times,db.club,db.swimmer,db.event_index,db.time_std,db.time_std_info 
cols = [dbt[c] for c in 
['ord','rank','evt','heat','lane','age','stime','stage','id']]
cols += [dbc[c] for c in ['code','name','id']]
cols += [dbei[c] for c in 
['course','sex','distance','stroke','lower_age','upper_age']]
cols += [dbs[c] for c in ['id','first','last','mi','preferred']]
subq = db(dbts.id>0).nested_select(dbts.ALL,

join=dbti.on((dbti.id==dbts.id_info)&(dbti.id_lsc=='51')&(dbti.code=='Default')))
dbtt = subq.with_alias('dbtt')
cols += [dbtt[c] for c in ['name','next','time']]
q = (dbt.id_meet==mid)&(dbt.id_event==eid)&(dbt.stage==stage)
rows = db(q).select(*cols,cacheable=True,processor=self.as_list,
   join=[dbei.on(dbei.id==dbt.id_event),
 dbc.on(dbc.id==dbt.id_club),
 dbs.on(dbs.id==dbt.id_swim)],
   left=dbtt.on
((dbtt.event_code==dbei.code2)&(dbt.stime>0)

&(dbtt.lower_age<=dbt.age)&(dbtt.upper_age>=dbt.age)

&(dbtt.next=dbt.stime)))
return rows

To save creation of Rows I used the "processor" keyword and made a little 
processor that basically returns a list of nested dicts, just as the normal 
"as_list" would to to a set of Rows.  But it does it without creating the 
Rows first, saving time and memory.

@staticmethod
def as_list(rows, fields, colnames, blob_decode=True, cacheable = 
False):
from collections import defaultdict
rtn = list()
cols = [(f.tablename,f.name) for f in fields]
for row in rows:
d = defaultdict(dict)
for r,v in zip(cols,row):
d[c[0]][c[1]] = r
rtn.append(d)
return rtn

I'm pleased to get really good performance and still keep the power and 
generality of DAL.  This feature might deserve additional explanation in 
the book.

-- Joe

If you want to see the executesql version, hold your nose and peek below. 
 I'm sure it is ghastly and could be done much better.  There are two 
variants I was playing with, one that uses Rows and as_list and another 
which makes the list of nested dicts directly.

def gettimes2(self, mid, eid, stage):
db = current.db
dbt, dbc, dbs, dbei, dbts, dbti = db.times, db.club, db.swimmer, 
db.event_index, db.time_std, db.time_std_info
assert mid and eid and stage
table_alias = 
{'times':'dbt','club':'dbc','swimmer':'dbs','event_index':'dbei','time_std':'dbtt'}
colnames = 
['times.ord','times.rank','times.evt','times.heat','times.lane','times.age','times.stime','times.stage','times.id',
'club.code','club.name','club.id',

'event_index.course','event_index.sex','event_index.distance','event_index.stroke',
'event_index.lower_age','event_index.upper_age',

'swimmer.id','swimmer.first','swimmer.last','swimmer.mi','swimmer.preferred',
'time_std.name','time_std.next','time_std.time']
split_colnames = [fld.split('.') for fld in colnames]
rnames=['.'.join([table_alias[t],db[t][f]._rname]) for t,f in 
split_colnames]
sqlvars = dict(eid=eid, mid=mid, stage=stage, 
fields=','.join(rnames))
stmt = """
SELECT %(fields)s FROM sstimes.times dbt
JOIN ssdata.event_index dbei ON dbei.id=dbt.id_event
JOIN ssdata.club dbc ON dbc.id=dbt.id_club
JOIN sstimes.swimmer dbs ON dbs.id=dbt.id_swim
LEFT JOIN (
SELECT dbts.*,dbti.id_lsc FROM ssdata.time_std dbts 
JOIN ssdata.time_std_info dbti 
ON dbti.id=dbts.id_info AND dbti.id_lsc=51 AND 
dbti.code='Default'
) dbtt ON (
dbtt.event_code=dbei.code2 AND dbt.stime>0
AND dbtt.lower_age<=dbt.age AND dbtt.upper_age>=dbt.age
AND dbtt.next=dbt.stime
) WHERE dbt.id_meet=%(mid)s AND dbt.id_event=%(eid)s AND 
dbt.stage='%(stage)s'
"""
if False:
fields = [db[t][f] for t,f in split_colnames]
rtn = db.executesql(stmt%sqlvars, fields=fields).as_list()

[web2py] Re: Using cache.action in a module

2018-08-02 Thread Joe Barnhart
I developed a widget pattern that resembles the Auth class.  It returns a 
dictionary when you create at the controller level.  During the first 
creation of the widget (which is in a module) it builds structure and 
passes it out in a dict() to make the page.  Later when Ajax is called it 
bypasses the creation of the structure and just goes straight to the bit 
that returns json.

I guess I could cache it at the controller level.  But the incoming url is 
like "scheme://app/control/func/subfunc?vars...".  So I guess I'd parse it 
at the controller level and then apply caching only for 
"func/subfunc?vars..." which is the json-returning part.  I've not really 
used cache.action much and it has a ton of options.

But maybe I should bite the bullet and plan on using something like 
memcache or redis for this.  I realized that these json call backs are 
ideal to cache because their data is (a) relatively large (~50k), (b) 
relatively costly to get (~300ms), and (c) unchanging for all time and all 
users.  They depend only on the supplied vars for uniqueness.  When I cache 
them the app really pops!

-- Joe


On Wednesday, August 1, 2018 at 11:28:39 AM UTC-7, Anthony wrote:
>
> By the way, why do you want to use cache.action for a non-action? Even if 
> this is an Ajax request, can't you still decorate the action that receives 
> the request? If you only want to cache part of the generated response, then 
> why not just use current.cache.ram, etc.?
>
> Anthony
>
> On Wednesday, August 1, 2018 at 11:17:55 AM UTC-4, Anthony wrote:
>>
>> Sorry, didn't realize you were trying to decorate a method. cache.action 
>> is designed to cache controller actions, so it is not expecting to decorate 
>> any functions that take arguments (methods always take at least the self 
>> argument).
>>
>> On Wednesday, August 1, 2018 at 4:27:02 AM UTC-4, Joe Barnhart wrote:
>>>
>>> Ah, well.  It seems a bit beyond me.  I think it's failing because I'm 
>>> caching a bound instance method (i.e. has "self").  I get "wrapped+_f takes 
>>> no arguments, 1 given)".
>>>
>>> def lazy_cache_action(time_expire=DEFAULT_TIME_EXPIRE, cache_model=None,
>>>prefix=None, session=False, vars=True, lang=True,
>>>user_agent=False, public=True, valid_statuses=None,
>>>quick=None):
>>> def decorator(f, time_expire=time_expire, cache_model=cache_model, 
>>> prefix=prefix, 
>>> session=session, vars=vars, lang=lang, 
>>> user_agent=user_agent, public=public, 
>>> valid_statuses=valid_statuses, quick=quick):
>>> def g(*c, **d):
>>> from gluon import current
>>> return current.cache.action(time_expire, cache_model, 
>>> prefix, session, 
>>> vars, lang, user_agent, public, valid_statuses, 
>>> quick)(f)(*c, **d)
>>> g.__name__ = f.__name__
>>> return g
>>> return decorator
>>>
>>>
>>>
>>>
>>> On Wednesday, August 1, 2018 at 12:50:12 AM UTC-7, Joe Barnhart wrote:

 Oops, I meant of course;

 current.cache.action

 instead of

 current.cache




 On Wednesday, August 1, 2018 at 12:48:00 AM UTC-7, Joe Barnhart wrote:
>
> You're a fountain of ideas!  I missed that one in the book.
>
> I wonder if this would work.  Off to go try it...
>
> def lazy_cache_action(self, time_expire=DEFAULT_TIME_EXPIRE, 
> cache_model=None,
>prefix=None, session=False, vars=True, lang=True,
>user_agent=False, public=True, valid_statuses=None,
>quick=None):
> def decorator(f, time_expire, cache_model, prefix, session, vars, 
> lang,
>user_agent, public, valid_statuses, quick):
> def g(*c, **d):
> from gluon import current
> return current.cache(f, time_expire, cache_model, prefix, 
> session, vars,
> lang, user_agent, public, valid_statuses, 
> quick)(f)(*c, **d)
> g.__name__ = f.__name__
> return g
> return decorator
>
>
>
> On Tuesday, July 31, 2018 at 11:25:10 AM UTC-7, Anthony wrote:
>>
>> On Tuesday, July 31, 2018 at 1:57:46 AM UTC-4, Joe Barnhart wrote:
>>>
>>> I was wondering about this.  I tried to search the group but didn't 
>>> find anything relevant.  Took a look at the source code and it seemed 
>>> like 
>>> I could use in a module which is called to produce a string of 
>>> Javascript 
>>> on demand of an Ajax routine.
>>>
>>> Beforehand, I save the global "cache" var in my "current" object. 
>>>  Then I rename my method "content" to "__content__", and last I do this:
>>>
>>> def content(self):
>>> c = current.cache
>>> return c.action(cache_model=c.disk, 
>>> quick="VP")(self.__content__)()
>>>
>>> Seems to work.  Am I asking for trouble?  Is there anything I should 

[web2py] Re: Ubuntu web2py

2018-08-02 Thread Peter
No pressure! but Ubuntu 9.04 is unsupported at this stage and probably not 
even getting security updates.   
There may be good reason not to (e.g. impact on other apps/requirements) 
but I would recommend a fresh install of Ubuntu 18.04 LTS (or Linux Mint 18 
which is based on Ubuntu ) rather than running through a load of time 
consuming downloads and distribution updates.* If there is no good reason 
not to! * it's a relatively painless exercise, you can get your hands on a 
Live CD (usually found with Linux Magazines) or download the ISO and write 
it to a CD - loads of instructions out there.  

-- 
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: heroku, web2py and gunicorn

2018-08-02 Thread Peter

In case it's of any benefit.
Just installed LinuxMint 18 on my laptop, installed gunicorn from the 
software manager

python anyserver.py -s gunicorn
starting gunicorn on 127.0.0.1:8000...
[2018-08-03 02:09:42 +] [31660] [INFO] Starting gunicorn 19.4.5
[2018-08-03 02:09:42 +] [31660] [INFO] Listening at: http://127.0.0.1:8000 
(31660)
[2018-08-03 02:09:42 +] [31660] [INFO] Using worker: sync
[2018-08-03 02:09:42 +] [31665] [INFO] Booting worker with pid: 31665

web2py opens without issue...
2.14.6-stable+timestamp.2016.05.10.00.21.47 
(Running on gunicorn/19.4.5, Python 2.7.12)

I have some python dependencies to sort (after new install) before I can 
dig much deeper but, on a cursory look, apps with no missing dependencies 
appear to be working fine.
  

-- 
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: heroku, web2py and gunicorn

2018-08-02 Thread 黄祥
had you try to run the gunicorn itself (without using anyserver.py) and set 
the gunicorn config with the parameter you want (max-requests, timeout, 
etc) ? 

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: heroku, web2py and gunicorn

2018-08-02 Thread appjarbiz
Is there a syntax to pass gunicorn options like --timeout or --max-requests 
into the anyserver.py command line?

python anyserver.py -s gunicorn -i 0.0.0.0 -p $PORT --max-requests 1000 

adding the --max-requests to the command line doesn't get passed through.  
Thanks.






On Thursday, April 19, 2012 at 3:26:45 AM UTC-5, Rahul wrote:
>
> in that case, I'll try to find some information on this but on low 
> priority :(   and keep this testing on hold for some time. 
>
> Thanks Massimo.
>
> Sincerely, Rahul D
>
> On Wednesday, April 18, 2012 7:14:06 PM UTC+5:30, Massimo Di Pierro wrote:
>>
>> I experience the same issue but I have a different diagnoses. It is not 
>> ignoring -s (although it says it does). In fact it is calling the gunicorn 
>> method. The problem is that it fails when when creating an instance of the 
>> gunicorn server and I do not know way. In stead of going into the server 
>> loop is continue execution and reports a wrong error. That code comes from 
>> Bottle and I cannot find any documentation on the gunicorn web page on how 
>> to access it from API. 
>>
>> On Wednesday, 18 April 2012 03:14:48 UTC-5, Rahul wrote:
>>>
>>> I tried with the latest code in trunk - There seems to be some issue. It 
>>> ignores -s or --server= parameters. it always starts rocket server. Please 
>>> see the logs below. 
>>>
>>> *-bash-3.2$ python anyserver.py -s gunicorn*
>>> starting gunicorn on 127.0.0.1:8000...
>>> Usage: anyserver.py [options]
>>>
>>> anyserver.py: error: no such option: -s
>>>
>>> *-bash-3.2$ python anyserver.py --server=gunicorn*
>>> starting gunicorn on 127.0.0.1:8000...
>>> Usage: anyserver.py [options]
>>>
>>> anyserver.py: error: no such option: --server
>>>
>>>
>>> *-bash-3.2$ python anyserver.py -s gunicorn -i 72.3.247.225 -p 9065*
>>> starting gunicorn on 72.3.247.225:9065...
>>> Usage: anyserver.py [options]
>>>
>>>
>>> anyserver.py: error: no such option: -s
>>>
>>> *It only starts rocket server*=* This works for me but  
>>> only on rocket*
>>> -bash-3.2$ *python anyserver.py  gunicorn -i 72.3.247.225 -p 9065*
>>> starting *rocket on 72.3.247.225:9065 *...
>>>
>>> *-bash-3.2$ python anyserver.py --server="gunicorn" -i 72.3.247.225 -p 
>>> 9065*
>>> starting gunicorn on 72.3.247.225:9065...
>>> Usage: anyserver.py [options]
>>>
>>> *anyserver.py: error: no such option: --server*
>>>
>>> *-bash-3.2$ python anyserver.py -s "gunicorn" -i 72.3.247.225 -p 9065*
>>> starting gunicorn on 72.3.247.225:9065...
>>> Usage: anyserver.py [options]
>>>
>>> anyserver.py: error: no such option: -s
>>>
>>> ===Starts rocket ===
>>> *-bash-3.2$ python anyserver.py  "gunicorn" -i 72.3.247.225 -p 9065*
>>> *starting rocket on 72.3.247.225:9065...*
>>>
>>> Please suggest - 
>>>
>>> Thanks, 
>>>
>>> Sincerely, Rahul D. [www.flockbird.com]
>>> =
>>> On Tuesday, April 17, 2012 8:54:58 PM UTC+5:30, Massimo Di Pierro wrote:

 Can you try the anyserver in trunk? Looks like they changed some API.

 On Tuesday, 17 April 2012 05:43:51 UTC-5, Rahul wrote:
>
> Hi Massimo,
>  I did the typo in the "anyserver.py" file but now I am 
> getting this issue. 
>
> -bash-3.2$ *python anyserver.py -s gunicorn*
> starting gunicorn on 127.0.0.1:8000...
> Traceback (most recent call last):
>   File "anyserver.py", line 299, in 
> main()
>   File "anyserver.py", line 295, in main
> 
> run(options.server,options.ip,options.port,logging=options.logging,profiler=options.profiler)
>   File "anyserver.py", line 157, in run
> getattr(Servers,servername)(application,(ip,int(port)))
>   File "anyserver.py", line 129, in gunicorn
> gunicorn.arbiter.Arbiter(address, 4, app).run()
> TypeError: __init__() takes exactly 2 arguments (4 given)
> ===
> Same case for custom ip and port
> ===
> -bash-3.2$ *python anyserver.py -s gunicorn -i 72.3.247.225 -p 9065*
> starting gunicorn on 72.3.247.225:9065...
> Traceback (most recent call last):
>   File "anyserver.py", line 299, in 
> main()
>   File "anyserver.py", line 295, in main
> 
> run(options.server,options.ip,options.port,logging=options.logging,profiler=options.profiler)
>   File "anyserver.py", line 157, in run
> getattr(Servers,servername)(application,(ip,int(port)))
>   File "anyserver.py", line 129, in gunicorn
> gunicorn.arbiter.Arbiter(address, 4, app).run()
> TypeError: __init__() takes exactly 2 arguments (4 given)
>
> Please suggest what could be wrong. I am new to gunicorn and 
> anyserver. Also direct me to some quality documentation for anyserver.py 
>
>
> Thanks, 
> Sincerely,  Rahul D.
>
>
> On Friday, July 22, 2011 8:36:11 PM UTC+5:30, Massimo Di Pierro wrote:
>>
>> Hello everybody, 

Re: [web2py] Re: update multiple tables from one csv and get row id after update_or_insert

2018-08-02 Thread 'Matthew J Watts' via web2py-users
Many thanks for your help all, i'm slowly getting my head around it.
I'll post the code once it's finished in case anyone needs it in future

cheers

Matt

On Wed, Aug 1, 2018 at 7:41 AM, sandeep patel 
wrote:

> @Mattew J Watts,
> #Model
>
> db.define_table('person',
> Field('name'),
> Field('age'),
> Field('country'),
> format='%(name)s')
>
> db.define_table('thing',
>
>Field('person_id,'reference preson')
> Field('thing_name'),
> Field('value'),
> Field('location'))
>
> #controller
> def import_csv():
>  form = FORM(DIV(LABEL('file input',_for='exampleInputFile'
> ),INPUT(_type='file',_name='csvsheet',_id="exampleInputFile"),_class='
> from-group'),BUTTON('click',_type='submit',_class="btn btn-default"))
> if form.process().accepted:
> try:
> for i in csv.DictReader(request.vars.csvsheet.file):
> # db['things'].insert(person_id= db['person'].insert(**i)
> ,.)
> a = db['person'].insert(**i)
> db['things'].insert(person_id=a,.)
> except:
> form.errors.csvfile = 'Invalid file format.'
> return locals()
>
> Hope, this will help you!
>
> Best/
>
> On Wed, Aug 1, 2018 at 12:51 AM Anthony  wrote:
>
>> On Tuesday, July 31, 2018 at 2:24:51 PM UTC-4, pbreit wrote:
>>>
>>> I know db.thing.insert will return the ID of the newly created record
>>> and am pretty sure update_or_insert does as well. I'm not exactly sure how
>>> you would determine if an update or insert was performed (but perhaps you
>>> do not need to know?).
>>>
>>
>> Actually, update_or_insert does *not* return the ID in case of an
>> update. If you need the ID, then don't use update_or_insert but instead
>> write your own logic (the method is fairly simple -- see
>> https://github.com/web2py/pydal/blob/c954d1a22a0b83d90f728a4ab2daaa
>> 954e3f16c8/pydal/objects.py#L822).
>>
>> Anthony
>>
>> --
>> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/EIFyKq78le4/unsubscribe.
> To unsubscribe from this group and all its topics, 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.


[web2py] Re: Insert in DB inside action, which was called AJAX

2018-08-02 Thread Константин Комков
Thank you, problem was generator GENID_ABIT_VALIDATION_CODES is not defined.
I changed:
db_xml.abit_validation_codes.insert(A_EMAIL=email,V_CODE=validCode)
on:
db_xml.executesql("""INSERT INTO abit_validation_codes (A_EMAIL,V_CODE) 
VALUES ('{0}','{1}') RETURNING id""".format(email,validCode))
and all work!

Maybe, you take advice here 
.



четверг, 2 августа 2018 г., 16:21:11 UTC+3 пользователь Anthony написал:
>
> Remove the try/except, and when you get the error, go to admin and view 
> the error ticket -- report here with the traceback. Also, show the database 
> model.
>
> Anthony
>
> On Thursday, August 2, 2018 at 9:09:36 AM UTC-4, Константин Комков wrote:
>>
>> I don't understand why the variable "CodeInDB" == False.
>> Controller:
>> def VcodeToDbAndMail():
>> form = SQLFORM(db_app.post)
>> if form.accepts(request, formname=None):
>> email=request.vars.email.strip()
>> validCode = random.randint(100,999)
>> CodeInDB = True
>> try:
>> 
>> db_xml.abit_validation_codes.insert(A_EMAIL=email,V_CODE=validCode)
>> db_xml.commit()
>> except Exception:
>> CodeInDB = False
>> return XML(""+str(CodeInDB)+"")
>> elif form.errors:
>> return TABLE(*[TR(k, v) for k, v in form.errors.items()])
>> >> False
>>
>> In DataBase I saw new record with my email and code.
>> If I do it witout "try ... except ...", I have error: "An error occured, 
>> please reload the page".
>>
>>

-- 
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] web2py book on github or web

2018-08-02 Thread 黄祥
seems the web2py book is updated in github 
 but not in http://web2py.com/books 
it means that better to read the book from github or what ?

thx n 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: How to hide parameter in link using url

2018-08-02 Thread Anthony
You could store the item in the session.

Anthony

On Thursday, August 2, 2018 at 8:44:49 AM UTC-4, isi_jca wrote:
>
> Hi
>
> When redirecting using  
> href=URL('abmpersona','ficha',args=(ls_verificador) from a controller
>
> I get this link
>
>
> https://www.dominio.com.ar/miapp/abmpersona/ficha/8630002323323238310
>
>
> How can I hide this parameter (8630002323323238310)?. Is there 
> another mechanism that I can use?.
>
> Thanks and greetings
>

-- 
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: Insert in DB inside action, which was called AJAX

2018-08-02 Thread Anthony
Remove the try/except, and when you get the error, go to admin and view the 
error ticket -- report here with the traceback. Also, show the database 
model.

Anthony

On Thursday, August 2, 2018 at 9:09:36 AM UTC-4, Константин Комков wrote:
>
> I don't understand why the variable "CodeInDB" == False.
> Controller:
> def VcodeToDbAndMail():
> form = SQLFORM(db_app.post)
> if form.accepts(request, formname=None):
> email=request.vars.email.strip()
> validCode = random.randint(100,999)
> CodeInDB = True
> try:
> 
> db_xml.abit_validation_codes.insert(A_EMAIL=email,V_CODE=validCode)
> db_xml.commit()
> except Exception:
> CodeInDB = False
> return XML(""+str(CodeInDB)+"")
> elif form.errors:
> return TABLE(*[TR(k, v) for k, v in form.errors.items()])
> >> False
>
> In DataBase I saw new record with my email and code.
> If I do it witout "try ... except ...", I have error: "An error occured, 
> please reload the page".
>
>

-- 
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] Insert in DB inside action, which was called AJAX

2018-08-02 Thread Константин Комков
I don't understand why the variable "CodeInDB" == False.
Controller:
def VcodeToDbAndMail():
form = SQLFORM(db_app.post)
if form.accepts(request, formname=None):
email=request.vars.email.strip()
validCode = random.randint(100,999)
CodeInDB = True
try:

db_xml.abit_validation_codes.insert(A_EMAIL=email,V_CODE=validCode)
db_xml.commit()
except Exception:
CodeInDB = False
return XML(""+str(CodeInDB)+"")
elif form.errors:
return TABLE(*[TR(k, v) for k, v in form.errors.items()])
>> False

In DataBase I saw new record with my email and code.
If I do it witout "try ... except ...", I have error: "An error occured, 
please reload the page".

-- 
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] How to hide parameter in link using url

2018-08-02 Thread isi_jca
Hi

When redirecting using  href=URL('abmpersona','ficha',args=(ls_verificador) 
from a controller

I get this link

https://www.dominio.com.ar/miapp/abmpersona/ficha/8630002323323238310


How can I hide this parameter (8630002323323238310)?. Is there 
another mechanism that I can use?.

Thanks and greetings

-- 
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.