[web2py] Re: Conditional re-direction to enforce page sequence

2012-04-20 Thread Anthony

>
> The auth.register() function does not set session.email, so that's 
> probably why you're still getting the redirect after successful 
> registration. You could instead use an auth.settings.registration_onaccept 
> callback to add a flag to the session, or if you want to automatically 
> login the user upon registration (by setting 
> auth.settings.login_after_registration=True), you could just do:
>
> elif not auth.user:
>

Actually, as long as you don't have 
auth.settings.registration_requires_verification = True, you can use the 
auth.user test even without setting auth.settings.login_after_registration 
= True.

Anthony
 


[web2py] Re: Adding permissions upon registration

2012-04-20 Thread Anthony
On Friday, April 20, 2012 5:50:25 PM UTC-4, Anthony wrote:
>
> The new user id should be in form.vars.id as well as session.auth.user.idat 
> that point.


Actually, looking at the code, auth.user.id should work as well, unless you 
have auth.settings.registration_requires_verification = True, in which 
case, session.auth.user.id won't work either (but form.vars.id will work in 
either case).

Anthony 


[web2py] Re: Conditional re-direction to enforce page sequence

2012-04-20 Thread Anthony

>
> In other words, I use 
> session.email
>  to test whether user gets to 'registered' page after the register form is 
> successfully processed or not. However, it seems that 'registered' function 
> is called before 'register' form is fully processed (i.e. 'session.email' 
> gets set), so that user is re-directed (from within the elif block above) 
> back to 'register' page.
>
>
> What would be an appropriate method here?
>

The auth.register() function does not set session.email, so that's probably 
why you're still getting the redirect after successful registration. You 
could instead use an auth.settings.registration_onaccept callback to add a 
flag to the session, or if you want to automatically login the user upon 
registration (by setting auth.settings.login_after_registration=True), you 
could just do:

elif not auth.user:

Anthony


[web2py] Re: WARNING:web2py.cron:WEB2PY CRON: Disabled because no file locking still showing up

