Re: [web2py] The Mystery of the Hidden View

2012-07-23 Thread Alec Taylor
On Mon, Jul 23, 2012 at 12:17 PM, howesc  wrote:
> Alec,
>
> the Mysterious part of this mystery is the "controller" called with a
> parameterin web2py land that is not really a controller, but just a
> helper method.  in your case event_page() returns it's value to the d()
> method (which web2py does think is a controller), and then web2py execution
> continuesso it's in the d() method before return from it that you must
> customize the view.
>
> anthony's answer is spot oni was just hoping to unravel the mystery
> slightly. :)
>
> cfh

Ahh, I see now :)

> On Sunday, July 22, 2012 11:48:13 AM UTC-7, Anthony wrote:
>>
>> Where did you set response.view -- should be something like:
>>
>> def d():
>> group = db(db.group_of_events.group_name == request.args(0)).select()
>> or redirect(URL('', 'groups'))
>> events = db(db.event.group_id == group[0].id).select()
>> if request.args(1):
>> response.view = 'group/event_page.html'
>> return event_page({'foo':'bar'})
>>  return dict(group=group, events=events, eventpage=eventpage)
>>
>> You could also set it in the event_page function.
>>
>> Anthony

Thanks, I was able to decouple the view thanks to that :)

>> On Sunday, July 22, 2012 2:39:07 PM UTC-4, Alec Taylor wrote:
>>>
>>> Thanks for the advise, unfortunately that didn't work either.
>>>
>>> I have been able to get it working though, within the "d.html" template:
>>>
>>> # /social/views/group/d.html
>>>
>>> {{if 'eventpage' in globals() and 'group_name' in globals():}}
>>> {{if len(eventpage):}}
>>> {{=group_name}}
>>> {{=eventpage}}
>>> {{else:}}
>>> Error: group ID not found
>>> {{pass}}
>>>
>>> {{elif 'group' in globals():}}
>>> ...
>>>
>>>
>>> # /social/controllers/group.py
>>> def d():
>>> group = db(db.group_of_events.group_name == request.args(0)).select()
>>> or redirect(URL('', 'groups'))
>>> events = db(db.event.group_id == group[0].id).select()
>>> if request.args(1):
>>> requested_event = None
>>> for event in events:
>>> if event.id==int(request.args(1)):
>>> requested_event = event
>>> break
>>> return event_page(requested_event, group[0].group_name)
>>> return dict(group=group, events=events)
>>>
>>> def event_page(requested_event, group):
>>> eventpage = requested_event or redirect(URL('',
>>> 'group/d/'+str(group)))
>>> return dict(group_name=group, eventpage=eventpage)
>>>
>>>
>>>
>>> :D
>
> --
>
>
>

-- 





[web2py] Production vs Localhost Working differently

2012-07-23 Thread lyn2py
Hello guys, 

I'm using the latest stable version, and need some assistance

I'm using args to validate and I found the following behavior:

On Localhost (copied directly from response toolbar, "request")
args:

edit
3
new-test-discussion




On Production
args:

3
new-test-discussion


I'm using args(1), which renders properly on localhost, but not on 
production (because it should be args(0) ). May I know why there is a 
discrepancy in args behavior?

Localhost and Production should be able to work with the same code right?

-- 





[web2py] How to hide items in Production?

2012-07-23 Thread lyn2py
I have the code working on Localhost, but along with localhost there are 
the response toolbar, the link to the admin site and the database used.

What code should I use to "test" if the code is being executed on the 
production server, so that I can "hide" or switch to use a different 
database?

I'm deploying on Amazon EC2, if this is any helpful. Thanks!

-- 





Re: [web2py] Re: Facebook login no longer works when done on remote host?

2012-07-23 Thread Michele Comitini
The simplest thing to do is give a name of choice put that in the
developers.facebook.com configuration panel of you application.

THEN if you want to test just add a record in you /etc/hosts file
pointing to localhost when testing locally, pointing to your server
when testing production.

For instance put http://my.facebook.app[:port] in the configuration
panel.  Remember the port i.e. if testing locally on port 8000 you
have to put that port in the configuration panel.

---8<
# hosts file
127.0.0.1 my.facebook.app
# comment above and uncomment below when testing on remote host
# 1.2.3.4 my.facebook.app
---8<-

Testing is easier is you can use same port locally or on production.

mic


2012/7/23 howesc :
> facebook is a picky pain in the ***
>
> in your facebook config you set a single domain name or ip address that is
> associated with the facebook app.  all redirects that you specify when
> making calls to the facebook API must be in that domain/ip address.  so your
> facebook config would need to have http://58.168.6.57 as the app domain (or
> whatever they call the setting these days) based on the URL above.
>
> this makes testing a PITA.  i have a plethora of facebook appsin real
> life i use 3: 1 for localhost, 1 for test server and 1 for production (with
> a squirrelly if statement to select which set of facebook keys to use based
> on the detected server environment)
>
> if anyone has better suggestions, i'm all ears!
>
> cfh
>
>
> On Sunday, July 22, 2012 6:59:48 AM UTC-7, Alec Taylor wrote:
>>
>> I generated a new application on Facebook—added in the new CLIENT_ID
>> and CLIENT_SECRET—but when I tried to login, the URL said:
>>
>>
>> https://graph.facebook.com/oauth/authorize?scope=user_photos%2Cfriends_photos&redirect_uri=http%3A%2F%2F58.168.6.57%2Fuser%2Flogin&response_type=code&client_id=> top-secret clientID here>
>>
>> And the page said:
>>
>> {
>>"error": {
>>   "message": "Invalid redirect_uri: Given URL is not allowed by
>> the Application configuration.",
>>   "type": "OAuthException",
>>   "code": 191
>>}
>> }
>>
>> Here is my db.py: http://pastebin.com/zULTxA7D
>>
>> What is going wrong? — I've tried modifying all my redirects, to no avail.
>>
>> Thanks for all suggestions,
>>
>> Alec Taylor
>
> --
>
>
>

-- 





[web2py] (virtualenv problems) ImportError for file in application/myapp/modules

2012-07-23 Thread Peter O
Help please.

I am preparing for a PaaS deployment on Heroku or Dotcloud.

I am following the setup on this page 
(https://devcenter.heroku.com/articles/django), which is essentially the 
same steps as in scripts/setup-virtualenv-web2py.sh.

However, I am getting an import error within virtualenv. The error doesn't 
exist if I run the app natively. I pretty much exhausted all the existing 
resource and still have no clues so far. Any suggestion is greatly 
appreciated. 

web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2011
Version 1.99.4 (2011-12-14 14:46:14) stable
Database drivers available: SQLite3, pymysql, PostgreSQL

Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/restricted.py", line 204, in restricted
exec ccode in environment
  File "applications/mvc/models/db.py", line 92, in 
import dbf
  File "/home/www-data/web2py/gluon/custom_import.py", line 293, in __call__
fromlist, level)
  File "/home/www-data/web2py/gluon/custom_import.py", line 78, in __call__
level)
ImportError: No module named mymodule



-- 





[web2py] Re: (virtualenv problems) ImportError for file in application/myapp/modules

2012-07-23 Thread Peter O
The problem is limited to the "import mymodule" line in models, but not in 
controllers.

I am using "mymodule = local_import("mymodule")" to get by.

-- 





Re: [web2py] DAL not migrating auth.settings.extra_fields to Postgres (nor is it creating new tables defined in

2012-07-23 Thread david waldrop
Massimo,  

I finally got it to work last night.   I am not sure what I did to get it 
working or why, but I manually modified the postgres tables(making sure the 
fields are in the same order as the extra_fileds  AND played with combinations 
of Migrate=True and Fake_migrate=True.  I ended up manually creating the new 
table in postgres because the migrate was not doing so.  In fact I do not think 
migrate made any schema changes to my prod database.  As I said I am not 100% 
sure what I did but my working theory is the sequence of the schema mods has a 
lot to do with whether or not migrate behaves properly.   Migration, especially 
with the auth tables, is an area that is very mysterious and frustrating.  That 
said I am happy to have COPSIS up and running. Tomorrow at the "2nd Annual - 
Building Resilience Through Public Private Partnerships Conference" in Colorado 
Springs FEMA will make the site available to all participants.  I still have 
work to do including an UX cleanup, about page, web2py reference, etc.  Take a 
look www.copsi.org - you are already a user.  Thanks again for you help.

/david


On Jul 22, 2012, at 10:15 PM, Massimo Di Pierro wrote:

> I suspect you have fake_migrate=True when you added the line:
> 
> Field('phone', label="Phone"),
> 
> Try the solution I just posted in the other thread. IF it does not work, you 
> can manually do the ALTER TABLE. web2py seems to already be aware of those 
> columns.
> 
> On Sunday, 22 July 2012 19:27:54 UTC-5, david.waldrop wrote:
> I create extra fields in auth_user like this
> 
> ## create all tables needed by auth if not custom tables
> auth.settings.extra_fields['auth_user'] = [
> Field('org_ref', 'integer', label="Organization"),
> Field('phone', label="Phone"),
> Field('show1stpage', 'boolean', label="Show Getting Started Page"),
> Field('Invitedby', label="Invited By"),
> Field('RegistrationCode', label="Registration Code")
> ]
> 
> ## create all tables needed by auth if not custom tables
> auth.define_tables(username=False, signature=False, Migrate=True)
> 
> 
> and am getting the following error after migrate. I have tried fake_migrate 
> in all combinations. 
> If i comments out the most recent fileds (i.e. the ones not in the current 
> Postgres DB, the app will run, but blows up when I reference one of the new 
> fields)
> If I add the fileds to the database directly (in the same order as the create 
> table in the /databases/log.sql file, I get the error below
> Lastly I create a new table RegistrationCodes that is not getting created in 
> the Postgres DB either.  Its as if the migrate is not doing anything.
> 
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
> 19.
> 20.
> 21.
> 22.
> 23.
> Traceback (most recent call last
> ):
>   File "/home/dlwatey/webapps/web2py/web2py/gluon/restricted.py", line 205, 
> in restricted
> exec ccode in environment
>   File 
> "/home/dlwatey/webapps/web2py/web2py/applications/COPSIS23/controllers/default.py",
>  line 226, in 
>   File "/home/dlwatey/webapps/web2py/web2py/gluon/globals.py", line 175, in 
> 
> self._caller = lambda f: f()
>   File 
> "/home/dlwatey/webapps/web2py/web2py/applications/COPSIS23/controllers/default.py",
>  line 85, in register
> inviterec = db((db.invite.id == request.args(0)) & (db.invite.host_ref == 
> db.auth_user.id)).select()
>   File "/home/dlwatey/webapps/web2py/web2py/gluon/dal.py", line 8147, in 
> select
> return adapter.select(self.query,fields,attributes)
>   File "/home/dlwatey/webapps/web2py/web2py/gluon/dal.py", line 1410, in 
> select
> rows = response(sql)
>   File "/home/dlwatey/webapps/web2py/web2py/gluon/dal.py", line 1400, in 
> response
> self.execute(sql)
>   File "/home/dlwatey/webapps/web2py/web2py/gluon/dal.py", line 1489, in 
> execute
> return self.log_execute(*a, **b)
>   File "/home/dlwatey/webapps/web2py/web2py/gluon/dal.py", line 1483, in 
> log_execute
> ret = self.cursor.execute(*a, **b)
> ProgrammingError: column auth_user.phone does not exist
> LINE 1: ...ey, auth_user.registration_id, auth_user.org_ref, auth_user
>  ^
>  
> db = DAL('postgres://idxxx:pwxxx@127.0.0.1:5432/dlwatey_copsis', 
> migrate_enabled=True, fake_migrate_all=False)  
> 
> I have tried the migrate=true, and fake_migrate flags but they are not 
> working.  I continue to see what is going on but am getting worried andmay 
> have to revert to the old system. 
> 
> -- 
>  
>  
>  

-- 





[web2py] prettydate question

2012-07-23 Thread ctrlSoft
datetime format is: 2012-07-18 10:00:00  

hi in view i have following code:
{{=prettydate(row.deadline,T)}}

but result is :
%d days ago 
%d days ago  
%d days ago   
%d days ago   
...
1 week ago
1 week ago
...
%d weeks ago 
%d weeks ago 
%d weeks ago 

how to display 
4 days ago
5 days ago
...
2 weeks ago
3 weeks ago
... 
...

-- 





Re: [web2py] Re: Facebook login no longer works when done on remote host?

2012-07-23 Thread Alec Taylor
Okay, this is a little strange.

Just did a bit morre troubleshooting, found that:
- That IP Address isn't associated with my domain in any way (I
emailed my host to confirm)
- The client ID is the one I'm using for my local web2py server, not
the one I modified it too in "fbappauth.py"
- There were .pyc files in my "/modules" folder, which have now been removed
- I had forgotten to add "App Domains" and "Site URL" to the Facebook app

Unfortunately I still can't login with facebook, and am still being
presented the same error :/

On Mon, Jul 23, 2012 at 6:40 PM, Michele Comitini
 wrote:
> The simplest thing to do is give a name of choice put that in the
> developers.facebook.com configuration panel of you application.
>
> THEN if you want to test just add a record in you /etc/hosts file
> pointing to localhost when testing locally, pointing to your server
> when testing production.
>
> For instance put http://my.facebook.app[:port] in the configuration
> panel.  Remember the port i.e. if testing locally on port 8000 you
> have to put that port in the configuration panel.
>
> ---8<
> # hosts file
> 127.0.0.1 my.facebook.app
> # comment above and uncomment below when testing on remote host
> # 1.2.3.4 my.facebook.app
> ---8<-
>
> Testing is easier is you can use same port locally or on production.
>
> mic
>
>
> 2012/7/23 howesc :
>> facebook is a picky pain in the ***
>>
>> in your facebook config you set a single domain name or ip address that is
>> associated with the facebook app.  all redirects that you specify when
>> making calls to the facebook API must be in that domain/ip address.  so your
>> facebook config would need to have http://58.168.6.57 as the app domain (or
>> whatever they call the setting these days) based on the URL above.
>>
>> this makes testing a PITA.  i have a plethora of facebook appsin real
>> life i use 3: 1 for localhost, 1 for test server and 1 for production (with
>> a squirrelly if statement to select which set of facebook keys to use based
>> on the detected server environment)
>>
>> if anyone has better suggestions, i'm all ears!
>>
>> cfh
>>
>>
>> On Sunday, July 22, 2012 6:59:48 AM UTC-7, Alec Taylor wrote:
>>>
>>> I generated a new application on Facebook—added in the new CLIENT_ID
>>> and CLIENT_SECRET—but when I tried to login, the URL said:
>>>
>>>
>>> https://graph.facebook.com/oauth/authorize?scope=user_photos%2Cfriends_photos&redirect_uri=http%3A%2F%2F58.168.6.57%2Fuser%2Flogin&response_type=code&client_id=>> top-secret clientID here>
>>>
>>> And the page said:
>>>
>>> {
>>>"error": {
>>>   "message": "Invalid redirect_uri: Given URL is not allowed by
>>> the Application configuration.",
>>>   "type": "OAuthException",
>>>   "code": 191
>>>}
>>> }
>>>
>>> Here is my db.py: http://pastebin.com/zULTxA7D
>>>
>>> What is going wrong? — I've tried modifying all my redirects, to no avail.
>>>
>>> Thanks for all suggestions,
>>>
>>> Alec Taylor
>>
>> --
>>
>>
>>
>
> --
>
>
>

-- 





[web2py] Re: Question about an xml file in use with a JS(jquery) Mappicker in web2py ...

2012-07-23 Thread Don_X
Finally, to solve this issue ...  I did two things : ( considering there 
are only 2 languages that are taken into considerations so  .. )

1st ) I embeded the js script inside the html page and put in some python 
codes into it, and also to solve the xml url calling inside the js script ( 
with condition statements etc .. )

