Re: [web2py] DAL read and variables

2014-01-18 Thread DAL read and variables
First, thank you very much for your help. The first solution works perfect 
:)

But i have some issues with the ongoing ones, i'm afraid

def ausgabe():
   a = 4
   records = SQLTABLE(dba(dba.person._id== 
a).select(dba.person.name),headers='fieldname:capitalize')
   newvariable = records[0].name
   return dict(records=records)

when i enter your code, it returns an error when i call it:



AttributeError: 'THEAD' object has no attribute 'name'



Am Freitag, 17. Januar 2014 22:13:12 UTC+1 schrieb Michele Comitini:

 My attempts to help inline below.


 2014/1/14 DAL read and variables trendhhcf...@googlemail.comjavascript:
 

 Hi guys,

 this question is about tree things at once.
 The first on is as follow:
 I have this code:

 [code]

 in the models (not so importantthis part works fine):

 dba = DAL('mysql://web2py:test@localhost/testdb')
 dba.define_table('person', Field('name', requires=IS_NOT_EMPTY()), 
 Field('email', requires=IS_NOT_EMPTY()))


 in the controller:


 def index():
 a = 'Hallo Besucher. Wie geht es ihnen?'
 b = 'Hier kann man Daten eingeben. ', URL('eingeben')
 c = 'Hier kann man daten ausgeben'
 

 b = A('Hier kann man Daten eingeben. ', _href=URL('eingeben'))

  

 return dict( Welcome=a, eingabe=b, showdata=c)
 
 def eingeben():
 form = SQLFORM(dba.person)
 form.add_button('records', URL('ausgabe'))
 if form.process().accepted:
 session.flash = 'form accepted'
 redirect(URL('ausgabe'))
 elif form.errors:
 response.flash = 'form has errors'
 else:
 response.flash = 'please fill out the form'

 return dict(form=form)
 
 def ausgabe():
 a = 4
 records = SQLTABLE(dba(dba.person._id== 1).select(dba.person.name
 ),headers='fieldname:capitalize')
 return dict(records=records)

 # I think I do not fully understand what is the problem but I try ;-)
 def ausgabe():
a = 4
records = SQLTABLE(dba(dba.person._id== a).select(dba.person.name
 ),headers='fieldname:capitalize')
newvariable = records[0].name
return dict(records=records)

 [/code]

 1. in def index(), you see this:
 b = 'Hier kann man Daten eingeben. ', URL('eingeben') 
 but this does not work fine, i want to get a link with the text Hier 
 kann man Daten eingeben. and a link to eingeben

 2. in def ausgabe(), you see this:

 variable = 4
 records = SQLTABLE(dba(dba.person._id== variable).select(
 dba.person.name),headers='fieldname:capitalize')
 it should work like this, the variable in the first line should be used 
 in the dba.person._id==variable


 3. 
 def ausgabe():
 a = 4
 records = SQLTABLE(dba(dba.person._id== 1).select(dba.person.name
 ),headers='fieldname:capitalize')
 return dict(records=records)

 ok, lets assume, the first line in the data bank is 1 marc 
 te...@gmail.com javascript:

 the code on the top leeds to the following output:
 Name
 marc

 is there some way to get a variable like 
 newvariable = 'marc'


 I hope you can help me, i spent hours in trying, but i didn't found 
 anything that  helped me. the handbook doesnt cover such basic stuff , or i 
 didn't found it :(

 Thank you very much,
 Darren

 -- 
 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+un...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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/groups/opt_out.


Re: [web2py] Re: DAL usage

2014-01-18 Thread Arnon Marcus
Thanks anthony, you're right - this models_to_run approach makes no sense in my 
use-case - it assumes a 1:1 correlation between controllers and their 
used-models, which would only occure in very simple apps. The whole point of 
using a relational database is to have great flexibility and diversity of 
relations. The models_to_run approach seems to assume a very restricted 
use-pattern of relations.

