Re: [web2py] Say hello to i-Track

2011-11-30 Thread Phyo Arkar
WOW
Thank you very much!

i have been waiting for this.And i was looking also looking at
rhodecode.organd thinking to do a web2py alternative of it.

How about we try integrating HG into it?

On Thu, Dec 1, 2011 at 1:08 PM, Julio Schwarzbeck wrote:

> Folks,
>
> I've just released i-Trac
>
> i-Track is a simple issue/bug tracking system developed in web2py, it
> is Open Source Software released under the Simplified BSD License, the
> site is "live" at:
>
> http://www.i-track.org/
>
> There is a "demo" site also at http://demo.i-track.org/ feel free to
> use to test the system if you wish, instructions on how to log in in
> the demo site are posted in there.
>
> i-Track is already fully functional and even has a couple of bugs
> posted for itself (eating our own dog food of course). If you wish to
> help develop or contribute to post bugs or issued, please create an
> account in the regular 'www' site, instructions on how to do and what
> to expect are also posted in the main homepage.
>
> Code is hosted in bitbucket (link at the footer of the website) in
> case you wish to get your own copy.
>
> Happy testing/posting/hacking
>
> Julio FS (Speedbird)
>


[web2py] Speed of JOIN vs Recursive SELECTs

2011-11-30 Thread lyn2py
Appreciate your input on this guys :)

I have two tables that are related.
>> db.define_table('person', Field('name'))
>> db.define_table('dog', Field('name'), Field('owner', db.person))

According to the book:
http://web2py.com/book/default/chapter/06#Inner-Joins

I can JOIN:
>> rows = db(db.person.id==db.dog.owner).select()
>> rows = db(db.person).select(join=db.person.on(db.person.id==db.dog.owner))

I can recursive SELECT:
>> dog.owner.name

And recursive SELECT is supposed to be slower than JOIN, because there
are more database transactions?
I tried both methods out (disclaimer: I do not have many testing
entries in the database, and I'm currently observing this on localhost/
sqlite) and I have found JOIN to be slower, I was literally waiting
for the page to load, watching the loading bar... a few seconds.
But recursive SELECT loads the page in a snap.

Is this correct behavior?
Should I use recursive select for few entries (less than, say, 30) and
JOIN for many?
If I move the site to production, what database(s) would you
recommend, and for which method (recursive select vs join)?

Thanks!


[web2py] "user" tickets vs. "system" exception tickets?

2011-11-30 Thread nick name
Currently, there are two ways exceptions are handled in web2py:

If the controller/view does *NOT* use try: except:, and an exception is 
raised, then it is very helpfully logged in the ticket system, and a 
somewhat-useful message (that can be customized a little, see e.g. 
), is given 
as a reply. The link in this message is, in general, useful to the 
developer, but not to the end user of the app (who will usually be unable 
to follow the ticket link). It is very likely to break the user's flow of 
work, as this message is not actually an app view/controller.

If the controller/view *DOES* use try: except: to catch errors, then any 
reply could be given to the user, but everything needs to be implemented in 
the app, including db rollback, logging of problems, etc.

It would be great if there was a *middle ground* in between them, where a 
ticket could be generated for the developer, logging everything that can be 
useful to diagnose the problem, but to let processing continue. For 
example, I would like to be able to do something like this:

try:
  # verify that the next insert will succeed
  table.insert(**record)
except integrity_error, e:
  # db.rollback() can be called here if needed.
  ticket_id = gluon.user_ticket(e)
  return dict(flash_message = "Unfortunately, we were unable to complete 
the request even though we should have. Our developer has been notified. 
You may use incident code %s to inquire about this" % 
make_a_user_facing_code(ticket_id))

return dict(flash_message="Completed successfully")

That is, logically there's a bug here, and I would love to have the ticket 
to diagnose the problem, so I'm tempted to not handle the exception at all. 
However, I do want to detect the problem and keep the user within the 
app-flow.

This situation appears quite often If you have a database model whose 
consistency cannot be encoded into SQL constraints that are automatically 
enforced - and it is thus possible that a bug in one place (creating an 
inconsistent database) manifests in another place. While developing, 
web2py's default tickets are great. But on deployment, I'd rather have 
friendlier logic-error handling, without giving up the snapshot/ticketing 
system that web2py provides.

Looks like it's quite easy to do already - something like:

def user_ticket(e):
  from restricted import RestrictedError
  ticket = None
  try: raise RestrictedError('user-ticket')
  except RestrictedError, e: ticket = e.log(request)
  return ticket

would probably work, except that it uses web2py internals that are likely 
to change. Is there an official way to get this kind of functionality? If 
not, do other people think this would be a useful addition?


Re: [web2py] ImportError with plugin

2011-11-30 Thread Johann Spies
On 30 November 2011 23:08, haikuvend Resident  wrote:

> I have downloaded a plugin from http://dev.s-cubism.com/plugin_solidform
>
>
Did you install the plugin in your app?  The easiest way is through the
admin interface.

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


[web2py] Say hello to i-Track

2011-11-30 Thread Julio Schwarzbeck
Folks,

I've just released i-Trac

i-Track is a simple issue/bug tracking system developed in web2py, it
is Open Source Software released under the Simplified BSD License, the
site is "live" at:

http://www.i-track.org/

There is a "demo" site also at http://demo.i-track.org/ feel free to
use to test the system if you wish, instructions on how to log in in
the demo site are posted in there.

i-Track is already fully functional and even has a couple of bugs
posted for itself (eating our own dog food of course). If you wish to
help develop or contribute to post bugs or issued, please create an
account in the regular 'www' site, instructions on how to do and what
to expect are also posted in the main homepage.

Code is hosted in bitbucket (link at the footer of the website) in
case you wish to get your own copy.

Happy testing/posting/hacking

Julio FS (Speedbird)


[web2py] Re: Help with socket timeout error

2011-11-30 Thread nick name
A possibly related (and possibly unrelated) data point:

I've always been running from source. Occasionally, when I try to read 
request.body I get a socket timeout, even though exactly zero seconds have 
passed, and the timeout is set at 60 seconds.

