[web2py] Re: How to code efficiently for multiple database engines with Exceptions

2016-09-08 Thread Joe Barnhart
Hi Massimo --

Two issues...

1.  I use a Mac.  For whatever reason, psycopg2 does not "pip install" on a 
Mac.  I researched it for a day or so -- even AFTER having had it WORKING 
on my system until I "upgraded" to El Capitan and it all quit.  I am so 
done with psycopg2 because its installation is crap.

2.  The future belongs to pypy and psycopg2 doesn't work with it.  pg8000 
does.  There is a psycopg2.cffi but I don't know how mature it is.

It's all enough to make me want to switch to MySql!

-- Joe


On Wednesday, September 7, 2016 at 5:38:57 PM UTC-7, Massimo Di Pierro 
wrote:
>
> I strongly recommend you do not use pg8000. We always run into issues with 
> it. 
>
> pip install psycopg2
>
> Massimo
>
> On Wednesday, 7 September 2016 17:05:28 UTC-5, Joe Barnhart wrote:
>>
>> Sweet!  That's exactly what I'm looking for.  I was missing the 
>> db._adapter connection to pg8000 or whatever driver is used at the moment. 
>>  This should totally fix my wagon.
>>
>> -- Joe
>>
>>
>> On Wednesday, September 7, 2016 at 12:47:48 PM UTC-7, Anthony wrote:
>>>
>>> According to the Python DB API specification, there should be a common 
>>> set of exceptions , 
>>> and they should be exposed as attributes on the connection object 
>>> . 
>>> Therefore, you should be able to do something like:
>>>
>>> try:
>>> db.mytable.insert(**fields)
>>> except (db._adapter.driver.IntegrityError, db._adapter.driver.
>>> OperationalError) as e:
>>> pass
>>>
>>> The above should catch the IntegrityError and OperationalError of any DB 
>>> API compliant driver.
>>>
>>> Also, when making inserts or updates, if you don't care about the 
>>> specific exception but just want to catch any database errors, the DAL API 
>>> includes the following:
>>>
>>> db.mytable._on_insert_error = my_insert_error_handler
>>> db.mytable._on_update_error = my_update_error_handler
>>>
>>>
>>> Anthony
>>>
>>> On Wednesday, September 7, 2016 at 1:14:54 PM UTC-4, Joe Barnhart wrote:

 So my website runs under PostgresSQL today but will likely be switched 
 to MySql at some point in the future.  My problem isn't with the DAL -- it 
 performs fine for what it does, insulating me very well from the nuances 
 of 
 the SQL syntax for each engine.

 No, my problem comes from Exceptions.  Each database engine defines its 
 own Exceptions within its driver.  Even different drivers for the same 
 database engine (psycopg2 vs pg8000) come with different Exception trees. 
  If I want to be able to handle database exceptions (and who doesn't?) how 
 do I load and use the RIGHT set of Exceptions for each driver?

 When using the pg8000 driver for example, the Exceptions raised are all 
 of the form:  "gluon.contrib.pg8000.ProgrammingError" or some such.  
 Errors 
 from psycopg2 and the mysql drivers are similarly formed.  I can't even 
 use 
 this in a try-except block unless I first import gluon.contrib.pg8000.  
 The 
 same is true for exceptions from all other database engines.

 Should we "alias" these database errors into a consistent tree inside 
 web2py?  If we created a database exception tree inside web2py, and then 
 added to the database driver module a section that raised the 
 corresponding 
 web2py Exception whenever a database exception was triggered, then we 
 could 
 just catch ProgrammingError (from web2py) instead of 
 gluon.contrib.pg8000.ProgrammingError.

 Or, should I just put somewhere in the db definition of the models a 
 line like "import gluon.contrib.pg8000 as mydb" and then use 
 "mydb.ProgrammingError" throughout my code?  I suppose I'd need to repeat 
 this in every module I create, and I create a LOT of modules

 Anyway, is this a real problem or am I missing something obvious??

 -- Joe



-- 
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: Is it risky to smuggle variables into a Row object?

2016-09-08 Thread Joe Barnhart
Nobody is answering your question, so I'll take a crack at it.  Mind you, 
I'm not a contrib or anything, just an enthusiastic user so caveat emptor...

Rows objects are just a form of BasicStorage object, which makes accessing 
dictionary items easier with the attribute ("dot") syntax.  I've "smuggled" 
(love the metaphor) data items into rows many times.  Like, when I'm 
processing some of the fields into new values and I want to pass them along 
with the original data for display later.

But know that this is not a strictly supported use of Row.  It has a lot of 
magic that it can do, such as "delete_record" and "update_record", as well 
as the useful filtering and combining of Row objects via Rows containers. 
 Realize that some of this magic may break if you add your own stuff to the 
Row and then expect it to behave normally.

Another possibility is to create your own Storage object.  You can 
initialize a Storage object directly from a dictionary just by 
foo=Storage(mydict).  I recommend you spend some time in the web2py source 
code -- there is SO MUCH hidden in there that you will find it a constant 
source of amazement.  Get a IDE such as Wing or others -- it makes it easy 
to delve into the source of web2py because you can go straight to a class.

On Wednesday, September 7, 2016 at 2:55:31 PM UTC-7, Antonio Salazar wrote:

> I have a function that returns several rows object, and each row needs a 
> small list with valid workflow transitions.
>
> I feel the workflow transitions belong in a separate variable, but I tried 
> adding it to each row, and it works and doesn't appear to interfere with 
> database operations.
> Am I at risk of breaking something by adding elements to a row object?
>
>

-- 
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: Preserving objects sort order between controller and view

2016-09-08 Thread Peter
Some times you just have to laugh!

I have totally screwed things up (I have a backup but was hoping not to use 
it)

I dropped the invoice table and started getting this...
 table invoice already exists
on investigation the error, I discovered I had not included  a db.commit() 
after the drop

Found somewhere (athough a bit drastic) I could just delete the 
storage.sqlite and start afresh
So I deleted storage.sqlite and on refresh I got
*PicklingError: Can't pickle : attribute lookup 
__builtin__.instancemethod failed* 


On investigation I found I must have assigned a function to a session 
object so had a look back over some code from today
and sure enough there was one so changed that and now I'm getting
* no such table: main.auth_user*

  
I decided to follow your link as a distraction from all of above
https://www.w3.org/TR/2011/REC-CSS2-20110607/generate.html#generated-text 

The page fails to open, but wait, it gets better...
www.w3.org is not even responding to pings

Re your comment...

> Okay, we'll keep an eye out for a follow-up.  Perhaps there was a browser 
> glitch involved.

you are being very kind, I think in reality it's a Peter Glitch :-) but hey 
I'm learning!

I've given up (for today) *but I will be back! *
 

-- 
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: scheduler task_id assigned to multiple workers

2016-09-08 Thread Niphlod
what driver are you using to connect to mssql ? and what are the properties 
of the database ? (sp_helpdb dbname).
seems rather strange that a box that handles "over 20k a second" can't 
stand the pressure of an additional 20 (without the "k").

On Tuesday, September 6, 2016 at 5:19:30 PM UTC+2, Jason Solack wrote:
>
> we're handing over 20k a second, the odd thing is if i move the scheduler 
> to mysql the deadlocks stop.  The mysql box is much lower specs and we only 
> use for internal stuff so i don't want that to be final solution.  As far 
> as load balancing i'm refering to our actualy webserver.  We load balance 
> on 3 machines, and each machine has 3 worker processes running on it.  it 
> seems that those web2py processes lock the table and cause deadlocks
>
> On Tuesday, August 30, 2016 at 3:37:41 PM UTC-4, Niphlod wrote:
>>
>> if 24cores 200+ GB RAM is the backend, how many transactions per second 
>> is that thing handling ? 
>> I saw lots of ultrabeefy servers that were poorly configured, hence did 
>> have poor performances, but it'd be criminal to blame on the product in 
>> that case (also, one the person who configured it). 
>>
>> I run 10 workers on 3 frontends backed by a single 2cpu 4GB RAM mssql 
>> backend and have no issue at all, so, network connectivity hiccups aside, 
>> sizing shouldn't be a problem. 
>> Since we're talking my territory here (I'm a DBA in real life), my 
>> backend doesn't sweat with 1k batchreq/sec.
>> To put theory into real data, 10 idle workers consume roughly 18 
>> batchreq/sec with the default heartbeat. And from 5 to 10 transactions/sec. 
>> That's less than 1% of "pressure".
>>
>> You're referring here and there "when we are load balancing the 
>> server"... are you talking about the server where workers live or the 
>> server that holds the database ?
>>
>> On Tuesday, August 30, 2016 at 6:03:56 PM UTC+2, Jason Solack wrote:
>>>
>>> the machine is plenty big (24 cores and over 200gb of RAM)... another 
>>> note, when we use mysql on a weaker machine the deadlocks go away, so i 
>>> feel that this must be something related to MSSQL. Also it only happens 
>>> when we are load balancing hte server.   
>>>
>>> we have it set up so each of the 3 machines is running 4 workers. they 
>>> all have the same group name, is that the proper way to configure on a load 
>>> balanced setup?
>>>
>>> On Tuesday, August 30, 2016 at 11:48:42 AM UTC-4, Niphlod wrote:

 when the backend has orrible performances :D
 12 workers with the default heartbeat are easily taken care by a dual 
 core 4GB RAM backend (without anything beefy on top of that).

 On Tuesday, August 30, 2016 at 5:41:01 PM UTC+2, Jason Solack wrote:
>
> So after more investigation we are seeing that our load balanced 
> server with processes runnin on all three machines are causing a lot of 
> deadlocks in MSSQL. Have you seen that before?
>
> On Friday, August 19, 2016 at 2:40:35 AM UTC-4, Niphlod wrote:
>>
>> yep. your worker setup clearly can't stably be connected to your 
>> backend.
>>
>> On Thursday, August 18, 2016 at 7:41:38 PM UTC+2, Jason Solack wrote:
>>>
>>> so after some digging what i'm seeing is the sw.insert(...) is not 
>>> committing and the mybackedstatus is None, this happens 5 times and 
>>> then 
>>> the worker appears and almost instantly disappers.  There are no 
>>> errors.  i 
>>> tried manually doing a db.executesql but i'm having trouble getting 
>>> self.w_stats converted to something i can insert via sql.
>>>
>>> another things i'm noticing is my "distribution" in w_stats is 
>>> None...
>>>
>>> Any ideas as to why this is happening?
>>>
>>> On Thursday, August 18, 2016 at 12:21:26 PM UTC-4, Jason Solack 
>>> wrote:

 doing that now, what i'm seeing is some problems here:

 # record heartbeat
mybackedstatus = db(sw.worker_name == self
 .worker_name).select().first()
if not mybackedstatus:
sw.insert(status=ACTIVE, worker_name=self
 .worker_name,
  first_heartbeat=now, last_heartbeat=now,
  group_names=self.group_names,
  worker_stats=self.w_stats)