-- 
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/groups/opt_out.


[web2py] simplest way to get rid of None strings

2014-01-18 Thread Stef Mientki

hello,

my database (sqlite) is (partially) filled by another program,
which inserts Null or None values.
Now if I use these fields in an HTML form, they show up as None 
instead of an empty string.


Is there a simple way to solve this for all fields at once ?

thanks,
Stef

--
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/groups/opt_out.


[web2py] SQLFORM with Auth UserID

2014-01-18 Thread David
Hey guys, 

It's been a while since I used web2py and I've pretty much forgotten 
everything.  Try as I might for the last two days I can't quite figure this 
out.

I used a web2pyslice to create a main application which manages 
authentication.  I have another app referencing main to 
login/logout/register etc.  It works great.

I'm having troubles understanding SQLFORM queries. The problem I'm having 
is using SQLFORM to select records only for a specific auth.user_id.  I 
can't seem to figure out how it wants to be handled.  I get all kinds of 
error messages while trying to perform this so I will just post my code 
that works and hopefully can advise on how I would select records 
pertaining to the user that created them.



db.define_table(
'rig',
Field('user_id', default=auth.user_id, readable=False, 
writable=False),
Field('name'),
Field('ipaddress'),
Field('port'),
format = '%s(name)s')

@auth.requires_login()
def edit_rigs():
form = SQLFORM.grid(db.rig,  user_signature=False)
return dict(form=form)

This returns all entries for all users.  I only want the current logged in 
user to see his/her own records.

Thank you for any help.

-- 
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/groups/opt_out.


[web2py] Re: simplest way to get rid of None strings

2014-01-18 Thread Niphlod
if you mean the other app fills the fields with an actual string that 
holds the 'None' value (it could be very well foo, bar or pizza) 
then

fake_none_value = 'foo'
for f in db.table.fields:
db(db.table[f] == fake_none_value).update(f=None)

should solve it

On Saturday, January 18, 2014 5:12:36 PM UTC+1, aapaap wrote:

 hello, 

 my database (sqlite) is (partially) filled by another program, 
 which inserts Null or None values. 
 Now if I use these fields in an HTML form, they show up as None 
 instead of an empty string. 

 Is there a simple way to solve this for all fields at once ? 

 thanks, 
 Stef 


-- 
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/groups/opt_out.


[web2py] Re: Can not run web2py_no_console.exe. Version 2.8.2 on win 7 x 64

2014-01-18 Thread Niphlod
we're trying to come up with something here 
http://code.google.com/p/web2py/issues/detail?id=1809

if you have any inputs please share ^_^

On Saturday, January 18, 2014 1:30:33 AM UTC+1, Ray (a.k.a. Iceberg) wrote:



 On Sunday, December 15, 2013 10:00:19 AM UTC-7, Rob Paire wrote:

 Hello all,
  I am having same problem running on Windows server 2003 32bit. When I 
 launch web2py.exe the following dialog error appears: 

 *Title: Error Entry Point Not Found*

 *Description: The procedure entry point wcscpy_s could not be located in 
 the dynamic link library msvcrt.dll*

 Clicking OK returns control to the web2py executable which fails with the 
 following console message:

 C:\web2pyweb2py
 Traceback (most recent call last):
   File string, line 6, in module
   File __main__.py, line 128, in module
   File __main__web2py__.py, line 18, in module
   File /home/mdipierro/make_web2py/web2py/gluon/__init__.py, line 15, 
 in modu
 le
   File /home/mdipierro/make_web2py/web2py/gluon/globals.py, line 19, in 
 modul
 e
   File /home/mdipierro/make_web2py/web2py/gluon/xmlrpc.py, line 10, in 
 module
 
   File SimpleXMLRPCServer.py, line 102, in module
   File xmlrpclib.py, line 144, in module
   File httplib.py, line 79, in module
   File mimetools.py, line 6, in module
   File tempfile.py, line 35, in module
   File random.py, line 879, in module
   File random.py, line 97, in __init__
   File random.py, line 111, in seed
 WindowsError: [Error -2146893795] Provider DLL failed to initialize 
 correctly

 I reverted back to 2.7.4 for the time being.

  
 Same problem here.  I guess that *msvcrt.dll* thing is because the 
 web2py282 windows builder is running on a different Windows platform than 
 before.
 Now I have to roll 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/groups/opt_out.