2nd ) I created 2 xml files ( one for english, and the other one for the 
french language .. )  so that way, depending on the language of the user, 
the appropriate xml file is parsed for data by the script embeded in the 
corresponding view !

On Friday, July 20, 2012 5:44:00 PM UTC-4, Don_X wrote:
>
> thank you Derek 
>
> However, If the data ( text, pics, sizes, tags. ... ) is in the xml file ( 
> within the static folder ), I will not be able to provide translation for 
> that information by using the web2py object T( )  for translation before 
> viewing those informations ... so I was wandering if I can have my 
> interactive map with the text information data ( from another source than 
> xml ) so it can be serialised or translated when needed ( such as in french 
> ) like the rest of the app ..  And that is where I am a stuck !! ..
>
> thank you for your input .. it got me to understand more about xml and 
> python ! ...
>
>
>
> On Friday, July 20, 2012 4:04:04 PM UTC-4, Derek wrote:
>>
>> Yes, don... XML drive means it takes an XML file as source for the map. 
>> It appears the XML is handled client side via javascript. There are no 
>> arguments passed to the XML so it is a static file. You would put it in 
>> your STATIC folder.
>>
>> On Friday, July 20, 2012 10:58:13 AM UTC-7, Don_X wrote:
>>>
>>>
>>> More information regarding this initiative :
>>>
>>> the scripts used for the interactive map is the one found at :
>>>
>>> http://codecanyon.net/item/interactive-svg-canada-map/2355460
>>>
>>> It is said to be XML driven 
>>>
>>> and i wish to port it to my web2py app. .
>>>
>>> But i am hitting a wall with this ! ...  the xml file is used as data 
>>> source for the JS ( jquery )
>>>
>>> I have looked at various alternatives to xml on the web for interaction 
>>> possibility with various scripting languages like JS, or Python etc ..  
>>>  I know there is  YAML   
>>>
>>> I am thinking that YAML can replace the xml method  for data interaction 
>>> with the js script .. and possibly be also serialized  by web2py for 
>>> translation (T) ?? ... 
>>>
>>> can anyone help me with this or shed some light about this for me ... I 
>>> am stuck ..??? .. thank you
>>>
>>>

-- 





[web2py] Re: SQLFORM.grid pagination refresh

2012-07-23 Thread Anthony
When you submit a form in an Ajax component, only the component will 
refresh -- so if you make a filter form contained in the component with the 
grid, when the form is submitted, it will reload the whole component. You 
can also customize the grid search widget to do whatever you want -- both 
"searchable" and "search_widget" take callables, so you can customize the 
search behavior. Finally, even if your filter form/widget is outside the 
grid component, you can use JS to trigger a reload of the component by 
calling the web2py_component() JS function directly.

Anthony

On Sunday, July 22, 2012 11:47:13 PM UTC-4, dave wrote:
>
> Wow, that was fast, first time asker here,
> I have an SQLFORM.grid in a view, when I click the pagination links at the 
> bottom of the page 1, 2, 3 etc, the whole page refreshes. To avoid this 
> problem, I created a component and put it in a view 
> 
> {{=LOAD('default','ajaxTable2.load',ajax=True, target='grid', 
> content='loading...')}}
>  
>
>
> 
> this will solve the whole page refresh problem, but now I want to filter 
> the table from an input box for example if I have 100 records, when I type 
> in 50 in the input box, the grid will return the first 50 records only, how 
> would I go about solving this problem that avoids the page refresh problem?
>

-- 





[web2py] Re: Foreign Key fields as null?

2012-07-23 Thread joe
The key error was because it was '%(name)' not '%(name)s'.  Everything 
works now! Thanks!