2012-04-20 Thread Chris
I figured out part of the problem. It's not win32con, it's win32file that's 
not importing. I'm disabling cron locally, and I posted a question on 
StackOverflow in case anyone wants to try and decipher this mystery 
(http://stackoverflow.com/questions/10256531/using-eclipse-with-pywin32).


On Monday, December 19, 2011 4:46:48 PM UTC-5, Chris wrote:
>
> (The first one is from Python started independently, the second from 
> Eclipse and the running instance of my app.)



[web2py] Re: LOAD and .load confusion.

2012-04-20 Thread Annet
Hi Anthony,

Ough, it must have been my focus on the modal window that made me overlook 
this :-(
Thanks for your reply.

Kind regards,

Annet.

row is actually a DAL Rows object -- if you want a Row object, you have to 
> select a specific row. Try:
>
> row=db(db.EventList.id ==request.args(0)).select(
> db.EventList.ALL).first()
>


[web2py] Conditional re-direction to enforce page sequence

2012-04-20 Thread mrtn

I have a 'registered' page/action which immediately follows 'register' 
page/action, and I would like to prevent someone who is currently on the 
'register' page to jump to 'registered' page by directly changing the URL 
(even if all the fields including email etc are filled), instead of 
clicking the submit button.

So I tried the following:

in the model, I have:

auth.settings.register_next = URL('registered')

in the controller, I have:


def register():
session.from_register = True 
session.register_arg = request.args(0) 
form = auth.register()
 
return dict(form=form)


and


def registered():
if not session.from_register: 
logger.debug('request NOT from registration page') 
session.from_register = False 
redirect(URL(c='default', f='index')) 
elif not session.email: 
logger.debug('request from registration page but registration form 
not processed') 
session.from_register = False 
redirect(URL(f='register', args=[session.register_arg])) 

return dict()


In other words, I use 
session.email
 to test whether user gets to 'registered' page after the register form is 
successfully processed or not. However, it seems that 'registered' function 
is called before 'register' form is fully processed (i.e. 'session.email' 
gets set), so that user is re-directed (from within the elif block above) 
back to 'register' page.


What would be an appropriate method here?



[web2py] Re: creating manual login form

2012-04-20 Thread Sanjeet Roy
Its come by default with web2py  so why you want to use manual login can 
you explain ? You have to customize it according to your requirements.

On Friday, April 20, 2012 3:53:41 PM UTC+5:30, Sonu Srivastava wrote:
>
> i create reagister form using auth_user but unable to create a manual 
> login form by which we login.please anyone help me.



Re: [web2py] Country list

2012-04-20 Thread Marco Mansilla
Take a look on


http://www.web2pyslices.com/slice/show/1378/ajax-live-search-auto-complete

El Fri, 20 Apr 2012 23:28:15 +0100
Simon Pickles  escribió:

> Does web2py have any built in support for country lists, the drop
> down list you use while entering an address?
> 
> Thx


[web2py] Re: Adding permissions upon registration

2012-04-20 Thread Anthony
On Friday, April 20, 2012 6:28:45 PM UTC-4, cyan wrote:
>
>
> The new user id should be in form.vars.id as well as session.auth.user.id at 
>> that point.
>
>
> Thanks Anthony. But is this documented anywhere in the manual or in any 
> doc of Web2py? Otherwise, it is really difficult for users to figure this 
> out without consulting experts like you.


Well, there's a register_onaccept example in the book that gets the new 
user id from form.vars.id: 
http://web2py.com/books/default/chapter/29/9#Authorization-and-CRUD. But I 
agree that usage of the Auth callbacks could be better documented. We're 
waiting for Massimo to make the online book editable so a few of us can go 
in and make corrections and additions like this. Hopefully that will happen 
soon.

In the meantime, it's often helpful to look directly at the code. For 
example, in the Auth register() function, here is where you can see the id 
can be found in form.vars.id: 
http://code.google.com/p/web2py/source/browse/gluon/tools.py#2022. And here 
is where you can see that the user record is stored in session.auth: 
http://code.google.com/p/web2py/source/browse/gluon/tools.py#2051. Once you 
start to get to know the code, it's usually fairly quick and easy to figure 
out these kinds of things.

Anthony


[web2py] Re: Adding permissions upon registration

2012-04-20 Thread cyan


> The new user id should be in form.vars.id as well as session.auth.user.id at 
> that point.


Thanks Anthony. But is this documented anywhere in the manual or in any doc 
of Web2py? Otherwise, it is really difficult for users to figure this out 
without consulting experts like you.

You second point regarding security is well taken, and is taken care of in 
the logic of other parts of the code. Thanks. 


[web2py] Country list

2012-04-20 Thread Simon Pickles
Does web2py have any built in support for country lists, the drop down list
you use while entering an address?

Thx


Re: [web2py] Re: Using static files in view confusion

2012-04-20 Thread Simon Pickles
Thanks

Nice to see web2py has a helpful and lively community
On Apr 20, 2012 2:24 PM, "Simon Pickles"  wrote:

> Thanks I suspected my path was a little wrong.
>
> Still got the problem that the image border appears then whole thing
> vanishes.
>
> On Friday, 20 April 2012 08:19:23 UTC+1, Simon Pickles wrote:
>>
>> Hi,
>>
>> New to web2py and having trouble with simple HTML in a view. In my
>> default/index.html:
>>
>>
>> {{=IMG(_src=URL('static','**images/map420x200.png'))}}
>> 
>>
>> The first line works, rendering the map png. However, the second HTML
>> equivalent doesnt. The bordered box appears empty then disappears. Is my
>> path wrong?
>>
>> The app is just created using wizard, and default layout.
>>
>> Thanks
>>
>> Simon
>>
>


Re: [web2py] Re: Modifying auth_navbar

2012-04-20 Thread Simon Pickles
Thanks all
On Apr 20, 2012 5:21 PM, "pbreit"  wrote:

> I ended up just coding my own navbar and sticking it in a function in
> models. Now that I look at it, I probably should have used URL()s.
>
> def user_bar():
> action = '/user'
> if auth.user:
> logout=A('logout', _href=action+'/logout')
> profile=A('profile', _href=action+'/profile')
> password=A('change password', _href=action+'/change_password')
> bar = SPAN(auth.user.email, ' | ', profile, ' | ', password, ' |
> ', logout, _class='auth_navbar')
> else:
> login=A('login', _href=action+'/login')
> register=A('register',_href=action+'/register')
> lost_password=A('lost password',
> _href=action+'/request_reset_password')
> bar = SPAN(' ', login, ' | ', register, ' | ', lost_password,
> _class='auth_navbar')
> return bar
>


[web2py] Re: css file changes don't effect webpage

2012-04-20 Thread Anthony
Your browser may be caching the CSS files (and other static files). Try 
clearing the cache.

Anthony

On Friday, April 20, 2012 4:31:50 PM UTC-4, BlueShadow wrote:
>
> Hi
> I include a css file called custum.css in the layout. I wanted to do a 
> little adjustment to one page included in the layout.html
> When I use the css directly on the page which is included in the 
> layout.html it wokrs without a problem. but when I move the css to the 
> custum.css file it doesn't work anymore.
> I used firefox to show me the code of the css file and it's still showing 
> the old custum.css (yes I did save the file) I even did a couple server 
> restarts.
>
> I also noticed that the css sometimes doesn't effect the paes at all when 
> playing around with a copy of the welcome app css files.
>


[web2py] Re: Adding permissions upon registration

2012-04-20 Thread Anthony
The new user id should be in form.vars.id as well as session.auth.user.id 
at that point.

Is there a potential security problem here -- what would prevent someone 
from manually altering the first arg in the URL to any arbitrary group 
(e.g., "admin")? Perhaps you should check the value of request.args(0) 
before making the group assignment.

Anthony

On Friday, April 20, 2012 4:49:24 PM UTC-4, cyan wrote:
>
>
> Hi Group,
>
> I have something like the following in a model:
>
> def grant_permissions(form):
> group_id = auth.id_group(role=request.args(0)) 
> auth.add_membership(group_id, auth.user.id)
>
> auth.settings.register_onaccept.append(grant_permissions)
>
>
> Basically, I want to assign a user to a group upon his/her successful 
> registration. However, when I execute the above, I get an 
> AttributeError: 'NoneType' object has no attribute 'id'
>
> . I tried to follow the code example on page 414 of the manual, but 
> referencing using 
> auth.user.id
>
> doesn't seem to work.
>
> So how can I get hold of the user id here for the user who has just 
> successfully registered? Thanks.
>
> *
> *
>


[web2py] Re: How can one retrieve user's email upon verify_email action

2012-04-20 Thread Anthony

>
> When you said '*an argument* of the verify_email_onaccept callback', you 
> meant an argument of the callback function supplied to
> auth.settings.verify_email_onaccept
>
> , right? My understanding is that you provide a callback function to 
> Web2py, which is going to be called upon the acceptance of verify_email 
> action.
>
> More importantly, how did you figure out which type of argument (form vs. 
> user here) the callback function would take? This sort of stuff is not 
> covered anywhere in the manual, yet it is important to know! Thanks a lot.
>

Yes, the callback takes a single argument, and when web2py calls the 
callback, it passes the user record as that argument. You're right, it 
appears this is not documented (should be) -- I figured it out by looking 
at the code: 
http://code.google.com/p/web2py/source/browse/gluon/tools.py#2111. When you 
think about it, though, it can't be a form, as there is no form involved in 
the email verification process.

Anthony



[web2py] Re: How can one retrieve user's email upon verify_email action

2012-04-20 Thread mrtn

Thanks for the suggestion, Anthony.

When you said '*an argument* of the verify_email_onaccept callback', you 
meant an argument of the callback function supplied to 
auth.settings.verify_email_onaccept

, right? My understanding is that you provide a callback function to 
Web2py, which is going to be called upon the acceptance of verify_email 
action.

More importantly, how did you figure out which type of argument (form vs. 
user here) the callback function would take? This sort of stuff is not 
covered anywhere in the manual, yet it is important to know! Thanks a lot.



On Thursday, April 19, 2012 5:47:25 PM UTC-4, Anthony wrote:
>
> I intend to do this in the model, via 
>> auth.settings.verify_email_onaccept.append(lambda form: mail.send(to='
>> user.em...@example.com',subject='Welcome!', 
>>   message="new 
>> user email is %s'%form.vars.email"))
>>
>>
>>
> I think the verify_email_onaccept callback actually takes the user record 
> as an argument, not a form (there is no form in this case). So, try:
>
> lambda user: mail.send(to=user.email, ...)
>
> Anthony 
>


Re: [web2py] Memory leak in standalone DAL (issue #731), can you please help test?

2012-04-20 Thread nick name
On Thursday, April 19, 2012 7:08:06 PM UTC-4, Ricardo Pedroso wrote:

> I post a comment on this issue:
> http://code.google.com/p/web2py/issues/detail?id=731#c4
>
> I think this is not a bug but an incorrect use of the dal api.
>

Ricardo, thanks! That is indeed the problem. Whether or not it is a misuse 
of the API, the API that I actually need (cleanly close only SOME 
dal/adapter instances and not ALL dal/adapter instances) does not currently 
exist, and I need to to reach into the underlying implementation to do what 
I want.

For massimo: something like the following might be useful (note: untested):

(added to ConnectionPool class)


def close_or_recycle(self, action):
""" to close cleanly in a multithreaded environment """
if self in thread.get(instances, []):
if action:
if callable(action):
action(self)
else:
getattr(self, action)()
# ## if you want pools, recycle this connection
really = True
if self.pool_size:
sql_locker.acquire()
pool = ConnectionPool.pools[self.uri]
if len(pool) < self.pool_size:
pool.append(self.connection)
really = False
sql_locker.release()
if really:
self.close()

if callable(action):
action(None)
return

and rewriting close_all_instances to use this while popping 
thread.instances on one hand, and having a DAL.close() method which calls 
self._adapter.close_or_recycle() (possibly also from DAL.__del__)

Thanks!


[web2py] Re: official book vs web2py cookbook

2012-04-20 Thread Gour
On Fri, 20 Apr 2012 13:20:39 -0700 (PDT)
Massimo Di Pierro
 wrote:

> There will be a 5th edition.

Thank you.


Sincerely,
Gour

-- 
You have a right to perform your prescribed duty, but you 
are not entitled to the fruits of action. Never consider 
yourself the cause of the results of your activities, 
and never be attached to not doing your duty.

http://atmarama.net | Hlapicina (Croatia) | GPG: 52B5C810


signature.asc
Description: PGP signature


[web2py] Adding permissions upon registration

2012-04-20 Thread cyan

Hi Group,

I have something like the following in a model:

def grant_permissions(form):
group_id = auth.id_group(role=request.args(0)) 
auth.add_membership(group_id, auth.user.id)

auth.settings.register_onaccept.append(grant_permissions)


Basically, I want to assign a user to a group upon his/her successful 
registration. However, when I execute the above, I get an 
AttributeError: 'NoneType' object has no attribute 'id'

. I tried to follow the code example on page 414 of the manual, but 
referencing using 
auth.user.id

doesn't seem to work.

So how can I get hold of the user id here for the user who has just 
successfully registered? Thanks.

*
*


[web2py] css file changes don't effect webpage

2012-04-20 Thread BlueShadow
Hi
I include a css file called custum.css in the layout. I wanted to do a 
little adjustment to one page included in the layout.html
When I use the css directly on the page which is included in the 
layout.html it wokrs without a problem. but when I move the css to the 
custum.css file it doesn't work anymore.
I used firefox to show me the code of the css file and it's still showing 
the old custum.css (yes I did save the file) I even did a couple server 
restarts.

I also noticed that the css sometimes doesn't effect the paes at all when 
playing around with a copy of the welcome app css files.


[web2py] Re: bootstrap in trunk

2012-04-20 Thread Massimo Di Pierro
Do you use a custom search_menu or do you call it explicitly? Yes the API 
for this thing have changed (for the better). This was clearly marked in 
the book as an experimental feature. If you show us your code, I can tell 
you now to adapt it. Yet, without seeing your code I can not 100% sure this 
is not a bug.

On Friday, 20 April 2012 04:44:08 UTC-5, Johann Spies wrote:
>
> Thanks for the bootstrap css and js in the trunk.  I am trying it out and 
> found  a problem when used with the grid:
>
> 
> 
>  >
> (,  at 0x44b41a50>, )
> 
> 
> 
> 
> 
> 
> 
> Export
> 
> 
> 11106 records found
> 
>
> Regards
> Johann
>


Re: [web2py] Re: What would be the best way to generate a summary of the 'count(*) 'of all my database table columns?

2012-04-20 Thread Khalil KHAMLICHI
db(db.legacy-db.table).select()

I think you are forgetting "db." in front of table name.


[web2py] Re: official book vs web2py cookbook

2012-04-20 Thread Massimo Di Pierro
There will be a 5th edition.

On Thursday, 19 April 2012 09:43:28 UTC-5, Gour wrote:
>
> On Thu, 19 Apr 2012 06:21:46 -0700 (PDT)
> Massimo Di Pierro
>  wrote:
>
> > No because most of what is in 2.0 is already in trunk and partially 
> > documented in the book.
>
> Good.
>
> Do you envison doing another book release for web2py or the next one
> will be web3py?
>
>
> Sincerely,
> Gour
>
> -- 
> One who restrains his senses, keeping them under full control, 
> and fixes his consciousness upon Me, is known as a man of 
> steady intelligence.
>
> http://atmarama.net | Hlapicina (Croatia) | GPG: 52B5C810
>
>

[web2py] scheduler "advanced" question

2012-04-20 Thread Niphlod
Hi all,
I'm trying to use extensively the scheduler for an application.

There are a few things I can't wrap my mind around the first, simplest, 
is how to setup DEBUG logging level on the scheduler when started as 
"python web2py.py -K appname" 

Second, and there's the "advanced" part, at least for me: if you want to 
use scheduler, you must istantiate it on a model file.
Until now I was firing some functions and I was happy with that..
Now I need to launch function that are "contained" in classes defined in 
modules.

My models/scheduler.py it's like this:

from gluon.scheduler import Scheduler
from mymodule import SomeClass

def myonlyfunction():
  myclass = SomeClass(db)
  return myclass.do_work()


myscheduler = Scheduler(db, dict(myonly=myonlyfunction))


Everything is working smoothly, but for every task the Scheduler runs, 
myclass is istantiated (obviuosly).
I'd like to istantiate the class only once, when the Scheduler is 
started how to do that ?

The "normal" way in python programs I did before was to move the class 
"istantiation" as a global object:


from gluon.scheduler import Scheduler
from mymodule import SomeClass

myclass = SomeClass(db)

def myonlyfunction():
  return myclass.do_work()


myscheduler = Scheduler(db, dict(myonly=myonlyfunction))

But doing that in web2py resorts in an istantiation every time a page is 
called (models file are executed for every request, I know)

Someone faced that before and has a solution ?

Many thanks in advance to all

Niphlod


[web2py] Cannot insert specific key into table

2012-04-20 Thread haggis
Hello,
I've got the following table:

db = DAL('sqlite://storage.sqlite')
db.define_table('variable',
Field('name', type='string', length=255),
Field('value', type='string', length=255),
format='%(name)s',
primarykey=['name'])

This is what happens by adding different name/value pairs via appadmin:

test/foobar: ok
any_name/myValue: ok
active_event/someevent: nothing happens but flash notfier signals 
successfull record

I can insert whatever I want - except "active_event" as name. It just 
doesn't appear in the table. It looks like that query would be ignored.
As I worked a lot in the database while development so far, I just removed 
the database folder from my applications to begin with a clean database. 
However, the problem still persists.

Do you have any idea?

Regards, haggis



[web2py] Re: What would be the best way to generate a summary of the 'count(*) 'of all my database table columns?

2012-04-20 Thread Cody Goodman
That is close to what I need guys, but I should have made a better example. 
I have a legacy database called my_legacy_db which is separate from the 
normal db.

my_legacy_db

users
 - email
 - username
 - name

So cliff, your first part would work to generate field names and put 
everything in a dict to build the query's. The problem is when I do this 
query:

db().select(my_legacy_db.users)

I get this error:
In [20] : db().select(my_legacy_db.users)
Traceback (most recent call last):
  File "/opt/web-apps/web2py/gluon/contrib/shell.py", line 233, in run
exec compiled in statement_module.__dict__
  File "", line 1, in 
  File "/opt/web-apps/web2py/gluon/dal.py", line 7578, in select
return adapter.select(self.query,fields,attributes)
  File "/opt/web-apps/web2py/gluon/dal.py", line 1307, in select
sql = self._select(query, fields, attributes)
  File "/opt/web-apps/web2py/gluon/dal.py", line 1196, in _select
raise SyntaxError, 'Set: no tables selected'
SyntaxError: Set: no tables selected

So I know how to fix the problem, but I don't know why I can't query 
my_legacy_db.


On Friday, April 20, 2012 7:46:23 AM UTC-5, Cliff wrote:
>
> Is this what you want?
>
> Table   |  column count
> ---
> dog | 3
> ---
> car | 3
> ---
>
> This will get the data.
> For table in db.tables:
>   column_count = 0
> for field in table.fields
>   column_count += 1
>   print table.name
>   print column_count
>
> On Thursday, April 19, 2012 9:57:57 PM UTC-4, Cody Goodman wrote:
>>
>> I have multiple databases:
>>
>> dog
>> ---
>> type
>> color
>> sound
>>
>> car
>> --
>> model
>> maker
>> condition
>>
>> I need to generate a grid with the table names, then under them the 
>> number of columns there are. I have made multiple DAL objects for each 
>> database like so:
>>
>> dog = DAL('mysql://root:@localhost/dog)
>> car = DAL('mysql://root:@localhost/car)
>>
>> I then thought I could just make select statements getting the count of 
>> each column like this:
>>
>> number_of_dog_colors = len(db().select(dog.type.color))
>>
>> Of course my syntax for that is wrong and I got a :
>>  'function' object has no attribute 
>> 'color'
>>
>> I was just wondering what the correct syntax to do that was, and if I'm 
>> going about it correctly. Once I get the syntax correct, I was going to 
>> make a list of all the table names, then get the count for each. If anyone 
>> knows a better way to do this, please let me know.
>>
>> Thanks in advance for any help.
>>
>> Sincerely,
>>
>> Cody Goodman
>>
>>

[web2py] Re: Using static files in view confusion

2012-04-20 Thread pbreit
Even when using  tag, best to use URL() function for the src url.

Re: [web2py] Re: bootstrap in trunk

2012-04-20 Thread Anthony
On Friday, April 20, 2012 11:08:50 AM UTC-4, Johann Spies wrote:
>
> On 20 April 2012 16:05, Anthony  wrote:
>
> Looks like a bug that was introduced -- the code was CAT(INPUT(...), 
>> DIV(...), SCRIPT(...)), but the CAT was dropped, so instead of returning a 
>> helper object, it is now returning a tuple of helpers, which doesn't get 
>> serialized properly.
>>
>>
>> http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py?r=8b8109f75c844b044d580eb770efda11f65141ea#1434
>>  -- 
>> need to add "CAT" before the "(" on that line.
>>
>> Thanks for the reply but your suggestion did not solve the problem.  I 
> still get the same when using the grid.after changing the return starting  
> in line 1434 to CAT()
>

Sorry, I didn't follow all the changes and spoke too quickly -- looks like 
the change to a tuple was intentional. I'll keep looking.

Anthony 


[web2py] Re: Modifying auth_navbar

2012-04-20 Thread pbreit
I ended up just coding my own navbar and sticking it in a function in 
models. Now that I look at it, I probably should have used URL()s.

def user_bar():
action = '/user'
if auth.user:
logout=A('logout', _href=action+'/logout')
profile=A('profile', _href=action+'/profile')
password=A('change password', _href=action+'/change_password')
bar = SPAN(auth.user.email, ' | ', profile, ' | ', password, ' | ', 
logout, _class='auth_navbar')
else:
login=A('login', _href=action+'/login')
register=A('register',_href=action+'/register')
lost_password=A('lost password', 
_href=action+'/request_reset_password')
bar = SPAN(' ', login, ' | ', register, ' | ', lost_password, 
_class='auth_navbar')
return bar


[web2py] Re: Great news! Markitup supports Markmin officially

2012-04-20 Thread Anthony
+1

On Friday, April 20, 2012 11:24:26 AM UTC-4, Massimo Di Pierro wrote:
>
> http://markitup.jaysalvat.com/downloads/demo.php?id=markupsets/markmin
>


[web2py] Re: computed field

2012-04-20 Thread pbreit
I'd probably use a function or virtual field for that, not store it in DB.

And it could be cleaned up a bit. Something like:

def trunc_desc(s)
if len(s) > 128:
return s[:128] + '...'
return s


[web2py] Re: Ajax

2012-04-20 Thread Anthony
Assuming the ajax() function does what you want (see 
http://web2py.com/books/default/chapter/29/11#The-ajax-function), you can 
put it in an onclick handler:

click here

Anthony

On Friday, April 20, 2012 11:31:26 AM UTC-4, Hassan Alnatour wrote:
>
> Dear ALL, 
>
> How can i use ajax in a  to post some vars to a controller 
> function ??
>
>
> Best Regards,
>


[web2py] Re: Page Title Tag

2012-04-20 Thread Anthony
Assuming you have something like this in your layout.html head:

{{=response.title}}

you just have to set the value of response.title separately for each page. 
You could do this in the controller, or in the view before the {{extend 
'layout.html'}} directive:

def mypage():
response.title = 'My Page'
[etc.]

or in /views/mycontroller/mypage.html:

{{response.title = 'My Page'}}
{{extend 'layout.html'}}

Anthony

On Friday, April 20, 2012 11:57:22 AM UTC-4, Hassan Alnatour wrote:
>
> Dear ALL , 
>
>  I am using a master page , now how can i let every page has its own title 
> tag ??
>
>
> Best Regards,
>


[web2py] Page Title Tag

2012-04-20 Thread Hassan Alnatour
Dear ALL , 

 I am using a master page , now how can i let every page has its own title 
tag ??


Best Regards,


Re: [web2py] computed field

2012-04-20 Thread Richard Vézina
http://web2py.com/books/default/chapter/29/6

{{extend 'layout.html'}}
Records
{{=SQLTABLE(rows,
 headers='fieldname:capitalize',
 truncate=100,
 upload=URL('download'))
}}


Richard

On Fri, Apr 20, 2012 at 11:42 AM, Richard Vézina <
ml.richard.vez...@gmail.com> wrote:

> Also, you could maybe search the book with "truncate" keyword, there is
> already a utility if you just want to control the lenght of free text field
> or other string field.
>
> Richard
>
>
> On Fri, Apr 20, 2012 at 11:35 AM, Richard Vézina <
> ml.richard.vez...@gmail.com> wrote:
>
>> I think you can't use compute since you modify a field where the user as
>> to enter something base on the len of user input, so I think you should
>> transform the code below into function and use onvalidation=function
>>
>>
>> x=len(form.vars.description)
>> if x>128:
>> i=128
>> dots="..."
>> else:
>> i=x-1
>> dots=""
>> s=form.vars.description[0:i] + dots
>>
>> Richard
>>
>>
>>
>>
>> On Fri, Apr 20, 2012 at 11:26 AM, Annet  wrote:
>>
>>> I defined a table eventList:
>>>
>>> db.define_table('EventList',
>>>...
>>> Field('description',type='text'),
>>> Field('shortdescr',length=128,writable=False,readable=False),
>>> 
>>> migrate=False)
>>>
>>> db.EventList.description.requires=IS_LENGTH(1536,error_message='length
>>> exceeds 1536 characters')
>>> db.EventList.shortdescr.requires=IS_LENGTH(128,error_message='length
>>> exceeds 128 characters')
>>>
>>> shortdescr should be the first 128 characters of description followed by
>>> three dots. In a function this works:
>>>
>>> x=len(form.vars.description)
>>> if x>128:
>>> i=128
>>> dots="..."
>>> else:
>>> i=x-1
>>> dots=""
>>> s=form.vars.description[0:i] + dots
>>>
>>> ... but I'd like to add it to the model file. I had a look at the
>>> compute option but wasn't able to figure out how to get it syntactically
>>> correct.
>>>
>>>
>>> Kind regards,
>>>
>>> Annet.
>>>
>>
>>
>


Re: [web2py] computed field

2012-04-20 Thread Richard Vézina
Also, you could maybe search the book with "truncate" keyword, there is
already a utility if you just want to control the lenght of free text field
or other string field.

Richard

On Fri, Apr 20, 2012 at 11:35 AM, Richard Vézina <
ml.richard.vez...@gmail.com> wrote:

> I think you can't use compute since you modify a field where the user as
> to enter something base on the len of user input, so I think you should
> transform the code below into function and use onvalidation=function
>
>
> x=len(form.vars.description)
> if x>128:
> i=128
> dots="..."
> else:
> i=x-1
> dots=""
> s=form.vars.description[0:i] + dots
>
> Richard
>
>
>
>
> On Fri, Apr 20, 2012 at 11:26 AM, Annet  wrote:
>
>> I defined a table eventList:
>>
>> db.define_table('EventList',
>>...
>> Field('description',type='text'),
>> Field('shortdescr',length=128,writable=False,readable=False),
>> 
>> migrate=False)
>>
>> db.EventList.description.requires=IS_LENGTH(1536,error_message='length
>> exceeds 1536 characters')
>> db.EventList.shortdescr.requires=IS_LENGTH(128,error_message='length
>> exceeds 128 characters')
>>
>> shortdescr should be the first 128 characters of description followed by
>> three dots. In a function this works:
>>
>> x=len(form.vars.description)
>> if x>128:
>> i=128
>> dots="..."
>> else:
>> i=x-1
>> dots=""
>> s=form.vars.description[0:i] + dots
>>
>> ... but I'd like to add it to the model file. I had a look at the compute
>> option but wasn't able to figure out how to get it syntactically correct.
>>
>>
>> Kind regards,
>>
>> Annet.
>>
>
>


Re: [web2py] computed field

2012-04-20 Thread Richard Vézina
I think you can't use compute since you modify a field where the user as to
enter something base on the len of user input, so I think you should
transform the code below into function and use onvalidation=function

x=len(form.vars.description)
if x>128:
i=128
dots="..."
else:
i=x-1
dots=""
s=form.vars.description[0:i] + dots

Richard




On Fri, Apr 20, 2012 at 11:26 AM, Annet  wrote:

> I defined a table eventList:
>
> db.define_table('EventList',
>...
> Field('description',type='text'),
> Field('shortdescr',length=128,writable=False,readable=False),
> 
> migrate=False)
>
> db.EventList.description.requires=IS_LENGTH(1536,error_message='length
> exceeds 1536 characters')
> db.EventList.shortdescr.requires=IS_LENGTH(128,error_message='length
> exceeds 128 characters')
>
> shortdescr should be the first 128 characters of description followed by
> three dots. In a function this works:
>
> x=len(form.vars.description)
> if x>128:
> i=128
> dots="..."
> else:
> i=x-1
> dots=""
> s=form.vars.description[0:i] + dots
>
> ... but I'd like to add it to the model file. I had a look at the compute
> option but wasn't able to figure out how to get it syntactically correct.
>
>
> Kind regards,
>
> Annet.
>


[web2py] Ajax

2012-04-20 Thread Hassan Alnatour
Dear ALL, 

How can i use ajax in a  to post some vars to a controller 
function ??


Best Regards,


[web2py] computed field

2012-04-20 Thread Annet
I defined a table eventList:

db.define_table('EventList',
   ...
Field('description',type='text'),
Field('shortdescr',length=128,writable=False,readable=False),

migrate=False)

db.EventList.description.requires=IS_LENGTH(1536,error_message='length 
exceeds 1536 characters')
db.EventList.shortdescr.requires=IS_LENGTH(128,error_message='length 
exceeds 128 characters')

shortdescr should be the first 128 characters of description followed by 
three dots. In a function this works:

x=len(form.vars.description)
if x>128:
i=128
dots="..."
else:
i=x-1
dots=""
s=form.vars.description[0:i] + dots

... but I'd like to add it to the model file. I had a look at the compute 
option but wasn't able to figure out how to get it syntactically correct.


Kind regards,

Annet.


[web2py] Great news! Markitup supports Markmin officially

2012-04-20 Thread Massimo Di Pierro
http://markitup.jaysalvat.com/downloads/demo.php?id=markupsets/markmin


[web2py] bootstrap modal window

2012-04-20 Thread Annet
I posted the following problem: 
https://groups.google.com/forum/?fromgroups#!topic/web2py/vm3WwFamfXQ

This is part of a problem I have been working on for a couple of they. I 
have two functions:

def eventList():
response.view='calendar/eventList.html'
rows=db(...).select()
return dict(rows=rows)

def event():
response.view='calendar/event.html'
row=db(db.EventList.id==request.args(0)).select(db.EventList.ALL)
return dict(row=row)

eventList is embedded in a tab and called in a tab-pane:

{{=LOAD('calendar','eventList.load',args=int(organization.nodeID),ajax=True,target='eventlist')}}

The eventList view lists all the events and each event has a view details 
button. When the user clicks this button I would like the event to open in 
a modal window. Bootstrap provides this:

Launch Modal



  ×
  ...


  ...


  Close



Which works fine with static content in a static view. But I cannot get it 
to work with my eventList and event functions. I hope one of you has done 
something similar and could provide me with a solution.


Kind regards,

Annet.


Re: [web2py] Re: bootstrap in trunk

2012-04-20 Thread Johann Spies
On 20 April 2012 16:05, Anthony  wrote:

Looks like a bug that was introduced -- the code was CAT(INPUT(...),
> DIV(...), SCRIPT(...)), but the CAT was dropped, so instead of returning a
> helper object, it is now returning a tuple of helpers, which doesn't get
> serialized properly.
>
>
> http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py?r=8b8109f75c844b044d580eb770efda11f65141ea#1434
>  --
> need to add "CAT" before the "(" on that line.
>
> Thanks for the reply but your suggestion did not solve the problem.  I
still get the same when using the grid.after changing the return starting
in line 1434 to CAT()

i have also tried putting CAT(INPUT(... in line 620, but that did not make
any difference.



Regards
Johann

-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


Re: [web2py] Re: Modifying auth_navbar

2012-04-20 Thread Richard Vézina
Like your answers Anthony :)

Richard

On Fri, Apr 20, 2012 at 10:39 AM, Anthony  wrote:

> I've worked out how to remove the 'forget username?' and 'Retrieve
>> Password' entries from the navbar by editing gluon/tools.py, and restarting
>> server.
>>
>> This seems a bit severe, altering web2py source code. I imagine my
>> changes will be overwritten at next update.
>>
>> Is there a way to do it in the layout.html view?
>>
>
> First, do you want to disable those two actions altogether, or simply
> remove the links from the navbar (but still allow users to use those
> functions)? If the former:
>
> auth.settings.actions_disabled = ['retrieve_username',
> 'request_reset_password']
>
> That will disable those actions (i.e., they won't be allowed via a call to
> auth(), though you could still call the individual functions themselves),
> and they will not appear in the navbar. See
> http://web2py.com/books/default/chapter/29/9#Settings-and-messages.
>
> If you just want to edit the navbar, note that it is simply an HTML helper
> object (a SPAN object containing opening and closing brackets, some links,
> and separators), so you can manipulate it via the server-side DOM:
> http://web2py.com/books/default/chapter/29/5#Server-side-DOM-and-parsing.
>
> In the navbar, those two items and their two separators start at the 5th
> item within the SPAN and include all but the last item (which is the
> closing bracket), so you could do:
>
> navbar = auth.navbar()
> del navbar[4:-1]
>
> Anthony
>
>


Re: [web2py] Re: 20 beautiful resources that complement twitter bootstrap

2012-04-20 Thread Khalil KHAMLICHI
http://bootswatch.com/#gallery


[web2py] Re: LOAD and .load confusion.

2012-04-20 Thread Anthony

>
> def event():
> response.view='calendar/event.html'
> row=db(db.EventList.id==request.args(0)).select(db.EventList.ALL)


row is actually a DAL Rows object -- if you want a Row object, you have to 
select a specific row. Try:

row=db(db.EventList.id ==request.args(0)).select(db
.EventList.ALL).first()

Anthony


[web2py] LOAD and .load confusion.

2012-04-20 Thread Annet
In a view with tabs I have the following tab-pane:

{{if vevent.event_list:}}
  

  

{{=LOAD('calendar','eventList.load',args=int(organization.nodeID),ajax=True,target='eventlist')}}
  

   
{{pass}}


In the eventList function I set the view to: calendar/eventList.html
This view contains the following link:

{{=A(XML("View details »"),_class="btn btn-primary btn-mini", 
_onclick="javascript:openwindow('%s','vcardwindow',1028,576)" 
%URL('event',args=row.id))}}

... which is rendered as follows:

View details »


The following event function renders a table in the generic view:

def event():
row=db(db.EventList.id==request.args(0)).select(db.EventList.ALL)
return dict(row=row)

Since I want the event to be rendered in the following view:

{{if row:}}


  ×
  {{=row.summary}}
  
{{=db.EventList.startDate.formatter(row.startDate)}}
{{if row.endDate:}} - {{=db.EventList.endDate.formatter(row.endDate)}} 
{{pass}}
  


  {{=row.description}}


  Close


{{pass}}

I rewrote the event function:

def event():
response.view='calendar/event.html'
row=db(db.EventList.id==request.args(0)).select(db.EventList.ALL)
return dict(row=row)

However, this result in an error:

Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 
205, in restricted
exec ccode in environment
  File 
"/Library/Python/2.5/site-packages/web2py/applications/bootstrap/views/calendar/event.html",
 line 85, in 
AttributeError: 'Rows' object has no attribute 'summary'


I don't understand why.

Kind regards,

Annet





Re: [web2py] Re: List of users with a specific permission

2012-04-20 Thread Jim Steil

Thanks Johann

Had to modify to also add (db.auth_group.id==db.auth_membership.group_id)

db((db.auth_user.id==db.auth_membership.user_id)&(db.auth_group.id==db.auth_permission.group_id)&(db.auth_permission.name=='load')).select(db.auth_user.id, 
distinct=True)


Thanks again for getting me down the right path.

-Jim

On 4/20/2012 8:54 AM, Johann Spies wrote:
On 20 April 2012 15:37, Jim Steil mailto:j...@qlf.com>> 
wrote:


That's not quite it either.  This is checking for a group 'role'
as opposed to looking for all users that have a specific
permission (auth_permission).


Then adapt it. Determine the group name that have the specific 
permission and from there it is easy to determine the id's of the 
members of that group. Something like


reds = [x.id  for x in db((db.auth_user.id 
 == 
db.auth_membership.user_id)&(db.auth_group.id 
 == db.auth_permission.group_id) & 
(db.auth.permission.name  == 
'kb_ed')).select(db.auth_user.id )]


Regards
Johann
--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)



[web2py] Re: Modifying auth_navbar

2012-04-20 Thread Anthony

>
> I've worked out how to remove the 'forget username?' and 'Retrieve 
> Password' entries from the navbar by editing gluon/tools.py, and restarting 
> server.
>
> This seems a bit severe, altering web2py source code. I imagine my changes 
> will be overwritten at next update.
>
> Is there a way to do it in the layout.html view?
>

First, do you want to disable those two actions altogether, or simply 
remove the links from the navbar (but still allow users to use those 
functions)? If the former:

auth.settings.actions_disabled = ['retrieve_username', 
'request_reset_password']

That will disable those actions (i.e., they won't be allowed via a call to 
auth(), though you could still call the individual functions themselves), 
and they will not appear in the navbar. See 
http://web2py.com/books/default/chapter/29/9#Settings-and-messages.

If you just want to edit the navbar, note that it is simply an HTML helper 
object (a SPAN object containing opening and closing brackets, some links, 
and separators), so you can manipulate it via the server-side DOM: 
http://web2py.com/books/default/chapter/29/5#Server-side-DOM-and-parsing.

In the navbar, those two items and their two separators start at the 5th 
item within the SPAN and include all but the last item (which is the 
closing bracket), so you could do:

navbar = auth.navbar()
del navbar[4:-1]

Anthony



Re: [web2py] Modifying auth_navbar

2012-04-20 Thread Richard Vézina
Maybe read in this chapter :
http://web2py.com/books/default/chapter/29/5?search=auth_nav

On Fri, Apr 20, 2012 at 9:15 AM, Simon Pickles  wrote:

> Hi,
>
> I've worked out how to remove the 'forget username?' and 'Retrieve
> Password' entries from the navbar by editing gluon/tools.py, and restarting
> server.
>
> This seems a bit severe, altering web2py source code. I imagine my changes
> will be overwritten at next update.
>
> Is there a way to do it in the layout.html view?
>
> Thanks
>
> Simon
>


[web2py] Re: bootstrap in trunk

2012-04-20 Thread Anthony
Looks like a bug that was introduced -- the code was CAT(INPUT(...), 
DIV(...), SCRIPT(...)), but the CAT was dropped, so instead of returning a 
helper object, it is now returning a tuple of helpers, which doesn't get 
serialized properly.

http://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py?r=8b8109f75c844b044d580eb770efda11f65141ea#1434
 -- 
need to add "CAT" before the "(" on that line.

Anthony

On Friday, April 20, 2012 5:44:08 AM UTC-4, Johann Spies wrote:
>
> Thanks for the bootstrap css and js in the trunk.  I am trying it out and 
> found  a problem when used with the grid:
>
> 
> 
>  >
> (,  at 0x44b41a50>, )
> 
> 
> 
> 
> 
> 
> 
> Export
> 
> 
> 11106 records found
> 
>
> Regards
> Johann
>


Re: [web2py] Re: List of users with a specific permission

2012-04-20 Thread Johann Spies
On 20 April 2012 15:37, Jim Steil  wrote:

>  That's not quite it either.  This is checking for a group 'role' as
> opposed to looking for all users that have a specific permission
> (auth_permission).
>

Then adapt it. Determine the group name that have the specific permission
and from there it is easy to determine the id's of the members of that
group. Something like

reds = [x.id for x in db((db.auth_user.id == db.auth_membership.user_id)&(
db.auth_group.id == db.auth_permission.group_id) &
(db.auth.permission.name== 'kb_ed')).select(
db.auth_user.id)]

Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


Re: [web2py] Re: Using static files in view confusion

2012-04-20 Thread Jonathan Lundell
On Apr 20, 2012, at 6:24 AM, Simon Pickles wrote:
> Thanks I suspected my path was a little wrong.
> 
> Still got the problem that the image border appears then whole thing vanishes.

Assuming that your app is set as the default, try:



otherwise:



If you leave out the leading slash, the browser interprets the URL as being 
relative to the current page, which is not likely to be right (unless the 
current page is / or /myapp).

However, you're better off letting URL handle the details for you, especially 
if you ever enable URL routing. You can pass your style argument to IMG by 
renaming it _style, or use  
> On Friday, 20 April 2012 08:19:23 UTC+1, Simon Pickles wrote:
> Hi,
> 
> New to web2py and having trouble with simple HTML in a view. In my 
> default/index.html:
> 
> 
> {{=IMG(_src=URL('static','images/map420x200.png'))}}
> 
> 
> The first line works, rendering the map png. However, the second HTML 
> equivalent doesnt. The bordered box appears empty then disappears. Is my path 
> wrong?
> 
> The app is just created using wizard, and default layout.
> 
> Thanks
> 
> Simon




Re: [web2py] Re: List of users with a specific permission

2012-04-20 Thread Jim Steil
That's not quite it either.  This is checking for a group 'role' as 
opposed to looking for all users that have a specific permission 
(auth_permission).


-Jim

On 4/20/2012 2:27 AM, Johann Spies wrote:
On 20 April 2012 03:07, Jim Steil mailto:j...@qlf.com>> 
wrote:


No, I'm looking for a list of user ids.  I don't want to filter by
user id.


In [25]: reds = [x.id  for x in db((db.auth_user.id 
 == 
db.auth_membership.user_id)&(db.auth_group.id 
 == db.auth_membership.group_id) & 
(db.auth_group.role == 'kb_ed')).select(db.auth_user.id 
)]


In [26]: reds
Out[26]: [2, 1, 4]

Regards
Johann
--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)



Re: [web2py] Re: routes.py

2012-04-20 Thread Jonathan Lundell
On Apr 20, 2012, at 6:20 AM, Wikus van de Merwe wrote:
> OK, so if I define the list of function, the situation is clear. If I don't 
> and I want to pass arguments to the default function I need to use the 
> default function name (/default_function/arg). Arguments alone (/arg) in that 
> case would be treated as if it is a function name (even if it does not exist 
> in the controller) and /app/ctrl/arg would be called instead of 
> /app/ctrl/default_function/arg. Thanks for clarifying this.

Yes. And URL() will do the right thing for you in all those cases.

[web2py] Re: Postgres expers -- interesting design issue

2012-04-20 Thread Sundar
Not sure if 'relinquish' is the right word since the foreign constraint is 
going to be enforced if you enter a value for the PO. (May be my statement 
was a little confusing).

Please see the example:

Create Table t1(a int primary key)

Create table t2 (b int primary key, ba null references t1(a))

I just wanted to make sure of this point.

Sundar
=
On Friday, April 20, 2012 6:03:47 PM UTC+5:30, Cliff wrote:
>
> Thank you, Sundar.
>
> I understand.  This solution means I relinquish the foreign key constraint 
> on the product_lots table.  
>
> It does seem simpler than using another table for raw materials.
>
> No third alternative, I guess...
>
> On Friday, April 20, 2012 2:37:38 AM UTC-4, Sundar wrote:
>>
>> Cliff 
>>
>> By adding the 'null' to the 'purchase_order_id' in the product_lots 
>> table, you automatically achieve it - that is, if the field is declared as 
>> Null, foreign key constraint is applicable only if it is non-null and a 
>> null value will automatically skip validation for foreign key.
>>
>> Another method (not really required, I guess) is to define a 'dummy' PO 
>> with id as zero (or non-negative) and refer to this PO in all product lots 
>> which do not require any PO reference. However, this method will mean that 
>> you have to have an additional where clause in all selects (on the PO 
>> table) to exclude this specific PO.
>>
>> Cheers.
>>
>> Sundar
>> ==
>> On Friday, April 20, 2012 3:16:24 AM UTC+5:30, Cliff wrote:
>>>
>>> nick,
>>> Thanks for the response.
>>>
>>> Here's a longer explanation.
>>>
>>> Two applications, one is purchasing, the other is production.
>>>
>>> Purchasing has two tables, purchase_orders and product_lots.  It's a 
>>> one-to-may relationship; a purchase order can have many product lots.  So 
>>> we get:
>>> db.define_table('purchase_orders', field('po_number' .
>>> db.define_table('product_lots', Field('purchase_order_id', 
>>> db.purchase_orders, requires=IS_IN_DB(db, 'purchase_orders.id', ...)),
>>>   Field('quantity_received', 'decimal'), Field('quantity_on_hand', 
>>> 'decimal') ...
>>>
>>> So, I have established a foreign table relationship between purchase 
>>> orders and product lots.
>>>
>>> Once a product_lot is released to production, the production app uses 
>>> the same table to find available raw materials, and decrements the 
>>> quantity_on_hand field as it goes.  The production app neither knows nor 
>>> cares about the purchase order table, so the purchase_order_id field is 
>>> irrelevant.
>>>
>>> This is fine as long as all production material enters the plant via the 
>>> purchasing process.  However, this is not the case.  So, either I devise a 
>>> way to get records into the product lots table without violating the 
>>> foreign key constraint that Postgres would apply.  One way would be to 
>>> define the purchase_order_id field as an integer and handle the key 
>>> relationships through code.  Not attractive.
>>>
>>> Another way would be to establish a third table for raw materials.  This 
>>> would be a clone of the product_lots table but it would not have a foreign 
>>> key to purchase_orders.  The purchase_order controller would then need to 
>>> create and update records in the raw materials table, while several 
>>> controllers in the production app would also create and update records in 
>>> the table as well.  I don't like this solution much, either.
>>>
>>> Can anybody suggest another approach?
>>>
>>>
>>>
>>> On Thursday, April 19, 2012 1:03:41 PM UTC-4, nick name wrote:

 I don't understand what you are trying to achieve, but whatever it is, 
 you are doing it wrong; your model should be:

 db.define_table('A', Field('name'))

 db.define_table('B', Field('name'), Field('id_from_table_a', 'reference 
 A'))
 # alternatively:
 # db.define_table('B', Field('name'), Field('id_from_table_a', db.A)) 

 This would create the foreign key reference, and would allow nulls by 
 default (which is what your condition does).

 But as I said, I'm not sure exactly what you are trying to achieve?

 On Wednesday, April 18, 2012 7:11:42 PM UTC-4, Cliff wrote:
>
> There are two tables, as follows:
>
> db.define_table('A', Field('name'))
>
> db.define_table('B', Field('name'), Field('id_from_table_a))
>
> Also there are two applications.  One, called 'both_a_and_b', uses 
> both tables and uses 'table_a_id'  as a foreign key in table B.  The 
> other, 
> called 'table_b_only' needs CRUD access to the information in table B, 
> but 
> it is not able to supply a value for 'id_from_table_a.'
>
> I think because Postgres recognizes foreign key constraints, 
> 'table_b_only' will not be able to create records in table B.  
>
> What Is the right solution?
>
> I can think of two.  First, create a 

[web2py] Re: Using static files in view confusion

2012-04-20 Thread Simon Pickles
Thanks I suspected my path was a little wrong.

Still got the problem that the image border appears then whole thing 
vanishes.

On Friday, 20 April 2012 08:19:23 UTC+1, Simon Pickles wrote:
>
> Hi,
>
> New to web2py and having trouble with simple HTML in a view. In my 
> default/index.html:
>
>
> {{=IMG(_src=URL('static','images/map420x200.png'))}}
> 
>
> The first line works, rendering the map png. However, the second HTML 
> equivalent doesnt. The bordered box appears empty then disappears. Is my 
> path wrong?
>
> The app is just created using wizard, and default layout.
>
> Thanks
>
> Simon
>


Re: [web2py] Re: routes.py

2012-04-20 Thread Wikus van de Merwe
OK, so if I define the list of function, the situation is clear. If I don't 
and I want to pass arguments to the default function I need to use the 
default function name (/default_function/arg). Arguments alone (/arg) in 
that case would be treated as if it is a function name (even if it does not 
exist in the controller) and /app/ctrl/arg would be called instead of 
/app/ctrl/default_function/arg. Thanks for clarifying this.



Re: [web2py] bootstrap in trunk

2012-04-20 Thread Johann Spies
Further information:  This happens only with SQLFORM.grid and not with
SQLFORM.smartgrid.  I have tested it on a new app using using the css and
js and layout.html from the welcome app.

Regards
Johann


-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


[web2py] Modifying auth_navbar

2012-04-20 Thread Simon Pickles
Hi,

I've worked out how to remove the 'forget username?' and 'Retrieve 
Password' entries from the navbar by editing gluon/tools.py, and restarting 
server.

This seems a bit severe, altering web2py source code. I imagine my changes 
will be overwritten at next update.

Is there a way to do it in the layout.html view?

Thanks

Simon


Re: [web2py] Re: Web2py + Python 2.7 on GAE: Can I use PIL and resize an image when uploading to datastore?

2012-04-20 Thread Wikus van de Merwe
I would just queue the image processing task (using GAE queue) to have the 
work done in the background. Doing it right when the form is submitted is 
possible too but will cause delays to the user.

You could insert a logo by converting the image into uncompressed format 
(e.g. bmp), modifying the pixel array directly and converting the image 
string again to png or jpg.

Using PIL is only possible with python2.7. You just do "import PIL" as 
usual and read images from the blob as strings.

 

Re: [web2py] .represent in case of empty field

2012-04-20 Thread Anthony

>
> Try db.EventList.startDate.represent = lambda v: v.strftime('%d/%m/%Y') or 
>> None
>
>
Note, that will still generate an error if v is None -- you have to first 
check for v before applying the strftime method to it.

Anthony 


[web2py] Re: web2py doesn't seem to be picking up posted json

2012-04-20 Thread Wikus van de Merwe
How do you post it? I'm guessing this is the part that needs fixing.


[web2py] Re: creating manual login form

2012-04-20 Thread Anthony
def login():
return dict(form=auth.login())

/default/login.html:
{{extend 'layout.html'}}
{{[custom form code goes here]}}

What exactly are you trying to do?

Anthony

On Friday, April 20, 2012 6:23:41 AM UTC-4, Sonu Srivastava wrote:
>
> i create reagister form using auth_user but unable to create a manual 
> login form by which we login.please anyone help me.



[web2py] Re: CRON tasks in Google App Engine

2012-04-20 Thread Wikus van de Merwe
Not directly. You can't execute scripts on GAE, so you would have to move 
the checking/sending code into a controller function and set up the GAE 
cron to call it periodically.

However, it might be easier to use the GAE queues and to delegate e-mail 
sending to a background task:
https://developers.google.com/appengine/docs/python/taskqueue/overview


[web2py] Re: What would be the best way to generate a summary of the 'count(*) 'of all my database table columns?

2012-04-20 Thread Cliff
Is this what you want?

Table   |  column count
---
dog | 3
---
car | 3
---

This will get the data.
For table in db.tables:
  column_count = 0
for field in table.fields
  column_count += 1
  print table.name
  print column_count

On Thursday, April 19, 2012 9:57:57 PM UTC-4, Cody Goodman wrote:
>
> I have multiple databases:
>
> dog
> ---
> type
> color
> sound
>
> car
> --
> model
> maker
> condition
>
> I need to generate a grid with the table names, then under them the number 
> of columns there are. I have made multiple DAL objects for each database 
> like so:
>
> dog = DAL('mysql://root:@localhost/dog)
> car = DAL('mysql://root:@localhost/car)
>
> I then thought I could just make select statements getting the count of 
> each column like this:
>
> number_of_dog_colors = len(db().select(dog.type.color))
>
> Of course my syntax for that is wrong and I got a :
>  'function' object has no attribute 
> 'color'
>
> I was just wondering what the correct syntax to do that was, and if I'm 
> going about it correctly. Once I get the syntax correct, I was going to 
> make a list of all the table names, then get the count for each. If anyone 
> knows a better way to do this, please let me know.
>
> Thanks in advance for any help.
>
> Sincerely,
>
> Cody Goodman
>
>

[web2py] Re: Postgres expers -- interesting design issue

2012-04-20 Thread Cliff
Thank you, Sundar.

I understand.  This solution means I relinquish the foreign key constraint 
on the product_lots table.  

It does seem simpler than using another table for raw materials.

No third alternative, I guess...

On Friday, April 20, 2012 2:37:38 AM UTC-4, Sundar wrote:
>
> Cliff 
>
> By adding the 'null' to the 'purchase_order_id' in the product_lots table, 
> you automatically achieve it - that is, if the field is declared as Null, 
> foreign key constraint is applicable only if it is non-null and a null 
> value will automatically skip validation for foreign key.
>
> Another method (not really required, I guess) is to define a 'dummy' PO 
> with id as zero (or non-negative) and refer to this PO in all product lots 
> which do not require any PO reference. However, this method will mean that 
> you have to have an additional where clause in all selects (on the PO 
> table) to exclude this specific PO.
>
> Cheers.
>
> Sundar
> ==
> On Friday, April 20, 2012 3:16:24 AM UTC+5:30, Cliff wrote:
>>
>> nick,
>> Thanks for the response.
>>
>> Here's a longer explanation.
>>
>> Two applications, one is purchasing, the other is production.
>>
>> Purchasing has two tables, purchase_orders and product_lots.  It's a 
>> one-to-may relationship; a purchase order can have many product lots.  So 
>> we get:
>> db.define_table('purchase_orders', field('po_number' .
>> db.define_table('product_lots', Field('purchase_order_id', 
>> db.purchase_orders, requires=IS_IN_DB(db, 'purchase_orders.id', ...)),
>>   Field('quantity_received', 'decimal'), Field('quantity_on_hand', 
>> 'decimal') ...
>>
>> So, I have established a foreign table relationship between purchase 
>> orders and product lots.
>>
>> Once a product_lot is released to production, the production app uses the 
>> same table to find available raw materials, and decrements the 
>> quantity_on_hand field as it goes.  The production app neither knows nor 
>> cares about the purchase order table, so the purchase_order_id field is 
>> irrelevant.
>>
>> This is fine as long as all production material enters the plant via the 
>> purchasing process.  However, this is not the case.  So, either I devise a 
>> way to get records into the product lots table without violating the 
>> foreign key constraint that Postgres would apply.  One way would be to 
>> define the purchase_order_id field as an integer and handle the key 
>> relationships through code.  Not attractive.
>>
>> Another way would be to establish a third table for raw materials.  This 
>> would be a clone of the product_lots table but it would not have a foreign 
>> key to purchase_orders.  The purchase_order controller would then need to 
>> create and update records in the raw materials table, while several 
>> controllers in the production app would also create and update records in 
>> the table as well.  I don't like this solution much, either.
>>
>> Can anybody suggest another approach?
>>
>>
>>
>> On Thursday, April 19, 2012 1:03:41 PM UTC-4, nick name wrote:
>>>
>>> I don't understand what you are trying to achieve, but whatever it is, 
>>> you are doing it wrong; your model should be:
>>>
>>> db.define_table('A', Field('name'))
>>>
>>> db.define_table('B', Field('name'), Field('id_from_table_a', 'reference 
>>> A'))
>>> # alternatively:
>>> # db.define_table('B', Field('name'), Field('id_from_table_a', db.A)) 
>>>
>>> This would create the foreign key reference, and would allow nulls by 
>>> default (which is what your condition does).
>>>
>>> But as I said, I'm not sure exactly what you are trying to achieve?
>>>
>>> On Wednesday, April 18, 2012 7:11:42 PM UTC-4, Cliff wrote:

 There are two tables, as follows:

 db.define_table('A', Field('name'))

 db.define_table('B', Field('name'), Field('id_from_table_a))

 Also there are two applications.  One, called 'both_a_and_b', uses both 
 tables and uses 'table_a_id'  as a foreign key in table B.  The other, 
 called 'table_b_only' needs CRUD access to the information in table B, but 
 it is not able to supply a value for 'id_from_table_a.'

 I think because Postgres recognizes foreign key constraints, 
 'table_b_only' will not be able to create records in table B.  

 What Is the right solution?

 I can think of two.  First, create a third table, C, for all the data 
 that 'table_b_only' needs.  This table would not have the 
 'id_from_table_a' 
 field.  The other application would need to write also to this table 
 whenever it creates a record in table B.

 A second possibility might be to define table B this way:
 db.define_table('B', 
   Field('name') , 
   Field('id_from_table_a', requires= IS_EMPTY_OR(IS_IN_DB(db, 'A.id', 
 ...)))
 )

 I would be grateful for any guidance,
 Cliff Kachinske

>>>

Re: [web2py] creating manual login form

2012-04-20 Thread Khalil KHAMLICHI
these stuff come by default built into web2py you just enjoy using them
(you can style them if you want),

look at the AUTH section in the book or google for "customize login form in
web2py" for more info

On Fri, Apr 20, 2012 at 10:23 AM, Sonu Srivastava <
sonu.srivast...@zero-group.com> wrote:

> i create reagister form using auth_user but unable to create a manual
> login form by which we login.please anyone help me.


Re: [web2py] Re: 20 beautiful resources that complement twitter bootstrap

2012-04-20 Thread Khalil KHAMLICHI
To this list of 4 elements can we add a 2 other elements ?


   - 5 lower the learning curve as much as possible for actual web2py users
   - 6 make the theming framework optional or choosable or modular (choose
   what you need from it)

It would be super fantastic to see something like : choose theming
framework in the admin page and to see that this list allows a 'None'
option, sometimes we just need web2py to play at the back-end only and to
not interfere with the front-end because we'll be fetching content thru
jquery for example.
for the learning curve, I have been to the bootstrap page it a huge
framework... tons of classes, two grids one by default and another flexible
.. so I guess at initial example application should be really documented
relative to this, and I hope its still time, because documenting while
coding is easier than documenting already coded code.



On Fri, Mar 2, 2012 at 6:44 PM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> There are four features I want:
> 1 a flexible layout
> 2 ability to easily change the default theme
> 3 a default theme that looks as close as possible to bootstrap
> 4 minimize the number of files that ship with "welcome"
>
> Currently we have 1, 3 and 4 but not 2.
> Now jQuery UI provides both 2 and 3 but not 1.
>
>
>
> On Friday, 2 March 2012 10:39:34 UTC-6, Anthony wrote:
>>
>> On Friday, March 2, 2012 11:12:44 AM UTC-5, Massimo Di Pierro wrote:
>>>
>>> I think we should include this in web2oy 2.0:
>>>
>>> http://addyosmani.github.com/**jquery-ui-bootstrap/
>>>
>>
>> Are you saying you want to change the welcome app to Bootstrap and also
>> add jQuery UI with this Bootstrap theme, or just add jQuery UI with the
>> Bootstrap theme (but not the rest of Bootstrap)? Note, Bootstrap itself
>> includes its own versions of some of the elements found in jQuery UI (e.g.,
>> tabs, accordian, dialog, buttons, icons, alerts, progress bar, etc.).
>>
>> Anthony
>>
>


[web2py] Re: Errors creating/reading tickets

2012-04-20 Thread selecta
yes I know this problem for a long time, would be nice if this would be 
fixed. I guess right now the problem is that the whole ticket display fails 
if one ticket is corrupted. I think this could be quickfixed by a simple 
try catch block around the deserialization of each ticket pickle file.

On Sunday, March 11, 2012 3:48:04 AM UTC+1, Brian M wrote:
>
> This has actually been plaguing me for a while but finally annoyed me 
> enough to ask.  I have several web2py (1.99.4) apps running under 
> Apache/2.2.17 (Win32) , mod_wsgi/3.3 and Python/2.6.4.  More often than 
> not when an error happens and a ticket is generated, the ticket seems to be 
> corrupt.  Attempting to view the ticket creates another error for which the 
> ticket says something like:
>
>  Version  web2py™ (1, 99, 4, 
> datetime.datetime(2011, 12, 22, 11, 20, 45), 'stable')  Python Python 
> 2.6.4: C:\vantage_dashboard\xampp\apache\bin\httpd.exe  Traceback 
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
>
> Traceback (most recent call last):
>   File "C:\vantage_dashboard\xampp\web2py\gluon\restricted.py", line 204, in 
> restricted
> exec ccode in environment
>   File 
> "C:/vantage_dashboard/xampp/web2py/applications/admin/controllers/default.py" 
> , line 
> 1341, in 
>   File "C:\vantage_dashboard\xampp\web2py\gluon\globals.py", line 172, in 
> 
> self._caller = lambda f: f()
>   File 
> "C:/vantage_dashboard/xampp/web2py/applications/admin/controllers/default.py" 
> , line 
> 1082, in errors
> error = pickle.load(fullpath_file)
>   File "C:\Python26\Lib\pickle.py", line 1370, in load
> return Unpickler(file).load()
>   File "C:\Python26\Lib\pickle.py", line 858, in load
> dispatch[key](self)
>   File "C:\Python26\Lib\pickle.py", line 880, in load_eof
> raise EOFError
> EOFError
>
>
> Which means that I have to attempt to read the original error ticket in a 
> text editor which is just slightly less than idea.  Any ideas what might be 
> happening? This problem doesn't seem to happen in my dev environment (also 
> Windows but just using rocket instead of apache/mod_wsgi).
>
> Thanks,
> Brian
>


Re: [web2py] Using static files in view confusion

2012-04-20 Thread Johann Spies
On 20 April 2012 09:19, Simon Pickles  wrote:

> Hi,
>
> New to web2py and having trouble with simple HTML in a view. In my
> default/index.html:
>
>
> {{=IMG(_src=URL('static','images/map420x200.png'))}}
> 
>
> The first line works, rendering the map png. However, the second HTML
> equivalent doesnt. The bordered box appears empty then disappears. Is my
> path wrong?
>
>
Hint:  Look at the generated html of the first line by doing the following
in the shell:

$ python web2py.py -M -N -S 

print URL('static','images/map420x200.png')

Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)


Re: [web2py] Using static files in view confusion

2012-04-20 Thread Khalil KHAMLICHI
To insert an image here is the url to use

or
URL('static', args='images/map420x200.png')
or simply
URL('static', 'images/map420x200.png') since its only one argument.

from the book : http://web2py.com/books/default/chapter/29/4#URL


1.

URL('a', 'c', 'f', args=['x', 'y'], vars=dict(z='t'))

 is mapped into

/a/c/f/x/y?z=t


a stands for application_name

c stands for controller name

f stands for function name

x and y are arguments

z is a variable of type string with value of 't'




On Fri, Apr 20, 2012 at 7:19 AM, Simon Pickles  wrote:

> Hi,
>
> New to web2py and having trouble with simple HTML in a view. In my
> default/index.html:
>
>
> {{=IMG(_src=URL('static','images/map420x200.png'))}}
> 
>
> The first line works, rendering the map png. However, the second HTML
> equivalent doesnt. The bordered box appears empty then disappears. Is my
> path wrong?
>
> The app is just created using wizard, and default layout.
>
> Thanks
>
> Simon
>


[web2py] Using static files in view confusion

2012-04-20 Thread Simon Pickles
Hi,

New to web2py and having trouble with simple HTML in a view. In my 
default/index.html:


{{=IMG(_src=URL('static','images/map420x200.png'))}}


The first line works, rendering the map png. However, the second HTML 
equivalent doesnt. The bordered box appears empty then disappears. Is my 
path wrong?

The app is just created using wizard, and default layout.

Thanks

Simon


[web2py] web2py doesn't seem to be picking up posted json

2012-04-20 Thread Matt Thompson
I'm using the following function from the documentation for a RESTful web 
service

def POST(table_name,**fields): 
string = ""
if table_name == 'person': 
for key in fields:
string = string + "another keyword arg: %s: %s" % (key, 
fields[key])
return string
#return db.t_person.validate_and_insert(fields) 
elif table_name == 'pet': 
return db.pet.validate_and_insert(**vars) 
else: 
raise HTTP(400)

The JSON that's being posted isn't being included in **fields, Some 
searching has lead me to information about the POST not being a key pair 
but just JSON so I wondered if web2py was struggling with that?

http://stackoverflow.com/questions/6702490/how-to-use-extjs4-save-in-php-server/6703326#6703326
 

The data being sent also includes data on the URL eg 
/api/person/?_dc=86876876

That is being returned in the response from the above function.

Any help appreciated.

Matt



[web2py] creating manual login form

2012-04-20 Thread Sonu Srivastava
i create reagister form using auth_user but unable to create a manual login 
form by which we login.please anyone help me.

[web2py] CRON tasks in Google App Engine

2012-04-20 Thread Jason (spot) Brower
I just wanted to confirm with you guys...
According to this page there is a way to send emails in a que.
http://web2py.com/books/default/chapter/29/8?search=cron
Does this work in Google App Engine?
BR,
Jason


[web2py] bootstrap in trunk

2012-04-20 Thread Johann Spies
Thanks for the bootstrap css and js in the trunk.  I am trying it out and 
found  a problem when used with the grid:




(, , )







Export


11106 records found


Regards
Johann


Re: [web2py] Re: pure css skins?

2012-04-20 Thread Vasile Ermicioi
100% agree,
naming convention + more features that's why I prefer bootstrap over
foundation

On Fri, Apr 20, 2012 at 8:55 AM, Annet  wrote:

> I had a look at both Foundation and Bootstrap 2 weeks ago and decided to
> use Bootstrap (by the way, they're both not pure css). Mainly because I
> didn't like the styling of Foundation (compare forms, buttons, alerts etc.)
> and I found their naming conventions, well, awkward:
>
> Foundation:
> 
>   ...
>   ...
> 
>
> Bootstrap:
> 
>   ...
>   ...
> 
>
> Foundation:
> 
>   ...
>   ...
> 
>
> Bootstrap:
> 
>   ...
>   ...
> 
>
>
> Besides, these two features are quite helpful:
>
> http://addyosmani.github.com/jquery-ui-bootstrap/
>
> http://twitter.github.com/bootstrap/less.html
>
>
> Kind regards,
>
> Annet.
>
>
>
>


Re: [web2py] Re: List of users with a specific permission

2012-04-20 Thread Johann Spies
On 20 April 2012 03:07, Jim Steil  wrote:

>  No, I'm looking for a list of user ids.  I don't want to filter by user
> id.
>
>
In [25]: reds = [x.id for x in db((db.auth_user.id ==
db.auth_membership.user_id)&(db.auth_group.id ==
db.auth_membership.group_id) & (db.auth_group.role == 'kb_ed')).select(
db.auth_user.id)]

In [26]: reds
Out[26]: [2, 1, 4]

Regards
Johann

-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)