[web2py] Re: SQLFORM with Auth UserID

2014-01-18 Thread Massimo Di Pierro
replace

form = SQLFORM.grid(db.rig,  user_signature=False)

with

form = SQLFORM.grid(db.rig.user_id = auth.user.id, 
 user_signature=False)


On Saturday, 18 January 2014 10:42:38 UTC-6, David wrote:

 Hey guys, 

 It's been a while since I used web2py and I've pretty much forgotten 
 everything.  Try as I might for the last two days I can't quite figure this 
 out.

 I used a web2pyslice to create a main application which manages 
 authentication.  I have another app referencing main to 
 login/logout/register etc.  It works great.

 I'm having troubles understanding SQLFORM queries. The problem I'm having 
 is using SQLFORM to select records only for a specific auth.user_id.  I 
 can't seem to figure out how it wants to be handled.  I get all kinds of 
 error messages while trying to perform this so I will just post my code 
 that works and hopefully can advise on how I would select records 
 pertaining to the user that created them.



 db.define_table(
 'rig',
 Field('user_id', default=auth.user_id, readable=False, 
 writable=False),
 Field('name'),
 Field('ipaddress'),
 Field('port'),
 format = '%s(name)s')

 @auth.requires_login()
 def edit_rigs():
 form = SQLFORM.grid(db.rig,  user_signature=False)
 return dict(form=form)

 This returns all entries for all users.  I only want the current logged in 
 user to see his/her own records.

 Thank you for any help.



-- 
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/groups/opt_out.


[web2py] Css cache problem

2014-01-18 Thread Sébastien Loix
Hi,
I'm new to web2py and just learning the framework.

I have an issue with my CSS static file which is not reloaded by the 
browser in local.
I have read thread about versioning of static files but it doesn't seem to 
solve the problem. Probably I don't it correctly.

Here is the line set in my db.py model:
response.static_version = '1.1.4'

Then each time I make a change in my css, I upgrate the number. But then 
even after 5 refresh of the page the old css is shown (I guess the cache).
Is there a way to completely deactivate cache in production?
Thank for any help!
Regards,
Sebastian

-- 
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/groups/opt_out.


[web2py] Re: Important New Year News: Edison Award

2014-01-18 Thread Greg Vaughan
Congratulations... and a big thank you also... I have just found web2py and 
absolutely amazed at how brilliant it is

On Saturday, 4 January 2014 14:08:38 UTC+10, Massimo Di Pierro wrote:

 Web2py/me have been nominated for the Edison Award. Please wish web2py 
 (and me) good luck. :-)



-- 
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/groups/opt_out.


[web2py] Re: SQLFORM with Auth UserID

2014-01-18 Thread David
Hi Massimo,

This is where I was having problems.  I tried what you posted.

@auth.requires_login()
def edit_rigs():
form = SQLFORM.grid(db.rig.user_id = auth.user.id, 
 user_signature=False)
return dict(form=form)


I get a Keyword can't be expression error on this.  That's where I am 
getting confused.