On Friday, July 20, 2012 3:37:11 PM UTC-5, Anthony wrote:
>
> Actually, I would think that would have caused an AttributeError (trying 
> to access an attribute of a NoneType object). Not sure where the KeyError 
> is arising.
>
> Anthony
>
> On Friday, July 20, 2012 4:31:52 PM UTC-4, Anthony wrote:
>>
>> Oh, right, since you allow empty values, you'll need to test for that 
>> before doing the query:
>>
>> represent=lambda id, row: db.person(id).name if id else 'Nobody owns 
>> this dog'
>>
>> Anthony
>>
>> On Friday, July 20, 2012 3:47:33 PM UTC-4, joe wrote:
>>>
>>> That hasn't worked for me.  When I try, I get the error:>> 'exceptions.KeyError'> 'name'
>>>
>>> It points to the smartgrid I made, with this code:  grid = 
>>> SQLFORM
>>> .smartgrid(db.dog)
>>>
>>> Thanks!
>>> -Joe Peacock
>>>
>>>
>>> On Tuesday, July 17, 2012 6:22:53 PM UTC-5, Anthony wrote:

 You should probably make it a reference field. By default, if you don't 
 specify any "requires", you'll automatically get an IS_IN_DB validator as 
 well as a "represent" attribute that displays whatever is specifying by 
 the 
 "format" attribute of the referenced table. However, if you specify your 
 own validator(s), then you don't get any default "represent" -- so just 
 add 
 your own explicit represent:

 db.define_table('dog',
 Field ('name'), 
 Field ('owner',db
 .person, 
 requires=IS_EMPTY_OR
 (IS_IN_DB (db, '
 person.id', '%(name)')),
   represent=lambda id, row: db.person(id).name),
 format = '%(name)s')

 Anthony

 On Tuesday, July 17, 2012 10:26:52 AM UTC-4, joe wrote:
>
> Is there any way to make a field in a form referencing a foreign key 
> null, while storing a foreign key as a foreign key, but making dropdowns 
> corrospond to the format.  Here is my example:
>
> Model:
>
> db = DAL 
> ('sqlite://storage.sqlite')
>
> db.define_table('person',
> Field ('name'),
> Field ('email'),
> format = '%(name)s')
> 
> db.define_table('dog',
> Field ('name'), 
> Field ('owner', 
> requires = IS_EMPTY_OR 
> (IS_IN_DB 
> (db,db.person))), #I 
> have also tried default=None, and required = False, no difference
> format = '%(name)s')
>
>
> Controller:
>
> *from gluon.tools import Crud
> crud = Crud(db)
>
> def index():
> form = SQLFORM(db.person)
> if form.process().accepted:
> response.flash = 'success'
> return dict(form=form)
> 
> def add_dog():
> form = SQLFORM(db.dog)
> if form.process().accepted:
> response.flash = 'success'
> return dict(form=form)
>
> def view():
> grid = SQLFORM.smartgrid(db.dog)
> grid2 = crud.select(db.person)
> return dict(grid=grid, grid2=grid2)
> *
>
> *
> *
>
> When I have the above code, a foreign key will be stored in the database, 
> but all views of that key will be rendered as the numerical value of the 
> foreign key, and not the name.  In the table definition, if I just have 
> *db.person* instead of requires = 
> *IS_EMPTY_OR*(*IS_IN_DB*(db,db.person)), It requires the field.  
>
>
> Are there any workarounds?
>
> -Joe Peacock
>
>

-- 





[web2py] Re: How to hide items in Production?

2012-07-23 Thread Anthony
request.is_local indicates whether the request is coming from localhost, so 
that can often be used to distinguish between development and production.

Anthony

On Monday, July 23, 2012 3:53:49 AM UTC-4, lyn2py wrote:
>
> I have the code working on Localhost, but along with localhost there are 
> the response toolbar, the link to the admin site and the database used.
>
> What code should I use to "test" if the code is being executed on the 
> production server, so that I can "hide" or switch to use a different 
> database?
>
> I'm deploying on Amazon EC2, if this is any helpful. Thanks!
>

-- 





[web2py] Re: Production vs Localhost Working differently

2012-07-23 Thread Anthony
Can you show the code where the args are generated (presumably via the URL 
function)? Is anything happening inside a request.is_local condition?

Anthony

On Monday, July 23, 2012 3:49:44 AM UTC-4, lyn2py wrote:
>
> Hello guys, 
>
> I'm using the latest stable version, and need some assistance
>
> I'm using args to validate and I found the following behavior:
>
> On Localhost (copied directly from response toolbar, "request")
> args:
>
> edit
> 3
> new-test-discussion
>
>
>
>
> On Production
> args:
>
> 3
> new-test-discussion
>
>
> I'm using args(1), which renders properly on localhost, but not on 
> production (because it should be args(0) ). May I know why there is a 
> discrepancy in args behavior?
>
> Localhost and Production should be able to work with the same code right?
>

-- 





Re: [web2py] How to hide items in Production?

2012-07-23 Thread Jonathan Lundell
On 23 Jul 2012, at 12:53 AM, lyn2py wrote:
> I have the code working on Localhost, but along with localhost there are the 
> response toolbar, the link to the admin site and the database used.
> 
> What code should I use to "test" if the code is being executed on the 
> production server, so that I can "hide" or switch to use a different database?
> 
> I'm deploying on Amazon EC2, if this is any helpful. Thanks!
> 
> 

One possibility: look at platform.node() or request.env.http_host or 
request.env.remote_addr in local_hosts.

Another: platform.system(). 

And a warning: I started out using request.is_local to, among other things, use 
sqlite instead of mysql. Its logic:

request.env.http_host.split(':',1)[0]
local_hosts = [http_host,'::1','127.0.0.1',':::127.0.0.1']
request.is_local = request.env.remote_addr in local_hosts

But. I was running on a managed Rackspace server, and there was a server 
monitoring process that made requests locally. Until I figured that out, it was 
*really* confusing.

This stuff become (necessarily?) a little ad hoc. 

One other note, something you might want to anticipate from the beginning. I 
distinguish between three levels of server. My localhost environment runs 
Rocket and sqlite. My production server runs Apache and MySQL. My production 
test server is configured identically to the production server. It's where I 
initially deploy all my changes to make sure that migrations perform correctly, 
and that anything that might be dependent on the specific configuration works 
right. For that, I depend on the host name (above) when I need to make a 
distinction.

I end up creating two flags: is_production and use_sqlite. 

You may of course require something different.

-- 





[web2py] Re: (virtualenv problems) ImportError for file in application/myapp/modules

2012-07-23 Thread Massimo Di Pierro
Which web2py and python versions? Looks like custom_import is not doing its 
job. Could also be a path issue.

On Monday, 23 July 2012 04:51:48 UTC-5, Peter O wrote:
>
> The problem is limited to the "import mymodule" line in models, but not in 
> controllers.
>
> I am using "mymodule = local_import("mymodule")" to get by.
>
>

-- 





[web2py] Re: prettydate question

2012-07-23 Thread Massimo Di Pierro
Are you saying you actually get "%d" in the output?

On Monday, 23 July 2012 05:32:08 UTC-5, ctrlSoft wrote:
>
> datetime format is: 2012-07-18 10:00:00  
>
> hi in view i have following code:
> {{=prettydate(row.deadline,T)}}
>
> but result is :
> %d days ago 
> %d days ago  
> %d days ago   
> %d days ago   
> ...
> 1 week ago
> 1 week ago
> ...
> %d weeks ago 
> %d weeks ago 
> %d weeks ago 
>
> how to display 
> 4 days ago
> 5 days ago
> ...
> 2 weeks ago
> 3 weeks ago
> ... 
> ...
>
>

-- 





[web2py] Re: Production vs Localhost Working differently

2012-07-23 Thread Massimo Di Pierro
You definitively have different routes.py

On Monday, 23 July 2012 02:49:44 UTC-5, lyn2py wrote:
>
> Hello guys, 
>
> I'm using the latest stable version, and need some assistance
>
> I'm using args to validate and I found the following behavior:
>
> On Localhost (copied directly from response toolbar, "request")
> args:
>
> edit
> 3
> new-test-discussion
>
>
>
>
> On Production
> args:
>
> 3
> new-test-discussion
>
>
> I'm using args(1), which renders properly on localhost, but not on 
> production (because it should be args(0) ). May I know why there is a 
> discrepancy in args behavior?
>
> Localhost and Production should be able to work with the same code right?
>

-- 





[web2py] Unit Testing Database Best Practices

2012-07-23 Thread Mark Li
I'm fairly new to test-driven development and have decided it is the best 
way to go for my new webapp. While functional tests with selenium seem to 
be more straightforward (as far as what the tests want to accomplish), I'm 
lost on what unit tests for the database should test for.

For example, if I have a database table with columns id, 'dogowner', and 
'dogname', and have a controller returning a dict with 'dogowners', what 
should I be testing in the unit tests for the database and controller? 

The database table will be fixed with a limited number of 'dogowner' 
entries, about 10, so should I be testing whether the database has 10 
entries, and if the len of the dict returned by the controller is 10? This 
datatable may not be fixed in the future, so what functionality of the 
database would I be testing for?



I'm following http://www.web2py.com/AlterEgo/default/show/260 , but while 
that page explains HOW to go about unit testing, it doesn't explain what I 
should be testing for. Anyone experienced with TDD in web2py want to point 
me in the right direction? Thanks in advance!

-- 





[web2py] Re: Best way to mix people and organizations on the same view? Opinions, please.

2012-07-23 Thread Cliff Kachinske
Annet,

Thanks for the response.

How do you handle sorting in the joined rows?

Thanks,
Cliff Kachinske

On Monday, July 23, 2012 1:37:03 AM UTC-4, Annet wrote:
>
> I solved a similar problem by adding a table which I called node. A node 
> can either be a person or an organization. When I need a list of both 
> people and organizations I use a left join for the tables person and 
> organization. In the view I use:
>
> {{if row.person.last_name:}}
> {{=row.person.first_name}} {{=row.person.last_name}}
> {{elif row.organization.name:}}
> {{=row.organization.name}}
> {{pass}}
>
>
> Kind regards,
>
> Annet.
>

-- 





Re: [web2py] Unit Testing Database Best Practices

2012-07-23 Thread Richard Vézina
I am interesting in what will come out of this thread...

But, to me I think your last question on fact that database will have
undertermined set of data mean that you maybe not validate your app base on
the entries of the database but on a testing database with a set of known
data, that you can even charge on need for the test. Also, you will just
test the limit with data that will for example help to demonstrate that a
field type is appropriately defined to get all type of data you intend to
put in in. Count, if variable get creates, etc., is more in the basic thing
you can always check for every function...

I am also pretty new to unit test in general and have most the same
questions.

Cheers!

Richard


On Sun, Jul 22, 2012 at 9:41 PM, Mark Li  wrote:

> I'm fairly new to test-driven development and have decided it is the best
> way to go for my new webapp. While functional tests with selenium seem to
> be more straightforward (as far as what the tests want to accomplish), I'm
> lost on what unit tests for the database should test for.
>
> For example, if I have a database table with columns id, 'dogowner', and
> 'dogname', and have a controller returning a dict with 'dogowners', what
> should I be testing in the unit tests for the database and controller?
>
> The database table will be fixed with a limited number of 'dogowner'
> entries, about 10, so should I be testing whether the database has 10
> entries, and if the len of the dict returned by the controller is 10? This
> datatable may not be fixed in the future, so what functionality of the
> database would I be testing for?
>
>
>
> I'm following http://www.web2py.com/AlterEgo/default/show/260 , but while
> that page explains HOW to go about unit testing, it doesn't explain what I
> should be testing for. Anyone experienced with TDD in web2py want to point
> me in the right direction? Thanks in advance!
>
> --
>
>
>
>

-- 





[web2py] Re: Production vs Localhost Working differently

2012-07-23 Thread lyn2py
Massimo is right.

I updated the routes.py (now both files are exactly the same) and now a 
different problem.

This is my routes.py file:

routers = dict( 
BASE = dict( 
default_controller = 'default', 
default_function = 'index'
),
myapp = dict(
default_controller = 'default', 
default_function = 'home'
)
)


Note: I only have 1 controller (default.py), and the function (discussion) 
is in that controller

On the local server,
the URL
http://127.0.0.1:8000/myapp/discussion/3/test-discussion
can access the webpage, no problem.

On the production server,
http://productionurl.com/myapp/*default*/discussion/3/test-discussion
Note that on the production server, it requires "default" to access the 
webpage, otherwise (if without the "default" in the URL), the error is 
invalid controller (discussion/3)

What should I do? Thanks.


On Monday, July 23, 2012 10:13:58 PM UTC+8, Massimo Di Pierro wrote:
>
> You definitively have different routes.py
>
> On Monday, 23 July 2012 02:49:44 UTC-5, lyn2py wrote:
>>
>> Hello guys, 
>>
>> I'm using the latest stable version, and need some assistance
>>
>> I'm using args to validate and I found the following behavior:
>>
>> On Localhost (copied directly from response toolbar, "request")
>> args:
>>
>> edit
>> 3
>> new-test-discussion
>>
>>
>>
>>
>> On Production
>> args:
>>
>> 3
>> new-test-discussion
>>
>>
>> I'm using args(1), which renders properly on localhost, but not on 
>> production (because it should be args(0) ). May I know why there is a 
>> discrepancy in args behavior?
>>
>> Localhost and Production should be able to work with the same code right?
>>
>

-- 





[web2py] Re: Production vs Localhost Working differently

2012-07-23 Thread Anthony
I think you have to list all the functions in the default controller if you 
want the default function removed from the URL when there are URL args. Not 
sure why it would work on localhost, though.

Anthony

On Monday, July 23, 2012 11:56:09 AM UTC-4, lyn2py wrote:
>
> Massimo is right.
>
> I updated the routes.py (now both files are exactly the same) and now a 
> different problem.
>
> This is my routes.py file:
>
> routers = dict( 
> BASE = dict( 
> default_controller = 'default', 
> default_function = 'index'
> ),
> myapp = dict(
> default_controller = 'default', 
> default_function = 'home'
> )
> )
>
>
> Note: I only have 1 controller (default.py), and the function (discussion) 
> is in that controller
>
> On the local server,
> the URL
> http://127.0.0.1:8000/myapp/discussion/3/test-discussion
> can access the webpage, no problem.
>
> On the production server,
> http://productionurl.com/myapp/*default*/discussion/3/test-discussion
> Note that on the production server, it requires "default" to access the 
> webpage, otherwise (if without the "default" in the URL), the error is 
> invalid controller (discussion/3)
>
> What should I do? Thanks.
>
>
> On Monday, July 23, 2012 10:13:58 PM UTC+8, Massimo Di Pierro wrote:
>>
>> You definitively have different routes.py
>>
>> On Monday, 23 July 2012 02:49:44 UTC-5, lyn2py wrote:
>>>
>>> Hello guys, 
>>>
>>> I'm using the latest stable version, and need some assistance
>>>
>>> I'm using args to validate and I found the following behavior:
>>>
>>> On Localhost (copied directly from response toolbar, "request")
>>> args:
>>>
>>> edit
>>> 3
>>> new-test-discussion
>>>
>>>
>>>
>>>
>>> On Production
>>> args:
>>>
>>> 3
>>> new-test-discussion
>>>
>>>
>>> I'm using args(1), which renders properly on localhost, but not on 
>>> production (because it should be args(0) ). May I know why there is a 
>>> discrepancy in args behavior?
>>>
>>> Localhost and Production should be able to work with the same code right?
>>>
>>

-- 





Re: [web2py] Re: Production vs Localhost Working differently

2012-07-23 Thread Jonathan Lundell
On 23 Jul 2012, at 8:56 AM, lyn2py wrote:
> Massimo is right.
> 
> I updated the routes.py (now both files are exactly the same) and now a 
> different problem.
> 
> This is my routes.py file:
> 
> routers = dict( 
> BASE = dict( 
> default_controller = 'default', 
> default_function = 'index'
> ),
> myapp = dict(
> default_controller = 'default', 
> default_function = 'home'
> )
> )
> 
> 
> Note: I only have 1 controller (default.py), and the function (discussion) is 
> in that controller
> 
> On the local server,
> the URL
> http://127.0.0.1:8000/myapp/discussion/3/test-discussion
> can access the webpage, no problem.
> 
> On the production server,
> http://productionurl.com/myapp/default/discussion/3/test-discussion
> Note that on the production server, it requires "default" to access the 
> webpage, otherwise (if without the "default" in the URL), the error is 
> invalid controller (discussion/3)
> 
> 
> What should I do? Thanks.
> 

At first glance it looks like your routes are not being activated on the 
production system for some reason. If you recently changed routes.py, did you 
restart the server, or reload the routes?

Where does http://productionurl.com/myapp/ get routed to? index or home?

Finally, double-check that there's no discussion.py in your myapp/controllers 
directory.

-- 





Re: [web2py] Re: Production vs Localhost Working differently

2012-07-23 Thread Jonathan Lundell
On 23 Jul 2012, at 9:02 AM, Anthony wrote:
> I think you have to list all the functions in the default controller if you 
> want the default function removed from the URL when there are URL args. Not 
> sure why it would work on localhost, though.

Yeah, but discussion is the function; it's default controller removal that 
isn't happening.

> 
> Anthony
> 
> On Monday, July 23, 2012 11:56:09 AM UTC-4, lyn2py wrote:
> Massimo is right.
> 
> I updated the routes.py (now both files are exactly the same) and now a 
> different problem.
> 
> This is my routes.py file:
> 
> routers = dict( 
> BASE = dict( 
> default_controller = 'default', 
> default_function = 'index'
> ),
> myapp = dict(
> default_controller = 'default', 
> default_function = 'home'
> )
> )
> 
> 
> Note: I only have 1 controller (default.py), and the function (discussion) is 
> in that controller
> 
> On the local server,
> the URL
> http://127.0.0.1:8000/myapp/discussion/3/test-discussion
> can access the webpage, no problem.
> 
> On the production server,
> http://productionurl.com/myapp/default/discussion/3/test-discussion
> Note that on the production server, it requires "default" to access the 
> webpage, otherwise (if without the "default" in the URL), the error is 
> invalid controller (discussion/3)
> 
> 
> What should I do? Thanks.
> 


-- 





Re: [web2py] Re: Production vs Localhost Working differently

2012-07-23 Thread lyn2py
Thanks Jonathan! Your answer worked!

I've reloaded routes all the time, but I forgot it this time. :(

On Tuesday, July 24, 2012 12:05:04 AM UTC+8, Jonathan Lundell wrote:
>
> On 23 Jul 2012, at 8:56 AM, lyn2py wrote:
>
> Massimo is right.
>
> I updated the routes.py (now both files are exactly the same) and now a 
> different problem.
>
> This is my routes.py file:
>
> routers = dict( 
> BASE = dict( 
> default_controller = 'default', 
> default_function = 'index'
> ),
> myapp = dict(
> default_controller = 'default', 
> default_function = 'home'
> )
> )
>
>
> Note: I only have 1 controller (default.py), and the function (discussion) 
> is in that controller
>
> On the local server,
> the URL
> http 
> :
> //127.0.0.1:8000/myapp/discussion/3/test-discussion
> can access the webpage, no problem.
>
> On the production server,
> http 
> : 
> //productionurl.com/myapp/
> *default
> */discussion/3/test-discussion
> Note that on the production server, it requires "default" to access the 
> webpage, otherwise (if without the "default" in the URL), the error is 
> invalid controller (discussion/3)
>
> What should I do? Thanks.
>
>
> At first glance it looks like your routes are not being activated on the 
> production system for some reason. If you recently changed routes.py, did 
> you restart the server, or reload the routes?
>
> Where does http://productionurl.com/myapp/ get routed to? index or home?
>
> Finally, double-check that there's no discussion.py in your 
> myapp/controllers directory.
>

-- 





[web2py] Re: prettydate question

2012-07-23 Thread ctrlSoft

>
> yes.
>>
> http://i.imgur.com/jaeop.jpg

http://i.imgur.com/xPBG1.jpg 

-- 





Re: [web2py] Unit Testing Database Best Practices

2012-07-23 Thread vinicius...@gmail.com

+1

On 07/23/2012 11:40 AM, Richard Vézina wrote:

I am interesting in what will come out of this thread...

But, to me I think your last question on fact that database will have
undertermined set of data mean that you maybe not validate your app base
on the entries of the database but on a testing database with a set of
known data, that you can even charge on need for the test. Also, you
will just test the limit with data that will for example help to
demonstrate that a field type is appropriately defined to get all type
of data you intend to put in in. Count, if variable get creates, etc.,
is more in the basic thing you can always check for every function...

I am also pretty new to unit test in general and have most the same
questions.

Cheers!

Richard


On Sun, Jul 22, 2012 at 9:41 PM, Mark Li mailto:markruole...@gmail.com>> wrote:

I'm fairly new to test-driven development and have decided it is the
best way to go for my new webapp. While functional tests with
selenium seem to be more straightforward (as far as what the tests
want to accomplish), I'm lost on what unit tests for the database
should test for.

For example, if I have a database table with columns id, 'dogowner',
and 'dogname', and have a controller returning a dict with
'dogowners', what should I be testing in the unit tests for the
database and controller?

The database table will be fixed with a limited number of 'dogowner'
entries, about 10, so should I be testing whether the database has
10 entries, and if the len of the dict returned by the controller is
10? This datatable may not be fixed in the future, so what
functionality of the database would I be testing for?



I'm following http://www.web2py.com/AlterEgo/default/show/260 , but
while that page explains HOW to go about unit testing, it doesn't
explain what I should be testing for. Anyone experienced with TDD in
web2py want to point me in the right direction? Thanks in advance!

--




--





--





[web2py] Re: How to hide items in Production?

2012-07-23 Thread lyn2py
Thank you both. It works. 
If I want to keep the response toolbar available to the logged in admin, 
how should I perform the IF test?

On Monday, July 23, 2012 9:57:55 PM UTC+8, Anthony wrote:
>
> request.is_local indicates whether the request is coming from localhost, 
> so that can often be used to distinguish between development and production.
>
> Anthony
>
> On Monday, July 23, 2012 3:53:49 AM UTC-4, lyn2py wrote:
>>
>> I have the code working on Localhost, but along with localhost there are 
>> the response toolbar, the link to the admin site and the database used.
>>
>> What code should I use to "test" if the code is being executed on the 
>> production server, so that I can "hide" or switch to use a different 
>> database?
>>
>> I'm deploying on Amazon EC2, if this is any helpful. Thanks!
>>
>

-- 





[web2py] None ?

2012-07-23 Thread Ashraf Mansour
Hi,

I just received 'None', when accessing certain page.
is this an error?

there is no ticket as normal.
Please explain...

Regards,

Ashraf

-- 





Re: [web2py] None ?

2012-07-23 Thread Jonathan Lundell
On 23 Jul 2012, at 9:53 AM, Ashraf Mansour wrote:
> I just received 'None', when accessing certain page.
> is this an error?
> 
> there is no ticket as normal.
> Please explain...
> 

Most likely a function that returns None or a function without a return value.

-- 





Re: [web2py] Re: prettydate question

2012-07-23 Thread Bruno Rocha
do you have an it-it.py in languages folder? looks like the encoding of
translations file is corrupted.

try replacing T with lamba x: x for testing

{{=prettydate(row.deadline, lambda x: x)}}



On Mon, Jul 23, 2012 at 1:28 PM, ctrlSoft  wrote:

>  yes.
>>>
>> http://i.imgur.com/jaeop.jpg
>
> http://i.imgur.com/xPBG1.jpg
>
> --
>
>
>
>

-- 





[web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread Alec Taylor
I'm confused at how I'm meant to do logic checks, e.g. with a test-case
model:

auth.settings.extra_fields['auth_user']= [Field('member_of',
'list:reference db.group_of_events', requires=IS_IN_DB(db,
db.group_of_events, '%(group_name)s', multiple=True))]

db.define_table(
'group_of_events',
Field('group_name', notnull=True, requires=[IS_SLUG(),
IS_NOT_IN_DB(db, 'group_of_events.group_name')]),
format='%(group_name)s')

And I want to do a check like this in the View:

{{if thisgroupid in request.auth_user.member_of:}}# BTW: I already
have the variable: `thisgroupid`{{T('Welcome back Mr
member!')}}{{else:}}{{T('Become a member')}}

*How do I perform the aforementioned check in a web2py view?*
*
*
Thanks for all information,

Alec Taylor

-- 





Re: [web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread vinicius...@gmail.com
If your doubt is about view syntax, it's just the way you outlined, with 
a few changes.


1) Change {{T(...)}} by {{=T(...)}}
2) Close the "else" with {{PASS}}

Always remember web2py views can have normal Python code. But don't 
overuse it, ok?


--
Vinicius Assef


On 07/23/2012 02:55 PM, Alec Taylor wrote:

I'm confused at how I'm meant to do logic checks, e.g. with a test-case
model:

auth.settings.extra_fields['auth_user']=  [Field('member_of',  'list:reference 
db.group_of_events',  requires=IS_IN_DB(db,  db.group_of_events,  
'%(group_name)s',  multiple=True))]

db.define_table(
 'group_of_events',
 Field('group_name',  notnull=True,  requires=[IS_SLUG(),  IS_NOT_IN_DB(db, 
 'group_of_events.group_name')]),
 format='%(group_name)s'
)

And I want to do a check like this in the View:

{{if  thisgroupidin  request.auth_user.member_of:}}
# BTW: I already have the variable: `thisgroupid`
{{T('Welcome back Mr member!')}}
{{else:}}
{{T('Become a member')}}

*How do I perform the aforementioned check in a web2py view?*
*
*
Thanks for all information,

Alec Taylor

--





--





Re: [web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread Alec Taylor
Thanks, but unfortunately that didn't work.

I forgot to mention my error before:
 'NoneType' object has no attribute
'member_of'

On Tue, Jul 24, 2012 at 4:03 AM, vinicius...@gmail.com <
vinicius...@gmail.com> wrote:

> If your doubt is about view syntax, it's just the way you outlined, with a
> few changes.
>
> 1) Change {{T(...)}} by {{=T(...)}}
> 2) Close the "else" with {{PASS}}
>
> Always remember web2py views can have normal Python code. But don't
> overuse it, ok?
>
> --
> Vinicius Assef
>
>
>
> On 07/23/2012 02:55 PM, Alec Taylor wrote:
>
>> I'm confused at how I'm meant to do logic checks, e.g. with a test-case
>> model:
>>
>> auth.settings.extra_fields['**auth_user']=  [Field('member_of',
>>  'list:reference db.group_of_events',  requires=IS_IN_DB(db,
>>  db.group_of_events,  '%(group_name)s',  multiple=True))]
>>
>> db.define_table(
>>  'group_of_events',
>>  Field('group_name',  notnull=True,  requires=[IS_SLUG(),
>>  IS_NOT_IN_DB(db,  'group_of_events.group_name')]**),
>>  format='%(group_name)s'
>> )
>>
>> And I want to do a check like this in the View:
>>
>> {{if  thisgroupidin  request.auth_user.member_of:}}
>>
>> # BTW: I already have the variable: `thisgroupid`
>> {{T('Welcome back Mr member!')}}
>> {{else:}}
>> {{T('Become a member')}}
>>
>> *How do I perform the aforementioned check in a web2py view?*
>> *
>>
>> *
>> Thanks for all information,
>>
>> Alec Taylor
>>
>> --
>>
>>
>>
>>
> --
>
>
>
>

-- 





Re: [web2py] Unit Testing Database Best Practices

2012-07-23 Thread Mark Li
Thanks Richard, for now I am going to create a special database table that 
will follow the structure of the actual data tables, but with a fixed data 
set like you suggested (controls for count very well).

I'm still interested in any real examples people use for unit testing 
databases and controller functions, I'm sure i'm glossing over something!

On Monday, July 23, 2012 7:40:51 AM UTC-7, Richard wrote:
>
> I am interesting in what will come out of this thread...
>
> But, to me I think your last question on fact that database will have 
> undertermined set of data mean that you maybe not validate your app base on 
> the entries of the database but on a testing database with a set of known 
> data, that you can even charge on need for the test. Also, you will just 
> test the limit with data that will for example help to demonstrate that a 
> field type is appropriately defined to get all type of data you intend to 
> put in in. Count, if variable get creates, etc., is more in the basic thing 
> you can always check for every function...
>
> I am also pretty new to unit test in general and have most the same 
> questions.
>
> Cheers!
>
> Richard
>
>
> On Sun, Jul 22, 2012 at 9:41 PM, Mark Li  wrote:
>
>> I'm fairly new to test-driven development and have decided it is the best 
>> way to go for my new webapp. While functional tests with selenium seem to 
>> be more straightforward (as far as what the tests want to accomplish), I'm 
>> lost on what unit tests for the database should test for.
>>
>> For example, if I have a database table with columns id, 'dogowner', and 
>> 'dogname', and have a controller returning a dict with 'dogowners', what 
>> should I be testing in the unit tests for the database and controller? 
>>
>> The database table will be fixed with a limited number of 'dogowner' 
>> entries, about 10, so should I be testing whether the database has 10 
>> entries, and if the len of the dict returned by the controller is 10? This 
>> datatable may not be fixed in the future, so what functionality of the 
>> database would I be testing for?
>>
>>
>>
>> I'm following http://www.web2py.com/AlterEgo/default/show/260 , but 
>> while that page explains HOW to go about unit testing, it doesn't explain 
>> what I should be testing for. Anyone experienced with TDD in web2py want to 
>> point me in the right direction? Thanks in advance!
>>
>> -- 
>>  
>>  
>>  
>>
>
>

-- 





Re: [web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread Bruno Rocha
there is no request.auth_user by default, did you created this?

I think you can do (with trunk)

{{if thisgroupid in auth.user_groups:}}

-- 





[web2py] Documentation nit

2012-07-23 Thread MichaelF
The last sentence of section 6.17 says, "Yes this is unusual and not rarely 
needed." It should read something like, "Yes this is unusual and rarely 
needed," or "Yes this is unusual and not often needed."

-- 





Re: [web2py] Unit Testing Database Best Practices

2012-07-23 Thread Martín Mulone
>
> I'm following http://www.web2py.com/AlterEgo/default/show/260
>

that guide is too old, have execfile() :S. Search in the group on how to
use modules in your app.

2012/7/22 Mark Li 

> I'm fairly new to test-driven development and have decided it is the best
> way to go for my new webapp. While functional tests with selenium seem to
> be more straightforward (as far as what the tests want to accomplish), I'm
> lost on what unit tests for the database should test for.
>
> For example, if I have a database table with columns id, 'dogowner', and
> 'dogname', and have a controller returning a dict with 'dogowners', what
> should I be testing in the unit tests for the database and controller?
>
> The database table will be fixed with a limited number of 'dogowner'
> entries, about 10, so should I be testing whether the database has 10
> entries, and if the len of the dict returned by the controller is 10? This
> datatable may not be fixed in the future, so what functionality of the
> database would I be testing for?
>
>
>
> I'm following http://www.web2py.com/AlterEgo/default/show/260 , but while
> that page explains HOW to go about unit testing, it doesn't explain what I
> should be testing for. Anyone experienced with TDD in web2py want to point
> me in the right direction? Thanks in advance!
>
> --
>
>
>
>



-- 
 http://www.tecnodoc.com.ar

-- 





[web2py] validate_and_insert() question

2012-07-23 Thread tiadobatima

Hi guys,

I'm trying to understand what validate_and_insert() 
and validate_and_update() are doing to see if I can use it reliably.
I'm writing an API, and I have no need for form validation. So after 
spending sometime reading the DAL code, I still have a few questions:

- When I insert a record that already exists (unique field), 
validate_and_insert() is smart enough to tell me that the record already 
exist, but I can't figure out how? I can't find out which "select" 
statement it's doing. 
- If the validation is per-field, and the table has 5 "unique" fields, will 
DAL make 5 selects before inserting?
- Is it possible to get more than one error in return dict from 
validate_and_insert() ret.errors?  
- What people are using for DAL/DB layer validations on rest APIs? From my 
google searches, it looks like not a lot of people are using 
validate_and_insert().

Thanks! :)

-- 





Re: [web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread Alec Taylor
On Tue, Jul 24, 2012 at 5:09 AM, Bruno Rocha  wrote:

>
> there is no request.auth_user by default, did you created this?
>
> I think you can do (with trunk)
>
> {{if thisgroupid in auth.user_groups:}}
>
>
Unfortunately that didn't work either... I'm running Version 2.0.0
(2012-07-20 17:37:48) dev:
 name 'auth_user' is not defined

-- 





Re: [web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread Alec Taylor
Just noticed I had underscore instead of point, still isn't working though:
 'NoneType' object has no attribute
'member_of'
On Tue, Jul 24, 2012 at 5:36 AM, Alec Taylor  wrote:

> On Tue, Jul 24, 2012 at 5:09 AM, Bruno Rocha wrote:
>
>>
>> there is no request.auth_user by default, did you created this?
>>
>> I think you can do (with trunk)
>>
>> {{if thisgroupid in auth.user_groups:}}
>>
>>
> Unfortunately that didn't work either... I'm running Version 2.0.0
> (2012-07-20 17:37:48) dev:
>  name 'auth_user' is not defined
>

-- 





[web2py] Confused re. "Validators in model not good MVC"

2012-07-23 Thread MichaelF
The documentation says, in section 6.17.4 (my highlighting):

1 {{extend 'layout.html'}}
> 2 Records
> 3 {{=SQLTABLE(rows)}}
>
 

SQLTABLE converts the rows into an HTML table with a header containing the
> column names and one row per record. ... 

The values extracted from the database are also formatted by the validators
> associated to the field and then escaped. (Note: Using a db in this way 
> in a
> view is usually not considered good MVC practice.)


I assume the doc means that validators shouldn't be used in a model file, 
as the formatting that gets done as a result should be done by the view. Or 
they should be used in a model file, but it's unfortunate that the 
formatting gets done as a result, as opposed to being done in the view.

1. Is my assumption correct? If not, then why is this "not considered good 
MVC practice"?

2. So what should be done in my web2py code, then? Add the validators in 
the controller code? Or is this just something we live with as web2py 
developers?

Thanks.

-- 





Re: [web2py] validate_and_insert() question

2012-07-23 Thread Alec Taylor
What kind of features are you looking to get from web2py?

To me it sounds like Twisted might be a better solution for you.

On Tue, Jul 24, 2012 at 5:27 AM, tiadobatima  wrote:

>
> Hi guys,
>
> I'm trying to understand what validate_and_insert()
> and validate_and_update() are doing to see if I can use it reliably.
> I'm writing an API, and I have no need for form validation. So after
> spending sometime reading the DAL code, I still have a few questions:
>
> - When I insert a record that already exists (unique field),
> validate_and_insert() is smart enough to tell me that the record already
> exist, but I can't figure out how? I can't find out which "select"
> statement it's doing.
> - If the validation is per-field, and the table has 5 "unique" fields,
> will DAL make 5 selects before inserting?
> - Is it possible to get more than one error in return dict from
> validate_and_insert() ret.errors?
> - What people are using for DAL/DB layer validations on rest APIs? From my
> google searches, it looks like not a lot of people are using
> validate_and_insert().
>
> Thanks! :)
>
> --
>
>
>
>

-- 





Re: [web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread Bruno Rocha
Do you have a member_of field in your auth_user table?

On Mon, Jul 23, 2012 at 4:40 PM, Alec Taylor  wrote:

> Just noticed I had underscore instead of point, still isn't working though:
>  'NoneType' object has no attribute
> 'member_of'
> On Tue, Jul 24, 2012 at 5:36 AM, Alec Taylor wrote:
>
>> On Tue, Jul 24, 2012 at 5:09 AM, Bruno Rocha wrote:
>>
>>>
>>> there is no request.auth_user by default, did you created this?
>>>
>>> I think you can do (with trunk)
>>>
>>> {{if thisgroupid in auth.user_groups:}}
>>>
>>>
>> Unfortunately that didn't work either... I'm running Version 2.0.0
>> (2012-07-20 17:37:48) dev:
>>  name 'auth_user' is not defined
>>
>
>  --
>
>
>
>

-- 





[web2py] load deletes the values of submit-buttons

2012-07-23 Thread Martin Weissenboeck
Hi, I have a simple form with two submit-buttons.

First try:

def index():
form=FORM(
INPUT(_type='submit', _value='A', _name='AA'),
INPUT(_type='submit', _value='B', _name='BB'),
)

if form.accepts(request, session):
return dict(AA=form.vars.AA, BB=form.vars.BB)

return dict(AA=form, BB='')


And a simple view index.html

AA: {{=AA}}BB: {{=BB}}


A click on button A gives

AA:A
BB:


and a click on B gives

AA:
BB:B


Everything works as expected - I need to know, which submit-button has been
pressed.

---

Secondy try:

Now I have two other views, index.load like index.html

AA: {{=AA}}BB: {{=BB}}


and an index2.html

{{extend 'layout.html'}}
{{=LOAD('default','index.load',ajax=True)}}


Calling index2.html allows a click on button A and button B, but the values
have gone. The result is always

AA:
BB:


It is not possible to decide, which submit button was active.
Any ideas?

Regard, Martin

-- 





[web2py] Re: Confused re. "Validators in model not good MVC"

2012-07-23 Thread Cliff Kachinske
Caveat: my opinions.  I am not a spokesperson for Web2py.  That said:

1.  No.  MVC provides separation of functions as a way of organizing code. 
 Usually programmers work together with designers, and MVC provides a way 
for them to interact without too much stepping on each other's toes. 
 Typically a view would be concerned with css and other design aspects.  To 
get some idea of what I mean, study the static/css files in your app.  Also 
look at layout.html.  MVC 

2.  You can put the validators anywhere in your code.  It is convenient to 
put them in the model because that way you only have to do them once.  Your 
validators would usually be the same across all controllers in your app, so 
why scatter them about?

This situation is not something i 'live with.'  It's a great convenience.

On Monday, July 23, 2012 3:41:39 PM UTC-4, MichaelF wrote:
>
> The documentation says, in section 6.17.4 (my highlighting):
>
> 1 {{extend 'layout.html'}}
>> 2 Records
>> 3 {{=SQLTABLE(rows)}}
>>
>  
>
> SQLTABLE converts the rows into an HTML table with a header containing the
>> column names and one row per record. ... 
>
> The values extracted from the database are also formatted by the validators
>> associated to the field and then escaped. (Note: Using a db in this way 
>> in a
>> view is usually not considered good MVC practice.)
>
>
> I assume the doc means that validators shouldn't be used in a model file, 
> as the formatting that gets done as a result should be done by the view. Or 
> they should be used in a model file, but it's unfortunate that the 
> formatting gets done as a result, as opposed to being done in the view.
>
> 1. Is my assumption correct? If not, then why is this "not considered good 
> MVC practice"?
>
> 2. So what should be done in my web2py code, then? Add the validators in 
> the controller code? Or is this just something we live with as web2py 
> developers?
>
> Thanks.
>

-- 





[web2py] Re: load deletes the values of submit-buttons

2012-07-23 Thread Anthony
This is not specific to the LOAD() helper but a limitation of the jQuery 
serialize() method used to post form data via Ajax. 
See https://groups.google.com/d/msg/web2py/708hxAdDGKY/2bNwbQVXc04J 
(includes link to possible workaround).

Anthony

On Monday, July 23, 2012 3:48:56 PM UTC-4, mweissen wrote:
>
> Hi, I have a simple form with two submit-buttons.
>
> First try:
>
> def index():
> form=FORM(
> INPUT(_type='submit', _value='A', _name='AA'),
> INPUT(_type='submit', _value='B', _name='BB'),
> )
> 
> if form.accepts(request, session):
> return dict(AA=form.vars.AA, BB=form.vars.BB)
> 
> return dict(AA=form, BB='')
>
>
> And a simple view index.html
>
> AA: {{=AA}}BB: {{=BB}}
>
>
> A click on button A gives 
>
> AA:A
> BB:
>
>
>  and a click on B gives 
>
> AA:
> BB:B
>
>
> Everything works as expected - I need to know, which submit-button has 
> been pressed.
>
> ---
>
> Secondy try:
>
> Now I have two other views, index.load like index.html
>
> AA: {{=AA}}BB: {{=BB}}
>
>
> and an index2.html
>
> {{extend 'layout.html'}}
> {{=LOAD('default','index.load',ajax=True)}}
>
>
> Calling index2.html allows a click on button A and button B, but the 
> values have gone. The result is always
>
> AA:
> BB:
>
>
> It is not possible to decide, which submit button was active.
> Any ideas?
>
> Regard, Martin
>
>
>

-- 





[web2py] Re: validate_and_insert() question

2012-07-23 Thread Niphlod
If you can't understand the code, just try it:

web2py.py -M -S mytestapp

db.define_table(
'tests',
Field('uniquefield', unique=True),
Field('withvalidator', requires=IS_NOT_IN_DB(db, 'tests.withvalidator'))
)
>>> ret = db.tests.validate_and_insert(uniquefield='a', withvalidator='b')
>>> ret
, 'id': 1}>
>>> ret = db.tests.validate_and_insert(uniquefield='a', withvalidator='b')
>>> ret
, 'id': None}>
>>> ret = db(db.tests.uniquefield=='a').validate_and_update(withvalidator=
'b')
>>> ret
}>
>>> ret = db(db.tests.uniquefield=='a').validate_and_update(withvalidator=
'c')
>>> ret
, 'update': 1}>



So, just as stated into the book, you have:
ret.errors that holds all errors if some costraint isn't fullfilled (and 
there is an error for every field that has an error, so multiple errors can 
be returned)
ret.id with the id of the newly inserted record
ret.update with the number of lines actually updated.