self.w_stats.status = ACTIVE
self.w_stats.sleep = self.heartbeat
mybackedstatus = ACTIVE

 mybackedstatus is consistently coming back as "None" i'm guessing 
 there is an error somewhere in that try block and the db commit is 
 being 
 rolled back

 i'm using MSSQL and nginx... currently upgrading web2py to see it 
 continues



 On Thursday, August 18, 2016 at 10:44:28 AM UTC-4, Niphlod wrote:
>
> turn on 

[web2py] Re: queue_task :: trouble with quoted json strings for pvars and args

2016-09-08 Thread Niphlod
queue_task just does json.dumps(vars)

https://github.com/web2py/web2py/blob/master/gluon/scheduler.py#L1483

the field is defined as 'text'

https://github.com/web2py/web2py/blob/master/gluon/scheduler.py#L813

IMHO it's an issue with the oracle driver.

On Thursday, September 8, 2016 at 8:14:49 PM UTC+2, Dave S wrote:
>
>
>
> On Thursday, September 8, 2016 at 6:27:15 AM UTC-7, Erwn Ltmann wrote:
>>
>> Hi Dave,
>>
>> thx for your response. I'm sorry, but it doesn't helps me. My problem 
>> concerning the usage of scheduler_task queueing. The web2py scheduler 
>> transforms automatically the dictionary parameter 'pvars' into a string 
>> represented JSON in order to save this value as VARCHAR2(512) into the vars 
>> column of database (oracle) table scheduler_task. So far so good. But IMHO 
>> with unnecessary quotes at begin and end. The scheduler part of web2py 
>> tried to read scheduler records and fails because this (damn) extra quotes.
>>
>> E.
>>
>>
> I don't use Oracle and I don't have JSON arguments for tasks (yet), so I 
> can't tell you if the "problem" is with the queue_task() call or with the 
> Oracle driver.  Niphlod is the Scheduler authority, having done the rewrite 
> of it.  I'm not sure who our local Oracle expert is.
>
> Does the error occur when you access vars[0] from your task (launched by 
> the Scheduler?)  Or does it occur when the Scheduler is trying to start up 
> your task?  Also, *are you accessing the Scheduler tables directly?  I 
> don't think you should be doing that* ... for one thing, that's an 
> implementation detail that's not an official API and is subject to change.  
> And I don't think it's needed, as your launched task is passed the args.
>
> /dps
> (edited for m-fassis)
>
>
> On Thursday, September 8, 2016 at 4:01:37 AM UTC+2, Dave S wrote:
>>>
>>>
>>>
>>> On Wednesday, September 7, 2016 at 5:30:49 PM UTC-7, Erwn Ltmann wrote:

 Hi, 

 I'm used to create a new task for example: 

 scheduler.queue_task( 
   "a_task", 
   pvars = dict(csid=row.id, csname=row.name, action=row.action), 
   ... 
 ) 

 In the past (version 2.10.1), everything was fine. Within the current 
 version (2.14.6) I have some trouble. See this code for example: 

 for row in db(db.scheduler_task.group_name == "agents").select( 
 db.scheduler_task.ALL): 
  ... 
  pvars = json.loads(row.vars) 

 ... will raise this exception: 

   ... 
   File "/usr/local/lib/python2.7/json/decoder.py", line 384, in 
 raw_decode 
 raise ValueError("No JSON object could be decoded") 
 ValueError: No JSON object could be decoded 

 The reason is a quoted string in column 'VARS' in table 
 'SCHEDULER_TASK' (no quotes in web2py's old version 2.10.1). 

 A new value for 'VARS' with quotes for example: 

 '{"action": "script", "csname": "list", "csid": 121}' 

 I can skip the quotes with a trick: 

 pvars = json.loads(row.vars[1:-1]) 

 But, it is not a general solution. The same problem appears for column 
 'ARGS' in scheduler.py when I process the tasks: 

   File "/export/home/armadm/dev01/release/web2py/gluon/scheduler.py", 
 line 311, in executor 
 args = _decode_list(loads(task.args)) 
   File "/usr/local/lib/python2.7/json/__init__.py", line 338, in loads 
 return _default_decoder.decode(s) 
   File "/usr/local/lib/python2.7/json/decoder.py", line 366, in decode 
 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
   File "/usr/local/lib/python2.7/json/decoder.py", line 384, in 
 raw_decode 
 raise ValueError("No JSON object could be decoded") 
 ValueError: No JSON object could be decoded 

 I use Oracle as database: 

 SQL> desc scheduler_task 
  Name  Null?Type 
  -  
  
  IDNOT NULL NUMBER 
  ... 
  ARGS  VARCHAR2(512) 
  VARS  VARCHAR2(512) 

 Any ideas? 

 Thx, Erwn 

>>>
>>> the vars field is a dict, with the var names as keys and the stuff you 
>>> want to pass as the values.  Both are strings.
>>>
>>> I use a single var in my code, the name is "where" and the value is a 
>>> path.  So I do
>>> if vars["where"]:
>>>mywhere = vars["where"]
>>>
>>>
>>> No stripping of quotes is needed to get the path.
>>>
>>> /dps
>>>
>>>

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

[web2py] Re: queue_task :: trouble with quoted json strings for pvars and args

2016-09-08 Thread Dave S


On Thursday, September 8, 2016 at 6:27:15 AM UTC-7, Erwn Ltmann wrote:
>
> Hi Dave,
>
> thx for your response. I'm sorry, but it doesn't helps me. My problem 
> concerning the usage of scheduler_task queueing. The web2py scheduler 
> transforms automatically the dictionary parameter 'pvars' into a string 
> represented JSON in order to save this value as VARCHAR2(512) into the vars 
> column of database (oracle) table scheduler_task. So far so good. But IMHO 
> with unnecessary quotes at begin and end. The scheduler part of web2py 
> tried to read scheduler records and fails because this (damn) extra quotes.
>
> E.
>
>
I don't use Oracle and I don't have JSON arguments for tasks (yet), so I 
can't tell you if the "problem" is with the queue_task() call or with the 
Oracle driver.  Niphlod is the Scheduler authority, having done the rewrite 
of it.  I'm not sure who our local Oracle expert is.

Does the error occur when you access vars[0] from your task (launched by 
the Scheduler?)  Or does it occur when the Scheduler is trying to start up 
your task?  Also, are you accessing the Scheduler tables directly?  I don't 
think you should be doing that ... for one thing, that's an implementation 
detail that's not an official API and is subject to change.  And I don't 
think it's needed, as your launched task is passed the args.

/dps

On Thursday, September 8, 2016 at 4:01:37 AM UTC+2, Dave S wrote:
>>
>>
>>
>> On Wednesday, September 7, 2016 at 5:30:49 PM UTC-7, Erwn Ltmann wrote:
>>>
>>> Hi, 
>>>
>>> I'm used to create a new task for example: 
>>>
>>> scheduler.queue_task( 
>>>   "a_task", 
>>>   pvars = dict(csid=row.id, csname=row.name, action=row.action), 
>>>   ... 
>>> ) 
>>>
>>> In the past (version 2.10.1), everything was fine. Within the current 
>>> version (2.14.6) I have some trouble. See this code for example: 
>>>
>>> for row in db(db.scheduler_task.group_name == "agents").select( 
>>> db.scheduler_task.ALL): 
>>>  ... 
>>>  pvars = json.loads(row.vars) 
>>>
>>> ... will raise this exception: 
>>>
>>>   ... 
>>>   File "/usr/local/lib/python2.7/json/decoder.py", line 384, in 
>>> raw_decode 
>>> raise ValueError("No JSON object could be decoded") 
>>> ValueError: No JSON object could be decoded 
>>>
>>> The reason is a quoted string in column 'VARS' in table 'SCHEDULER_TASK' 
>>> (no quotes in web2py's old version 2.10.1). 
>>>
>>> A new value for 'VARS' with quotes for example: 
>>>
>>> '{"action": "script", "csname": "list", "csid": 121}' 
>>>
>>> I can skip the quotes with a trick: 
>>>
>>> pvars = json.loads(row.vars[1:-1]) 
>>>
>>> But, it is not a general solution. The same problem appears for column 
>>> 'ARGS' in scheduler.py when I process the tasks: 
>>>
>>>   File "/export/home/armadm/dev01/release/web2py/gluon/scheduler.py", 
>>> line 311, in executor 
>>> args = _decode_list(loads(task.args)) 
>>>   File "/usr/local/lib/python2.7/json/__init__.py", line 338, in loads 
>>> return _default_decoder.decode(s) 
>>>   File "/usr/local/lib/python2.7/json/decoder.py", line 366, in decode 
>>> obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
>>>   File "/usr/local/lib/python2.7/json/decoder.py", line 384, in 
>>> raw_decode 
>>> raise ValueError("No JSON object could be decoded") 
>>> ValueError: No JSON object could be decoded 
>>>
>>> I use Oracle as database: 
>>>
>>> SQL> desc scheduler_task 
>>>  Name  Null?Type 
>>>  -  
>>>  
>>>  IDNOT NULL NUMBER 
>>>  ... 
>>>  ARGS  VARCHAR2(512) 
>>>  VARS  VARCHAR2(512) 
>>>
>>> Any ideas? 
>>>
>>> Thx, Erwn 
>>>
>>
>> the vars field is a dict, with the var names as keys and the stuff you 
>> want to pass as the values.  Both are strings.
>>
>> I use a single var in my code, the name is "where" and the value is a 
>> path.  So I do
>> if vars["where"]:
>>mywhere = vars["where"]
>>
>>
>> No stripping of quotes is needed to get the path.
>>
>> /dps
>>
>>

-- 
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: crud.delete and record versioning error

2016-09-08 Thread Dave S


On Thursday, September 8, 2016 at 2:50:54 AM UTC-7, Kirill Shatalaev wrote:
>
> So, is CRUD going to be deprecated?
>

That's been discussed in this forum.

The changelog doesn't discuss it, but way back in 1.99.1-1.99.2,
"- new SQLFORM.grid and SQLFORM.smartgrid (should replace crud.search and 
crud.select)"

Obviously the book is a a little behind, because in Chapter 7 (Forms and 
Validators) it is referred to as "a recent addition."

/dps


> вторник, 6 сентября 2016 г., 18:39:03 UTC+4 пользователь Massimo Di Pierro 
> написал:
>>
>> please do not use crud. it has not been supported in long time. just use 
>> db(...).delete()
>>
>>
>>

-- 
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: queue_task :: trouble with quoted json strings for pvars and args

2016-09-08 Thread Erwn Ltmann
Hi Dave,

thx for your response. I'm sorry, but it doesn't helps me. My problem 
concerning the usage of scheduler_task queueing. The web2py scheduler 
transforms automatically the dictionary parameter 'pvars' into a string 
represented JSON in order to save this value as VARCHAR2(512) into the vars 
column of database (oracle) table scheduler_task. So far so good. But IMHO 
with unnecessary quotes at begin and end. The scheduler part of web2py 
tried to read scheduler records and fails because this (damn) extra quotes.

E.

On Thursday, September 8, 2016 at 4:01:37 AM UTC+2, Dave S wrote:
>
>
>
> On Wednesday, September 7, 2016 at 5:30:49 PM UTC-7, Erwn Ltmann wrote:
>>
>> Hi, 
>>
>> I'm used to create a new task for example: 
>>
>> scheduler.queue_task( 
>>   "a_task", 
>>   pvars = dict(csid=row.id, csname=row.name, action=row.action), 
>>   ... 
>> ) 
>>
>> In the past (version 2.10.1), everything was fine. Within the current 
>> version (2.14.6) I have some trouble. See this code for example: 
>>
>> for row in db(db.scheduler_task.group_name == "agents").select( 
>> db.scheduler_task.ALL): 
>>  ... 
>>  pvars = json.loads(row.vars) 
>>
>> ... will raise this exception: 
>>
>>   ... 
>>   File "/usr/local/lib/python2.7/json/decoder.py", line 384, in 
>> raw_decode 
>> raise ValueError("No JSON object could be decoded") 
>> ValueError: No JSON object could be decoded 
>>
>> The reason is a quoted string in column 'VARS' in table 'SCHEDULER_TASK' 
>> (no quotes in web2py's old version 2.10.1). 
>>
>> A new value for 'VARS' with quotes for example: 
>>
>> '{"action": "script", "csname": "list", "csid": 121}' 
>>
>> I can skip the quotes with a trick: 
>>
>> pvars = json.loads(row.vars[1:-1]) 
>>
>> But, it is not a general solution. The same problem appears for column 
>> 'ARGS' in scheduler.py when I process the tasks: 
>>
>>   File "/export/home/armadm/dev01/release/web2py/gluon/scheduler.py", 
>> line 311, in executor 
>> args = _decode_list(loads(task.args)) 
>>   File "/usr/local/lib/python2.7/json/__init__.py", line 338, in loads 
>> return _default_decoder.decode(s) 
>>   File "/usr/local/lib/python2.7/json/decoder.py", line 366, in decode 
>> obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
>>   File "/usr/local/lib/python2.7/json/decoder.py", line 384, in 
>> raw_decode 
>> raise ValueError("No JSON object could be decoded") 
>> ValueError: No JSON object could be decoded 
>>
>> I use Oracle as database: 
>>
>> SQL> desc scheduler_task 
>>  Name  Null?Type 
>>  -  
>>  
>>  IDNOT NULL NUMBER 
>>  ... 
>>  ARGS  VARCHAR2(512) 
>>  VARS  VARCHAR2(512) 
>>
>> Any ideas? 
>>
>> Thx, Erwn 
>>
>
> the vars field is a dict, with the var names as keys and the stuff you 
> want to pass as the values.  Both are strings.
>
> I use a single var in my code, the name is "where" and the value is a 
> path.  So I do
> if vars["where"]:
>mywhere = vars["where"]
>
>
> No stripping of quotes is needed to get the path.
>
> /dps
>
>

-- 
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: crud.delete and record versioning error

2016-09-08 Thread Kirill Shatalaev
So, is CRUD going to be deprecated?

вторник, 6 сентября 2016 г., 18:39:03 UTC+4 пользователь Massimo Di Pierro 
написал:
>
> please do not use crud. it has not been supported in long time. just use 
> db(...).delete()
>
>
>

-- 
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] st_within example

2016-09-08 Thread Manuele Pesenti
Il 08/09/16 10:57, Gael Princivalle ha scritto:
> Hello.
>
> Could someone give me an example of the postgis st_within function?
>
> http://postgis.org/docs/ST_DWithin.html
>
> Model
> |
> db.define_table('places',Field('loc','geometry()'))
> |
> Where I insert 3 geoPoints:
> |
> geoPoint(1,1)geoPoint(3,2)geoPoint(6,5)
> |
>
> |
> query =db.places.loc.st_within(geoPoint(0,0),3)
> |
> geoPoint(0, 0) is my geometry 3 is the max. distance from this geometry
> |
> results =db(query).select(sp.id,sp.loc)
> |
> Ticket is:
> |
> st_within()takes exactly 2arguments (3given)
> |
|Hi Gael,
the st_within and st_dwithin are two different method, the second one is
the only you want now :)
|
>
> That's strange because I have 2 arguments:
> |
> geoPoint(0,0)3
> |
> Can someone give a hand? Thanks.
>
> -- 
> 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.