On Saturday, January 18, 2014 12:35:01 PM UTC-6, Massimo Di Pierro wrote:

 replace

 form = SQLFORM.grid(db.rig,  user_signature=False)

 with

 form = SQLFORM.grid(db.rig.user_id = auth.user.id, 
  user_signature=False)


 On Saturday, 18 January 2014 10:42:38 UTC-6, David wrote:

 Hey guys, 

 It's been a while since I used web2py and I've pretty much forgotten 
 everything.  Try as I might for the last two days I can't quite figure this 
 out.

 I used a web2pyslice to create a main application which manages 
 authentication.  I have another app referencing main to 
 login/logout/register etc.  It works great.

 I'm having troubles understanding SQLFORM queries. The problem I'm having 
 is using SQLFORM to select records only for a specific auth.user_id.  I 
 can't seem to figure out how it wants to be handled.  I get all kinds of 
 error messages while trying to perform this so I will just post my code 
 that works and hopefully can advise on how I would select records 
 pertaining to the user that created them.



 db.define_table(
 'rig',
 Field('user_id', default=auth.user_id, readable=False, 
 writable=False),
 Field('name'),
 Field('ipaddress'),
 Field('port'),
 format = '%s(name)s')

 @auth.requires_login()
 def edit_rigs():
 form = SQLFORM.grid(db.rig,  user_signature=False)
 return dict(form=form)

 This returns all entries for all users.  I only want the current logged 
 in user to see his/her own records.

 Thank you for any help.



-- 
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/groups/opt_out.


[web2py] Re: SQLFORM with Auth UserID

2014-01-18 Thread David
I see my problem was a simple syntax error.

== not =

Yes it is working like that.  Thank you Massimo!

On Saturday, January 18, 2014 12:50:07 PM UTC-6, David wrote:

 Hi Massimo,

 This is where I was having problems.  I tried what you posted.

 @auth.requires_login()
 def edit_rigs():
 form = SQLFORM.grid(db.rig.user_id = auth.user.id, 
  user_signature=False)
 return dict(form=form)


 I get a Keyword can't be expression error on this.  That's where I am 
 getting confused.





 On Saturday, January 18, 2014 12:35:01 PM UTC-6, Massimo Di Pierro wrote:

 replace

 form = SQLFORM.grid(db.rig,  user_signature=False)

 with

 form = SQLFORM.grid(db.rig.user_id = auth.user.id, 
  user_signature=False)


 On Saturday, 18 January 2014 10:42:38 UTC-6, David wrote:

 Hey guys, 

 It's been a while since I used web2py and I've pretty much forgotten 
 everything.  Try as I might for the last two days I can't quite figure this 
 out.

 I used a web2pyslice to create a main application which manages 
 authentication.  I have another app referencing main to 
 login/logout/register etc.  It works great.

 I'm having troubles understanding SQLFORM queries. The problem I'm 
 having is using SQLFORM to select records only for a specific auth.user_id. 
  I can't seem to figure out how it wants to be handled.  I get all kinds of 
 error messages while trying to perform this so I will just post my code 
 that works and hopefully can advise on how I would select records 
 pertaining to the user that created them.



 db.define_table(
 'rig',
 Field('user_id', default=auth.user_id, readable=False, 
 writable=False),
 Field('name'),
 Field('ipaddress'),
 Field('port'),
 format = '%s(name)s')

 @auth.requires_login()
 def edit_rigs():
 form = SQLFORM.grid(db.rig,  user_signature=False)
 return dict(form=form)

 This returns all entries for all users.  I only want the current logged 
 in user to see his/her own records.

 Thank you for any help.



-- 
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/groups/opt_out.


[web2py] Re: Css cache problem

2014-01-18 Thread LightDot
Hi and welcome!

If you look at the source of the page in a browser, do you see the 
static_version inserted as a part of the path to your css? It should be 
something like /static/_1.1.4/css/somecssfile.css.

After a change to 1.1.5, the path should change to 
/static/_1.1.5/css/somecssfile.css.

Do you see this happen?

Regards


On Saturday, January 18, 2014 12:34:17 PM UTC+1, Sébastien Loix wrote:

 Hi,
 I'm new to web2py and just learning the framework.

 I have an issue with my CSS static file which is not reloaded by the 
 browser in local.
 I have read thread about versioning of static files but it doesn't seem to 
 solve the problem. Probably I don't it correctly.

 Here is the line set in my db.py model:
 response.static_version = '1.1.4'

 Then each time I make a change in my css, I upgrate the number. But then 
 even after 5 refresh of the page the old css is shown (I guess the cache).
 Is there a way to completely deactivate cache in production?
 Thank for any help!
 Regards,
 Sebastian