Running the same request again (it's programatically generated) succeeds.

I haven't been able to recreate that consistently; it almost always happens 
on the *first* request to the server, and then randomly (and rarely)



[web2py] Best practices: When to use classes

2011-11-30 Thread lyn2py
Hi,

I'm obviously super new at this. I appreciate any gentle pointers,
guidelines and best practices on when to use classes when writing code
with web2py (and/or python for that matter).

I ask this because:
- In Ruby on Rails, everything is put under a class of some kind
- I have briefly seen a few discussion posts on here that have used
classes in their code
- I want to learn from experienced python coders (like you!)

Thank you.


[web2py] Re: fedora, pip, web2py, virtualenv, and mysql

2011-11-30 Thread Christopher Steel
OK, now I get it. {gigantic knowing smile}, You are right, the Web2py 
solution of changing the database line would not work in this particular 
situation.

In a nutshell something that wold work is this: Start over and use either 
w2p_clone or [ w2p_apps and w2p_run ] but never ever mix them in the same 
environment unless it is just to have some fun. While w2p_apps and w2p_run 
are really interesting they also make it very easy to make your install 
foobar unless handled very carefully.*

w2p_clone (recommended, straight forward)*
 
w2p_clone is pretty straight forward. If you are using w2p_clone (I would 
recommend this) then launch web2py the "normal way". In other words from 
your venv directory do something like:

source ./bin/activate
python ./web2py/web2py.py --nogui --password=test

Things should work just like a normal installation and editing the db.py 
database is really all you should need to do to setup Web2py for your 
backend.
*
w2p_apps and w2p_run* *(challenging to master, easy to foobar)*

These two are really interesting and I would highly recommend playing with 
them, but most people (everyone) finds them really tricky to use at first. 
I would hesitate to use them in a production environment myself without a 
very compelling reason, not because the are unstable or bad in any way, but 
because it is so easy for you or someone who follows you to make a good 
installation foobar with them. This is a quick explanation of what they do.
*
w2p_apps* creates a "floating", "headless" applications directory. If you 
run w2p_apps once and the run w2p_run Web2py will magically start and your 
headless applications directory will act as if it was nested under a fairly 
standard Web2py installation only it's not... Confused? everyone is at 
first... Ways to foobar your install with w2p_apps include running it 
twice, once in the intended location and once somewhere else. What happens 
when you have two headless applications directories running under a virtual 
web2py... 

*w2p_run *starts the web2py install the pip install web2py installs (NOT 
the version of Web2py that w2p_clone installs) and makes your headless 
applications directory work like a regular applications directory in a 
normal web2py installation unless you have more than one applications 
directory.
*
Which is which

*When you where seeing 1.98.2 you where running the pip installed version 
of Web2py and when you ran your cloned version you where running 1.99.3. 

If you can figure out a better way to explain all of this then I would be 
happy to include it with the next upgrade of the pip installed version 
which I should probably do A.S.A.P. ...
*
*Hope this helps

Cheers,

Chris










[web2py] JQuery Mobile + web2py - how to set data-url attribute dynamically?

2011-11-30 Thread Constantine Vasil
JQuery Mobile + web2py presents unique challenge because JQuery Mobile 
takes over control after server side. One issue I had was with redirections 
which does not work properly in this environment. JQuery Mobile recognized 
this and added an option how to make this working properly by returning 
your page div with a *data-url* attribute already specified. When you do 
this, jQuery Mobile will use that attribute's value for updating the URL, 
instead of the url used to request that page.


 


If this attribute is set from web2py the redirection will work properly 
(right now it adds a hash '#', which creates a lot of issues.

here is example of the page I got from jQuery Mobile documentation. If 
there is a way to change data-url dynamically from web2py when the page is 
generated the redirection will work properly. Additionally it needs to have 
a trailing slash.

How to do that in web2py?

Regards,
--Constantine

 
 


 
jQuery Mobile Framework - Test URL Example 
  





 
 


 
 URL Test Page
 
 
 This is a regular page that updated the url with a different value than 
was requested.
 






http://jquerymobile.com/demos/1.0/docs/pages/page-links.html

Redirects and linking to directories

When linking to directory indexes (such as href="typesofcats/" instead of 
href="typesofcats/index.html"), you must provide a trailing slash. This is 
because jQuery Mobile assumes the section after the last "/" character in a 
url is a filename, and it will remove that section when creating base urls 
from which future pages will be referenced.

However, you can work around this issue by returning your page div with a 
data-url attribute already specified. When you do this, jQuery Mobile will 
use that attribute's value for updating the URL, instead of the url used to 
request that page. This also allows you to return urls that change as the 
result of a redirect, for example, you might post a form to "/login.html" 
but return a page from the url "/account" after a successful submission. 
This tool allows you to take control of the jQuery Mobile history stack in 
these situations.


[web2py] Re: message "application is compiled and cannot be installed"

2011-11-30 Thread Massimo Di Pierro
It gets compiled without you clicking the button?

On Nov 30, 8:44 pm, Nik Go  wrote:
> This is a trifle behavior that I experience every time I create a new
> "simple application" from the admin interface.  For some reason, the new
> app gets compiled. I'm running Ubuntu 10.04 and running web2py from source.
>
> I need to press the "remove compiled" to proceed with editing the new app. 
> I've
> had this behavior prior to 1.99 but ignored it since I use Komodo as editor
> anyway.
>
> How do I fix this?


[web2py] Re: trunk error

2011-11-30 Thread Massimo Di Pierro
sorry. fixed.

On Nov 30, 12:21 pm, Anthony  wrote:
> Or you can just add that missing comma to user_agent_parser.py.
>
>
>
>
>
>
>
> On Wednesday, November 30, 2011 1:11:49 PM UTC-5, rochacbruno wrote:
>
> > I just removed the {{is_mobile=request.user_agent().is_mobile}} from the
> > */layout views and admin controller
>
> > it worked..
>
> > On Wed, Nov 30, 2011 at 4:03 PM, Anthony  wrote:
>
> >> Note, this is also causing 'admin' to fail. I submitted a ticket.
>
> >> On Wednesday, November 30, 2011 12:19:48 PM UTC-5, rochacbruno wrote:
>
> >>> Just got the same with firefox on windows
>
> >>> (dp1
> >>> S'output'
> >>> p2
> >>> S" invalid syntax (user_agent_parser.py,
> >>> line 214)
>
> >>> --
>
> >>> Bruno Rocha
> >>> [http://rochacbruno.com.br]
>
> > --
>
> > Bruno Rocha
> > [http://rochacbruno.com.br]


[web2py] Re: Fwd: How disable date widget?

2011-11-30 Thread Massimo Di Pierro
I would consider this an improvement. Please open a ticket.

On Nov 30, 9:46 am, Vinicius Assef  wrote:
> On Tue, Nov 29, 2011 at 1:39 PM, Massimo Di Pierro
>
>  wrote:
> > sorry it took me a while
>
> > SQLFORM.widgets.string.widget and SQLFORM.widgets.date.widget
> > are the same.
>
> I couldn't find anything in the docs about it. Reading there, we are
> lead to face them as different widgets.
>
> > what you want is to eliminate the datepicker popup. Technically that
> > is not part of the widget but handled by the JS in the page.
>
> > try this, immediately after you insert the form or field:
>
> > 
> > jQuery('#table_field').removeClass('date'); // or datetime
> > 
>
> It worked. Thank you. :-D
> I'm not so good in Javascript. Not even in jQuery, yet.
>
> Talking about this case, I understand technically it's not inside the
> widget. But, think with me: if I have a date field with a string
> widget, couldn't web2py generate this field with another class?
> Something like "date without_picker" (or something better. rsrs) Or,
> the opposite, generate "date date_picker" in case of using this
> picker. And just "date" if not using it.
>
> Could we consider it a problem to be fixed?
>
> --
> Vinicius Assef.


[web2py] Re: web2py logo and layout has changed one year ago...

2011-11-30 Thread Massimo Di Pierro
I do not like names that have google search conflicts. Others like
that because their search results go up.
We had a different name and I was threatened to be sued. I spend $500
to trademark web2py.

Can anybody find a better name that has no search conflicts, is not
trademarked, and is willing to donate $500?

It does take time and effort in building a brand and we are succeeded.
We should not start again. We can give animal names to various stable
version if you like.

Massimo

On Nov 30, 9:46 am, Omi Chiba  wrote:
> >I love the framework but hate the name Web2py
>
> Honestly, I agree. Django sounds cool but not web2py. I like gluon
> better :)
>
> On Nov 30, 9:16 am, António Ramos  wrote:
>
>
>
>
>
>
>
> > I love the framework but hate the name Web2py
> > Everyone uses names related to animals, objects,etc. At least it gives a
> > better change for a nice logo.
>
> > Best regards
>
> > 2011/11/30 stefaan 
>
> > > Web2py default layouts certainly have come a long way since the (IMHO,
> > > quite awful :p )  fluorescent orange and black-green looks.
>
> > > I do seem to miss some "best-practices" documentation about how to
> > > effectively apply themes to a web2py application. The downloadable
> > > themes do not always properly display the newer widgets (like
> > > sqlform.grid), leaving me (as a css nitwit) not much option but to use
> > > the default layout. Unlike web2py functionality, the css classes do
> > > not seem to be kept backward compatible (your layout won't be
> > > overwritten if you upgrade to a newer web2py, but if you want the
> > > newer features to render properly you may have to manually merge old
> > > layouts with newer layouts)
>
> > > 
> > > I'm wondering if there aren't any WYSIWYM web layout solutions (what-
> > > you-see-is-what-you-mean, a web equivalent to LaTeX macros for
> > > printable documents), e.g. providing standardized css classes that all
> > > scaffolding applications/widgets/user views ought to restrict
> > > themselves to. Themes would also have to be implemented in terms of
> > > those standardized css classes, hopefully leading to a smoother
> > > theming experience. Approaches like the "ui" argument in sqlform.grid
> > > do not seem ideal to me.
> > > 


[web2py] How to add a trailig slash? web2py + trailing slash needed from jQuery Mobile

2011-11-30 Thread Constantine Vasil
Are there a way to use trailing slash after page name like: /about/

This is because jQuery Mobile requires it to work properly. Otherwise
it adds a hash '#' after redirection which prevents from form submitting.

I had a lot of issues with the hash which is generated and initially
disabled Ajax jQuery but the hash still appears. Now it turns out I need to 
add
a trailing slash after page name. I mentioned on the forum that web2py 
strips out
the trailing slash - is that true? Is adding a trailing slash to my 
routes.py 
will make the trick?

Regards,
--Constantine

http://jquerymobile.com/test/docs/pages/page-navmodel.html

When linking to directories, without a filename url, (such as 
href="typesofcats/" instead ofhref="typesofcats/index.html"), you must 
provide a *trailing slash.* This is because jQuery Mobile assumes the 
section after the last "/" character in a url is a filename, and it will 
remove that section when creating base urls from which future pages will be 
referenced.


[web2py] Re: @reboot task started twice when a init simbolink link is present

2011-11-30 Thread Massimo Di Pierro
Please submit a ticket about this. Althought I am not sure how to fix
this because web2py will think you have two apps.

On Nov 30, 4:54 am, dsanchez  wrote:
> Hello all
>
> I have the following crontab file:
> #crontab
> @reboot cht *applications/atvestpp/modules/SchedulerDownload.py
>
> In the applications folder, I have a simbolik link 'init' pointing to
> my application 'atvestpp'.
>
> When I started the web2py server, two instances of
> SchedulerDownload.py are started, one for 'atvestpp' and a second for
> 'init'
> ps -ef
> ...
> cht       2379  2198  9 11:51 pts/1    00:00:00 python web2py.py
> cht       2388  2379 12 11:51 pts/1    00:00:00 /usr/bin/python /home/
> cht/web2py/web2py.py -J -M -S atvestpp -a  -R
> cht       2392  2379 12 11:51 pts/1    00:00:00 /usr/bin/python /home/
> cht/web2py/web2py.py -J -M -S init -a  -R appl
>
> The problem disappears if a remove the 'init' symbolic link
>
> I think this is a bug. (I have version 1.99.2) Hope it helps!
>
> David


[web2py] Re: could use some help ... mobile admin

2011-11-30 Thread Massimo Di Pierro
Mind that with this change anybody who can intercept your network
traffic can get full access to your account.

On Nov 30, 1:55 am, Angelo Compagnucci 
wrote:
> Get the trunk!
>
> If you want to use the admin app whitout setting aup https in a
> private environment, you have to comment out these lines in
> models/access.py:
>
> #elif not request.is_local and not DEMO_MODE:
> #    raise HTTP(200, T('Admin is disabled because insecure channel'))
>
> 2011/11/30 Javier Quarite :
>
>
>
> > On Tue, Nov 29, 2011 at 6:40 PM, Angelo Compagnucci
> >  wrote:
>
> >> I almost done the admin mobilization!
>
> >> I have to get rid of an error on design.html, when done, I'll send you
> >> patches!
>
> >> Thanks!
>
> > Is there a way to see an example? it sounds interesting and it could be a
> > good reason to make my friends use web2py :D
>
> --
> Profile:http://www.gild.com/compagnucciangelo
> Register on Gild:http://www.gild.com/referral/compagnucciangelo


[web2py] Re: default value in Model (define_table)

2011-11-30 Thread Massimo Di Pierro
you just should not do this:

Field(...,default=request.args(0))

in models.

You can do (as a workaround)

if request.args:
   db.table.field.default=request.args(0)

but I still would not do it this way. Instead do in the controller
where you need it:

def myaction():
db.table.field.default=request.args(0)
form = SQLFORM(db.table,...)

On Nov 30, 1:17 am, lyn2py  wrote:
> If I have:
>
> #model
> db.define_table('mytable',
>   ...
>   Field('other_table_id','reference
> other_table',default=request.args(0),...),
>   ...
> )
>
> It works fine on the webpage (Views) and SQLFORM, but when I try to
> access the database from appadmin, it runs into an error:>> ValueError: 
> invalid literal for int() with base 10: 'db'
>
> because the first item is "db" and it's not an integer.
>
> Normally we will put:>> Field('other_table_id','reference 
> other_table',default=db.other_table.id,...)
>
> which will load fine, but on the webpage (Views), "None" comes up,
> which is not desirable.
>
> The only way I can think up is to use Try...Except... but syntax
> errors come up.
> How will you resolve this?
>
> Thanks!


[web2py] Re: Current transaction aborted error when trying to save session in database

2011-11-30 Thread Massimo Di Pierro
Are your servers behing a load balancer? If so, do you have sticky
sessions? If not you may run into trouble if two servers try access
the same session.



On Nov 30, 1:25 am, Rohan  wrote:
> web2py version: 1.98.2
>
> I have two servers with shared database and I am trying to store session in
> database using
>     session.connect(request, response, db=db, migrate=False)
>
> but  session._try_store_in_db is throwing Internal Error from one of the
> servers but it works fine from second server.
> Here is traceback
>
> Traceback (most recent call last):
>   File "/home/www-data/web2py/gluon/main.py", line 497, in
> wsgibase
>     session._try_store_in_db(request, response)
>   File "/home/www-data/web2py/gluon/globals.py", line 474, in
> _try_store_in_db
>     record_id = table.insert(**dd)
>   File "/home/www-data/web2py/gluon/dal.py", line 4786, in insert
>     return self._db._adapter.insert(self,self._listify(fields))
>   File "/home/www-data/web2py/gluon/dal.py", line 844, in insert
>     raise e
> InternalError: current transaction is aborted, commands ignored until end
> of transaction block
>
> Any pointers will be appreciated
> Regards


[web2py] Re: SQLTABLE images for id fields

2011-11-30 Thread Alan Etkin
I made a new diff with Anthony suggestions: Now any helper instance
can be returned by lambda as a second argument.

diff -r 7dd85a51bb2a gluon/sqlhtml.py
--- a/gluon/sqlhtml.py  Tue Nov 29 22:32:30 2011 -0600
+++ b/gluon/sqlhtml.py  Thu Dec 01 00:44:05 2011 -0300
@@ -1972,6 +1972,8 @@
 optional arguments:

 :param linkto: URL (or lambda to generate a URL) to edit
individual records
+To wrap an IMG object or alike with de the id
field link,
+the lambda function can return a (href, obj)
tuple
 :param upload: URL to download uploaded files
 :param orderby: Add an orderby link to column headers.
 :param headers: dictionary of headers to headers redefinions
@@ -2142,16 +2144,25 @@
 if not field:
 pass
 elif linkto and field.type == 'id':
+linkwrapped = None
 try:
-href = linkto(r, 'table', tablename)
+t = linkto(r, 'table', tablename)
+if isinstance(t, (tuple, list)):
+href, linkwrapped = t
+else:
+href = t
 except TypeError:
 href = '%s/%s/%s' % (linkto, tablename,
r_old)
-r = A(r, _href=href)
+r = self.link_or_image(r, href, linkwrapped)
 elif field.type.startswith('reference'):
 if linkto:
 ref = field.type[10:]
 try:
-href = linkto(r, 'reference', ref)
+t = linkto(r, 'reference', ref)
+if isinstance(t, (tuple, list)):
+href = t[0]
+else:
+href = t
 except TypeError:
 href = '%s/%s/%s' % (linkto, ref, r_old)
 if ref.find('.') >= 0:
@@ -2247,6 +2258,14 @@

 return css

+
+def link_or_image(self, r, href, linkwrapped):
+if linkwrapped is not None:
+return A(linkwrapped, _href=href)
+else:
+return A(r, _href=href)
+
+
 form_factory = SQLFORM.factory # for backward compatibility,
deprecated




On Nov 30, 10:32 pm, Anthony  wrote:
> Instead, why not make it more general and simply allow the linkto lambda to
> return an (r, href) tuple, where r could be an IMG object or anything else.
> Something like:
>
> elif linkto and field.type == 'id':
>     try:
>         href = linkto(r, 'table', tablename)
>         if isinstance(href, (list, tuple)):
>             r, href = href
>
> Then we don't need a new argument -- all the work can be done in the linkto
> function.
>
> Anthony
>
> On Wednesday, November 30, 2011 8:01:18 PM UTC-5, Alan Etkin wrote:
>
> > I think that it would be practical to have the option when calling
> > SQLTABLE to specify images in place of id links.
>
> > Here is how i would change it (seems to work with version 1.99.2)
>
> > diff -r 7dd85a51bb2a gluon/sqlhtml.py
> > --- a/gluon/sqlhtml.py Tue Nov 29 22:32:30 2011 -0600
> > +++ b/gluon/sqlhtml.py Wed Nov 30 21:50:01 2011 -0300
> > @@ -1972,6 +1972,7 @@
> >      optional arguments:
>
> >      :param linkto: URL (or lambda to generate a URL) to edit
> > individual records
> > +    :param imagelink: URL of an image to wrap the linkto field
> >      :param upload: URL to download uploaded files
> >      :param orderby: Add an orderby link to column headers.
> >      :param headers: dictionary of headers to headers redefinions
> > @@ -2043,6 +2044,7 @@
> >          self,
> >          sqlrows,
> >          linkto=None,
> > +        imagelink=None,
> >          upload=None,
> >          orderby=None,
> >          headers={},
> > @@ -2146,7 +2148,7 @@
> >                          href = linkto(r, 'table', tablename)
> >                      except TypeError:
> >                          href = '%s/%s/%s' % (linkto, tablename,
> > r_old)
> > -                    r = A(r, _href=href)
> > +                    r = self.image_link(r, href, imagelink)
> >                  elif field.type.startswith('reference'):
> >                      if linkto:
> >                          ref = field.type[10:]
> > @@ -2247,6 +2249,14 @@
>
> >          return css
>
> > +
> > +    def image_link(self, r, href, imagelink):
> > +        if isinstance(imagelink, basestring):
> > +            return A(IMG(_src=imagelink, _alt=r), _href=href)
> > +        else:
> > +            return A(r, _href=href)
> > +
> > +
> >  form_factory = SQLFORM.factory # for backward compatibility,
> > deprecated



Re: [web2py] app slow to death (sorry double post because empyt object)

2011-11-30 Thread Christopher Steel
That sound peculiar Richard. Could we get a little more info on your load 
test? Where are you getting the 45% and 100% figures from, the Gnome 
monitoring applet? If it is an app you can share, I could try the same 
setup on a similar system for you.

Chris








[web2py] Re: web2py hosting

2011-11-30 Thread Plumo
their install script setup needs to be changed to use less memory by 
default. Seems quite a few people have contacted their support about this. 

[web2py] Re: cannot login or register, missing links: login|register|lost password

2011-11-30 Thread Nik Go
Arghh... for some reason or another, I lost my:
auth.define_tables()

Thanks for the feedback Massimo.

On Tuesday, November 29, 2011, Nik Go wrote:

> I've been deleting tables and playing around with various settings, so I
> don't know what I've done exactly but now my app lost the links for logging
> in, registering or resetting passwords.
>
> If I try to access the links manually (i.e.
> http://127.0.0.1:8000/s1/default/user/register) or do the same for
> resetting the password, I get the same error:
>
> Traceback (most recent call last):
>
>   File "/home/n1k/web2py/gluon/restricted.py", line 194, in restricted
>
> exec ccode in environment
>
>   File "/home/n1k/web2py/applications/s1/controllers/default.py", line 243, 
> in 
>
>   File "/home/n1k/web2py/gluon/globals.py", line 149, in 
>
> self._caller = lambda f: f()
>
>   File "/home/n1k/web2py/applications/s1/controllers/default.py", line 205, 
> in user
>
> return dict(form=auth())
>
>   File "/home/n1k/web2py/gluon/tools.py", line 1126, in __call__
>
> return getattr(self,args[0])()
>
>   File "/home/n1k/web2py/gluon/tools.py", line 1804, in register
>
> separator=self.settings.label_separator
>
>   File "/home/n1k/web2py/gluon/sqlhtml.py", line 735, in __init__
>
> fields = [f.name for f in table if (ignore_rw or f.writable or 
> f.readable) and not f.compute]
> TypeError: 'NoneType' object is not iterable
>
> I've deleted my cookies, and tried using another browser with a different 
> profile. But I still get the same thing: no links, no way to register a user.
>
> Using the admin app, I manually registered a new user. It worked, but I could 
> get login, to.
>
>
>


[web2py] displaying virtualfields in auth_user

2011-11-30 Thread Nik Go
I needed an advanced profile for a registered user with fields coming from
another table. Since I want to keep the same auth_user profile link, I
thought I'd used a virtual field in the auth_user table to display a link
to the other table.

class VFprofile(object):
def advanced_profile(self):
return self.auth_user.id
#append to my auth_user table
db.auth_user.virtualfields.append(VFprofile())
#db.auth_user.advanced_profile.represent=lambda v,r: A('Click
here',_href=URL('my_profile'))

I could check the values of the advanced_profile however the virtual field
wouldn't display when a user clicks his own profile. I commented out the
last line because it generates an error "KeyError:advanced_profile", but
without it the advanced_profile virtualfield is generated and accessible.
for i in db(db.auth_user.id>0).select():
print i.advanced_profile
   :
   :
1
2

I know that I can customize the auth_table, but I don't want to mess up
that table with optional information. Are virtual fields displayable?
Comments are welcome, or suggestions for the "proper" of way of doing this.

Nik


[web2py] message "application is compiled and cannot be installed"

2011-11-30 Thread Nik Go
This is a trifle behavior that I experience every time I create a new
"simple application" from the admin interface.  For some reason, the new
app gets compiled. I'm running Ubuntu 10.04 and running web2py from source.

I need to press the "remove compiled" to proceed with editing the new app. I've
had this behavior prior to 1.99 but ignored it since I use Komodo as editor
anyway.

How do I fix this?


[web2py] Re: Relative path in css for @font-face embedding

2011-11-30 Thread Christopher Steel
Here is a working example and the corresponding googlecode project used to 
create it that you can use as a reference. FYI squirrelfont has a nice  
automated system that allows you to create font "packages" that include 
most of what you will need. I used if for the following project.

Running example
http://www.chrissteel.com/fonts

Fonts
http://code.google.com/p/uc-font/

The example uses openfonts. It is a little sloppybut it works as an 
example. I have a newer, cleaner version around somewhere, if I can locate 
it I will update the repository.

Cheers,

Chris


[web2py] Re: SQLTABLE images for id fields

2011-11-30 Thread Anthony
Instead, why not make it more general and simply allow the linkto lambda to 
return an (r, href) tuple, where r could be an IMG object or anything else. 
Something like:

elif linkto and field.type == 'id':
try:
href = linkto(r, 'table', tablename)
if isinstance(href, (list, tuple)):
r, href = href

Then we don't need a new argument -- all the work can be done in the linkto 
function.

Anthony

On Wednesday, November 30, 2011 8:01:18 PM UTC-5, Alan Etkin wrote:
>
> I think that it would be practical to have the option when calling
> SQLTABLE to specify images in place of id links.
>
> Here is how i would change it (seems to work with version 1.99.2)
>
> diff -r 7dd85a51bb2a gluon/sqlhtml.py
> --- a/gluon/sqlhtml.py Tue Nov 29 22:32:30 2011 -0600
> +++ b/gluon/sqlhtml.py Wed Nov 30 21:50:01 2011 -0300
> @@ -1972,6 +1972,7 @@
>  optional arguments:
>
>  :param linkto: URL (or lambda to generate a URL) to edit
> individual records
> +:param imagelink: URL of an image to wrap the linkto field
>  :param upload: URL to download uploaded files
>  :param orderby: Add an orderby link to column headers.
>  :param headers: dictionary of headers to headers redefinions
> @@ -2043,6 +2044,7 @@
>  self,
>  sqlrows,
>  linkto=None,
> +imagelink=None,
>  upload=None,
>  orderby=None,
>  headers={},
> @@ -2146,7 +2148,7 @@
>  href = linkto(r, 'table', tablename)
>  except TypeError:
>  href = '%s/%s/%s' % (linkto, tablename,
> r_old)
> -r = A(r, _href=href)
> +r = self.image_link(r, href, imagelink)
>  elif field.type.startswith('reference'):
>  if linkto:
>  ref = field.type[10:]
> @@ -2247,6 +2249,14 @@
>
>  return css
>
> +
> +def image_link(self, r, href, imagelink):
> +if isinstance(imagelink, basestring):
> +return A(IMG(_src=imagelink, _alt=r), _href=href)
> +else:
> +return A(r, _href=href)
> +
> +
>  form_factory = SQLFORM.factory # for backward compatibility,
> deprecated
>
>
>

[web2py] SQLTABLE images for id fields

2011-11-30 Thread Alan Etkin
I think that it would be practical to have the option when calling
SQLTABLE to specify images in place of id links.

Here is how i would change it (seems to work with version 1.99.2)

diff -r 7dd85a51bb2a gluon/sqlhtml.py
--- a/gluon/sqlhtml.py  Tue Nov 29 22:32:30 2011 -0600
+++ b/gluon/sqlhtml.py  Wed Nov 30 21:50:01 2011 -0300
@@ -1972,6 +1972,7 @@
 optional arguments:

 :param linkto: URL (or lambda to generate a URL) to edit
individual records
+:param imagelink: URL of an image to wrap the linkto field
 :param upload: URL to download uploaded files
 :param orderby: Add an orderby link to column headers.
 :param headers: dictionary of headers to headers redefinions
@@ -2043,6 +2044,7 @@
 self,
 sqlrows,
 linkto=None,
+imagelink=None,
 upload=None,
 orderby=None,
 headers={},
@@ -2146,7 +2148,7 @@
 href = linkto(r, 'table', tablename)
 except TypeError:
 href = '%s/%s/%s' % (linkto, tablename,
r_old)
-r = A(r, _href=href)
+r = self.image_link(r, href, imagelink)
 elif field.type.startswith('reference'):
 if linkto:
 ref = field.type[10:]
@@ -2247,6 +2249,14 @@

 return css

+
+def image_link(self, r, href, imagelink):
+if isinstance(imagelink, basestring):
+return A(IMG(_src=imagelink, _alt=r), _href=href)
+else:
+return A(r, _href=href)
+
+
 form_factory = SQLFORM.factory # for backward compatibility,
deprecated




[web2py] Re: Creating URL-safe links/strings?

2011-11-30 Thread lyn2py
Gotcha!

On Dec 1, 8:19 am, Anthony  wrote:
> On Wednesday, November 30, 2011 6:56:50 PM UTC-5, lyn2py wrote:
>
> > Good thing you mentioned Bruno's solution. It appeared as "show quoted
> > text" to me, and at first glance didn't look like it contained new
> > text. *sorry Bruno!*
>
> > Just a side question on best practices, where should I put my little
> > lambda so that all files (and functions) in my app can use it? Geez,
> > did I mention I'm new to python too...
>
> The simplest thing to do is put it in a model file (maybe called
> 0_helpers.py, or if it's a simple app and you just have one or two, stick
> it in db.py). (Note, model files are executed in alphabetical order, so
> preceding the file name with "0_" ensures it will be executed early and the
> helpers will therefore be available in later executed model files.)  You
> could also put it in a module and import it where needed, but in that case,
> the module will have to import the IS_SLUG validator from gluon.validators.
> There are a number of API objects (including validators) that are
> automatically imported into the web2py execution environment and are
> therefore available in any model, controller, or view without requiring
> explicit import (http://web2py.com/book/default/chapter/04#API). However,
> those API objects are not readily available in modules, so they must be
> imported there
> (seehttp://web2py.com/book/default/chapter/04#Accessing-the-API-from-Pyth...).
>
> Anthony


[web2py] Help with socket timeout error

2011-11-30 Thread lyn2py
Hello,

I was previously using the binaries, and hadn't run into this error
before.
I just downloaded and run from source, and ran into:

>> (Socket timed out before request.)

Why did I encounter this issue and how do I resolve it?

Thanks!


[web2py] Re: question with db.requires

2011-11-30 Thread chawk
Thanks Anthony!

I must have skimmed over this part of the book. I got it now.

chawk


"" > Note, the 'requires' argument to Field sets validators for form
submissions
> -- it does not affect regular insert() or update() methods on the table.
> The validate_and_insert() and validate_and_update() methods were created to
> enable use of the form validators without actual form processing. ""


[web2py] Re: Creating URL-safe links/strings?

2011-11-30 Thread Anthony
On Wednesday, November 30, 2011 6:56:50 PM UTC-5, lyn2py wrote:
>
> Good thing you mentioned Bruno's solution. It appeared as "show quoted
> text" to me, and at first glance didn't look like it contained new
> text. *sorry Bruno!*
>
> Just a side question on best practices, where should I put my little
> lambda so that all files (and functions) in my app can use it? Geez,
> did I mention I'm new to python too...
>
The simplest thing to do is put it in a model file (maybe called 
0_helpers.py, or if it's a simple app and you just have one or two, stick 
it in db.py). (Note, model files are executed in alphabetical order, so 
preceding the file name with "0_" ensures it will be executed early and the 
helpers will therefore be available in later executed model files.)  You 
could also put it in a module and import it where needed, but in that case, 
the module will have to import the IS_SLUG validator from gluon.validators. 
There are a number of API objects (including validators) that are 
automatically imported into the web2py execution environment and are 
therefore available in any model, controller, or view without requiring 
explicit import (http://web2py.com/book/default/chapter/04#API). However, 
those API objects are not readily available in modules, so they must be 
imported there 
(see 
http://web2py.com/book/default/chapter/04#Accessing-the-API-from-Python-modules).

Anthony


[web2py] Re: question with db.requires

2011-11-30 Thread Anthony

>
> p.s.  Should i be adding something to my post to show that a question
>
> is solved, like they do on stackoverflow?  i saw somebody do that on
> this forum and did not know if I should be doing the same.
>
Most people don't, but I suppose you could add [SOLVED] to the subject, or 
something like that.
 

> MODEL:
>
> db.define_table('president',
> Field('name', 'string'))
>
> db.president.name.requires = IS_NOT_IN_DB(db, 'president.name')
>
>
> CONTROLLER:
>
> def test():
> message = ""
> form = FORM('Join President?', INPUT(_name='join',
> _type='radio'),
> INPUT(_name="name"), INPUT(_type='submit'))
> if form.process().accepted:
> db.president.insert(name=form.vars.name)
> return dict(form=form, message=message)
>
The FORM object doesn't know anything about your db table, and you haven't 
defined any validators in your form INPUTs, so form.process() doesn't  do 
any validation. You have a couple options. First, INPUT() takes a 
'requires' argument, just like Field(), so you could define your 
IS_NOT_IN_DB validator there. Or, you can do your insert like this:

response = db.president.validate_and_insert(name=form.vars.name)

If there are any errors, they will be in response.errors and response.id 
will be None -- otherwise, response.id will be the id of the inserted 
record.

Note, the 'requires' argument to Field sets validators for form submissions 
-- it does not affect regular insert() or update() methods on the table. 
The validate_and_insert() and validate_and_update() methods were created to 
enable use of the form validators without actual form processing.

Anthony



Re: [web2py] hard time understanding query and set objects

2011-11-30 Thread chandrakant kumar
On Thu, Dec 1, 2011 at 5:26 AM, Anthony  wrote:

> 2. A query object represents a sql 'where' clause like, myquery =
 (db.mytable.myfield != None) | (db.mytable.myfield > 'A')
  Can't the same thing be done like, rows =
 db((db.mytable.myfield!=None) | (db.mytable.myfield >'A'))
   what is the need of having a query object?

>>>
>>>  What is your proposed alternative?
>>>
>>> using, myset = db((db.mytable.myfield!None)|(**db.mytable.myfield>'A'))
>> and then
>> rows = myset.select()
>> will do the same thing, will it? so that we can skip two lines , one
>> defining the myquery(db.mytable.myfield!**None)|(db.mytable.myfield>'A')*
>> *,
>> then calling myset=db(myquery)
>>
>
> Oh, certainly, there's no need to define the query first and then pass it
> to db(). Your alternative is actually the more common usage. I thought you
> were suggesting there is no need for a separate query object at all. It can
> be useful in some cases, though. Consider a base query to which you might
> want to add various optional conditions:
>
> base_query = (db.mytable.myfield != None)
>
> You might want to add additional conditions to that query in different
> scenarios:
>
> db(base_query & (db.mytable.myfield > 'A'))
>
> You might also want to use the same query with different db objects.
>
Things are much clear now for me, thank you so much.


[web2py] Re: Creating URL-safe links/strings?

2011-11-30 Thread lyn2py
Good thing you mentioned Bruno's solution. It appeared as "show quoted
text" to me, and at first glance didn't look like it contained new
text. *sorry Bruno!*

Just a side question on best practices, where should I put my little
lambda so that all files (and functions) in my app can use it? Geez,
did I mention I'm new to python too...



On Dec 1, 6:33 am, Anthony  wrote:
> On Wednesday, November 30, 2011 5:16:59 PM UTC-5, lyn2py wrote:
>
> > Thanks Anthony.
>
> > That's interesting syntax to use a validator!
>
> Well, the validators are mostly intended to be used for validating form
> fields. They are callable objects, so you instantiate a validator like
> IS_SLUG(), which is an object with a __call__ method that takes a value and
> validates it. The __call__ method returns a tuple, which is the (possibly
> transformed) value and either an error message or None. A few of the
> validators, such as IS_SLUG, actually transform the input value rather than
> simply checking it, so they can also be used independently for their
> transformation effects. Of course, in that case, the required syntax seems
> a bit awkward:
>
> IS_SLUG()  # creates a callable object - usually passed as the 'requires'
> arg to Field()
> IS_SLUG()('My Title')  # passes a value to the __call__ method of the
> validator object
> IS_SLUG()('My Title')[0]  # extracts the returned value, which is the first
> element of the returned tuple
>
> To make it easier, you can write your own helper:
>
> make_slug = lambda v: IS_SLUG()(v)[0]
>
> Then do:
>
> title_slug = make_slug('My Title')
>
> This is like Bruno's compute example. You could also make a more general
> helper that works with any validator:
>
> >>> transform = lambda v, validator: validator()(v)[0]
> >>> transform('my title', IS_SLUG)
> 'my-title'
> >>> transform('My Title', IS_UPPER)
>
> 'MY TITLE'
>
> Anthony


Re: [web2py] hard time understanding query and set objects

2011-11-30 Thread Anthony

>
> 2. A query object represents a sql 'where' clause like, myquery = 
>>> (db.mytable.myfield != None) | (db.mytable.myfield > 'A')
>>>  Can't the same thing be done like, rows = 
>>> db((db.mytable.myfield!=None) | (db.mytable.myfield >'A')) 
>>>   what is the need of having a query object?
>>>
>>
>>  What is your proposed alternative?
>>
>> using, myset = db((db.mytable.myfield!None)|(db.mytable.myfield>'A')) and 
> then
> rows = myset.select()
> will do the same thing, will it? so that we can skip two lines , one
> defining the myquery(db.mytable.myfield!None)|(db.mytable.myfield>'A'),
> then calling myset=db(myquery)
>

Oh, certainly, there's no need to define the query first and then pass it 
to db(). Your alternative is actually the more common usage. I thought you 
were suggesting there is no need for a separate query object at all. It can 
be useful in some cases, though. Consider a base query to which you might 
want to add various optional conditions:

base_query = (db.mytable.myfield != None)

You might want to add additional conditions to that query in different 
scenarios:

db(base_query & (db.mytable.myfield > 'A'))

You might also want to use the same query with different db objects.

Anthony
 


[web2py] question with db.requires

2011-11-30 Thread chawk
this should be simple but it is not working right.   All i am trying
to do is insert form variables into the database and make sure
duplicates are not inserted.   I would imagine the controller is
bypassing the db.requires, but i am a newbie and don't understand why
it is being bypassed.   What is happening is that my controller inputs
the form.vars.name even if it is already in the database.   I know
that i can use the SQLFORM, but i am practicing the lower level form
stuff to get a better understanding of forms and databases.


Thanks in advance for any help,


Chawk

p.s.  Should i be adding something to my post to show that a question
is solved, like they do on stackoverflow?  i saw somebody do that on
this forum and did not know if I should be doing the same.

MODEL:

db.define_table('president',
Field('name', 'string'))

db.president.name.requires = IS_NOT_IN_DB(db, 'president.name')


CONTROLLER:

def test():
message = ""
form = FORM('Join President?', INPUT(_name='join',
_type='radio'),
INPUT(_name="name"), INPUT(_type='submit'))
if form.process().accepted:
db.president.insert(name=form.vars.name)
return dict(form=form, message=message)

VIEW:

{{=form}}
{{pass}}
{{=message}}



Re: [web2py] hard time understanding query and set objects

2011-11-30 Thread chandrakant kumar
On Thu, Dec 1, 2011 at 4:31 AM, Anthony  wrote:

> On Wednesday, November 30, 2011 5:41:34 PM UTC-5, Chandra wrote:
>>
>> I'm going through the official book, currently at the DAL chapter. I'm
>> having confusions over query and set objects.
>>
>> for e.g.
>> 1.  To fetch rows one uses , rows = db(db.mytable.myfield!=None).select()
>>it returns a collection of rows, that is fine. But, what is a
>> 'set' then? Isn't 'rows' itself a set of records?
>>
>
> A Set defines a set of records but doesn't actually select them from the
> db -- so it's like a conceptual representation of the records, but not the
> records themselves. When you apply the select() method to the Set, you
> actually pull the records from the database and transform them to a Python
> object (a Rows object). The distinction is useful because Sets have other
> methods besides select(), such as update(), count(), and delete().
>
>
This makes things clear now.

>
>> 2. A query object represents a sql 'where' clause like, myquery =
>> (db.mytable.myfield != None) | (db.mytable.myfield > 'A')
>>  Can't the same thing be done like, rows =
>> db((db.mytable.myfield!=None) | (db.mytable.myfield >'A'))
>>   what is the need of having a query object?
>>
>
>  What is your proposed alternative?
>
> using, myset = db((db.mytable.myfield!None)|(db.mytable.myfield>'A')) and
then
rows = myset.select()
will do the same thing, will it? so that we can skip two lines , one
defining the myquery(db.mytable.myfield!None)|(db.mytable.myfield>'A'),
then calling myset=db(myquery)


Re: [web2py] hard time understanding query and set objects

2011-11-30 Thread Anthony
On Wednesday, November 30, 2011 5:41:34 PM UTC-5, Chandra wrote:
>
> I'm going through the official book, currently at the DAL chapter. I'm 
> having confusions over query and set objects.
>
> for e.g.
> 1.  To fetch rows one uses , rows = db(db.mytable.myfield!=None).select()
>it returns a collection of rows, that is fine. But, what is a 'set' 
> then? Isn't 'rows' itself a set of records?
>

A Set defines a set of records but doesn't actually select them from the db 
-- so it's like a conceptual representation of the records, but not the 
records themselves. When you apply the select() method to the Set, you 
actually pull the records from the database and transform them to a Python 
object (a Rows object). The distinction is useful because Sets have other 
methods besides select(), such as update(), count(), and delete().
 

>
> 2. A query object represents a sql 'where' clause like, myquery = 
> (db.mytable.myfield != None) | (db.mytable.myfield > 'A')
>  Can't the same thing be done like, rows = 
> db((db.mytable.myfield!=None) | (db.mytable.myfield >'A')) 
>   what is the need of having a query object?
>

 What is your proposed alternative?

Anthony


Re: [web2py] best practice: subclassing Auth

2011-11-30 Thread pbreit
OK, I think that probably requires subclassing. I subclassed once for 
customizing the navbar but ended up just creating my own navbar independent 
of auth. I don't recall it being too bad.

Re: [web2py] hard time understanding query and set objects

2011-11-30 Thread pbreit
I guess you can think of a collection and set as the same thing. The key is 
that you can iterate through it like:

for row in rows:
if row.myfield == 'Joe':
...

That's just a style thing if you want to separate out the query from the 
rest of the db() function.



[web2py] hard time understanding query and set objects

2011-11-30 Thread chandrakant kumar
I'm going through the official book, currently at the DAL chapter. I'm
having confusions over query and set objects.

for e.g.
1.  To fetch rows one uses , rows = db(db.mytable.myfield!=None).select()
   it returns a collection of rows, that is fine. But, what is a 'set'
then? Isn't 'rows' itself a set of records?

2. A query object represents a sql 'where' clause like, myquery =
(db.mytable.myfield != None) | (db.mytable.myfield > 'A')
 Can't the same thing be done like, rows =
db((db.mytable.myfield!=None) | (db.mytable.myfield >'A'))
  what is the need of having a query object?


Re: [web2py] Relative path in css for @font-face embedding

2011-11-30 Thread Jonathan Lundell
On Nov 30, 2011, at 2:15 PM, Martín Mulone wrote:

> I'm not sure, what do you want to do?, or why do you need to include app 
> path?. But you can also make it this in the view to make use of URL() in the 
> view or layout include the tag style simil to this:
> 
> 
> ...
> @font-face {  
> src: url('{{=URL('static','myfont.eot')}}');  
> }
> 
> 

You can also serve CSS files as views and embed template code in them. 

> 2011/11/30 monotasker 
> I'll try these again. So far they didn't seem to work for me.
> 




[web2py] Re: Creating URL-safe links/strings?

2011-11-30 Thread Anthony
On Wednesday, November 30, 2011 5:16:59 PM UTC-5, lyn2py wrote:
>
> Thanks Anthony.
>
> That's interesting syntax to use a validator!
>
Well, the validators are mostly intended to be used for validating form 
fields. They are callable objects, so you instantiate a validator like 
IS_SLUG(), which is an object with a __call__ method that takes a value and 
validates it. The __call__ method returns a tuple, which is the (possibly 
transformed) value and either an error message or None. A few of the 
validators, such as IS_SLUG, actually transform the input value rather than 
simply checking it, so they can also be used independently for their 
transformation effects. Of course, in that case, the required syntax seems 
a bit awkward:

IS_SLUG()  # creates a callable object - usually passed as the 'requires' 
arg to Field()
IS_SLUG()('My Title')  # passes a value to the __call__ method of the 
validator object
IS_SLUG()('My Title')[0]  # extracts the returned value, which is the first 
element of the returned tuple

To make it easier, you can write your own helper:

make_slug = lambda v: IS_SLUG()(v)[0]

Then do:

title_slug = make_slug('My Title')

This is like Bruno's compute example. You could also make a more general 
helper that works with any validator:

>>> transform = lambda v, validator: validator()(v)[0]
>>> transform('my title', IS_SLUG)
'my-title'
>>> transform('My Title', IS_UPPER)
'MY TITLE'

Anthony



[web2py] Re: Creating URL-safe links/strings?

2011-11-30 Thread lyn2py
Thanks Anthony.

That's interesting syntax to use a validator!

Yes it works :)

On Nov 30, 11:24 pm, Anthony  wrote:
> If you're receiving the title from a form submission, you can use the
> IS_SLUG validator on the title field, which will convert it to a slug
> (remove non-alphanumeric characters and convert spaces to hyphens). You can
> also use the validator on it's own:
>
> >>> title_slug = IS_SLUG()('Today is Wonderful!')[0]
> >>> print title_slug
>
> today-is-wonderful
>
> Seehttp://web2py.com/book/default/chapter/07#Validators.
>
> Anthony
>
>
>
>
>
>
>
> On Wednesday, November 30, 2011 10:09:33 AM UTC-5, lyn2py wrote:
>
> > If I want to create a link from a string, is there a function in
> > web2py to do that?
>
> > For example I have a post title "Today is Wonderful!" and I want to
> > create
> > >> /blog/show/today-is-wonderful
> > instead of
> > >> /blog/show/today-is-wonderful%21
> > which gives a Invalid Request error...
>
> > Thanks!


Re: [web2py] Relative path in css for @font-face embedding

2011-11-30 Thread Martín Mulone
I'm not sure, what do you want to do?, or why do you need to include app
path?. But you can also make it this in the view to make use of URL() in
the view or layout include the tag style simil to this:


...
@font-face {
src: url('{{=URL('static','myfont.eot')}}');
}


2011/11/30 monotasker 

> I'll try these again. So far they didn't seem to work for me.




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


[web2py] Re: URL helper - using "register" and "next"

2011-11-30 Thread lyn2py
Hi Anthony,

Thanks for the clarification.

Regarding:
> Are you sure the 'next' value for login isn't being set somewhere else (or
> isn't simply the default 'index')? Using 'next' (rather than '_next') in
> the URL should not work.

I'm new to this, and I am not sure if the 'next' value isn't being set
somewhere else.
I am not using auth.settings.login_next (the only other place that I
know of, I'm assuming it is still the default).
login and register are 2 links I created in view by hand.

Thanks both for your helpful replies!


[web2py] Re: GAE and 'cannot set memcache' error

2011-11-30 Thread howesc
try:
  #get/set something with memcache
except:
  #get/set from DB  (or other authoritative source)


Re: [web2py] best practice: subclassing Auth

2011-11-30 Thread Carlos Hanson
Good question. I want to override retrieve_username(). Of course, I expect 
I'll eventually want to override any of the methods exposed by Auth. If 
there is another way, I would prefer it.While subclassing is easy, it may 
be overkill.

Re: [web2py] Re: Relative path in css for @font-face embedding

2011-11-30 Thread Jonathan Lundell
If you use the relative URL "static/...", what does the browser resolve it to?

On Nov 30, 2011, at 12:55 PM, monotasker  wrote:

> I would keep using that url, but it includes my app name -- a problem since 
> I'm trying to build a presentation *plugin* that includes the font-face 
> embedding. So I need a url that begins above the "appname" folder.


[web2py] Re: db.tablename alias?

2011-11-30 Thread Anthony
On Wednesday, November 30, 2011 3:13:54 PM UTC-5, juanduke wrote:
>
> Maybe something like: db['tableA'] = db.tableA_test and then the rest of 
> the code, always reference: db.tableA.etc
>

Yes, I think you can do that, or just:

db.tableA = db.tableA_test

That may cause problems in some cases, though. For example, in that case, I 
believe db.tables will include 'tableA_test' but not 'tableA'.
 
Anthony


[web2py] ImportError with plugin

2011-11-30 Thread haikuvend Resident
I have downloaded a plugin from http://dev.s-cubism.com/plugin_solidform

It consists of two files:
 - controller/plugin_solidform.py (demo)
 - *modules/plugin_solidform.py* (the actual plugin)

When using the exact same command as in the provided example:

from plugin_solidform import SOLIDFORM

in *controller/default.py*

it gives me the following Traceback:

Traceback (most recent call last):
  File "C:\Users\xxx\web2py\gluon\restricted.py", line 194, in 
restricted
exec ccode in environment
  File "
C:/Users/xxx/web2py/applications/haikuvend/controllers/default.py", 
line 56, in 
  File "C:\Users\xxx\web2py\gluon\globals.py", line 149, in 

self._caller = lambda f: f()
  File "
C:/Users/xxx/web2py/applications/haikuvend/controllers/default.py", 
line 13, in contact
from plugin_solidform import SOLIDFORM
  File "C:\Users\xxx\web2py\gluon\custom_import.py", line 294, 
in __call__
fromlist, level)
  File "C:\Users\xxx\web2py\gluon\custom_import.py", line 78, 
in __call__
level)
ImportError: No module named plugin_solidform

Again, I'm using the exact same syntax as on that page. Why doesn't it work 
for me?


[web2py] Re: db.tablename alias?

2011-11-30 Thread Carlos Hanson
I can't answer your question specifically, but if you were to rewrite your 
code, you could use db.get() to get your table.

tableA = db.get(table_name)


You could then set table_name based on whether "test mode" was set or not.


Re: [web2py] best practice: subclassing Auth

2011-11-30 Thread pbreit
Also, what do you need to do exactly? There are some customizations 
available that don't require sub-classing.

Re: [web2py] Relative path in css for @font-face embedding

2011-11-30 Thread monotasker
I'll try these again. So far they didn't seem to work for me.

[web2py] Re: Relative path in css for @font-face embedding

2011-11-30 Thread monotasker
I would keep using that url, but it includes my app name -- a problem since 
I'm trying to build a presentation *plugin* that includes the font-face 
embedding. So I need a url that begins above the "appname" folder.

[web2py] db.tablename alias?

2011-11-30 Thread juanduke
Hi All:

I've this situation:
Based in a config file, the app must read /modify rows from some table, 
i.e. "tableA" BUT if in config file have setted an "test mode" must 
read/modify rows from another tables. i.e. "tableA_test"
So, in db.py i read if is setted "test mode" or not, and then initalize 
db.tableA or db.tableA_test model.

That is not so unconfortable to code. 
BUT the problem is with the rest of the app, I already made the code, for *
db.tableA* object reference. And I dont want to re.write the code to attend 
the "test mode". I get a ticket with: Key Error: *tableA* when is set to 
use *tableA_test* 
So I'm asking  if is possible to always code db.tableA even if declare 
db.define_table('*tableA_test*').

Maybe something like: db['tableA'] = db.tableA_test and then the rest of 
the code, always reference: db.tableA.etc

Thanks in advance!



[web2py] Re: How to get the only the value of the Sum in a sum Query?

2011-11-30 Thread Carlos Hanson
It is probably useful to see the following as well:

>>> sum = db.operations.amount.sum().coalesce_zero()

>>> sum

>>> print sum
COALESCE(SUM(operations.amount),0)

>>> monthly_amount_first = db((db.operations.date.year()==current_year) & 
...   (db.operations.date.month()==current_month)
...  ).select(sum).first()
>>> monthly_amount_first
}>
>>> monthly_amount_first[sum]
45.0




Re: [web2py] best practice: subclassing Auth

2011-11-30 Thread Carlos Hanson
Thanks. Modules is actually where I started to put it last night, but 
decided I should ask the question, since I really want to learn web2py well.

[web2py] Re: How to get the only the value of the Sum in a sum Query?

2011-11-30 Thread Carlos Hanson
I used the following example:

http://web2py.com/book/default/chapter/06?search=sum#sum,-min,-max-and-len


I created your operations table, but not the budget table:

>>> sum = db.operations.amount.sum().coalesce_zero()
>>> monthly_amount = db((db.operations.date.year()==current_year) & 

... (db.operations.date.month()==current_month)
...).select(sum).first()[sum]
>>> monthly_amount
45.0




Re: [web2py] Re: trunk error

2011-11-30 Thread Anthony
Or you can just add that missing comma to user_agent_parser.py.

On Wednesday, November 30, 2011 1:11:49 PM UTC-5, rochacbruno wrote:
>
> I just removed the {{is_mobile=request.user_agent().is_mobile}} from the 
> */layout views and admin controller
>
> it worked..
>
> On Wed, Nov 30, 2011 at 4:03 PM, Anthony  wrote:
>
>> Note, this is also causing 'admin' to fail. I submitted a ticket.
>>
>>
>> On Wednesday, November 30, 2011 12:19:48 PM UTC-5, rochacbruno wrote:
>>>
>>> Just got the same with firefox on windows
>>>
>>> (dp1
>>> S'output'
>>> p2
>>> S" invalid syntax (user_agent_parser.py, 
>>> line 214)
>>>
>>>
>>> -- 
>>>  
>>> Bruno Rocha
>>> [http://rochacbruno.com.br]
>>>
>>>
>
>
> -- 
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>

Re: [web2py] Re: trunk error

2011-11-30 Thread Angelo Compagnucci
There is an error on line 214 of gluon/contrib/user_agent_parser.py,

should be:

dist=['WindowsMobile'], flavor=None

2011/11/30 Bruno Rocha :
> I just removed the {{is_mobile=request.user_agent().is_mobile}} from the
> */layout views and admin controller
>
> it worked..
>
>
> On Wed, Nov 30, 2011 at 4:03 PM, Anthony  wrote:
>>
>> Note, this is also causing 'admin' to fail. I submitted a ticket.
>>
>>
>> On Wednesday, November 30, 2011 12:19:48 PM UTC-5, rochacbruno wrote:
>>>
>>> Just got the same with firefox on windows
>>>
>>> (dp1
>>> S'output'
>>> p2
>>> S" invalid syntax (user_agent_parser.py,
>>> line 214)
>>>
>>>
>>> --
>>>
>>> Bruno Rocha
>>> [http://rochacbruno.com.br]
>>>
>
>
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>



-- 
Profile: http://www.gild.com/compagnucciangelo
Register on Gild: http://www.gild.com/referral/compagnucciangelo


Re: [web2py] best practice: subclassing Auth

2011-11-30 Thread Bruno Rocha
Dont do it in models, do in /modules


in modules/myauth.py

from gluon.tools import Auth
form gluon import *

class MyAuth(Auth):
def __init__(self):
   #do whatever you want here
   Auth.__init__(self)


in any place of app (model, controller)

from myauth import MyAuth
auth = MyAuth()


On Wed, Nov 30, 2011 at 4:07 PM, Carlos Hanson wrote:

> Chapter 8 says, "All of the methods above can be extended or replaced by
> subclassing Auth." However, it does not give the best place to add the code
> to do so. There is mention of adding to your model, but I'm a little
> unclear about that too.
>
> It seems that the models are imported in order, since the wizard created a
> 0.py. I've created a db_accounts.py, so it comes after db.py. Since I need
> to subclass Auth, I think I need to either create a file that sorts before
> db.py or add code to db.py. My thought is to minimize the number of changes
> to db.py. I know I will need to change the line which instantiates Auth to
> use MyAuth.
>
> Does anyone have suggestions on how to organize models and customizations
> to Auth?
>
> Thanks.
>
> Carlos
>



-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Re: web2py hosting

2011-11-30 Thread HittingSmoke
+1 for Webfaction. It takes a bit of tweaking and configuration to get your 
app running with the cheapest plan without hitting the RAM limit (which is 
what I suspect some of the mentioned issues were) but once it's up and 
running, it works great. I have my apps running on Lighttpd and couldn't be 
happier.

Re: [web2py] Re: trunk error

2011-11-30 Thread Bruno Rocha
I just removed the {{is_mobile=request.user_agent().is_mobile}} from the
*/layout views and admin controller

it worked..

On Wed, Nov 30, 2011 at 4:03 PM, Anthony  wrote:

> Note, this is also causing 'admin' to fail. I submitted a ticket.
>
>
> On Wednesday, November 30, 2011 12:19:48 PM UTC-5, rochacbruno wrote:
>>
>> Just got the same with firefox on windows
>>
>> (dp1
>> S'output'
>> p2
>> S" invalid syntax (user_agent_parser.py,
>> line 214)
>>
>>
>> --
>>
>> Bruno Rocha
>> [http://rochacbruno.com.br]
>>
>>


-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Re: Remove first and last name from Auth.

2011-11-30 Thread HittingSmoke
Thanks, I'll use this for now.

[web2py] best practice: subclassing Auth

2011-11-30 Thread Carlos Hanson
Chapter 8 says, "All of the methods above can be extended or replaced by 
subclassing Auth." However, it does not give the best place to add the code 
to do so. There is mention of adding to your model, but I'm a little 
unclear about that too.

It seems that the models are imported in order, since the wizard created a 
0.py. I've created a db_accounts.py, so it comes after db.py. Since I need 
to subclass Auth, I think I need to either create a file that sorts before 
db.py or add code to db.py. My thought is to minimize the number of changes 
to db.py. I know I will need to change the line which instantiates Auth to 
use MyAuth.

Does anyone have suggestions on how to organize models and customizations 
to Auth?

Thanks.

Carlos


[web2py] How to get the only the value of the Sum in a sum Query?

2011-11-30 Thread Manakel
Hello,

I have the following models for "Operations".
db.define_table('operations',Field('date','date'),Field('budget',db.budgets),Field('title','string'),Field('amount','double'),format='%
(budget)s-%(amount)d-%(date)s:%(title)s')


I'm performing the following query to get the total amount of
operations for 1 budget within the month.
monthly_amount_per_budget=db((db.operations.budget==budget['id'])&
(db.operations.date.year()==current_year) &
(db.operations.date.month()==current_month)).select(db.operations.amount.sum().coalesce_zero(),
groupby=db.operations.budget)

So i get the expected results
LOGEMENT_PRET : COALESCE(SUM(operations.amount),0)
1100

NOURRITURE : COALESCE(SUM(operations.amount),0)
24.0

Now i would like to store only the value "1100" in a variable, but how
to get this value?
I've tried and failed with:
   monthly_amount_per_budget.first()[sum]
   monthly_amount_per_budget.first()[db.operations.amount.sum]
   monthly_amount_per_budget.first()['COALESCE(SUM(operations.amount),
0)']
etc...

Thanks a lot for your help. I have hard time trying to make sql from
python code (too much used to direct SQL))




Re: [web2py] Re: trunk error

2011-11-30 Thread Anthony
Note, this is also causing 'admin' to fail. I submitted a ticket.

On Wednesday, November 30, 2011 12:19:48 PM UTC-5, rochacbruno wrote:
>
> Just got the same with firefox on windows
>
> (dp1
> S'output'
> p2
> S" invalid syntax (user_agent_parser.py, 
> line 214)
>
>
> -- 
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>

Re: [web2py] Re: trunk error

2011-11-30 Thread Bruno Rocha
Just got the same with firefox on windows

(dp1
S'output'
p2
S" invalid syntax (user_agent_parser.py,
line 214)


-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Re: call submit from an A tag

2011-11-30 Thread apple
You can do this or equivalent using web2py helpers:

Submit

On Nov 30, 3:15 pm, thodoris  wrote:
> Is there a way to change the submit button into clickable text?
>
> Lets say i have this form:
>
> form = SQLFORM.factory(Field('my_table'))
>
> and i can do
>
> table = form.element() to get the element
> table.append(INPUT(_type='submit', _value='submit')): this appends the
> submit button next to the element
>
> but is there a way to call submit for an A, like this ???
>
> table.append(A('Submit',_type='submit', _value='submit')))


Re: [web2py] call submit from an A tag

2011-11-30 Thread Bruno Rocha
table.append(A('Submit',_href="#", _onclick=*"$('form').submit(); return
false;"*))

You shoould define an id to form if you have more than one form in a page.

*$('#form_id').submit(); return false;"*

-- 

Bruno Rocha
[http://rochacbruno.com.br]


Re: [web2py] call submit from an A tag

2011-11-30 Thread Bruno Rocha
On Wed, Nov 30, 2011 at 1:15 PM, thodoris  wrote:

> table.append(A('Submit',_type='submit', _value='submit')))
>


table.append(A('Submit',_href="#", _onclick="$('form').submit()"))


-- 

Bruno Rocha
[http://rochacbruno.com.br]


Re: [web2py] Re: Creating URL-safe links/strings?

2011-11-30 Thread Bruno Rocha
>
> *db.define_table('pages',*
> *Field('title', unique=True, notnull=True),*
> *Field('slug', unique=True)*
> *)*
>
> *db.pages.slug.compute = lambda row: IS_SLUG()(row.title)[0]*
>



On Wed, Nov 30, 2011 at 1:24 PM, Anthony  wrote:

> If you're receiving the title from a form submission, you can use the
> IS_SLUG validator on the title field, which will convert it to a slug
> (remove non-alphanumeric characters and convert spaces to hyphens). You can
> also use the validator on it's own:
>
> >>> title_slug = IS_SLUG()('Today is Wonderful!')[0]
> >>> print title_slug
> today-is-wonderful
>
> See http://web2py.com/book/default/chapter/07#Validators.
>
> Anthony
>
> On Wednesday, November 30, 2011 10:09:33 AM UTC-5, lyn2py wrote:
>>
>> If I want to create a link from a string, is there a function in
>> web2py to do that?
>>
>> For example I have a post title "Today is Wonderful!" and I want to
>> create
>> >> /blog/show/today-is-wonderful
>> instead of
>> >> /blog/show/today-is-wonderful%**21
>> which gives a Invalid Request error...
>>
>> Thanks!
>>
>>
>>


-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Re: Unable to define the right query to get the first matching record of each category in a group by expression

2011-11-30 Thread Manakel
Hello,

Thanks for the help.
I'll perform the request in 2 steps to achieve the results.


On 30 nov, 04:09, monotasker  wrote:
> When I've done date-related operations I've had to use the python datetime
> and calendar modules. They're both in the standard library so you can just
> do "import datetime, calendar" at the top of your model or controller. Then
> you could do a simple query for all the transactions on that budget in a
> particular month. As a second step you could then use these python modules
> to determine which row object has the latest date or datetime field.
>
> If you haven't worked with the datetime module much before it's a bit
> counter-intuitive at first, but it's powerful. The key is that time *spans*
> have to be represented with a datetime.timedelta() object. You can subtract
> one datetime object from another using arithmetic operators, but the result
> is a .timedelta(). One way to figure out the latest in a series of dates,
> then, would be something like this (untested code that might be full of
> syntax errors!!!):
>
> #assume you've made a dict of datetimes and id's from the rows returned by
> your db query -- let's call it "dateset".
>
> nowtime = datetime.datetime.utcnow()
> latest = {}
> for i,d in datelist.items():
>     if (nowtime - d) > latest:
>         pass
>     else:
>         latest = {i:d}
> return latest
>
> The dict returned should provide you with the latest datetime (i.e., the
> one closest to now) from your query results, along with the id of the row
> holding that date. You can then filter your original query to retrieve just
> that row.
>
> #it's a good idea to use .utcnow() instead of the simple .now() to avoid
> any timezone issues


Re: [web2py] Re: Fwd: How disable date widget?

2011-11-30 Thread Vinicius Assef
On Tue, Nov 29, 2011 at 1:39 PM, Massimo Di Pierro
 wrote:
> sorry it took me a while
>
> SQLFORM.widgets.string.widget and SQLFORM.widgets.date.widget
> are the same.

I couldn't find anything in the docs about it. Reading there, we are
lead to face them as different widgets.


> what you want is to eliminate the datepicker popup. Technically that
> is not part of the widget but handled by the JS in the page.
>
> try this, immediately after you insert the form or field:
>
> 
> jQuery('#table_field').removeClass('date'); // or datetime
> 

It worked. Thank you. :-D
I'm not so good in Javascript. Not even in jQuery, yet.

Talking about this case, I understand technically it's not inside the
widget. But, think with me: if I have a date field with a string
widget, couldn't web2py generate this field with another class?
Something like "date without_picker" (or something better. rsrs) Or,
the opposite, generate "date date_picker" in case of using this
picker. And just "date" if not using it.

Could we consider it a problem to be fixed?

--
Vinicius Assef.


[web2py] Re: web2py logo and layout has changed one year ago...

2011-11-30 Thread Omi Chiba
>I love the framework but hate the name Web2py
Honestly, I agree. Django sounds cool but not web2py. I like gluon
better :)

On Nov 30, 9:16 am, António Ramos  wrote:
> I love the framework but hate the name Web2py
> Everyone uses names related to animals, objects,etc. At least it gives a
> better change for a nice logo.
>
> Best regards
>
> 2011/11/30 stefaan 
>
>
>
>
>
>
>
> > Web2py default layouts certainly have come a long way since the (IMHO,
> > quite awful :p )  fluorescent orange and black-green looks.
>
> > I do seem to miss some "best-practices" documentation about how to
> > effectively apply themes to a web2py application. The downloadable
> > themes do not always properly display the newer widgets (like
> > sqlform.grid), leaving me (as a css nitwit) not much option but to use
> > the default layout. Unlike web2py functionality, the css classes do
> > not seem to be kept backward compatible (your layout won't be
> > overwritten if you upgrade to a newer web2py, but if you want the
> > newer features to render properly you may have to manually merge old
> > layouts with newer layouts)
>
> > 
> > I'm wondering if there aren't any WYSIWYM web layout solutions (what-
> > you-see-is-what-you-mean, a web equivalent to LaTeX macros for
> > printable documents), e.g. providing standardized css classes that all
> > scaffolding applications/widgets/user views ought to restrict
> > themselves to. Themes would also have to be implemented in terms of
> > those standardized css classes, hopefully leading to a smoother
> > theming experience. Approaches like the "ui" argument in sqlform.grid
> > do not seem ideal to me.
> > 


[web2py] Re: URL helper - using "register" and "next"

2011-11-30 Thread Anthony
On Wednesday, November 30, 2011 10:00:05 AM UTC-5, lyn2py wrote:
>
> And how did I miss that??
> Thanks Bruno!
>
> Funny behavior?:
> * I used "next" and it worked for the login link.
>
Are you sure the 'next' value for login isn't being set somewhere else (or 
isn't simply the default 'index')? Using 'next' (rather than '_next') in 
the URL should not work.
 

> * if I used auth.login(_next=...) and an error tells me I can't use
> _next (I have to use "next") - but I didn't try what works with
> auth.register(_next or next?)
>
The register() and login() functions directly take 'next' arguments to 
specify the next URL, or you can add a '_next' variable to the link clicked 
(the former, if specified, will override the latter). You can also set 
auth.settings.login_next and auth.settings.registration_next (which will be 
overridden by '_next' in the URL or passing a 'next' argument to the 
login() and register() functions).

Anthony



Re: [web2py] Re: web2py logo and layout has changed one year ago...

2011-11-30 Thread Bruno Rocha
web2python.

we have 'web' an object and 'python' an animal  :)

http://zerp.ly/rochacbruno
Em 30/11/2011 13:16, "António Ramos"  escreveu:

> I love the framework but hate the name Web2py
> Everyone uses names related to animals, objects,etc. At least it gives a
> better change for a nice logo.
>
> Best regards
>
>
>
> 2011/11/30 stefaan 
>
>> Web2py default layouts certainly have come a long way since the (IMHO,
>> quite awful :p )  fluorescent orange and black-green looks.
>>
>> I do seem to miss some "best-practices" documentation about how to
>> effectively apply themes to a web2py application. The downloadable
>> themes do not always properly display the newer widgets (like
>> sqlform.grid), leaving me (as a css nitwit) not much option but to use
>> the default layout. Unlike web2py functionality, the css classes do
>> not seem to be kept backward compatible (your layout won't be
>> overwritten if you upgrade to a newer web2py, but if you want the
>> newer features to render properly you may have to manually merge old
>> layouts with newer layouts)
>>
>> 
>> I'm wondering if there aren't any WYSIWYM web layout solutions (what-
>> you-see-is-what-you-mean, a web equivalent to LaTeX macros for
>> printable documents), e.g. providing standardized css classes that all
>> scaffolding applications/widgets/user views ought to restrict
>> themselves to. Themes would also have to be implemented in terms of
>> those standardized css classes, hopefully leading to a smoother
>> theming experience. Approaches like the "ui" argument in sqlform.grid
>> do not seem ideal to me.
>> 
>>
>>
>


[web2py] Re: Creating URL-safe links/strings?

2011-11-30 Thread Anthony
If you're receiving the title from a form submission, you can use the 
IS_SLUG validator on the title field, which will convert it to a slug 
(remove non-alphanumeric characters and convert spaces to hyphens). You can 
also use the validator on it's own:

>>> title_slug = IS_SLUG()('Today is Wonderful!')[0]
>>> print title_slug
today-is-wonderful

See http://web2py.com/book/default/chapter/07#Validators.

Anthony

On Wednesday, November 30, 2011 10:09:33 AM UTC-5, lyn2py wrote:
>
> If I want to create a link from a string, is there a function in
> web2py to do that?
>
> For example I have a post title "Today is Wonderful!" and I want to
> create
> >> /blog/show/today-is-wonderful
> instead of
> >> /blog/show/today-is-wonderful%21
> which gives a Invalid Request error...
>
> Thanks!
>
>
>

Re: [web2py] Re: web2py logo and layout has changed one year ago...

2011-11-30 Thread António Ramos
I love the framework but hate the name Web2py
Everyone uses names related to animals, objects,etc. At least it gives a
better change for a nice logo.

Best regards



2011/11/30 stefaan 

> Web2py default layouts certainly have come a long way since the (IMHO,
> quite awful :p )  fluorescent orange and black-green looks.
>
> I do seem to miss some "best-practices" documentation about how to
> effectively apply themes to a web2py application. The downloadable
> themes do not always properly display the newer widgets (like
> sqlform.grid), leaving me (as a css nitwit) not much option but to use
> the default layout. Unlike web2py functionality, the css classes do
> not seem to be kept backward compatible (your layout won't be
> overwritten if you upgrade to a newer web2py, but if you want the
> newer features to render properly you may have to manually merge old
> layouts with newer layouts)
>
> 
> I'm wondering if there aren't any WYSIWYM web layout solutions (what-
> you-see-is-what-you-mean, a web equivalent to LaTeX macros for
> printable documents), e.g. providing standardized css classes that all
> scaffolding applications/widgets/user views ought to restrict
> themselves to. Themes would also have to be implemented in terms of
> those standardized css classes, hopefully leading to a smoother
> theming experience. Approaches like the "ui" argument in sqlform.grid
> do not seem ideal to me.
> 
>
>


[web2py] call submit from an A tag

2011-11-30 Thread thodoris
Is there a way to change the submit button into clickable text?

Lets say i have this form:

form = SQLFORM.factory(Field('my_table'))

and i can do

table = form.element() to get the element
table.append(INPUT(_type='submit', _value='submit')): this appends the
submit button next to the element

but is there a way to call submit for an A, like this ???

table.append(A('Submit',_type='submit', _value='submit')))


[web2py] Creating URL-safe links/strings?

2011-11-30 Thread lyn2py
If I want to create a link from a string, is there a function in
web2py to do that?

For example I have a post title "Today is Wonderful!" and I want to
create
>> /blog/show/today-is-wonderful
instead of
>> /blog/show/today-is-wonderful%21
which gives a Invalid Request error...

Thanks!




[web2py] Re: simpatiCA -- A simple PKI for x509 in web2py

2011-11-30 Thread Christopher Steel
Very nice! Thank You!


[web2py] Re: URL helper - using "register" and "next"

2011-11-30 Thread lyn2py
And how did I miss that??
Thanks Bruno!

Funny behavior?:
* I used "next" and it worked for the login link.
* if I used auth.login(_next=...) and an error tells me I can't use
_next (I have to use "next") - but I didn't try what works with
auth.register(_next or next?)



On Nov 30, 10:52 pm, Bruno Rocha  wrote:
> should be _next
>
> http://zerp.ly/rochacbruno
> Em 30/11/2011 12:46, "lyn2py"  escreveu:
>
>
>
>
>
>
>
> > Hi guys,
>
> > I created two links:
> > >>  > href="{{=URL('default','user',args='login',vars=dict(next=request.env.path_ 
> > info))}}">login
> > >>  > href="{{=URL('default','user',args='register',vars=dict(next=request.env.pa 
> > th_info))}}">register
>
> > The first link (login) works. After logging in, the user is redirected
> > to the page they were previously on.
> > The second link (register), doesn't work. After logging in, the user
> > is flashed "login successful" message and redirected back to myapp/
> > default/index.
>
> > How can I get the second link to work, or is this intentional?
>
> > Thanks!


Re: [web2py] URL helper - using "register" and "next"

2011-11-30 Thread Bruno Rocha
should be _next

http://zerp.ly/rochacbruno
Em 30/11/2011 12:46, "lyn2py"  escreveu:

> Hi guys,
>
> I created two links:
> >>  href="{{=URL('default','user',args='login',vars=dict(next=request.env.path_info))}}">login
> >>  href="{{=URL('default','user',args='register',vars=dict(next=request.env.path_info))}}">register
>
> The first link (login) works. After logging in, the user is redirected
> to the page they were previously on.
> The second link (register), doesn't work. After logging in, the user
> is flashed "login successful" message and redirected back to myapp/
> default/index.
>
> How can I get the second link to work, or is this intentional?
>
> Thanks!
>


[web2py] URL helper - using "register" and "next"

2011-11-30 Thread lyn2py
Hi guys,

I created two links:
>> > href="{{=URL('default','user',args='login',vars=dict(next=request.env.path_info))}}">login
>> > href="{{=URL('default','user',args='register',vars=dict(next=request.env.path_info))}}">register

The first link (login) works. After logging in, the user is redirected
to the page they were previously on.
The second link (register), doesn't work. After logging in, the user
is flashed "login successful" message and redirected back to myapp/
default/index.

How can I get the second link to work, or is this intentional?

Thanks!


[web2py] Re: Remove first and last name from Auth.

2011-11-30 Thread Anthony
Or if you really don't want to use them for any purpose, you can create a 
custom auth_user table without 
them: http://web2py.com/book/default/chapter/08#Customizing-Auth

On Wednesday, November 30, 2011 3:19:18 AM UTC-5, pbreit wrote:
>
> One way is to insert these lines in the user() function:
>
> db.auth_user.first_name.writable=False
> db.auth_user.first_name.readable=False
> db.auth_user.last_name.writable=False
> db.auth_user.last_name.readable=False
>


[web2py] Re: trunk error

2011-11-30 Thread Anthony
Thanks.

[web2py] Re: web2py logo and layout has changed one year ago...

2011-11-30 Thread stefaan
Web2py default layouts certainly have come a long way since the (IMHO,
quite awful :p )  fluorescent orange and black-green looks.

I do seem to miss some "best-practices" documentation about how to
effectively apply themes to a web2py application. The downloadable
themes do not always properly display the newer widgets (like
sqlform.grid), leaving me (as a css nitwit) not much option but to use
the default layout. Unlike web2py functionality, the css classes do
not seem to be kept backward compatible (your layout won't be
overwritten if you upgrade to a newer web2py, but if you want the
newer features to render properly you may have to manually merge old
layouts with newer layouts)


I'm wondering if there aren't any WYSIWYM web layout solutions (what-
you-see-is-what-you-mean, a web equivalent to LaTeX macros for
printable documents), e.g. providing standardized css classes that all
scaffolding applications/widgets/user views ought to restrict
themselves to. Themes would also have to be implemented in terms of
those standardized css classes, hopefully leading to a smoother
theming experience. Approaches like the "ui" argument in sqlform.grid
do not seem ideal to me.




[web2py] Re: unable to set reference Field back to None once set

2011-11-30 Thread Anthony
On Wednesday, November 30, 2011 6:07:16 AM UTC-5, thodoris wrote:
>
> db.B[id].my_table = None
>
db.B[id] is a Row object (i.e., the result of a select), not a reference to 
the db record. So, you are simply changing the value in the Row object, not 
the db. To change the value in the db, you can do:

db.B[id] = dict(my_table=None)

or

db(db.B.id == id).update(my_table=None)

Anthony



[web2py] Re: unable to set reference Field back to None once set

2011-11-30 Thread thodoris
I found the solution myself

In order to save the change i have to use:  update_record

On Nov 30, 12:07 pm, thodoris  wrote:
> I have this field
>
> db.define_table('B',
>     Field('my_table', db.A, notnull=False, ondelete="SET NULL"),
>
> db.B.my_table.requires = IS_EMPTY_OR (
>                      IS_IN_DB(db(db.A.author_id==auth.user_id),
> db.A.id, '%(title)s'))
>
> That means that my_table can have references from A but only the ones
> that the same user has made OR is empty (None). And also when the
> referenced object is deleted the value becomes None.
>
> What i want to do is to remove a reference at some point. I have the
> id of the entry i want to change and i do
>
> db.B[id].my_table = None
>
> but it doesn't work. Actually it doesn't allow me to change it from a
> function. Do i do something wrong?


[web2py] trunk error

2011-11-30 Thread Marin Pranjić
I get this:

 invalid syntax (user_agent_parser.py,
line 214)

This is the line:

prefs = dict(browser=["Microsoft Internet Explorer", 'Firefox'],
 dist=['WindowsMobile'] flavor=None)


Should be (comma is missing):

prefs = dict(browser=["Microsoft Internet Explorer", 'Firefox'],
 dist=['WindowsMobile'], flavor=None)




Marin


[web2py] Re: help

2011-11-30 Thread Anthony
Are you sure this works when not on GAE -- looks like there are some 
problems even in that case? More below...

def mailid():
>
> #import Mail
> from gluon.tools import Mail
> mail=Mail()
>
No need to instantiate mail with Mail() if you are going to use 
auth.settings.mailer (below) -- auth.settings.mailer is already a Mail() 
object. Also, if you need to use mail anywhere else, you might move the 
mail configuration code to a model file so you don't have to repeat it when 
needed elsewhere.
 

> #specify server
> mail=auth.settings.mailer
> mail.settings.server='GAE'#'smtp.gmail.com:587'
>
Try 'gae' (lowercase) instead of 'GAE'.
 

> mail.settings.login='y...@domain.com:pwd'
> #specify address to send as
> mail.settings.sender=request.vars.email
>
The sender is the account that is sending the email, which should be your 
own account, not the account of the person submitting the form (you cannot 
send email from their account). If you want to be able to reply to the 
user, you can specify their email as the 'reply-to' parameter:

mail.send(..., reply_to=request.vars.email).

#send the message
> msg = request.vars.name,
> request.vars.email,request.vars.contact
>
What is msg -- you don't appear to use it?
 
Anthony 


[web2py] Converting mongodb collection to row

2011-11-30 Thread Mark Breedveld
I have got the select function of mongodb adapter working, but know I
need to convert a pymongo cursor to row.
The point is the pymongo supports nested documents and that can be a
bit hard to convert for a parameter of the parse method.

Here is the select function a have ajusted, but this one won't work
with yours because I also altered a lot of other functions. But this
is to get the idea. The line that has to be changed is pointed to with
<--
def select(self,query,fields,attributes):
#if not isinstance(query,Query):
#raise SyntaxError, "Not Supported"
definition = self._select(query,fields,attributes)

ctable = self.connection[str(definition['tablename'])]
if ((definition['sort'] == None) & (definition['skip'] ==
None)):
result = ctable.find(definition['query'])
elif((definition['sort'] != None) & (definition['skip'] ==
None)):
result =
ctable.find(definition['query']).sort(definition['sort'])
elif((definition['sort'] == None) & (definition['skip'] !=
None)):
result =
ctable.find(definition['query']).skip(definition['skip'])
elif((definition['sort'] != None) & (definition['skip'] !=
None)):
result =
ctable.find(definition['query']).sort(definition['sort']).skip(definition['skip'])
else:
raise RuntimeError, "No valid query information found"
print str(result)
#rows = [cols['value'] for cols in result] <--- This line
converts the result to be parsed
return self.parse(rows, definition['colnames'], False)

Anyone with advise on the matter or ideas?


[web2py] help

2011-11-30 Thread Prakhar Srivastava
Hello all of you ,
I need a help from web2py group actually i want to develop feedback
from for my website so for thats i'm using this controller code and
this code is working when, i'm using rock server  with smtp and when i
use with 'gae' with google appengine it not working so

so i need your suggest on this code guys ...


def feedback():
form=FORM(TABLE(TR("Your
name:",INPUT(_type="text",_name="name",requires=IS_NOT_EMPTY(error_message='Please
Enter Your Name'))),
TR("Your
email:",INPUT(_type="text",_name="email",requires=IS_EMAIL())),
TR("Contact
No",INPUT(_type="text",_name="contact",requires=IS_NOT_EMPTY(error_message='Please
Enter Your Contact Number'))),
TR("Looking For",SELECT('Career','Contact
Us','Complaints','Feedback',_name="query",requires=IS_IN_SET(['Career','Contact
Us','Complaints','Feedback']))),
 
TR("Message",TEXTAREA(_name="message",value="",requires=IS_NOT_EMPTY(error_message='Please
Enter Your Message'))),
 
TR("",INPUT(_type="submit",_value="SUBMIT" 
if form.accepts(request,session):
mailid()
response.flash = 'Your Query is Submited
Successfully'

return dict(form=form)#,recipients = recipients, message_text
= message_text)

def mailid():

#import Mail
from gluon.tools import Mail
mail=Mail()
#specify server
mail=auth.settings.mailer
mail.settings.server='GAE'#'smtp.gmail.com:587'
mail.settings.login='y...@domain.com:pwd'
#specify address to send as
mail.settings.sender=request.vars.email
#send the message
msg = request.vars.name,
request.vars.email,request.vars.contact
mail.send(to=['oth...@domain.com'],
subject=request.vars.query,
message= request.vars.message)

#recipients = ['John Smith ']
#subject = "Your Order Has Shipped"

#for recipient in recipients:
#status = Mail.send(to=recipient, subject=subject,
message_text=message_text, message_html=message_html)

return ''


[web2py] change form submit button to clickable text

2011-11-30 Thread thodoris
Is there a way to change the submit button into clickable text (like
an _href) next to a field?

Lets say i have this form:

form = SQLFORM.factory(Field('my_table'))



[web2py] Re: SQLForm.grid - How do I use it properly?

2011-11-30 Thread Rahul
Great! It works. This is so fantastic. I love the way stuff works in
web2py. Thanks Massimo.


Thanks Rahul D (www.flockbird.com - web2py powered)



On Nov 29, 7:16 pm, Massimo Di Pierro 
wrote:
> gird(,...user_sigature=fFalse)
>
> than do your own authentication outside the function.
>
> On Nov 29, 5:10 am, Rahul  wrote:
>
>
>
>
>
>
>
> > All,
> >    How do I view SQLForm.grid View, Edit or Delete forms without using
> > auth? I have implemented my own custom authorization mechanism which
> > does not use web2py auth in any way. Now the problem is in SQLForm
> > grid that is serialized in my view It say "not authorised" when I
> > click on View button. How do I override the default auth mechanism for
> > the SQLForm grid.
>
> > code---
> > form = SQLFORM.grid( query=query, fields=fields, headers=headers,
> > orderby=default_sort_order,
> >                          create=False, deletable=False,
> > editable=False,  csv=False, maxtextlength=64, paginate=20 )
>
> > Please suggest,
> > Thanks Rahul D (www.flockbird.com-web2py powered)
>
> > --- 
> > ---
>
> > On Nov 22, 6:54 pm, Anthony  wrote:
>
> > > Massimo, the issue is that the grid doesn't provide an easy way to include
> > > virtual fields. You can do it by using the 'links' argument with a
> > > dictionary for each virtual field (though that's a bit cumbersome), but
> > > then you cannot use the 'fields' argument to select only a subset of 
> > > fields
> > > or the virtual fields references will fail. A workaround is to set the
> > > readable attribute of fields you don't want to include to False, but 
> > > that's
> > > even more cumbersome and results in the selecting unnecessary fields.
>
> > > Side note: I wonder if 'links' should be changed to a more generic name,
> > > such as 'extra', since it can be used to add extra columns of any type, 
> > > not
> > > just links.
>
> > > Anthony
>
> > > On Monday, November 21, 2011 9:58:18 PM UTC-5, Massimo Di Pierro wrote:
>
> > > > I am bit lost in this thread. Can you summarize the issue?
>
> > > > On Nov 21, 7:55 pm, villas  wrote:
> > > > > Yes,  that's a good idea and it does seem to work.
> > > > > On the downside, I have a huge number of fields and I think the query
> > > > will
> > > > > still fetch them all.  Also I have to make a very long list of
> > > > > field.readable = False.
> > > > > So,  if a better solution appears,  I would be very grateful.
> > > > > However,  in any case,  I really do appreciate your assistance.
> > > > > Thank you and best regards,  David


[web2py] Hello i need help in web2py

2011-11-30 Thread Data-House Informática


I have one application in web2py



This application executes somes instructions for me in my sql bank



One this make download of one table choosed in one directory



I put one file called produtos.csv in directory called requisicao

And then the application make download of table called produtos inside
my bank and create a copy in format .CSV for directory called consulta



See the code for this:



def make_backup():

requisicoes= os.listdir(RequisicaoPath )

requisicoes = filter(filtro.search, requisicoes)

for requisicao in requisicoes :

try:

table=requisicao .split('.')[0]

path = os.path.join(ConsultPath ,"%s.csv"
%table).replace('\\','/')

id_field = SPECIALS.get(table,'id')

q = getattr(db[table],id_field ) > 0

open(path , 'w').write(str(db(q).select()))



 
os.remove(os.path.join(RequisicaoPath ,requisicao ).replace('\\','/'))

except: pass





But I need execute one search inside one table for a critery
specified.



Then I am trying create the code. But fault some details



See:



def pesquisa_in_db():

pesquisa= os.listdir(PesquisaPath )

pesquisa = filter(filtro.search, pesquisa)

for da_pesquisa in pesquisa :

try:

table=da_pesquisa .split('.')[0]

path = os.path.join(PesquisaPath ,"%s.csv"
%table).replace('\\','/')

id_field = SPECIALS.get(table,'id')

q = getattr(db[table],id_field ) > 0



‘the command up make



open(path , 'w').write(str(db(q).select()))



 
os.remove(os.path.join(RequisicaoPath ,requisicao ).replace('\\','/'))

except: pass





 the above command takes the whole table and placed in the variable q
and the next:
open (path, 'w'.) write (str (db (q). select ()))
opens a path and records all variable (which is the copy of the table)
in the file mentioned in the back

But what I need is:
in this command:
 q = getattr (db [table] id_field)> 0
Instead of writing all the table that he ran a search (research) in
the table following a criterion.
Consider the example:

strSQL = "SELECT count (*) FROM products WHEREqtdFretegratis the
frete_gratis and idprod = 1 in (SELECTFROM orders WHERE idprod
idcompra = '" & intOrderID & "')"

And then just record the contents of strSQL ok?

open (path, 'w'.) write (str (strsql.select ()))

Please
Correct me if I'm wrong.
Thank you.
Mario



Data-House Informática

Passeio São Luiz, 209-Sala A

Zona Norte

15385-000   /   Ilha Solteira-p

E-mail: house...@uol.com.br

MSN: house...@hotmail.com

SKYPE: mario.antonio.pereira

Site: www.isashop.com.br








Re: [web2py] Relative path in css for @font-face embedding

2011-11-30 Thread Martín Mulone
relative url in css have to work, have nothing to do with web2py.

My files are:
static/css/myfont.eot
static/css/layout.css

My def:

src: url('myfont.eot');


My files are:
static/css/fonts/myfont.eot
static/css/layout.css

My def:
src: url('fonts/myfont.eot');

2011/11/30 monotasker 

> I'm trying to use an embedded font referenced in a stylesheet. The only
> url that seems to work in the @font-face declaration (in my css file) is
> one that begins with the appname: /[appname]/static/[font folder]. It
> seems, though, like I can't generate the URL programmatically (with the URL
> helper) in the css file. So is there a relative address that will work?
>
> It just occurred to me that the problem might be my use of the less.js css
> processing script. Could the URL helper not be working because it conflicts
> somehow with less.js?
>



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


[web2py] @reboot task started twice when a init simbolink link is present

2011-11-30 Thread dsanchez
Hello all

I have the following crontab file:
#crontab
@reboot cht *applications/atvestpp/modules/SchedulerDownload.py

In the applications folder, I have a simbolik link 'init' pointing to
my application 'atvestpp'.

When I started the web2py server, two instances of
SchedulerDownload.py are started, one for 'atvestpp' and a second for
'init'
ps -ef
...
cht   2379  2198  9 11:51 pts/100:00:00 python web2py.py
cht   2388  2379 12 11:51 pts/100:00:00 /usr/bin/python /home/
cht/web2py/web2py.py -J -M -S atvestpp -a  -R
cht   2392  2379 12 11:51 pts/100:00:00 /usr/bin/python /home/
cht/web2py/web2py.py -J -M -S init -a  -R appl

The problem disappears if a remove the 'init' symbolic link

I think this is a bug. (I have version 1.99.2) Hope it helps!

David


  1   2   >