PS: if you have 5 unique fields, the only way to validate them (before 
inserting or updating) all is firing 5 different queries ( DAL does "under 
the hood" this by default with unique (it gets by default a "IS_NOT_IN_DB 
validator"), IS_IN_DB and IS_NOT_IN_DB validators). 

On Monday, July 23, 2012 9:27:37 PM UTC+2, tiadobatima wrote:
>
>
> Hi guys,
>
> I'm trying to understand what validate_and_insert() 
> and validate_and_update() are doing to see if I can use it reliably.
> I'm writing an API, and I have no need for form validation. So after 
> spending sometime reading the DAL code, I still have a few questions:
>
> - When I insert a record that already exists (unique field), 
> validate_and_insert() is smart enough to tell me that the record already 
> exist, but I can't figure out how? I can't find out which "select" 
> statement it's doing. 
> - If the validation is per-field, and the table has 5 "unique" fields, 
> will DAL make 5 selects before inserting?
> - Is it possible to get more than one error in return dict from 
> validate_and_insert() ret.errors?  
> - What people are using for DAL/DB layer validations on rest APIs? From my 
> google searches, it looks like not a lot of people are using 
> validate_and_insert().
>
> Thanks! :)
>

-- 





[web2py] Re: Confused re. "Validators in model not good MVC"