-- 
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/groups/opt_out.


Re: [web2py] Re: DAL usage

2014-01-18 Thread Anthony
Only the default value of models_to_run assumes a 1:1 correspondence 
between controllers and models. You can set the value of models_to_run to 
whatever you want conditionally (and it can even change multiple times from 
model file to model file). So, for example, you could do:

if request.controller in ['controller1', 'controller2', 'controller3']:
response.models_to_run = ['path/to/modelA.py', 'path/to/modelB.py']

In any case, you still might prefer to put model definitions in modules and 
import where needed.

Anthony

On Saturday, January 18, 2014 8:11:29 AM UTC-5, Arnon Marcus wrote:

 Thanks anthony, you're right - this models_to_run approach makes no sense 
 in my use-case - it assumes a 1:1 correlation between controllers and their 
 used-models, which would only occure in very simple apps. The whole point 
 of using a relational database is to have great flexibility and diversity 
 of relations. The models_to_run approach seems to assume a very restricted 
 use-pattern of relations.

-- 
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/groups/opt_out.


Re: [web2py] Re: DAL usage

2014-01-18 Thread Anthony
Also, note that models_to_run is a list of regexes (relative to the /models 
folder), so you don't need to list each individual model file.

Anthony

On Saturday, January 18, 2014 2:08:16 PM UTC-5, Anthony wrote:

 Only the default value of models_to_run assumes a 1:1 correspondence 
 between controllers and models. You can set the value of models_to_run to 
 whatever you want conditionally (and it can even change multiple times from 
 model file to model file). So, for example, you could do:

 if request.controller in ['controller1', 'controller2', 'controller3']:
 response.models_to_run = ['path/to/modelA.py', 'path/to/modelB.py']

 In any case, you still might prefer to put model definitions in modules 
 and import where needed.

 Anthony

 On Saturday, January 18, 2014 8:11:29 AM UTC-5, Arnon Marcus wrote:

 Thanks anthony, you're right - this models_to_run approach makes no sense 
 in my use-case - it assumes a 1:1 correlation between controllers and their 
 used-models, which would only occure in very simple apps. The whole point 
 of using a relational database is to have great flexibility and diversity 
 of relations. The models_to_run approach seems to assume a very restricted 
 use-pattern of relations.



-- 
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/groups/opt_out.


Re: [web2py] Re: simplest way to get rid of None strings

2014-01-18 Thread Stef Mientki

thanks,

it's a workaround,

but I mean the field is empty / Null / None (type),
which is translated by web2py into a string value 'None'.

cheers,
Stef

On 18-01-14 19:06, Niphlod wrote:
if you mean the other app fills the fields with an actual string 
that holds the 'None' value (it could be very well foo, bar or 
pizza) then


fake_none_value = 'foo'
for f in db.table.fields:
db(db.table[f] == fake_none_value).update(f=None)

should solve it

On Saturday, January 18, 2014 5:12:36 PM UTC+1, aapaap wrote:

hello,

my database (sqlite) is (partially) filled by another program,
which inserts Null or None values.
Now if I use these fields in an HTML form, they show up as None
instead of an empty string.

Is there a simple way to solve this for all fields at once ?

thanks,
Stef

--
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/groups/opt_out.


--
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/groups/opt_out.


[web2py] Update table data on form submission

2014-01-18 Thread Jochen Schoenfeld
Hi!

I have a problem with web2py ... I want to timestamp user-initiated changes 
in tables which perfectly works when using

Field('modified_on', 'datetime', default=request.now, 
update=request.now, readable=False, writable=False),

But since my application also changes values in rows in that database, the 
field modified_on does not contain the timestamp of the last change made 
by a users.