[web2py] st_within example

2016-09-08 Thread Gael Princivalle
Hello.

Could someone give me an example of the postgis st_within function?

http://postgis.org/docs/ST_DWithin.html

Model

db.define_table('places', Field('loc', 'geometry()'))

Where I insert 3 geoPoints:
geoPoint(1, 1)
geoPoint(3, 2)
geoPoint(6, 5)


query = db.places.loc.st_within(geoPoint(0, 0), 3)
geoPoint(0, 0) is my geometry
3 is the max. distance from this geometry

results = db(query).select(sp.id, sp.loc)

Ticket is:
st_within() takes exactly 2 arguments (3 given)

That's strange because I have 2 arguments:

geoPoint(0, 0)
3

Can someone give a hand?

Thanks.


-- 
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: Preserving objects sort order between controller and view

2016-09-08 Thread Dave S


On Wednesday, September 7, 2016 at 10:00:05 PM UTC-7, Peter wrote:
>
>
> Thanks for the response Dave,
>
> I haven't got the hang of this editor yet so I hope this doesn't appear as 
> a total mess...  
>
> My view code...
>
>  {{ line=0 }}
>  {{=inv_lines  }}
>  {{ for item in inv_lines: }}
>  {{ line+=1}}
>   
>  
> {{ =line   }}  
> {{ =item.start_time.date() }}  
> {{ =item.duration  }}  
> PAP{{ =item.person+1000   }}/ {{ =
> item.task_type }}/ {{ =item.title }}/ {{=item.task_status}}
>   € {{ =item.charge}}  
> {{ =button('edit' , 'edit_task' , (
> item.task.id)) }} 
> 
>  {{ pass }}
> O
>
> which is similar to your last example   
>

Looks good.  (I had a TABLE example on hand, too, but the LI was more 
compact)
 

> (however the  wrapper screws with my formatting by forcing bullet 
> points)
>
>
Footnote:  the   can be styled with list-style-image:none, or you can 
use an  to get your numbering back.

With the UL() and OL() helpers, you'd use the _class argument;  the web2py 
css files probably already have some appropriate classes defined.

 

> *The weird thing is the problem seems to be gone.   *
>

Good news!
 

>
> I set up some new transactions, out of sequence by datetime, like 
>
> 1st/Aug...  
> 23rd/Aug..  
> 7th/Aug...  
> 15th/Aug...  
>
> So these would have transaction table ids in sequence e.g. 5,6,7,8 
> respectively  
> When I run the view now (with these newly created transactions) it ignores 
> the id sequence and preserves the 'orderby=start_time'.  
>
> The old transactions that I was working are still there but currently not 
> available until I do some adjustments to let them   
> invoice again - so I will try them again tomorrow just to see if there was 
> something in there that I am missing.  
>
>
Okay, we'll keep an eye out for a follow-up.  Perhaps there was a browser 
glitch involved.

 

> Thanks again!
> Peter
>

/dps
 

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