2012-07-23 Thread Anthony
In a previous edition of the book, that view example included the following:

{{=db().select(db.person.ALL)}}

I believe the note was referring to that usage of the db object in the 
view. I have removed the note, as the view has been updated since then and 
no longer refers directly to the db object.

I assume the doc means that validators shouldn't be used in a model file, 
> as the formatting that gets done as a result should be done by the view.
>

I don't think this is really an issue. The validators don't really do any 
formatting/presenting of the data, though in some cases they transform the 
data (which I think is properly the role of the model). The "represent" 
attibute of a field, on the other hand, can sometimes straddle the line 
between mere data transformation and actual formatting/presentation -- but 
even then, it may still make sense to keep these in the model because they 
will apply to all places where the field is represented, keeping the code 
DRY.

Anthony

-- 





Re: [web2py] Unit Testing Database Best Practices

2012-07-23 Thread Richard Vézina
I know it is not exactly what you want, but there is this tutorial for TDD
and web2py :

http://killer-web-development.com/section/4/3

Richard

On Mon, Jul 23, 2012 at 3:13 PM, Martín Mulone wrote:

> I'm following http://www.web2py.com/AlterEgo/default/show/260
>>
>
> that guide is too old, have execfile() :S. Search in the group on how to
> use modules in your app.
>
>
> 2012/7/22 Mark Li 
>
>> I'm fairly new to test-driven development and have decided it is the best
>> way to go for my new webapp. While functional tests with selenium seem to
>> be more straightforward (as far as what the tests want to accomplish), I'm
>> lost on what unit tests for the database should test for.
>>
>> For example, if I have a database table with columns id, 'dogowner', and
>> 'dogname', and have a controller returning a dict with 'dogowners', what
>> should I be testing in the unit tests for the database and controller?
>>
>> The database table will be fixed with a limited number of 'dogowner'
>> entries, about 10, so should I be testing whether the database has 10
>> entries, and if the len of the dict returned by the controller is 10? This
>> datatable may not be fixed in the future, so what functionality of the
>> database would I be testing for?
>>
>>
>>
>> I'm following http://www.web2py.com/AlterEgo/default/show/260 , but
>> while that page explains HOW to go about unit testing, it doesn't explain
>> what I should be testing for. Anyone experienced with TDD in web2py want to
>> point me in the right direction? Thanks in advance!
>>
>> --
>>
>>
>>
>>
>
>
>
> --
>  http://www.tecnodoc.com.ar
>
>  --
>
>
>
>

-- 