My idea is not to use update=request.now in the model but to implement 
some logic in the form processing that only updates the modified_on field 
if a user changed that row.

In my controller I use

form = crud.update(...)

to create the form. I guess I have to add an onaccept function but don't 
know how to implement exactly. I am also not sure if this would work 
because the field is neither readable nor writable so generally not even 
part of the form.

I appreciate every hints and solutions! :)

Greetings,

Jochen

-- 
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/groups/opt_out.


[web2py] Re: SQLFORM with Auth UserID

2014-01-18 Thread Massimo Di Pierro
My bad. I put the typo in the example.

On Saturday, 18 January 2014 12:51:30 UTC-6, David wrote:

 I see my problem was a simple syntax error.

 == not =

 Yes it is working like that.  Thank you Massimo!

 On Saturday, January 18, 2014 12:50:07 PM UTC-6, David wrote:

 Hi Massimo,

 This is where I was having problems.  I tried what you posted.

 @auth.requires_login()
 def edit_rigs():
 form = SQLFORM.grid(db.rig.user_id = auth.user.id, 
  user_signature=False)
 return dict(form=form)


 I get a Keyword can't be expression error on this.  That's where I am 
 getting confused.





 On Saturday, January 18, 2014 12:35:01 PM UTC-6, Massimo Di Pierro wrote:

 replace

 form = SQLFORM.grid(db.rig,  user_signature=False)

 with

 form = SQLFORM.grid(db.rig.user_id = auth.user.id, 
  user_signature=False)


 On Saturday, 18 January 2014 10:42:38 UTC-6, David wrote:

 Hey guys, 

 It's been a while since I used web2py and I've pretty much forgotten 
 everything.  Try as I might for the last two days I can't quite figure 
 this 
 out.

 I used a web2pyslice to create a main application which manages 
 authentication.  I have another app referencing main to 
 login/logout/register etc.  It works great.

 I'm having troubles understanding SQLFORM queries. The problem I'm 
 having is using SQLFORM to select records only for a specific 
 auth.user_id. 
  I can't seem to figure out how it wants to be handled.  I get all kinds 
 of 
 error messages while trying to perform this so I will just post my code 
 that works and hopefully can advise on how I would select records 
 pertaining to the user that created them.



 db.define_table(
 'rig',
 Field('user_id', default=auth.user_id, readable=False, 
 writable=False),
 Field('name'),
 Field('ipaddress'),
 Field('port'),
 format = '%s(name)s')

 @auth.requires_login()
 def edit_rigs():
 form = SQLFORM.grid(db.rig,  user_signature=False)
 return dict(form=form)

 This returns all entries for all users.  I only want the current logged 
 in user to see his/her own records.

 Thank you for any help.



-- 
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/groups/opt_out.


[web2py] Re: custom one-to-many left-join python object and json object

2014-01-18 Thread Alan Etkin


 Hey,
 I have a simple one-to-many relation, between questions and answers. Each 
 question may have 0 or more answers, so any *db.answer.question* refers 
 to a certain *db.question.id http://db.question.id*.

 Now, in order to create a code for efficiently displaying the questions 
 and their belonging answers, I wonder: how to make the sql query, and how 
 to generate the json object of the question and answer data?


Have you tried this?

 data = db(query).select().as_json()

-- 
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/groups/opt_out.


[web2py] How to update the whole column after new insert

2014-01-18 Thread Jaime Sempere

Hi everyone,

Although I have used database serveral times, I have not done anything 
beyond very basic, so I am wondering what would be the best practice for 
this case:


I have a database table for storing a 'real-time' playlist of songs like 
this:

db.define_table('playlist',Field('title','string'),
Field('start_time','integer'),
Field('duration','integer')
)

For example:  

  row 0:   Title:Imagine;   start time: 
0:00; duration 3:43  
  row 1:   Title:My way;   start  time: 
3:43   ; duration  4:00
  row 2:   Title:I feel good;   start  time: 
7:43   ; duration  4:00

 
As you see, start time of every song stands for the 'real time' at which 
the song will be played.

What I need to know is the best approach in web2py for insert a new row in 
the middle of the table and update songs below. 

Example, say that I add, my song between 0 and 1:

  row 0:   Title:Imagine;   start time: 
0:00; duration 3:43  
  row 1:   Title:My Song;   start time: 
3:43; duration 3:00  
  row 2:   Title:My way;   start  time: 
7:43   ; duration  4:00
  row 3:   Title:I feel good;   start  time: 
11:43   ; duration  4:00

I need to update and change start times for old rows 1 and 2...

I have never face this kind of problem but I have seen that in a SQL 
triggers could do the update. How could I approach this problem in web2py?

Thanks in advance

-- 
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/groups/opt_out.


[web2py] How can I use a view in combination with a service ?

2014-01-18 Thread Stef Mientki

hello,

maybe I'm doing this completely wrong, but it's a long time ago I used 
web2py.


In the main page I have a lot of links.
In fact these links are just indexes to a row in the database.

As I understand, the only way to pass parameters from clicking a link, 
is to use services.


An example of the link in my main document:

a href={{=URL('call/run/Show_Page/%s' % record.id)}} 
{{=record.id}}.Link/a


So I created a service:
  @service.run
def Show_Page(ID):
return 'Test'

'Test' is shown as the result, but the view 
views/default/Show_Page.html is not used.


Can I not use a view with a service, or is it located on a different 
location ?


thanks,
Stef

--
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/groups/opt_out.


[web2py] Running google visualization js in a LOAD component

2014-01-18 Thread Jordan Ladora
Example from 
https://google-developers.appspot.com/chart/interactive/docs/gallery/combochart

If I place this code in a standard .html view, it works fine-

script
jQuery(document).ready(function() {

setTimeout(function() {
// Google Visualization stuff goes here

  function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
  ['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 
'Rwanda', 'Average'],
  ['2004/05',  165,  938, 522, 
998,   450,  614.6],
  ['2005/06',  135,  1120,599, 
1268,  288,  682],
  ['2006/07',  157,  1167,587, 
807,   397,  623],
  ['2007/08',  139,  1110,615, 
968,   215,  609.4],
  ['2008/09',  136,  691, 629, 
1026,  366,  569.6]
]);

var options = {
  title : 'Monthly Coffee Production by Country',
  vAxis: {title: Cups},
  hAxis: {title: Month},
  seriesType: bars,
  series: {5: {type: line}}
};

var chart = new 
google.visualization.ComboChart(document.getElementById(chart_div));
chart.draw(data, options);
  }
  google.setOnLoadCallback(drawVisualization);

}, 0);

});
/script

div id=chart_div style=width: 900px; height: 500px;/div

...but if I move this code to a LOAD component, and call it from the view, 
the graph is not rendered. I can't tell why this is and don't get any 
helpful error msgs (eg in the web console).

It's also necessary to put these lines of code in the .html that calls the 
LOAD component (not in the .load file)-

script type=text/javascript src=https://www.google.com/jsapi;/script
script type=text/javascript
  google.load('visualization', '1', {packages: ['corechart']});
/script


TIA for any pointers,
-jl

-- 
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/groups/opt_out.


[web2py] Re: Important New Year News: Edison Award

2014-01-18 Thread Matheus Cardoso
You deserve it, Massimo. I wish the best for you and to the awesome web2py!

On Saturday, January 4, 2014 1:08:38 AM UTC-3, Massimo Di Pierro wrote:

 Web2py/me have been nominated for the Edison Award. Please wish web2py 
 (and me) good luck. :-)



-- 
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/groups/opt_out.


[web2py] automatically count field edits

2014-01-18 Thread Robin Manoli
I'm trying to automatically count each time a record is being updated. I 
could make a lambda function that worked for a dictionary:
Field('edits', 'integer', compute=lambda r: int(r['edits'] or 0) + 1 ),