Re: [web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread Alec Taylor
Yes I do.

I have also tried with a bunch of other permutations.

Reading through the `Auth` reference, I found a few useful functions, most
helpful being:
{{=auth._get_user_id()}}

Using that I will be able to query the db, but will need to put the
reference on the group side rather than the user side. Was planning that
(or a two-way reference) anyway.

On Tue, Jul 24, 2012 at 5:46 AM, Bruno Rocha  wrote:

>
> Do you have a member_of field in your auth_user table?
>
> On Mon, Jul 23, 2012 at 4:40 PM, Alec Taylor wrote:
>
>> Just noticed I had underscore instead of point, still isn't working
>> though:
>>  'NoneType' object has no attribute
>> 'member_of'
>> On Tue, Jul 24, 2012 at 5:36 AM, Alec Taylor wrote:
>>
>>> On Tue, Jul 24, 2012 at 5:09 AM, Bruno Rocha wrote:
>>>

 there is no request.auth_user by default, did you created this?

 I think you can do (with trunk)

 {{if thisgroupid in auth.user_groups:}}


>>> Unfortunately that didn't work either... I'm running Version 2.0.0
>>> (2012-07-20 17:37:48) dev:
>>>  name 'auth_user' is not defined
>>>
>>
>>  --
>>
>>
>>
>>
>
>  --
>
>
>
>

-- 





[web2py] Pagination with no database

2012-07-23 Thread adohertyd
I have an application that returns a list of between 50-100 items. I have 
no database layer it isn't required for my app. I want to display 10 of 
those items on a page, and only generate the number of pages needed to view 
those results. Can anyone point me in the right direction (not the docs, 
they don't make any sense to me for this problem). Thank you

-- 





Re: [web2py] Unit Testing Database Best Practices

2012-07-23 Thread Richard Vézina
http://ncdegroot.blogspot.ca/2011/09/web2py-automate-unittesting-doctesting.html

http://www.web2pyslices.com/slice/show/1392/unit-testing

On Mon, Jul 23, 2012 at 4:17 PM, Richard Vézina  wrote:

> I know it is not exactly what you want, but there is this tutorial for TDD
> and web2py :
>
> http://killer-web-development.com/section/4/3
>
> Richard
>
>
> On Mon, Jul 23, 2012 at 3:13 PM, Martín Mulone wrote:
>
>> I'm following http://www.web2py.com/AlterEgo/default/show/260
>>>
>>
>> that guide is too old, have execfile() :S. Search in the group on how to
>> use modules in your app.
>>
>>
>> 2012/7/22 Mark Li 
>>
>>> I'm fairly new to test-driven development and have decided it is the
>>> best way to go for my new webapp. While functional tests with selenium seem
>>> to be more straightforward (as far as what the tests want to accomplish),
>>> I'm lost on what unit tests for the database should test for.
>>>
>>> For example, if I have a database table with columns id, 'dogowner', and
>>> 'dogname', and have a controller returning a dict with 'dogowners', what
>>> should I be testing in the unit tests for the database and controller?
>>>
>>> The database table will be fixed with a limited number of 'dogowner'
>>> entries, about 10, so should I be testing whether the database has 10
>>> entries, and if the len of the dict returned by the controller is 10? This
>>> datatable may not be fixed in the future, so what functionality of the
>>> database would I be testing for?
>>>
>>>
>>>
>>> I'm following http://www.web2py.com/AlterEgo/default/show/260 , but
>>> while that page explains HOW to go about unit testing, it doesn't explain
>>> what I should be testing for. Anyone experienced with TDD in web2py want to
>>> point me in the right direction? Thanks in advance!
>>>
>>> --
>>>
>>>
>>>
>>>
>>
>>
>>
>> --
>>  http://www.tecnodoc.com.ar
>>
>>  --
>>
>>
>>
>>
>
>

-- 





[web2py] Re: validate_and_insert() question

2012-07-23 Thread Niphlod
With that statement ("""if you don't understand the code, try it""") I 
meant that you can always check a functionality testing it before loosing 
your mind on the code.

All the "magic" is done by:

gluon/dal.py (validate_and_insert())

...
for key,value in fields.items():
value,error = self[key].validate(value)
if error:
response.errors[key] = error
...

the "validate()" method on the field calls the validators, defined into 
gluon/validators.py and "associated" by table definitions (db.define_table) 
or field requirements (Field('a', *requires=*)).

>>> print db.tests.uniquefield.requires
[, 
]


A unique field gets a IS_IN_DB validator in order to check before inserting 
the record (otherwise the commit() would raise an exception at the database 
level. Unfortunately, there is no universal way to tell WHICH field failed 
(and why) when you blindly insert a record, and you should wait for the 
commit() to raise that exception, so you'll lose "multiple" inserts with 
their properly related errors).

Some definitions (like the "unique" one) defaults to a "hidden" requires to 
your ones (as documented in the book 
http://web2py.com/books/default/chapter/29/6#Record-representation). 
Datetime fields, for example, are checked with a IS_DATETIME() validator,  
reference 
with a IS_IN_DB(), etc. etc. etc.

This is done into the sqlhtml_validators() function in gluon/dal.py. You 
can find there that a unique Field gets a IS_IN_DB() validator by default

... 
if field.unique:
requires._and = validators.IS_NOT_IN_DB(field.db,field)
...


PS: all code excerpts are from the trunk version. May be a little different 
from your web2py version, but this is sort of an "introduction" on where to 
find answers to your questions.



-- 





Re: [web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread Anthony
Have you tried:

{{if thisgroupid in auth.user.member_of:}}

Once the user is logged in, auth.user contains the user record from the 
auth_user table, so auth.user.member_of should be the list of 
group_of_events id's for the logged in user.

Anthony

On Monday, July 23, 2012 4:20:36 PM UTC-4, Alec Taylor wrote:
>
> Yes I do.
>
> I have also tried with a bunch of other permutations.
>
> Reading through the `Auth` reference, I found a few useful functions, most 
> helpful being:
> {{=auth._get_user_id()}}
>
> Using that I will be able to query the db, but will need to put the 
> reference on the group side rather than the user side. Was planning that 
> (or a two-way reference) anyway.
>
> On Tue, Jul 24, 2012 at 5:46 AM, Bruno Rocha wrote:
>
>>
>> Do you have a member_of field in your auth_user table?
>>
>> On Mon, Jul 23, 2012 at 4:40 PM, Alec Taylor wrote:
>>
>>> Just noticed I had underscore instead of point, still isn't working 
>>> though:
>>>   'NoneType' object has no attribute 
>>> 'member_of'
>>> On Tue, Jul 24, 2012 at 5:36 AM, Alec Taylor wrote:
>>>
 On Tue, Jul 24, 2012 at 5:09 AM, Bruno Rocha wrote:

>
> there is no request.auth_user by default, did you created this?
>
> I think you can do (with trunk)
>
> {{if thisgroupid in auth.user_groups:}} 
>
>
 Unfortunately that didn't work either... I'm running Version 2.0.0 
 (2012-07-20 17:37:48) dev:
  name 'auth_user' is not defined

>>>
>>>  -- 
>>>  
>>>  
>>>  
>>>
>>
>>  -- 
>>  
>>  
>>  
>>
>
>

-- 





[web2py] Re: Documentation nit

2012-07-23 Thread Anthony
Thanks. Fixed.

On Monday, July 23, 2012 3:13:00 PM UTC-4, MichaelF wrote:
>
> The last sentence of section 6.17 says, "Yes this is unusual and not 
> rarely needed." It should read something like, "Yes this is unusual and 
> rarely needed," or "Yes this is unusual and not often needed."

-- 





[web2py] Re: Pagination with no database

2012-07-23 Thread Niphlod
That's math!
e.g.
records_per_page = 10 records
all_records = 137 records

pages_needed = all_records / records_per_page (division)
last_page = all_records % records_per_page (module)

that is 13 "full pages" + 1 page with 7 records.

So, you'll have to count the total of your records, divide it by the number 
of "records per page" , an voila.

If you want urls in the form of (/myapp/mycontroller/myfunction/1, 
/myapp/mycontroller/myfunction/2, /myapp/mycontroller/myfunction/3, etc) it 
would roughly translate to:

all_records = 137
records_per_page = 10
urls = [URL('myapp', 'mycontroller', 'myfunction', args=[page+1]) for page 
in range(all_records+1)]



On Monday, July 23, 2012 10:20:48 PM UTC+2, adohertyd wrote:
>
> I have an application that returns a list of between 50-100 items. I have 
> no database layer it isn't required for my app. I want to display 10 of 
> those items on a page, and only generate the number of pages needed to view 
> those results. Can anyone point me in the right direction (not the docs, 
> they don't make any sense to me for this problem). Thank you

-- 





Re: [web2py] None ?

2012-07-23 Thread Ashraf Mansour

Right, there was no return statement.

Thank you, nice community.

Ashraf

-- 





[web2py] Re: How to hide items in Production?

2012-07-23 Thread Anthony
Maybe:

{{if auth.user and auth.has_membership(role='admin'):}}{{=response.toolbar
()}}{{pass}}

Anthony

On Monday, July 23, 2012 12:51:18 PM UTC-4, lyn2py wrote:
>
> Thank you both. It works. 
> If I want to keep the response toolbar available to the logged in admin, 
> how should I perform the IF test?
>
> On Monday, July 23, 2012 9:57:55 PM UTC+8, Anthony wrote:
>>
>> request.is_local indicates whether the request is coming from localhost, 
>> so that can often be used to distinguish between development and production.
>>
>> Anthony
>>
>> On Monday, July 23, 2012 3:53:49 AM UTC-4, lyn2py wrote:
>>>
>>> I have the code working on Localhost, but along with localhost there are 
>>> the response toolbar, the link to the admin site and the database used.
>>>
>>> What code should I use to "test" if the code is being executed on the 
>>> production server, so that I can "hide" or switch to use a different 
>>> database?
>>>
>>> I'm deploying on Amazon EC2, if this is any helpful. Thanks!
>>>
>>

-- 





[web2py] Re: Pagination with no database

2012-07-23 Thread adohertyd
Thank you for that makes perfect sense. This might be a stupid question but 
do I need to create an individual HTML page for each result set? The whole 
pagination thing is a mystery to me!

On Monday, 23 July 2012 21:33:34 UTC+1, Niphlod wrote:
>
> That's math!
> e.g.
> records_per_page = 10 records
> all_records = 137 records
>
> pages_needed = all_records / records_per_page (division)
> last_page = all_records % records_per_page (module)
>
> that is 13 "full pages" + 1 page with 7 records.
>
> So, you'll have to count the total of your records, divide it by the 
> number of "records per page" , an voila.
>
> If you want urls in the form of (/myapp/mycontroller/myfunction/1, 
> /myapp/mycontroller/myfunction/2, /myapp/mycontroller/myfunction/3, etc) it 
> would roughly translate to:
>
> all_records = 137
> records_per_page = 10
> urls = [URL('myapp', 'mycontroller', 'myfunction', args=[page+1]) forpage 
> in range(all_records+1)]
>
>
>
> On Monday, July 23, 2012 10:20:48 PM UTC+2, adohertyd wrote:
>>
>> I have an application that returns a list of between 50-100 items. I have 
>> no database layer it isn't required for my app. I want to display 10 of 
>> those items on a page, and only generate the number of pages needed to view 
>> those results. Can anyone point me in the right direction (not the docs, 
>> they don't make any sense to me for this problem). Thank you
>
>

-- 





[web2py] Re: Confused re. "Validators in model not good MVC"

2012-07-23 Thread Massimo Di Pierro
Anthony is right. That comment makes little sense in that context.

On Monday, 23 July 2012 15:16:29 UTC-5, Anthony wrote:
>
> In a previous edition of the book, that view example included the 
> following:
>
> {{=db().select(db.person.ALL)}}
>
> I believe the note was referring to that usage of the db object in the 
> view. I have removed the note, as the view has been updated since then and 
> no longer refers directly to the db object.
>
> I assume the doc means that validators shouldn't be used in a model file, 
>> as the formatting that gets done as a result should be done by the view.
>>
>
> I don't think this is really an issue. The validators don't really do any 
> formatting/presenting of the data, though in some cases they transform the 
> data (which I think is properly the role of the model). The "represent" 
> attibute of a field, on the other hand, can sometimes straddle the line 
> between mere data transformation and actual formatting/presentation -- but 
> even then, it may still make sense to keep these in the model because they 
> will apply to all places where the field is represented, keeping the code 
> DRY.
>
> Anthony
>

-- 





[web2py] Re: Confused re. "Validators in model not good MVC"

2012-07-23 Thread MichaelF
My thoughts exactly, hence my confusion with the highlighted sentence. As 
explained by Anthony in another reply, that sentence was let over from a 
previous version of the doc. I like the idea of putting validators in the 
model, assuming they are valid throughout the app (which makes sense).

Thanks again.

On Monday, July 23, 2012 1:58:26 PM UTC-6, Cliff Kachinske wrote:
>
> Caveat: my opinions.  I am not a spokesperson for Web2py.  That said:
>
> 1.  No.  MVC provides separation of functions as a way of organizing code. 
>  Usually programmers work together with designers, and MVC provides a way 
> for them to interact without too much stepping on each other's toes. 
>  Typically a view would be concerned with css and other design aspects.  To 
> get some idea of what I mean, study the static/css files in your app.  Also 
> look at layout.html.  MVC 
>
> 2.  You can put the validators anywhere in your code.  It is convenient to 
> put them in the model because that way you only have to do them once.  Your 
> validators would usually be the same across all controllers in your app, so 
> why scatter them about?
>
> This situation is not something i 'live with.'  It's a great convenience.
>
> On Monday, July 23, 2012 3:41:39 PM UTC-4, MichaelF wrote:
>>
>> The documentation says, in section 6.17.4 (my highlighting):
>>
>> 1 {{extend 'layout.html'}}
>>> 2 Records
>>> 3 {{=SQLTABLE(rows)}}
>>>
>>  
>>
>> SQLTABLE converts the rows into an HTML table with a header containing the
>>> column names and one row per record. ... 
>>
>> The values extracted from the database are also formatted by the 
>>> validators
>>> associated to the field and then escaped. (Note: Using a db in this way 
>>> in a
>>> view is usually not considered good MVC practice.)
>>
>>
>> I assume the doc means that validators shouldn't be used in a model file, 
>> as the formatting that gets done as a result should be done by the view. Or 
>> they should be used in a model file, but it's unfortunate that the 
>> formatting gets done as a result, as opposed to being done in the view.
>>
>> 1. Is my assumption correct? If not, then why is this "not considered 
>> good MVC practice"?
>>
>> 2. So what should be done in my web2py code, then? Add the validators in 
>> the controller code? Or is this just something we live with as web2py 
>> developers?
>>
>> Thanks.
>>
>

-- 





[web2py] Empty Database value is not None, but an empty string

2012-07-23 Thread Mark Li
I have a table defined in the following manner:

db.define_table('songinfo',
Field('songtitle'),
Field('artist'))

When I add an empty entry, or upload a CSV with empty values, I can only 
access those values with a database call like

songs = db(db.songinfo.artist=="").select()

as opposed to db(db.songinfo.artist==None).select()


The web2py book states that fields default=None, but I'm getting an empty 
string. Is there an appropriate way to have None instead of an empty string 
in the database?


-- 





[web2py] Re: Empty Database value is not None, but an empty string

2012-07-23 Thread Anthony
default=None means that no default is specified, not that a default value 
of None will be inserted.

Anthony

On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li wrote:
>
> I have a table defined in the following manner:
>
> db.define_table('songinfo',
> Field('songtitle'),
> Field('artist'))
>
> When I add an empty entry, or upload a CSV with empty values, I can only 
> access those values with a database call like
>
> songs = db(db.songinfo.artist=="").select()
>
> as opposed to db(db.songinfo.artist==None).select()
>
>
> The web2py book states that fields default=None, but I'm getting an empty 
> string. Is there an appropriate way to have None instead of an empty string 
> in the database?
>
>
>

-- 





[web2py] Re: Empty Database value is not None, but an empty string

2012-07-23 Thread Anthony
To enter a value of None, this might work:

default=lambda: None

Anthony

On Monday, July 23, 2012 5:04:44 PM UTC-4, Anthony wrote:
>
> default=None means that no default is specified, not that a default value 
> of None will be inserted.
>
> Anthony
>
> On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li wrote:
>>
>> I have a table defined in the following manner:
>>
>> db.define_table('songinfo',
>> Field('songtitle'),
>> Field('artist'))
>>
>> When I add an empty entry, or upload a CSV with empty values, I can only 
>> access those values with a database call like
>>
>> songs = db(db.songinfo.artist=="").select()
>>
>> as opposed to db(db.songinfo.artist==None).select()
>>
>>
>> The web2py book states that fields default=None, but I'm getting an empty 
>> string. Is there an appropriate way to have None instead of an empty string 
>> in the database?
>>
>>
>>

-- 





[web2py] Re: SQLFORM.grid pagination refresh

2012-07-23 Thread dave
the problem is whatever I do, the clicking the pagination triggers a whole 
page refresh, the links are not trapped, 

This describes the problem

Trapped Ajax links
A
Ajax links

Normally a link is not trapped, and by clicking in a link inside a 
component, the entire linked page is loaded. Sometimes you want the linked 
page to be loaded inside the component. This can be achieved using the A
helper:

1.

{{=A('linked page',_href='http://example.com',cid=request.cid)}}

If cid is specified, the linked page is loaded via Ajax. The cid is the id of 
the html element where to place the loaded page content. In this case we 
set it to request.cid, i.e. the id of the component that generates the 
link. The linked page can be and usually is an internal URL generated using 
the URL command.

-- 





[web2py] Re: Empty Database value is not None, but an empty string

2012-07-23 Thread Mark Li
Unfortunately the lambda method didn't work, Anthony. Any other ideas for 
having a None default for empty entries?


On a side note, if the 'integer' field type is used, then a blank entry 
results in a None. Don't know if that helps but it's something I've noticed.

On Monday, July 23, 2012 2:07:51 PM UTC-7, Anthony wrote:
>
> To enter a value of None, this might work:
>
> default=lambda: None
>
> Anthony
>
> On Monday, July 23, 2012 5:04:44 PM UTC-4, Anthony wrote:
>>
>> default=None means that no default is specified, not that a default value 
>> of None will be inserted.
>>
>> Anthony
>>
>> On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li wrote:
>>>
>>> I have a table defined in the following manner:
>>>
>>> db.define_table('songinfo',
>>> Field('songtitle'),
>>> Field('artist'))
>>>
>>> When I add an empty entry, or upload a CSV with empty values, I can only 
>>> access those values with a database call like
>>>
>>> songs = db(db.songinfo.artist=="").select()
>>>
>>> as opposed to db(db.songinfo.artist==None).select()
>>>
>>>
>>> The web2py book states that fields default=None, but I'm getting an 
>>> empty string. Is there an appropriate way to have None instead of an empty 
>>> string in the database?
>>>
>>>
>>>

-- 





[web2py] Auth has no attribute signature

2012-07-23 Thread David

I just upgraded my web2py to latest trunk.

I get an exception

S'("\'Auth\' object has no attribute \'signature\'",)'

did something change. I tried the mailing list archive to see, but maybe 
I missed something.


Thanks.


--





Re: [web2py] Re: Empty Database value is not None, but an empty string

2012-07-23 Thread vinicius...@gmail.com
As far as I know, let "notnull=False" and "required=False" for your 
fields and don't set "default" property.




On 07/23/2012 06:32 PM, Mark Li wrote:

Unfortunately the lambda method didn't work, Anthony. Any other ideas
for having a None default for empty entries?


On a side note, if the 'integer' field type is used, then a blank entry
results in a None. Don't know if that helps but it's something I've noticed.

On Monday, July 23, 2012 2:07:51 PM UTC-7, Anthony wrote:

To enter a value of None, this might work:

|
default=lambda:None
|

Anthony

On Monday, July 23, 2012 5:04:44 PM UTC-4, Anthony wrote:

default=None means that no default is specified, not that a
default value of None will be inserted.

Anthony

On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li wrote:

I have a table defined in the following manner:

db.define_table('songinfo',
Field('songtitle'),
Field('artist'))

When I add an empty entry, or upload a CSV with empty
values, I can only access those values with a database call like

songs = db(db.songinfo.artist=="").select()

as opposed to db(db.songinfo.artist==None).select()


The web2py book states that fields default=None, but I'm
getting an empty string. Is there an appropriate way to have
None instead of an empty string in the database?


--





--





[web2py] weird behavior in crud update

2012-07-23 Thread Najtsirk
Hi,

each time i want to update crud, i have to submit changes twice to get it 
actually updated.

I set crud.settings.detect_record_change = False, which helps with 'text' 
fields, but the problem presists with 'boolean'. Boolean field get changed 
each time i update form, even though I do not change it. 

I'm getting this on 1.99.4 and on 1.99.7.

I'm seeing this for the first time, but then againi'm doing Blog app 
for the first time and there is a little more updating than in my other 
apps.

Any clues?

Best,
Kristjan


-- 





Re: [web2py] Re: Empty Database value is not None, but an empty string

2012-07-23 Thread Mark Li
Aren't those the default values for a Field Contructor? I tried explicitly 
adding "notnull=False" and "required=False", and didn't set the default 
property, but empty values still come out as an empty string instead of 
None.

On Monday, July 23, 2012 2:48:56 PM UTC-7, viniciusban wrote:
>
> As far as I know, let "notnull=False" and "required=False" for your 
> fields and don't set "default" property. 
>
>
>
> On 07/23/2012 06:32 PM, Mark Li wrote: 
> > Unfortunately the lambda method didn't work, Anthony. Any other ideas 
> > for having a None default for empty entries? 
> > 
> > 
> > On a side note, if the 'integer' field type is used, then a blank entry 
> > results in a None. Don't know if that helps but it's something I've 
> noticed. 
> > 
> > On Monday, July 23, 2012 2:07:51 PM UTC-7, Anthony wrote: 
> > 
> > To enter a value of None, this might work: 
> > 
> > | 
> > default=lambda:None 
> > | 
> > 
> > Anthony 
> > 
> > On Monday, July 23, 2012 5:04:44 PM UTC-4, Anthony wrote: 
> > 
> > default=None means that no default is specified, not that a 
> > default value of None will be inserted. 
> > 
> > Anthony 
> > 
> > On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li wrote: 
> > 
> > I have a table defined in the following manner: 
> > 
> > db.define_table('songinfo', 
> > Field('songtitle'), 
> > Field('artist')) 
> > 
> > When I add an empty entry, or upload a CSV with empty 
> > values, I can only access those values with a database call 
> like 
> > 
> > songs = db(db.songinfo.artist=="").select() 
> > 
> > as opposed to db(db.songinfo.artist==None).select() 
> > 
> > 
> > The web2py book states that fields default=None, but I'm 
> > getting an empty string. Is there an appropriate way to have 
> > None instead of an empty string in the database? 
> > 
> > 
> > -- 
> > 
> > 
> > 
>
>

-- 





[web2py] Re: Pagination with no database

2012-07-23 Thread Niphlod
Usually you have some means to "order" the records (e.g., a "id" field that 
is 1,2,3,4,5,  a "name" field that is a,b,c,d, an inserted_on datetime 
field that is 2012-07-23m, 2012-07-24, etc etc etc).

When the order of the records is established in a list:

all_records = ['a','b','c','d',...]



you can (this is python, not strictly web2py)
>>> all_records[0]
'a'
>>> all_records[-1]
'd'
>>> all_records[2:4]
['c', 'd']

NB: list indexes are 0 indexed (the first record is [0], not [1])
So, back to your example, you'd need on the first page to show records from 
0 to 9, on the second page records from 10 to 19, and so on.

Given that in web2py you can catch (with the previous example) the 
/myapp/mycontroller/myfunction/*thenumberofthepage* with request.args(0), 
still refreshing some math you need to "associate" the number of pages to 
the range you want. This is what you need to calculate:

page 1 : all_records[0:10]
page 2: all_records[10:20]
page 3: all_records[20:30] 

and so on.

page_number = request.args(0)
records_per_page = 10
records_to_show = all_records[(page_number-1)*records_per_page:page_number*
records_per_page]

and that's pretty much about it. There are smarter way, different 
implementations, etc etc but this is the straightforward way to show a 
"universal" method based on a simple calculation.

NB: 
all_records = ['a','b']
all_records[10:20]
>>> []

no exceptions are thrown. If you get an empty list you are "requesting a 
too far page", i.e. a page with a too high *thenumberofthepage*












On Monday, July 23, 2012 10:38:01 PM UTC+2, adohertyd wrote:
>
> Thank you for that makes perfect sense. This might be a stupid question 
> but do I need to create an individual HTML page for each result set? The 
> whole pagination thing is a mystery to me!
>
> On Monday, 23 July 2012 21:33:34 UTC+1, Niphlod wrote:
>>
>> That's math!
>> e.g.
>> records_per_page = 10 records
>> all_records = 137 records
>>
>> pages_needed = all_records / records_per_page (division)
>> last_page = all_records % records_per_page (module)
>>
>> that is 13 "full pages" + 1 page with 7 records.
>>
>> So, you'll have to count the total of your records, divide it by the 
>> number of "records per page" , an voila.
>>
>> If you want urls in the form of (/myapp/mycontroller/myfunction/1, 
>> /myapp/mycontroller/myfunction/2, /myapp/mycontroller/myfunction/3, etc) it 
>> would roughly translate to:
>>
>> all_records = 137
>> records_per_page = 10
>> urls = [URL('myapp', 'mycontroller', 'myfunction', args=[page+1]) forpage 
>> in range(all_records+1)]
>>
>>
>>
>> On Monday, July 23, 2012 10:20:48 PM UTC+2, adohertyd wrote:
>>>
>>> I have an application that returns a list of between 50-100 items. I 
>>> have no database layer it isn't required for my app. I want to display 10 
>>> of those items on a page, and only generate the number of pages needed to 
>>> view those results. Can anyone point me in the right direction (not the 
>>> docs, they don't make any sense to me for this problem). Thank you
>>
>>

-- 





Re: [web2py] Re: Multi-tenant social-network?

2012-07-23 Thread Cliff Kachinske
> Separate DBs sounds messy.

Some elaboration on that point.

Methinks you will lose the advantage of connection pooling.  Every request 
will need its own connection, and performance will suffer.

How will you avoid duplicate db names?  You will need a central repository, 
which probably should be another db.  This set of connections could pool, 
though.

At some point your rdbms will impose a penalty for keeping track of so many 
db's, assuming you get a lot of users.

The Web2py manual elaborates on multi-tenancy at 
http://web2py.com/books/default/chapter/29/6#Common-fields-and-multi-tenancy


On Friday, July 20, 2012 1:15:08 AM UTC-4, Alec Taylor wrote:
>
> On Fri, Jul 20, 2012 at 4:12 AM, Andrew  wrote: 
> > If users can create groups, will you want to create a database on the 
> fly? 
> > 
>
> Yes. In the same way that in Massimo talk from a few months ago he 
> talked about using the multi-tenant feature in an e-commerce setup, 
> presumable where individuals would click a button "Create a new 
> shop"... 
>
> My use-case is quite similar. 
>
> On Fri, Jul 20, 2012 at 8:22 AM, pbreit  wrote: 
> > Separate DBs sounds messy. You could either use Web2py's multi-tenant 
> > functionality and/or auth_group. Or just code it. 
> > 
>
> Could you please elaborate? 
>

-- 





Re: [web2py] Re: Facebook login no longer works when done on remote host?

2012-07-23 Thread howesc
are you explicitly setting the redirect_uri for the FB call?  you should 
beand then you can control it to be what you want it to be.  how you 
set it depends on exactly which version of the FB APIs you are using, but 
it's been a config option in most of the calls i have ever done.

On Monday, July 23, 2012 4:02:17 AM UTC-7, Alec Taylor wrote:
>
> Okay, this is a little strange. 
>
> Just did a bit morre troubleshooting, found that: 
> - That IP Address isn't associated with my domain in any way (I 
> emailed my host to confirm) 
> - The client ID is the one I'm using for my local web2py server, not 
> the one I modified it too in "fbappauth.py" 
> - There were .pyc files in my "/modules" folder, which have now been 
> removed 
> - I had forgotten to add "App Domains" and "Site URL" to the Facebook app 
>
> Unfortunately I still can't login with facebook, and am still being 
> presented the same error :/ 
>
> On Mon, Jul 23, 2012 at 6:40 PM, Michele Comitini 
> > wrote: 
> > The simplest thing to do is give a name of choice put that in the 
> > developers.facebook.com configuration panel of you application. 
> > 
> > THEN if you want to test just add a record in you /etc/hosts file 
> > pointing to localhost when testing locally, pointing to your server 
> > when testing production. 
> > 
> > For instance put http://my.facebook.app[:port] in the configuration 
> > panel.  Remember the port i.e. if testing locally on port 8000 you 
> > have to put that port in the configuration panel. 
> > 
> > ---8< 
> > # hosts file 
> > 127.0.0.1 my.facebook.app 
> > # comment above and uncomment below when testing on remote host 
> > # 1.2.3.4 my.facebook.app 
> > ---8<- 
> > 
> > Testing is easier is you can use same port locally or on production. 
> > 
> > mic 
> > 
> > 
> > 2012/7/23 howesc: 
> >> facebook is a picky pain in the *** 
> >> 
> >> in your facebook config you set a single domain name or ip address that 
> is 
> >> associated with the facebook app.  all redirects that you specify when 
> >> making calls to the facebook API must be in that domain/ip address.  so 
> your 
> >> facebook config would need to have http://58.168.6.57 as the app 
> domain (or 
> >> whatever they call the setting these days) based on the URL above. 
> >> 
> >> this makes testing a PITA.  i have a plethora of facebook appsin 
> real 
> >> life i use 3: 1 for localhost, 1 for test server and 1 for production 
> (with 
> >> a squirrelly if statement to select which set of facebook keys to use 
> based 
> >> on the detected server environment) 
> >> 
> >> if anyone has better suggestions, i'm all ears! 
> >> 
> >> cfh 
> >> 
> >> 
> >> On Sunday, July 22, 2012 6:59:48 AM UTC-7, Alec Taylor wrote: 
> >>> 
> >>> I generated a new application on Facebook—added in the new CLIENT_ID 
> >>> and CLIENT_SECRET—but when I tried to login, the URL said: 
> >>> 
> >>> 
> >>> 
> https://graph.facebook.com/oauth/authorize?scope=user_photos%2Cfriends_photos&redirect_uri=http%3A%2F%2F58.168.6.57%2Fuser%2Flogin&response_type=code&client_id=  
>
> >>> top-secret clientID here> 
> >>> 
> >>> And the page said: 
> >>> 
> >>> { 
> >>>"error": { 
> >>>   "message": "Invalid redirect_uri: Given URL is not allowed by 
> >>> the Application configuration.", 
> >>>   "type": "OAuthException", 
> >>>   "code": 191 
> >>>} 
> >>> } 
> >>> 
> >>> Here is my db.py: http://pastebin.com/zULTxA7D 
> >>> 
> >>> What is going wrong? — I've tried modifying all my redirects, to no 
> avail. 
> >>> 
> >>> Thanks for all suggestions, 
> >>> 
> >>> Alec Taylor 
> >> 
> >> -- 
> >> 
> >> 
> >> 
> > 
> > -- 
> > 
> > 
> > 
>

-- 





[web2py] Select Distinct for more than 1 distinct value

2012-07-23 Thread Mark Li
I have a database setup with id and 'dogname.' I would like to retrieve 
distinct values of dogname, but allow for 2 of each dogname. So instead of 
limiting it to one distinct value, there could be 2 identical dognames that 
are retrieved, but no more than that.

Is there a way to set this kind of limit for distinct?

-- 





[web2py] Re: Select Distinct for more than 1 distinct value

2012-07-23 Thread villas
I can't see how distinct would help there because it only returns unique 
rows.

I would say that the main question is how much data you have.  I mean,  it 
is probably easier to grab all the data and then discard (or simply loop 
over) the data you do not need.  However,  if you have a huge number of 
records that may not be practical.


On Monday, July 23, 2012 11:15:14 PM UTC+1, Mark Li wrote:
>
> I have a database setup with id and 'dogname.' I would like to retrieve 
> distinct values of dogname, but allow for 2 of each dogname. So instead of 
> limiting it to one distinct value, there could be 2 identical dognames that 
> are retrieved, but no more than that.
>
> Is there a way to set this kind of limit for distinct?
>

-- 





[web2py] Re: Select Distinct for more than 1 distinct value

2012-07-23 Thread Mark Li
I'll be looping over them for now, is there anyway to use a query or 
select() to return a set with no more than 2 of each name?

On Monday, July 23, 2012 3:43:38 PM UTC-7, villas wrote:
>
> I can't see how distinct would help there because it only returns unique 
> rows.
>
> I would say that the main question is how much data you have.  I mean,  it 
> is probably easier to grab all the data and then discard (or simply loop 
> over) the data you do not need.  However,  if you have a huge number of 
> records that may not be practical.
>
>
> On Monday, July 23, 2012 11:15:14 PM UTC+1, Mark Li wrote:
>>
>> I have a database setup with id and 'dogname.' I would like to retrieve 
>> distinct values of dogname, but allow for 2 of each dogname. So instead of 
>> limiting it to one distinct value, there could be 2 identical dognames that 
>> are retrieved, but no more than that.
>>
>> Is there a way to set this kind of limit for distinct?
>>
>

-- 





Re: [web2py] Re: Multi-tenant social-network?

2012-07-23 Thread pbreit
On Monday, July 23, 2012 3:01:40 PM UTC-7, Cliff Kachinske wrote:
>
> > Separate DBs sounds messy.
>
> Some elaboration on that point.
>

Everything that is simple to do on one DB becomes complicated to do on 
multiple DBs. For example, I run a multi-tenant site that I constantly run 
queries against all tenants. That would be a pain with separate DBs. Same 
with migrations, backups, etc.

And I don't see much actual benefit of splitting into multiple DBs. The 
benefits I hear about seem mostly perceptual (data isolation, etc). 

-- 





[web2py] Re: bootstrap and user panel

2012-07-23 Thread juaneduardo
Great Martin... I will test right now.

El lunes, 23 de julio de 2012 20:02:47 UTC-4, Martin.Mulone escribió:
>
> I want to share this two applications*
>
> Bootstrap welcome application*
>
> I made my own welcome scatfold app, using twitter bootstrap template. My 
> version is more like from the example template. 
> Download: https://bitbucket.org/mulonemartin/bootstrap/overview also you 
> can test here .
>
> *User Panel Admin*
>
> An application to administer the auth_user table. You can add, remove, 
> activate users/ add groups, also add users to groups and so on. 
> https://bitbucket.org/mulonemartin/usersadmin
>
>
>
>

-- 





[web2py] Re: SQLFORM.grid pagination refresh

2012-07-23 Thread Anthony
I see. I was responding to your request for filtering (e.g., showing only 
50 records). If you put the grid in a web2py component (e.g., via LOAD()), 
then the links should automatically get trapped. Is there a reason you 
don't want to use a component?

Anthony

On Monday, July 23, 2012 5:09:52 PM UTC-4, dave wrote:
>
> the problem is whatever I do, clicking the pagination triggers a whole 
> page refresh, the links are not trapped, 
>
> This describes the problem
>
> Trapped Ajax links
> A
> Ajax links
>
> Normally a link is not trapped, and by clicking in a link inside a 
> component, the entire linked page is loaded. Sometimes you want the linked 
> page to be loaded inside the component. This can be achieved using the A
> helper:
>
> 1.
>
> {{=A('linked page',_href='http://example.com',cid=request.cid)}}
>
> If cid is specified, the linked page is loaded via Ajax. The cid is the id of 
> the html element where to place the loaded page content. In this case we 
> set it to request.cid, i.e. the id of the component that generates the 
> link. The linked page can be and usually is an internal URL generated using 
> the URL command.
>

-- 





Re: [web2py] Re: new plugin - web2py Form Wizard - PowerFormWizard

2012-07-23 Thread Don_X
Bruno Rocha,

This is a very nice plugin ! ... very useful, thanks for sharing !

I have to create 2 registrations methods ( one short and one long method to 
register )

I have one problem, how would you suggest to user the wizard when there are 
3 tables involved in the long signup method ??

for example in my db I have many tables ... but the full registration for 
the app affects 3 tables, while the short one which is already done only 
affects 1 table ( the auth-user table) !
I need to manipulate the powerformwizard for all 3 tables in the complete 
registration approach

table1 is the auth-user table with first and lastname, password and email, 
birthdate and user type.
table2 is the coordinates of the user ( with street adress, city, Zip or 
postal code, Country of residence, Origin and language spoken )
table3 is the profile informations ( like picture upload, description, 
story,  bio, ..)

Any suggestions ? ... 

thanks

Don


-- 





Re: [web2py] Re: new plugin - web2py Form Wizard - PowerFormWizard

2012-07-23 Thread Bruno Rocha
Also, there is a nice example in the "web2py cookbook"

Source code is here:

https://github.com/mdipierro/web2py-recipes-source/tree/master/source/04_advanced_forms/06_Creating_a_Form_Wizard

App is here:

https://github.com/mdipierro/web2py-recipes-source/blob/master/apps/04_advanced_forms/web2py.app.form_wizard.w2p

-- 





Re: [web2py] Unit Testing Database Best Practices

2012-07-23 Thread Mark Li
Regarding Martin's response for anyone who is learning the ropes like me, I 
removed the execfile() line and placed my unit_test.py script in the module 
folder.

On Monday, July 23, 2012 12:13:07 PM UTC-7, Martin.Mulone wrote:
>
> I'm following http://www.web2py.com/AlterEgo/default/show/260 
>>
>
> that guide is too old, have execfile() :S. Search in the group on how to 
> use modules in your app.
>
> 2012/7/22 Mark Li 
>
>> I'm fairly new to test-driven development and have decided it is the best 
>> way to go for my new webapp. While functional tests with selenium seem to 
>> be more straightforward (as far as what the tests want to accomplish), I'm 
>> lost on what unit tests for the database should test for.
>>
>> For example, if I have a database table with columns id, 'dogowner', and 
>> 'dogname', and have a controller returning a dict with 'dogowners', what 
>> should I be testing in the unit tests for the database and controller? 
>>
>> The database table will be fixed with a limited number of 'dogowner' 
>> entries, about 10, so should I be testing whether the database has 10 
>> entries, and if the len of the dict returned by the controller is 10? This 
>> datatable may not be fixed in the future, so what functionality of the 
>> database would I be testing for?
>>
>>
>>
>> I'm following http://www.web2py.com/AlterEgo/default/show/260 , but 
>> while that page explains HOW to go about unit testing, it doesn't explain 
>> what I should be testing for. Anyone experienced with TDD in web2py want to 
>> point me in the right direction? Thanks in advance!
>>
>> -- 
>>  
>>  
>>  
>>
>
>
>
> -- 
>  http://www.tecnodoc.com.ar
>
>

-- 





Re: [web2py] Re: new plugin - web2py Form Wizard - PowerFormWizard

2012-07-23 Thread Bruno Rocha
fixed link for app:

https://github.com/mdipierro/web2py-recipes-source/raw/master/apps/04_advanced_forms/web2py.app.form_wizard.w2p

-- 





[web2py] displacement of password button [web2py twitter bootstrap]

2012-07-23 Thread Kevin Miller
Hi all,

Anyone knows why the password button is displaced by the welcome message
when using twitter bootstrap and Nightly Build?
I have attached a picture as example.


Thanks.

Kevin

-- 



<>

[web2py] Re: How to hide items in Production?

2012-07-23 Thread lyn2py
Thanks Anthony, I meant the web2py admin login, rather than the per-site 
login.



On Tuesday, July 24, 2012 4:34:58 AM UTC+8, Anthony wrote:
>
> Maybe:
>
> {{if auth.user and auth.has_membership(role='admin'):}}{{=response.toolbar
> ()}}{{pass}}
>
> Anthony
>
> On Monday, July 23, 2012 12:51:18 PM UTC-4, lyn2py wrote:
>>
>> Thank you both. It works. 
>> If I want to keep the response toolbar available to the logged in admin, 
>> how should I perform the IF test?
>>
>> On Monday, July 23, 2012 9:57:55 PM UTC+8, Anthony wrote:
>>>
>>> request.is_local indicates whether the request is coming from localhost, 
>>> so that can often be used to distinguish between development and production.
>>>
>>> Anthony
>>>
>>> On Monday, July 23, 2012 3:53:49 AM UTC-4, lyn2py wrote:

 I have the code working on Localhost, but along with localhost there 
 are the response toolbar, the link to the admin site and the database used.

 What code should I use to "test" if the code is being executed on the 
 production server, so that I can "hide" or switch to use a different 
 database?

 I'm deploying on Amazon EC2, if this is any helpful. Thanks!

>>>

-- 





[web2py] Re: Auth has no attribute signature

2012-07-23 Thread Massimo Di Pierro
Yes. auth.signature used to be defined when Auth() is instantiated. Now it 
is defined when auth.define_tables() is called. There is disagreement on 
whether this is a breaking of backward compatibility since this is 
not exactly documented. There are reason for the switch. Is this a big 
deal? It is not clear whether this change of behavior should propagate to 
stable.

On Monday, 23 July 2012 16:38:18 UTC-5, David J wrote:
>
> I just upgraded my web2py to latest trunk. 
>
> I get an exception 
>
> S'("\'Auth\' object has no attribute \'signature\'",)' 
>
> did something change. I tried the mailing list archive to see, but maybe 
> I missed something. 
>
> Thanks. 
>
>
>

-- 





[web2py] Re: weird behavior in crud update

2012-07-23 Thread Massimo Di Pierro
Please do not use crud. It is not needed any more. You can do everything 
and better with SQLFORM().process().
We are not going to change the behavior of curd now that we have a more 
powerful tool (SQLFORM).

On Monday, 23 July 2012 16:55:49 UTC-5, Najtsirk wrote:
>
> Hi,
>
> each time i want to update crud, i have to submit changes twice to get it 
> actually updated.
>
> I set crud.settings.detect_record_change = False, which helps with 'text' 
> fields, but the problem presists with 'boolean'. Boolean field get changed 
> each time i update form, even though I do not change it. 
>
> I'm getting this on 1.99.4 and on 1.99.7.
>
> I'm seeing this for the first time, but then againi'm doing Blog app 
> for the first time and there is a little more updating than in my other 
> apps.
>
> Any clues?
>
> Best,
> Kristjan
>
>
>

-- 





[web2py] Re: bootstrap and user panel

2012-07-23 Thread Massimo Di Pierro
This looks great. Are you proposing it as a replacement for the current 
welcome? pros? cons?

On Monday, 23 July 2012 19:02:47 UTC-5, Martin.Mulone wrote:
>
> I want to share this two applications*
>
> Bootstrap welcome application*
>
> I made my own welcome scatfold app, using twitter bootstrap template. My 
> version is more like from the example template. 
> Download: https://bitbucket.org/mulonemartin/bootstrap/overview also you 
> can test here .
>
> *User Panel Admin*
>
> An application to administer the auth_user table. You can add, remove, 
> activate users/ add groups, also add users to groups and so on. 
> https://bitbucket.org/mulonemartin/usersadmin
>
>
>
>

-- 





Re: [web2py] Re: new plugin - web2py Form Wizard - PowerFormWizard

2012-07-23 Thread Don_X
Bruno,

I did follow these examples already ... I tried different things ... 
different approaches ... but for 3 tables it seems not do-able ! 
I am still searching for ways for it to be done ! .. so far .. no luck ! ...
I tried using the method with 3 tables like this ( by combining the method 
described in ch: 4  page 153 of the same book you refereed to )
 form = SQLFORM.factory(db.auth_user,db.coord_user,db.user_profile)

but ..no luck ! ...

I wander is the form wizard ... or the powerformwizard can work with more 
than 2 tables ?
if yes ... I have not figure out how to do it  not yet ! .. meanwhile 
if anyone have any suggestion  please enlighten me !!

thx

Don


On Monday, July 23, 2012 8:46:36 PM UTC-4, rochacbruno wrote:
>
> fixed link for app:
>
>
> https://github.com/mdipierro/web2py-recipes-source/raw/master/apps/04_advanced_forms/web2py.app.form_wizard.w2p
>

-- 





Re: [web2py] Re: Empty Database value is not None, but an empty string

2012-07-23 Thread Anthony
>From the code, it looks like doing an insert without specifying a field 
should result in a NULL, not an empty string. However, I think a CSV file 
with empty fields is handled differently. The .import_from_csv_file() 
method takes a "null" argument that defaults to "" -- so, I think if 
the CSV file contains a "", it will be converted to a NULL in the 
database insert -- otherwise the value will be inserted as is (presumably 
even an empty string). To convert empty strings to NULL's, perhaps you just 
have to do:

db.mytable.import_from_csv_file([file object], null='')

Does that work?

Anthony

On Monday, July 23, 2012 5:58:19 PM UTC-4, Mark Li wrote:
>
> Aren't those the default values for a Field Contructor? I tried explicitly 
> adding "notnull=False" and "required=False", and didn't set the default 
> property, but empty values still come out as an empty string instead of 
> None.
>
> On Monday, July 23, 2012 2:48:56 PM UTC-7, viniciusban wrote:
>>
>> As far as I know, let "notnull=False" and "required=False" for your 
>> fields and don't set "default" property. 
>>
>>
>>
>> On 07/23/2012 06:32 PM, Mark Li wrote: 
>> > Unfortunately the lambda method didn't work, Anthony. Any other ideas 
>> > for having a None default for empty entries? 
>> > 
>> > 
>> > On a side note, if the 'integer' field type is used, then a blank entry 
>> > results in a None. Don't know if that helps but it's something I've 
>> noticed. 
>> > 
>> > On Monday, July 23, 2012 2:07:51 PM UTC-7, Anthony wrote: 
>> > 
>> > To enter a value of None, this might work: 
>> > 
>> > | 
>> > default=lambda:None 
>> > | 
>> > 
>> > Anthony 
>> > 
>> > On Monday, July 23, 2012 5:04:44 PM UTC-4, Anthony wrote: 
>> > 
>> > default=None means that no default is specified, not that a 
>> > default value of None will be inserted. 
>> > 
>> > Anthony 
>> > 
>> > On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li wrote: 
>> > 
>> > I have a table defined in the following manner: 
>> > 
>> > db.define_table('songinfo', 
>> > Field('songtitle'), 
>> > Field('artist')) 
>> > 
>> > When I add an empty entry, or upload a CSV with empty 
>> > values, I can only access those values with a database call 
>> like 
>> > 
>> > songs = db(db.songinfo.artist=="").select() 
>> > 
>> > as opposed to db(db.songinfo.artist==None).select() 
>> > 
>> > 
>> > The web2py book states that fields default=None, but I'm 
>> > getting an empty string. Is there an appropriate way to 
>> have 
>> > None instead of an empty string in the database? 
>> > 
>> > 
>> > -- 
>> > 
>> > 
>> > 
>>
>>

-- 





[web2py] Re: weird behavior in crud update

2012-07-23 Thread Anthony
Should we mark Crud as deprecated in the book?

On Monday, July 23, 2012 11:55:14 PM UTC-4, Massimo Di Pierro wrote:
>
> Please do not use crud. It is not needed any more. You can do everything 
> and better with SQLFORM().process().
> We are not going to change the behavior of curd now that we have a more 
> powerful tool (SQLFORM).
>
> On Monday, 23 July 2012 16:55:49 UTC-5, Najtsirk wrote:
>>
>> Hi,
>>
>> each time i want to update crud, i have to submit changes twice to get it 
>> actually updated.
>>
>> I set crud.settings.detect_record_change = False, which helps with 'text' 
>> fields, but the problem presists with 'boolean'. Boolean field get changed 
>> each time i update form, even though I do not change it. 
>>
>> I'm getting this on 1.99.4 and on 1.99.7.
>>
>> I'm seeing this for the first time, but then againi'm doing Blog app 
>> for the first time and there is a little more updating than in my other 
>> apps.
>>
>> Any clues?
>>
>> Best,
>> Kristjan
>>
>>
>>

-- 





Re: [web2py] Re: Auth has no attribute signature

2012-07-23 Thread David

Ok.

I am not going to complain about it because I fixed the app,

However, I did see it in the docs. if you search the docs for 
auth.signature it shows the usage.


But here is where it broke..I had a custom auth table, and in that table 
I called


db.define_table(
auth.settings.table_user_name,
Field('first_name', length=64, default='',widget = lambda f, v: 
SQLFORM.widgets.string.widget(f, v, _class='span6')),


...,
auth.signature)

custom_auth_table = db[auth.settings.table_user_name] # get the 
custom_auth_table

custom_auth_table.first_name.requires = \
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.last_name.requires = \
IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.password.requires = [CRYPT(key=auth.settings.hmac_key)]
custom_auth_table.email.requires = [
IS_EMAIL(error_message=auth.messages.invalid_email),
IS_NOT_IN_DB(db, custom_auth_table.email)]


db.auth_user.is_active.writable = db.auth_user.is_active.readable=False

db.define_tables()


Anyway; like I said, I am fine either way, if other users complain about 
it, then I may change my opinion.


I just thought I would bring it up as I am sure you like feedback 
regarding these types of changes.


Thanks.
David



On 7/23/12 11:53 PM, Massimo Di Pierro wrote:
Yes. auth.signature used to be defined when Auth() is instantiated. 
Now it is defined when auth.define_tables() is called. There is 
disagreement on whether this is a breaking of backward compatibility 
since this is not exactly documented. There are reason for the switch. 
Is this a big deal? It is not clear whether this change of behavior 
should propagate to stable.


On Monday, 23 July 2012 16:38:18 UTC-5, David J wrote:

I just upgraded my web2py to latest trunk.

I get an exception

S'("\'Auth\' object has no attribute \'signature\'",)'

did something change. I tried the mailing list archive to see, but
maybe
I missed something.

Thanks.


--





--





Re: [web2py] Re: Empty Database value is not None, but an empty string

2012-07-23 Thread vinicius...@gmail.com

Yes, they are default settings.

It's quite strange you get empty strings instead null (None, in Python).

How are you inserting data into db? Are you using a SQLFORM or 
my_table.validate_and_insert() or simply mytable.insert()?


Do you get same results (blank values) inserting it from web2py shell 
using simply mytable.insert()?


--
Vinicius Assef



On Monday, July 23, 2012 5:58:19 PM UTC-4, Mark Li wrote:

Aren't those the default values for a Field Contructor? I tried
explicitly adding "notnull=False" and "required=False", and didn't
set the default property, but empty values still come out as an
empty string instead of None.

On Monday, July 23, 2012 2:48:56 PM UTC-7, viniciusban wrote:

As far as I know, let "notnull=False" and "required=False" for your
fields and don't set "default" property.



On 07/23/2012 06:32 PM, Mark Li wrote:
> Unfortunately the lambda method didn't work, Anthony. Any other ideas
> for having a None default for empty entries?
>
>
> On a side note, if the 'integer' field type is used, then a blank 
entry
> results in a None. Don't know if that helps but it's something I've 
noticed.
>
> On Monday, July 23, 2012 2:07:51 PM UTC-7, Anthony wrote:
>
> To enter a value of None, this might work:
>
> |
> default=lambda:None
> |
>
> Anthony
>
> On Monday, July 23, 2012 5:04:44 PM UTC-4, Anthony wrote:
>
> default=None means that no default is specified, not that a
> default value of None will be inserted.
>
> Anthony
>
> On Monday, July 23, 2012 5:02:33 PM UTC-4, Mark Li wrote:
>
> I have a table defined in the following manner:
>
> db.define_table('songinfo',
> Field('songtitle'),
> Field('artist'))
>
> When I add an empty entry, or upload a CSV with empty
> values, I can only access those values with a database 
call like
>
> songs = db(db.songinfo.artist=="").select()
>
> as opposed to db(db.songinfo.artist==None).select()
>
>
> The web2py book states that fields default=None, but I'm
> getting an empty string. Is there an appropriate way to 
have
> None instead of an empty string in the database?
>
>
> --
>
>
>

--





--





[web2py] Re: bootstrap and user panel

2012-07-23 Thread murtaza52

Hello Martin,

The CSS is cool so +1 for this.

1) I cloned your welcome app repo and placed it under applications, this is 
the summary of the error I get when I browse to the app - 

127.0.0.1.2012-07-24.11-12-36.3a36305c-435d-4087-ab03-e427b4e00812
 table auth_user already exists

2) Below is the error I recieved from the useradmin app when I did the same 
- 

127.0.0.1.2012-07-24.11-17-36.3a723b6d-872c-49e2-878d-65fab3349ca5
 define_tables() got an unexpected keyword 
argument 'signature'
What am I doing wrong ?

Thanks,
Murtaza


On Tuesday, July 24, 2012 9:27:49 AM UTC+5:30, Massimo Di Pierro wrote:
>
> This looks great. Are you proposing it as a replacement for the current 
> welcome? pros? cons?
>
> On Monday, 23 July 2012 19:02:47 UTC-5, Martin.Mulone wrote:
>>
>> I want to share this two applications*
>>
>> Bootstrap welcome application*
>>
>> I made my own welcome scatfold app, using twitter bootstrap template. My 
>> version is more like from the example template. 
>> Download: https://bitbucket.org/mulonemartin/bootstrap/overview also you 
>> can test here .
>>
>> *User Panel Admin*
>>
>> An application to administer the auth_user table. You can add, remove, 
>> activate users/ add groups, also add users to groups and so on. 
>> https://bitbucket.org/mulonemartin/usersadmin
>>
>>
>>
>>

-- 





Re: [web2py] Logic check in View, to check if auth.user.group_id...

2012-07-23 Thread Alec Taylor
Thanks, that worked. I think the problem was I wasn't using `auth.user` but
`auth_user`. Full working example:

{{if auth.is_logged_in():}}{{if group[0].id in
auth.user.member_of:}}{{=T('Welcome back Mr
member!')}}{{else:}}{{=T('Become a member today')}}{{pass}}{{pass}}


On Tue, Jul 24, 2012 at 6:28 AM, Anthony  wrote:

> Have you tried:
>
> {{if thisgroupid in auth.user.member_of:}}
>
> Once the user is logged in, auth.user contains the user record from the
> auth_user table, so auth.user.member_of should be the list of
> group_of_events id's for the logged in user.
>
> Anthony
>
>
> On Monday, July 23, 2012 4:20:36 PM UTC-4, Alec Taylor wrote:
>>
>> Yes I do.
>>
>> I have also tried with a bunch of other permutations.
>>
>> Reading through the `Auth` reference, I found a few useful functions,
>> most helpful being:
>> {{=auth._get_user_id()}}
>>
>> Using that I will be able to query the db, but will need to put the
>> reference on the group side rather than the user side. Was planning that
>> (or a two-way reference) anyway.
>>
>> On Tue, Jul 24, 2012 at 5:46 AM, Bruno Rocha wrote:
>>
>>>
>>> Do you have a member_of field in your auth_user table?
>>>
>>> On Mon, Jul 23, 2012 at 4:40 PM, Alec Taylor wrote:
>>>
 Just noticed I had underscore instead of point, still isn't working
 though:
   'NoneType' object has no attribute
 'member_of'
 On Tue, Jul 24, 2012 at 5:36 AM, Alec Taylor wrote:

> On Tue, Jul 24, 2012 at 5:09 AM, Bruno Rocha wrote:
>
>>
>> there is no request.auth_user by default, did you created this?
>>
>> I think you can do (with trunk)
>>
>> {{if thisgroupid in auth.user_groups:}}
>>
>>
> Unfortunately that didn't work either... I'm running Version 2.0.0
> (2012-07-20 17:37:48) dev:
>  name 'auth_user' is not defined
>

  --




>>>
>>>  --
>>>
>>>
>>>
>>>
>>
>>  --
>
>
>
>

--