However, I don't get this to work in practice. Can a lambda for edits not 
use its own value?

-- 
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/groups/opt_out.


Re: [web2py] Re: simplest way to get rid of None strings

2014-01-18 Thread Anthony


 but I mean the field is empty / Null / None (type),
 which is translated by web2py into a string value 'None'.


None is translated into a string value as 'None' by Python, not web2py. If 
you want different behavior, you have to be explicit (no reason to assume 
the default behavior should be an empty string). You can achieve that by 
setting the represent attribute of the field:

Field('myfield', represent=lambda v, r: '' if v is None else v)

or more simply:

Field('myfield', map_none='')

Those methods will work in the grid and SQLFORMs, but not if you simply do 
{{=row.myfield}} somewhere. In that case, you would have to do something 
like {{=row.myfield or ''}}, or use the Rows.render() method to extract the 
row, which will automatically apply the represent function -- 
{{=rows.render(0).myfield}}.

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/groups/opt_out.


[web2py] Re: Update table data on form submission

2014-01-18 Thread Jaime Sempere



 I have tried this and work, let me know if it's the think you wanted. I 
have used SQLFORM but i guess the code will be the same for CRUD (I have 
never used it)

Just my workaround, I think there will be a better method perhaps
 
import time   # This is required to include time module.
import datetime


db.define_table(  'sample',
   Field('end_time','integer'),
   Field('duration','integer'),
   Field('mytimestamp','datetime', readable=False,
 writable=False)
   )

form = SQLFORM(db.sample)
if form.process().accepted:
  response.flash = 'form accepted'
  db(db.sample.id == 
form.vars.id).update(mytimestamp=datetime.datetime.now())


return dict(form=form)

-- 
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/groups/opt_out.


[web2py] Re: call a function inside the same view

2014-01-18 Thread Jaime Sempere

I think you are mixing concepts you cannot return something from 
process().accepted, you need to return at the end of your tracer_form() 
function, is the function who returns things. In the proccess().accepted 
you can do some operations, and modify variables that will be later 
returned by the function (like response.flash)

I would do this:

{{extend 'layout.html'}}
h4centerTracking/center/h4
{{=form}}

{{=grid}}

{{=BEAUTIFY(request.vars)}} h4 a href = 
http://127.0.0.1:8000/WnD/default/show_form;Show Records/a -- this is a 
link to show_form()
 /h4


def tracker_form():
record = db.content(request.args(0))
show_record = request.args(0)
form = SQLFORM(db.content, record)
grid = None
if form.process().accepted:
response.flash = 'Submitted Successfully!'
response.view = 'http://127.0.0.1:8000/WnD/default/show_form'
#show_form function here!
grid=SQLFORM.grid(db.content)

elif form.errors:
response.flash = 'Form is not correct'

else:
response.flash = 'Please fill out the damn form'

   
return dict(form=form, grid = grid)


def show_form(results):
return dict(grid=SQLFORM.grid(db.content))


This is if you want to hide the grid in the beggining and show it only 
after submission. If you want to show the grid from the beggining just move 
the line of grid = SQLFORM(...) where grid= None


-- 
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/groups/opt_out.


[web2py] Re: automatically count field edits

2014-01-18 Thread Jaime Sempere


 I'm trying to automatically count each time a record is being updated. I 
 could make a lambda function that worked for a dictionary:
 Field('edits', 'integer', compute=lambda r: int(r['edits'] or 0) + 1 ),

 However, I don't get this to work in practice. Can a lambda for edits not 
 use its own value?


I think you are right in that point, from book:


   - compute is an optional function. If a record is inserted or updated, 
   the compute function will be executed and the field will be populated with 
   the function result. The record is passed to the compute function as a 
   dict, and *the dict will not include the current value of that, or any 
   other compute field.*

 

-- 
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/groups/opt_out.