[web2py] Re: [py4web] - how to disable some auth actions?

2020-03-29 Thread Limedrop
+1 on this request.  For some apps this is a deal-breaker.  For example, a 
client who wants a secure place for their employees and doesn't want any 
random registration requests.

FYI, other Auth requirements that I've been asked to implement to 'secure' 
an app are:

- Lock account after x failed login attempts.
- Force new password on first login
- Force new password every x days.
- No re-use of passwords within 8 changes.
- No sequential passwords (for example, can't change your password from 
'password1' to 'password2').
- Force logout after x hours.
- Two-factor authentication for users with 'administrator' access.
- Require passwords of various complexity.

I'm not saying that py4web should have all of these functions right now, 
but pointing out some of the options it might need to have in the future.


On Sunday, 29 March 2020 11:54:17 UTC+13, Massimo Di Pierro wrote:
>
> Let me give some thought to this. Only complication is a mechanism for 
> sever to tell auth.js that some pages should be available.
>
> On Saturday, 28 March 2020 13:55:06 UTC-7, Paolo Caruccio wrote:
>>
>> In my case I only need login and logout.
>> The creation of an account will be done by other users with privileges 
>> established by the administrators. The modification of the profile will 
>> also be done partially by the user himself (change password, change email, 
>> add / change personal data etc) who has the account enabled and is already 
>> logged in.
>> Obviously I can delete all links and specific functions from the 
>> frontend, as well as I can require to approve any registration made from 
>> the outside but it would be more secure to also do a server-side prevention 
>> by disabling actions that do not need.
>>
>>
>> Translated with www.DeepL.com/Translator (free version)
>>
>> Il giorno sabato 28 marzo 2020 20:30:48 UTC+1, Massimo Di Pierro ha 
>> scritto:
>>>
>>> not possible yet. I can implement it easily but I would like to 
>>> understand some use cases.
>>>
>>> On Saturday, 28 March 2020 10:12:32 UTC-7, Paolo Caruccio wrote:

 In py4web is there any way to disable some auth actions? I can't find 
 anything in the code about this.

 In web2py this is possible via auth.settings.action_disabled

 For example:

 auth.settings.action_disabled=['register']

 prevents the "register" action from working.

 Tank you.

>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/5b017426-a182-4a93-817e-35fdd4b6f07b%40googlegroups.com.


[web2py] Custom Delimiters Broken in 2.18.1?

2019-02-24 Thread Limedrop

Hi there,

I think the custom template delimiters are broken in 2.18.1.  Here's my 
test code and the exception I'm getting:


CONTROLLER
def index():
response.delimiters = ('') 
return dict(message=T('Welcome!'))

VIEW - index.html
{{extend 'layout.html'}}
 Note that each column needs at least {{minCards}} 
cards.

EXCEPTION 
File "\web2py2.18.1\web2py\gluon\restricted.py", line 230, in restricted
sys.excepthook(etype, evalue, tb) File 
"c:\Users\Playtech\Documents\Development\web2py2.18.1\web2py\applications\app\views\default\index.html",
 
line 2, in 
NameError: name 'minCards' is not defined


Or have I done something wrong?

Thanks

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: does field object know it's tablename?

2016-11-21 Thread Limedrop
Yes, it does.  You can access the tablename like this:

>>>db.auth_user.email._tablename
'auth_user'


On Monday, 21 November 2016 23:14:00 UTC+13, Jurgis Pralgauskis wrote:
>
> or should I pass tablename to function alongside?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to check if new password is different from the actual?

2016-06-27 Thread Limedrop
The function you are looking for is CRYPT.  You could but something like 
this in an on_validation function:

if auth.user.password == CRYPT()(request.vars.new_password)[0]:
form.errors.new_password = 'Cannot re-use password'

On Friday, 24 June 2016 03:53:47 UTC+12, Marvix wrote:
>
> Hello, 
>
> when an user is changing his password, is it possible to check if it is 
> equal to the current? and refuse it in that case?
>
> Thanks!
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: generic.docx ?

2016-06-15 Thread Limedrop
If you want to produce *simple *documents that can be edited in MS Word, it 
might be easier to use the RTF format, which is supported by web2py out of 
the box:

http://www.web2py.com/books/default/chapter/29/10/services#PyRTF

BUT be warned...my experience with PyRTF is that, while it is easy to 
produce simple documents, the more complex documents (eg, lots of different 
paragraph styles, tables with borders, etc.) have a very big learning curve.


On Wednesday, 15 June 2016 15:46:35 UTC+12, H. Das wrote:
>
> Would it be possible in web2py to create a generic.docx (word document, 
> odf, or similar) view that can convert from HTML? Basically it should work 
> just like generic.pdf. Thanks, love you guys.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: update_or_insert

2016-05-02 Thread Limedrop
It looks like update_or_insert() will always do two database hits and, as 
you say, even then doesn't give you the id of the existing record.  It goes 
something like this (pseudo code for clarity):

record = db.table.select()
if record:
update_record()
else:
   insert record()

So it's a simple function that you could easily substitute with your own 
code.  However if you want to reduce database hits, I guess you could use 
try/except instead.
Is it more likely that the record will exist or not exist?  Do the most 
likely thing.  And then if that fails, and only then, do the second query. 
 This assumes that the appropriate fields in the index table have been 
defined with unique=True.










On Monday, 2 May 2016 22:13:07 UTC+12, Mirek Zvolský wrote:
>
> I have 'many:many' table relationship:base =< join >= index
>
> I need to be sure that I have some value in 'index', if no, then add them 
> there.
> And I need to know its ID, because in last step I will add both ID's (from 
> 'index' and from 'base') to the 'join' table.
>
> It is not very plesant for me that db.index.update_or_insert()
> - will return ID in case of insert,
> - but will return None if the row exists already.
>
> I think this is behaviour by design.
> However can I get the ID of existing row somewhere after the 
> .update_or_insert() ?
> Or what should I use instead of .update_or_insert() ?
> I need very fast record lookup, because I need run the cycle with ~3000 
> tests in 'index' table
>
> Thanks...
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: When will we have a proper forum ?

2015-08-06 Thread Limedrop
The first step would be to add it to the web2py roadmap :-)  I don't know 
enough about the code-base to comment on the implementation specifics.  
Would you see comment functionality being added to directly to the 
auth.wiki() code or developed as a separate app/plugin?


On Thursday, 6 August 2015 18:12:00 UTC+12, Massimo Di Pierro wrote:

 I very much agree with this. How do you propose we do it?

 On Wednesday, 5 August 2015 17:37:19 UTC-5, Limedrop wrote:

 I hesitate to comment on this as it's one of those topics were there's 
 not one obvious way to do it (obviously I'm not Dutch). Essentially, I 
 think google groups does an okay job and the benefits of any change are 
 likely to be outweighed by the heavy cost of that change.

 Having said that, I've always thought that we're missing a trick by not 
 integrating forum questions with the web2py book. Imagine having 
 medium.com-style side comments with the book, making it more of a living 
 document. Questions and answers would be right next to the relevant section 
 of the book, providing further explanation and reducing RTFM answers. I 
 guess you'd also add a better search facility, a stack-overflow style 
 'homepage' and possibly a slight re-structure of the book sections. Ask a 
 question and it gets tagged to a book section.  The book is already built 
 with auth.wiki() - so we would be adding to functionality/infrastructure 
 that has to be maintained anyway.

 We can always dream ;-)



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: When will we have a proper forum ?

2015-08-05 Thread Limedrop
I hesitate to comment on this as it's one of those topics were there's not 
one obvious way to do it (obviously I'm not Dutch). Essentially, I think 
google groups does an okay job and the benefits of any change are likely to 
be outweighed by the heavy cost of that change.

Having said that, I've always thought that we're missing a trick by not 
integrating forum questions with the web2py book. Imagine having 
medium.com-style side comments with the book, making it more of a living 
document. Questions and answers would be right next to the relevant section 
of the book, providing further explanation and reducing RTFM answers. I 
guess you'd also add a better search facility, a stack-overflow style 
'homepage' and possibly a slight re-structure of the book sections. Ask a 
question and it gets tagged to a book section.  The book is already built 
with auth.wiki() - so we would be adding to functionality/infrastructure 
that has to be maintained anyway.

We can always dream ;-)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Decoding file name.

2015-07-28 Thread Limedrop
You could try something like this:

(filename, fullfilename) = 
db.tablename.uploadfield.retrieve(record.uploadfield, nameonly=True)



On Wednesday, 29 July 2015 01:05:58 UTC+12, Prasad Muley wrote:

 Hi All,

  file name gets store as *93f00342868f4085.73716c2e6c6f67.log *in db 
 field.
 I've tried to decode it using base64 But didn't get the original file name.

 Is there any way to decode it and get the original file name?





-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How do I check of the version of pysimplesoap in web2py.

2015-06-24 Thread Limedrop
SOAP can really be a world of pain.  I spent hours trying to connect to a 
SOAP service and the best I could get was a 400 Bad Request.  It turned 
out that they were using wsHttpBinding - which seems to only be supported 
by .NET clients.  The work-around is to manually inject the WS-Security 
headers into the SOAP envelope.  In the end I gave up and reverted to a 
service using basicHttp binding.

Long story, short: pysimplesoap works really well.  It is SOAP itself that 
is overly complex and mostly broken.

And for anyone out there experiencing the pain, here's some sample code 
that I use as a sanity check.  The 'trace' option leaves a nice trail on 
the console - but remember to turn it off in production.

from gluon.contrib.pysimplesoap.client import SoapClient, 
SoapFault
url = http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL;
client = SoapClient(wsdl=url, trace = True) 

parameters = {}
parameters['ZIP'] = 90210

try:
response = client.GetCityWeatherByZIP(**parameters) 
except SoapFault as e:
response = ERROR {0}: {1}.format(e.faultcode, 
e.faultstring)


On Thursday, 25 June 2015 06:32:00 UTC+12, Dave S wrote:



 On Wednesday, June 24, 2015 at 4:39:57 AM UTC-7, Encompass solutions wrote:

 Found it.  it's in the init.py file in gluon/contrib/pysimplesoap/
 It's version 1.11 which is a little behind, but there are some regression 
 as of last year, we should check before bumping up the version.


 FWIW, I also use pysimplesoap (it's what brought me to web2py), both with 
 a third party target and with my own SOAP target.  It works well with these.

 I tried using it with a different third party target that had some special 
 WSDL handling required , and I wasn't successful with that.  I had some 
 conversations here about it, and the dev (M Reingart) tried to help, but I 
 didn't know my way around the code well enough to nail things down, and 
 didn't have time then to come more up to speed.  (I have a TooManyTabs 
 bookmark for Fixing Broken WSDL)


 /dps



 On Wednesday, June 24, 2015 at 9:52:08 AM UTC+3, Encompass solutions 
 wrote:

 I am trying to use soap and I am comming across errors from 2012 is the 
 version included in web2py always the latest with each new version of 
 web2py?  I do I check what version is included?
 I am getting a Tag not found: service (No elements found) error when 
 trying to get the wsdl file. (The file seems very good and well tested)
 BR,
 Jason



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Select multiple rows

2015-06-14 Thread Limedrop
Try something like this:

rows = db(db.cikmis_soru.id.belongs(ids)).select()


On Monday, 15 June 2015 07:13:02 UTC+12, xmarx wrote:

 Hi.

 I want to select a list of id from database.

 ids=[12,145,69]

 how can i do this? Is there any quick way of it?

 for example:

 query=
 for i in ids:
 if not i==ids[-1]:
 query+=(db.cikmis_soru.id==+i+)
 else:
 query+=(db.cikmis_soru.id==+i+)

 rows=db(query).select()



 i get an error: SyntaxError: Set: no tables selected

 Thanks all.
  

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to write dynamic part of a select?

2015-04-18 Thread Limedrop
That's a bit more involved.  For groupby you need to build a query using | 
and for left you need a list of db.table.on().  Have a look at the sample 
code below for a rough outline of the process.

grouping_fields = [db.table.field1, db.table.field2]
groupby = grouping_fields[0]
if len(grouping_fields)  1:
for g in grouping_fields[1:]:
groupby = groupby|g
fields = fields + grouping_fields # the grouping fields must be selected
left = [db.table1.on((db.table1.id == db.table2.table1_id)), 
db.table1.on((db.table1.id == db.table3.table1_id))]
rows = db(query).select(*fields, groupby=groupby, left=left)




On Saturday, 18 April 2015 14:50:37 UTC+12, Sébastien Loix wrote:

 One last thing, any idea if it is also possible to dynamically add 
 left=[.], orderby=

 For now I can't as it (logically) tells me that 'append() takes no keyword 
 arguments'

 thank you! 

 On Wednesday, 15 April 2015 00:52:53 UTC+2, Limedrop wrote:

 You can do this by building a list of fields and then using the python 
 unpack operator.  For example:

 field_list = [db.auth_user.first_name]
 if ask_for_lastname:
 field_list.append(db.auth_user.last_name)
 rows = db(query).select(*field_list)

 See 
 https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to write dynamic part of a select?

2015-04-14 Thread Limedrop
You can do this by building a list of fields and then using the python 
unpack operator.  For example:

field_list = [db.auth_user.first_name]
if ask_for_lastname:
field_list.append(db.auth_user.last_name)
rows = db(query).select(*field_list)

See 
https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Design flaw in auth.impersonate ?

2015-04-05 Thread Limedrop
Well the easy answer is to simply open the impersonated user in a different 
browser (eg, have Support Team login in chrome and impersonated user login 
in firefox).

For us it is important that impersonate is restricted to the user's 
permissions...we have several classes of user and it is essential to see 
what the site looks like from their environment.


On Monday, 6 April 2015 06:51:53 UTC+12, Louis Amon wrote:

 When you impersonate a user in web2py, your whole auth session gets 
 replaced with the user's, and that means you lose access to whatever 
 permissions you used to have (
 http://web2py.readthedocs.org/en/latest/tools.html#gluon.tools.Auth.impersonate
 ) 

 Practically : if you're a staff member (Support Team, not geek) and you're 
 using a permission-locked back-office to impersonate a user, that means you 
 won't be able to access the back-office to check for extra data until you 
 impersonate(0) to go back to your own session and permissions.

 So far I've just asked my team to chew on it and just de-impersonate every 
 time they need to go back to the back-office... but they keep complaining 
 about it and they're quite right.


 I've been thinking about how to improve this, and so far I've only managed 
 to narrow down a few options :

1. Building a second Session() object to manage both sessions 
separately
2. Using session.connect(masterapp=...) to use another application's 
sessions (between main app and back-office app for instance, if those are 
separate... which is a pain in terms of model management)
3. Messing with the permission system to add up permissions (staff 
member's permissions + impersonated user's permissions) before permission 
checks


 I'm really not sure what strategy I should adopt here and how I should go 
 about implementing this.

 Pointers would be very welcome :)


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: advice on creating multi purpose table

2015-01-19 Thread Limedrop
Hi Leonel,

I like your suggestion, but I always wonder with these sorts of solutions 
whether or not you need a separate field in the person_meta table for each 
data type?  For example:

db.define_table('person_meta',
Field('person', 'reference person'),
Field('name'),
Field('val_string', 'string'), 
Field('val_integer', 'integer'), 
Field('val_double', 'double'), 
Field('val_list_string', 'list:string'), 
Field('val_list_integer', 'list:integer'),
Field('val_datetime', 'datetime'), 
Field('val_text', 'text')
)

That way you have the option of using the database to do the sorting, 
filtering and manipulations.  You can also use the web2py validators 
directly on the table.  Or is the overhead of having so many empty fields 
on every record too much?

I'd be interested in your thoughts.


On Saturday, 17 January 2015 06:51:25 UTC+13, Leonel Câmara wrote:

 Right now you have 4 types of companies with different profiles, that may 
 not always be so, also, company a, b, c or d may change the fields they 
 want in the future. What you need is a way to let the companies specify the 
 fields they want.

 What's more efficient depends on your objectives. I would do something 
 like this:

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


 db.define_table('person',
 Field('name'),
 Field('company', 'reference company'),
 )


 db.define_table('company_person_meta',
 Field('company', 'reference company'),
 Field('name'),
 Field('mandatory', 'boolean'),
 # The next one is optional and just an example in case you want to 
 # validate, format, etc for different types.
 Field('value_type', requires=IS_IN_SET(('email', 'url', 'integer', 
 'date'))),
 )


 db.define_table('person_meta',
 Field('person', 'reference person'),
 Field('name'),
 Field('val'),
 )


 # Notes when inserting into person_meta you should check it's one of the 
 names
 # defined for that person's company. 


 The field names are a bit convoluted because I use check_reserved=['all'], 
 but this would give you complete flexibility and would let you use the same 
 controller functions for all companies.

 For instance, using this model, list all persons from a company with their 
 attributes:

 Controller:

 def show_persons():
 return {'persons': db(db.person.company == request.args(0, cast=int)).
 select()}

 View:

 {{extend 'layout.html'}}
 {{for person in persons:}}
 h2{{=person.name}}/h2
 dl class=dl-horizontal
 {{for meta in person.person_meta.select():}}
 dt{{=meta.name}}/dt
 dd{{=meta.val}}/dd
 {{pass}}
 /dl
 {{pass}}


 Both the controller and the view would work for any type of company 
 whatever the fields they could want.

 This may not be the most efficient in terms of hardware use, but it future 
 proofs your app, so it's certainly the most efficient if you want to be 
 proactively lazy as I think all developers should strive to be.


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to fix 'list' TypeError with many-to-many SQLFORM.factory and multiple=True?

2014-12-09 Thread Limedrop
Hi there,

The issue you have is that you are mixing a fully normalized solution and 
the web2py short-cut. 

In the table you have defined db.component_package_association.component_id 
as a single integer, but the validator is giving the field multiple values.

The easy option is to delete the component_package_association table and 
have something like this:

db.define_table('package',
 Field('components','list:reference component'),
Field('another_field'),
format='%(another_field)s'
)

That way multiple references will be handled automatically in forms and 
they are transparent to the DAL.  See the list_reference example in chapter 
6 of the book.


On Wednesday, December 10, 2014 5:50:42 AM UTC+13, Jan Beilicke wrote:


 Hi everybody,

 since a couple of days I am trying to implement a *normalized 
 many-to-many model* that can be managed using a single form consisting of 
 a couple of fields from one table and a multiple select drop-down list 
 containing references to an intersection table.

 My problem is an exception that is thrown when the form is validated after 
 submit:

 int() argument must be a string or a number, not 'list'

 The exception is caused by a list of reference ids defined by selected 
 options in the drop-down list.

 A way to circument this exception might be to denormalize the intersection 
 table by using the field type list:reference which I want to avoid for 
 various reasons.

 I have created a similar model for demonstration purposes, where the 
 entity package has one or many components:

 db.define_table('component',
 Field('some_field'),
 format='%(some_field)s'
 )

 db.define_table('package',
 Field('another_field'),
 format='%(another_field)s'
 )

 db.define_table('component_package_association',
 Field('component_id', 'reference component'),
 Field('package_id', 'reference package'))

 db.component_package_association.component_id.requires = IS_IN_DB(
 db, 'component.id', '%(some_field)s', multiple=True)

 And the controller:

 def manage_packages():
 if request.args(0) == 'new' and request.args(1) == 'package':
 form = SQLFORM.factory(db.package, 
 db.component_package_association)

 if form.process().accepted:
 # Code to store the new package and associations to 
 components
 # ...
 response.flash = 'Package successfully created.'

 content = form
 else:
 content = SQLFORM.grid(db.package)

 return dict(content=content)

 I did some research in the web2py-users ML and some search engines but 
 could not find a way to tackle this issue.

 Following a couple of ideas for which I am thankful to get helpful 
 comments and advice:

 1. Create a custom validator for the form or
 2. Disable form.process().accepted or
 3. Disable the validation for the specific field
 4. Something completely different

 I try to avoid options 2 and 3.

 Thank you for your time!

 //jotbe


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Comments/notes and api documentation

2014-09-17 Thread Limedrop
Have you seen the medium.com in-context notes?  That would be a great way 
to bring it all together:
https://medium.com/about/why-medium-notes-are-different-and-how-to-use-them-well-5972c72b18f2

There's even a jQuery clone that could be used:
https://github.com/aroc/side-comments


On Thursday, September 18, 2014 11:07:44 AM UTC+12, Derek wrote:

 I'd like to see a wiki... it could be run on web2py even...

 On Tuesday, September 16, 2014 3:12:52 PM UTC-7, Anthony wrote:

 Maybe submit a Github issue in the book repo requesting this feature.

 Anthony

 On Tuesday, September 16, 2014 6:12:06 PM UTC-4, Anthony wrote:

 Agreed, but for the most part, if something is truly lacking from the 
 documentation, it would be best if it could be included in the 
 documentation itself, rather than in a long list of unorganized comments at 
 the bottom of the page. You can always make a pull request on the book repo 
 (https://github.com/mdipierro/web2py-book) for direct changes to the 
 documentation.

 Allowing user comments/feedback isn't a bad idea, though, but we would 
 probably have to change the UI -- currently each chapter is a very long 
 HTML page, and putting comments at the bottom would in many cases place 
 them very far from the relevant context in the chapter.

 Note, the old version of the book did in fact allow comments at the 
 bottom of each page (though there was no upvote/downvote feature), but that 
 functionality was not migrated to the newer book app.

 Anthony

 On Tuesday, September 16, 2014 6:02:42 PM UTC-4, Robin Manoli wrote:

 It's not really what I'm looking for. There are many benefits to the 
 php documentation way:
 1. the comments are where you are looking for help
 2. when you are looking for help, and find a solution of your own, you 
 can post it where you were looking
 3. the current documentation is unclear in many places, and it's not 
 very efficient to browse around the form/slices/stackoverflow/examples to 
 get to the solution, when it could already be there where you look first
 4. the documentation could become verbose instead of lacking
 5. there are many little tricks that i have read about in the forum 
 that i couldn't find in the documentation... if all these tricks would be 
 more accessible, web2py's many hidden features could be used more

 Den torsdagen den 11:e september 2014 kl. 00:27:10 UTC+2 skrev Anthony:

 It's not embedded with the main documentation, but for user 
 contributed content, we do have http://www.web2pyslices.com/home.

 Anthony

 On Wednesday, September 10, 2014 5:55:36 PM UTC-4, Robin Manoli wrote:

 Hey,
 the php documentation has user comments with examples of how to use 
 different functions. This is a great complement to their documentation.

 With web2py I have stumbled upon many things in these forums that I 
 have not seen in the documentation. I'm not sure how often you update 
 it, 
 since I keep finding new things there too.

 Still, don't you think it would be better if we all could contribute 
 with common and examples to an api-type of documentation for web2py? I 
 think the php documentation does this really well.



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Strange ajax problem

2014-08-14 Thread Limedrop
You might want to check out the javascript that Leonel submitted here:

https://groups.google.com/d/msg/web2py/JFy3BCHXgYc/7npKiqs6BOUJ

In particular see how he uses:

$.web2py.disableElement(form.find($.web2py.formInputClickSelector));





On Friday, August 15, 2014 8:20:05 AM UTC+12, Michael Beller wrote:

 Thanks Cliff and Niphlod,

 I've used ajax several times and think I understand the process.  My 
 problem now involves using a form inside a bootstrap modal and using ajax 
 to submit the form.  What I meant by web2py intercepting the event was 
 that web2py.js registers an event handler for the submit which interferes 
 with the modal submit handler.  web2py.js adds the 'disabled' class but 
 does not detect the succesful ajax response and then remove the class.

 Per Niphlod's request, I've recreated the problem using a minimum of code 
 that I've pasted below.  This codes works if I remove web2py.js and fails 
 if I leave it.  To recreate, click the button to open the model and then 
 click submit on the modal.  You can see the button becomes disabled (even 
 if you close and reopen it remains disabled).  In other testing, I also had 
 web2py add 'display='none' ' to the target but the code below doesn't do 
 that.

 Thanks again for your help.

 Controller Actions:
 def display_page():
return dict(foo='bar')
 def return_data():
 data= {'foo':'text processed: %s' % request.vars.formdata}
return data

 View:
 {{extend 'layout.html'}}

 script
 $(document).ready(function() {
 $('#note-btn').click(function() {
 $('#note-modal').modal({
 show: true
});
});
 $('#note-form').submit(function(e) {
 e.preventDefault();
 $form= $(this);
 $.post('{{=URL('default', 'return_data.json')}}',
{formdata: $form.serialize()},
function(data) {$('#form-feedback').html(data.foo);}
);
});
 });
 /script

 a href=# id=note-btnOpen modal/a

 div id=note-modal class=modal fade tabindex=-1 role=dialog
div class=modal-dialog
div class=modal-content
form class=form-horizontal id=note-form
div class=modal-header
button type=button class=close data-dismiss=
 modal
span aria-hidden=truetimes;/spanspan class=
 sr-onlyClose/span
 /button
h4 class=modal-titleEnter Notes/h4
 div class='bg-success text-center' 
 id='form-feedback'/div
/div
 div class=modal-body
 div class=form-group
 div
 textarea class=form-control id=note-text 
 name=note_text/textarea
/div
 /div
/div
 div class=modal-footer
 a class=btn btn-default data-dismiss=modalClose/
 a
button type=submit class=btn btn-primarySave 
 Notes/button
 /div
/form
 /div!-- /.modal-content --
/div!-- /.modal-dialog --
 /div!-- /.modal --


 On Wednesday, August 13, 2014 11:31:39 PM UTC-4, Cliff Kachinske wrote:

 Here's how I do it and I assume Web2py does something similar when it, 
 for example, resets the Working caption on buttons.

 The Javascript/Jquery whatever in the client changes the state of the 
 button. I do it before sending the ajax post. I don't know how Web2py does 
 it.

 It doesn't matter whether it's JQuery's ajax or Web2py's ajax. The syntax 
 is a little different between the two, but the overall process is the same. 
 The client sends a request that gets routed to a function. The function 
 returns a response.

 In that response you would include, assuming JQuery has been loaded on 
 the page, something like 
 $('#somentity_on_page').whatever_attribute_needs_changing('new state of 
 the attribute');

 Web2py isn't intercepting anything. You push a button, click a link, 
 whatever, the browser sends a request. The request goes to your web server, 
 be it Rocket, Apache, Nginx, any other. The web server sends the request to 
 Web2py because the server is set up that way. Web2py then processes the 
 request and returns a response. 

 Excuse me if I'm interpreting incorrectly, but your questions suggest a 
 certain misunderstanding about what's going on. Chapters 1, 3 and 4 of the 
 Web2py manual provide a pretty good overview of how this all works. If I 
 recall correctly, Wikipedia has some reasonably good articles about http, 
 http requests and http responses.

 On Wednesday, August 13, 2014 6:51:59 PM UTC-4, Michael Beller wrote:

 Thanks ...

 Niphlod - I'll try to create a minimal app to reproduce.

 Cliff - are you suggesting to use the web2py ajax function rather 
 the jQuery post?

 I'm also trying to understand why web2py is intercepting the event and 
 why it doesn't think the response is succesful which I assume is why the 
 button is not 

[web2py] Re: scheduler new feature: task dependencies

2014-08-05 Thread Limedrop
Thanks Niphlop, that's brilliant!  I've been using a work-around to 
schedule dependent jobs, and this will help to tidy things up.

On Tuesday, August 5, 2014 8:51:25 PM UTC+12, Niphlod wrote:

 Hi @all,
we have another feature in trunk for the scheduler... Jobs (i.e. task 
 dependencies)

 Directly from https://github.com/niphlod/w2p_scheduler_tests/ (that has 
 been updated to accomodate the new feature explanation...)


 What are Jobs, you ask ? Well, it's a way to coordinate a set of tasks 
 that have dependencies (what in Celery is called Canvas).

 As always, the Scheduler sticks to the basics. Every Job is considered to 
 be a DAG (a  Directed Acyclic Graph 
 http://en.wikipedia.org/wiki/Directed_acyclic_graph).
 Without going into silly details, every task can have one or more 
 dependencies, but of course you can't have mutual dependencies among the 
 same tasks.
 If a job can't be represented as a DAG, then it can't be processed in 
 its entirety. You can still queue it, but it won't ever complete (i.e. you 
 could have a
   complete stall at the first task or just a task left on 100 queued...)

 So... what can you do ?
 Let's take a trivial example (there are a few based on mathematics, 
 map/reduce, etc... but hey, this is an example!!!)
 Suppose you need to create a job that describes what is needed to get 
 dressed ( thanks to http://hansolav.net/sql/graphs.html )...

 We have a few items to wear, and there's an order to respect...
 Items are: watch, jacket, shirt, tie, pants, undershorts, belt, shoes, 
 socks

 Now, we can't put on the tie without wearing the shirt first, etc...

 http://yuml.me/995413d6



 Suppose we have those tasks queued in a controller (for example's sake, 
 the same function, with different task_name(s))...
 watch = s.queue_task(fname, task_name='watch')
 jacket = s.queue_task(fname, task_name='jacket')
 shirt = s.queue_task(fname, task_name='shirt')
 tie = s.queue_task(fname, task_name='tie')
 pants = s.queue_task(fname, task_name='pants')
 undershorts = s.queue_task(fname, task_name='undershorts')
 belt = s.queue_task(fname, task_name='belt')
 shoes = s.queue_task(fname, task_name='shoes')
 socks = s.queue_task(fname, task_name='socks')


 Now, there's a helper class to construct and validate a job.
 First, let's declare a job named job_1


 #from gluon.scheduler import JobGraph
 myjob = JobGraph(db, 'job_1')



 Next, we'd need to establish dependencies


 # before the tie, comes the shirt
 myjob.add_deps(tie.id, shirt.id)
 # before the belt too comes the shirt
 myjob.add_deps(belt.id, shirt.id)
 # before the jacket, comes the tie
 myjob.add_deps(jacket.id, tie.id)
 # before the belt, come the pants
 myjob.add_deps(belt.id, pants.id)
 # before the shoes, comes the pants
 myjob.add_deps(shoes.id, pants.id)
 # before the pants, comes the undershorts
 myjob.add_deps(pants.id, undershorts.id)
 # before the shoes, comes the undershorts
 myjob.add_deps(shoes.id, undershorts.id)
 # before the jacket, comes the belt
 myjob.add_deps(jacket.id, belt.id)
 # before the shoes, comes the socks
 myjob.add_deps(shoes.id, socks.id)



 Then, we can ask JobGraph if what we asked is a job that is accomplishable

 myjob.validate('job_1')

 And voilà, job done! If it's not a DAG, then an exception will be raised 
 and the jobs won't be committed (of course their dependencies won't be 
 committed too)

 How it works under the hood ?

 There's a new table called scheduler_task_deps that holds a reference to 
 the job_name, the task parent, the task child and
 a boolean to mark the path (the arrows in the graph) as visitable.
 To be fair, the job name isn't that important, you can have task 
 dependencies amongst
 different jobs, it's just not that easy to verify that the Job is a DAG at 
 a later stage.
 If a path is visitable it means that the DAG graph can be walked in 
 that direction.
 Every time a task gets COMPLETED, the paths gets updated to be 
 visitable. The algo to pick up tasks has been updated
 to work fetching only tasks that have no dependencies, or dependencies 
 that have already been satisfied (i.e. tasks that depends
 on nothing, or tasks that depend on tasks that are yet COMPLETED).


 Let me know what you think, and if you spot bugs.





-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: rname and reserved names

2014-07-21 Thread Limedrop
This worked for me on postgresql 9.1...

db = DAL('%s%s' % (dal_connection, app_database)) 
rname = db._adapter.__class__.QUOTE_TEMPLATE % 'ALL'
db.define_table('test', Field('whatever', rname=rname))

Note that I used ALL rather than position as position is not a reserved 
word on postgresql



On Monday, July 21, 2014 6:14:05 PM UTC+12, Simon Ashley wrote:

 Thanks. I could, but need to check this for postgres. Seems a little bit 
 strange when I have a look at the sql.log file:

 timestamp: 2014-07-21T15:57:35.749000
 CREATE TABLE auth_cas(
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 user_id INTEGER REFERENCES auth_user (id) ON DELETE CASCADE,
 created_on TIMESTAMP,
 service CHAR(512),
 ticket CHAR(512),
 renew CHAR(1)
 );
 success!
 timestamp: 2014-07-21T15:59:39.06
 CREATE TABLE this_is_the_easy_name_table(
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 this_is_the_field_name CHAR(512)
 );
 success!


 and when I look at the table generated, I get this:

 (dp1
 S'position1'
 p2
 (dp3
 S'length'
 p4
 I512
 sS'unique'
 p5
 I00

  
 Note that I've changed* position* to *position1* to escape the error and 
 generate the table. I would have thought that it would have generated the 
 rname. I might try a fresh dal.py source.



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: rname and reserved names

2014-07-20 Thread Limedrop
The error message suggests that it is the field name (ie, position) that 
is reserved.


On Monday, July 21, 2014 4:19:39 PM UTC+12, Simon Ashley wrote:


 Haven't used rname before but the way I read it it should work with 
 reserved names. Have changed a given example to read:

 db.define_table('easy_name',
  Field http://127.0.0.1:8000/examples/global/vars/Field('position', 
 rname='this_is_the_field_name'),
  rname='this_is_the_easy_name_table')

 but it returns an error as follows:

 Traceback (most recent call last):
   File C:\w2p_5\gluon\restricted.py, line 220, in restricted
 exec ccode in environment
   File C:/w2p_5/applications/test_1/models/db_1.py 
 http://127.0.0.1:8000/admin/default/edit/test_1/models/db_1.py, line 11, in 
 module
 rname='this_is_the_easy_name_table')
   File C:\w2p_5\gluon\dal.py, line 8223, in define_table
 table = self.lazy_define_table(tablename,*fields,**args)
   File C:\w2p_5\gluon\dal.py, line 8240, in lazy_define_table
 table = table_class(self, tablename, *fields, **args)
   File C:\w2p_5\gluon\dal.py, line 8754, in __init__
 check_reserved(field_name)
   File C:\w2p_5\gluon\dal.py, line 7931, in check_reserved_keyword
 'invalid table/column name %s is a %s reserved SQL/NOSQL keyword' % 
 (name, backend.upper()))
 SyntaxError: invalid table/column name position is a ALL reserved 
 SQL/NOSQL keyword

 Running 2.9.5

 *There there something I've overlooked? TIA*






-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: rname and reserved names

2014-07-20 Thread Limedrop
I think you just need to turn the warning off.  

db = DAL(..., check_reserved=None)


On Monday, July 21, 2014 5:05:06 PM UTC+12, Simon Ashley wrote:

 Yep,  agree with that but to quote Niphlod 


 *For the ones in need of:*

 *- accessing legacy tables with some funny names *

 *- use reserved keywords for table and field names  *


 https://groups.google.com/forum/#!msg/web2py/_q5qcARON4E/6JLCHM3eQHAJ 


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Brainstorming

2014-06-22 Thread Limedrop
Have you looked at breezejs? A JavaScript library that helps you manage 
data in rich client applications. 

Breeze dynamically builds a mirror of the server-side db model on the 
client and then binds to UI controls so the UI updates when the data model 
changes. Each object knows when it has changed and what has changed. 
Essentially it builds a client-side cache of the db.

On the surface it's focused on .NET (with it's own .NET components), but if 
you look underneath you see that web2py could easily provide the back-end.

Nice overview here:
http://www.breezejs.com/documentation/introduction

MIT license.


On Saturday, June 21, 2014 9:33:04 PM UTC+12, Massimo Di Pierro wrote:

 web2py is mostly serverside and that is not going to change. I think what 
 we are discussing is the future...

 In the future I envision a new framework that has more client-side logic. 
 In order to do that we have make some choices of client-side frameworks. I 
 also agree that communication between client and server needs to rely on 
 standards. One possible standard are using hypermedia API for self 
 documenting json services. Yet I find it to be insufficient. I am spending 
 lot of time thinking about a generic way for client and server to 
 communicate. The problem is that they need to communicate more than data, 
 but also templates, and workflow information.


 On Friday, 20 June 2014 16:26:44 UTC-5, Phyo Arkar wrote:


 On Sat, Jun 21, 2014 at 3:31 AM, Michele Comitini michele@gmail.com 
 javascript: wrote:

 My POV is that web2py should have a rather agnostic attitude toward a 
 wide range of frameworks, by having some kind of layer that would allow to 
 keep server side code mostly untouched when changing js framework, easily 
 add support for a new js framework.
 In practice web2py should use a well defined protocol between client and 
 server, to pass actions, messages and events back and forth.


 My POV is that web2py should have a rather agnostic attitude toward a 
 wide range of frameworks, by having some kind of layer that would allow to 
 keep server side code mostly untouched when changing js framework, easily 
 add support for a new js framework.
 In practice web2py should use a well defined protocol between client and 
 server, to pass actions, messages and events back and forth.


 + 100!

 Exactly my toughts too.



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Download inside component

2014-06-13 Thread Limedrop
I use that jquery plugin and it is very good.  Note that you need to set 
cookies within the download function, something  like this...

response.cookies['fileDownload'] = 'true'
response.cookies['fileDownload']['path'] = /


On Saturday, June 14, 2014 3:40:01 AM UTC+12, Anthony wrote:

 Maybe have a look at this: 
 http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/


 On Friday, June 13, 2014 11:08:22 AM UTC-4, LaDarrius Stewart wrote:

 Currently have a modal being filled by the following code
 links=[lambda row: BUTTON('Apply Payment',
 _onclick=web2py_component('%s', 
 'modalinfo'); % \
  URL('default', 'applypayment2.load', 
 args=row.Inv_Header.id),
 **{'_data-toggle': 'modal',  '_data-target' : 
 '#myModal',
'_class' : 'two btn btn-success', '_id' : 
 'show'})]
 Inside this modal I have a submit button with a call to a ReportLab 
 method that returns a response.stream. Within the modal it returns the raw 
 PDF data(garbage) instead of initiating the automatic download as the same 
 code does on non-component views.

 This message is for named person(s) only.  It may contain confidential 
 and/or legally privileged information.  No confidentiality or privilege is 
 waived or lost should mis-transmission occur.  If you receive this message 
 in error, delete it (and all copies) and notify the sender.  You must not, 
 directly or indirectly,use, disclose, distribute, print, or copy any part 
 of this message if you are not the intended recipient. GAD GROUP 
 TECHNOLOGY, INC. reserves the right to monitor all e-mail communications 
 through its networks.

 Any views expressed in this message are those of the individual sender, 
 except where the message states otherwise and the sender is authorized to 
 state them to be the views of any such entity.

 This e-mail has been virus and content scanned by GAD GROUP TECHNOLOGY, 
 INC.



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: get value of value attribute of input of SQLFORM

2014-06-11 Thread Limedrop
A more robust way to do this is to use the element search helper.  Use the 
id (or whatever) to find the INPUT like this:

element = form.element(_id='table_field')

and then the value will be:

element['_value']

See the book for all the other cool things you can do:
http://www.web2py.com/books/default/chapter/29/05/the-views?search=element#elements


On Wednesday, June 11, 2014 3:39:35 PM UTC+12, lucas wrote:

 omg, i figured it out.  i had to drill down one more layer.

 uform[0][0][1][0]['value']

 where, form is the form element itself, the first [0] is the table, the 
 second [0] is the first TR line of the table, the [1] is the TD element of 
 the TR line, and the last [0] is the INPUT element under the TD.

 i had a brainy storm.  thanx, lucas


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: I'd like to know what is a suitable tool to generate document templates.

2014-03-26 Thread Limedrop
If your customer is happy using MS Word why force them to change?  Word 
files are just zipped up xml that can be manipulated using tools such as 
lxml.etree.  We let our customers upload Word templates that we then 
populate with data and return to them as docx.  That way they can use Word 
to apply all the formatting they want, using the tool they already know - 
and we don't need to handle any formatting. 

I don't know if such an approach would meet your need, but perhaps the 
better option is to find a docx preview tool?

On Thursday, March 27, 2014 6:30:05 AM UTC+13, Omar Meat Boy Gutiérrez 
wrote:

 Thanks for the answer Massimo, 

 We discarded MS Word to HTML conversion because we have problems with the 
 code generated (we have a kind of preview in HTML)

 Thanks to mention Reportlab, we are using xhtml2pdf Pisa tool. 

 Cheers


 On Wed, Mar 26, 2014 at 10:55 AM, Massimo Di Pierro 
 massimo@gmail.comjavascript:
  wrote:

 MS Word documents can be easily be converted to HTML because Word can 
 export to HTML. The resulting HTML is terrible and not humanly readable, 
 but works.
 If you use markmin notice in web2py there is a 
 gluon.contrib.markmin.markmin2pdf which is designed to generate documents. 
 markmin is more powerful then markdown.
 You may also want to look into reportlab.

 On Wednesday, 26 March 2014 11:16:40 UTC-5, Omar Meat Boy Gutiérrez wrote:


 Hi everyone, 

 I'd like to discuss with you about your experience with document 
 templates.

 *I have the next problem:*

 a) A customer want to generate different kinds of documents. He creates 
 the `templates` using programs like Word. 
 b) I receive the document and I need to convert it to HTML. 

 *What I need is the next:*

 A tool intended to be used by the customer where he can to generate 
 `templates` adding special fields, tables, titles.

 My boss is thinking in use markmin, I guess markdown is also a good 
 choice. 

 According to your experience, what other tool can be used? Is it markmin 
 a good choice? Am I missing something?

 Greetings

  -- 
 Resources:
 - http://web2py.com
 - http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py (Source code)
 - https://code.google.com/p/web2py/issues/list (Report Issues)
 --- 
 You received this message because you are subscribed to a topic in the 
 Google Groups web2py-users group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/web2py/vkmSNzY3oTA/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 web2py+un...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/d/optout.




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] calling download function page by ajax

2014-03-18 Thread Limedrop
You might want to look at 
http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/

The only fiddly bit is to make sure you set the cookies correctly (see the 
documentation for details).

For example:

  {{view}}
  
response.files.append(URL('static','js/jquery.fileDownload/jquery.fileDownload.js'))
  
  
  {{controller}}
  response.js = 
'$.fileDownload(http://127.0.0.1:8000/sgddms/label/download_func1?var1=2676var1=2673var1=2678;);'
  response.js += 
'$.fileDownload(http://127.0.0.1:8000/sgddms/label/download_func1?var1=2676var1=2673var1=2678;);'
  # these cookies are required by jQuery.fileDownload.js
  # to enable download via ajax
  response.cookies['fileDownload'] = 'true'
  response.cookies['fileDownload']['path'] = /





On Wednesday, March 19, 2014 1:38:43 PM UTC+13, Richard wrote:

 :(

 I already have a workaround where I show buttons for starting download for 
 each files that are appended on submit, but I hate that from user 
 experience point of view... I thought about an other solution, where I 
 could get vars values from javascritp once form is submit trought 
 session.var but I am not sure it will work.

 Do you know such a library?

 Thanks

 Richard


 On Tue, Mar 18, 2014 at 6:05 PM, Niphlod nip...@gmail.com 
 javascript:wrote:

 content-disposition on ajax requests is not allowed, therefore browser 
 refuse to show the usual download as file dialog, plain and simple :D

 You need to come up with an alternative plan (such as, opening a new 
 window pointing to the url, open a hidden iframe, using 3rd party libraries 
 that do the previous, etc)


 On Tuesday, March 18, 2014 9:59:40 PM UTC+1, Richard wrote:

 Hello,

 I want to call 2 functions that return a file to be upload/download into 
 client computer... I have been able to make the first call page to upload 
 file correctly, but I can't figure out how to make upload both files, I 
 thought I could solve the issue with ajax call, no lock.

 # controller

 def form_func_that_call_my_download_funcs():
 ...
 if form.process().accpet:
 ...
 redirect(URL(c='label', f='download_func1', extension=False,
vars=dict(var1=var1, **other_vars_dict)), 
 client_side=True) # This work for one file as it should...
 ...


 def shell_func():
 return dict(a='')


 # view
 # shell_func()
 div id=batch_div
 {{=LOAD('lotns', 'other_func_that_just_return_so_var_input', 
 extension='load', ajax=True, target='batch_div')}}
 !-- On submit of this view form_func_that_call_my_download_funcs() is 
 loaded below with web2py_component() --
 /div

 div id=form_func_that_call_my_download_funcs_div
 !-- form_func_that_call_my_download_funcs() loaded here with 
 web2py_component() --
 /div


 I try to change form_func_that_call_my_download_funcs() like this :

 def form_func_that_call_my_download_funcs():
 ...
 if form.process().accpet:
 ...
 response.js = $.get(url='http://127.0.0.1:
 8000/sgddms/label/download_func1?var1=2676var1=2673var1=2678');
 response.js += $.get(url='http://127.0.0.1:
 8000/sgddms/label/download_func2?var1=2676var1=2673var1=2678'); # I 
 see the call passing in chrome dev tool both the files are not download??? 
 Try with $.post() too...
 ...


 # Here what look my download function, both are the same so I just show 
 the important thing in one of them...
 def download_func1():
 ...
 final = StringIO(final_wordml)
 response.headers['Content-Type'] = 'xml'
 response.headers['Content-Disposition'] = \
 'attachment;filename=filename123_%s.xml;' % 
 request.now.strftime('%Y-%m-%d_%H-%M-%S-%f')
 response.write(final.getvalue(), escape=False)
 raise HTTP(200, str(final.getvalue()), **response.headers)


 Thanks for any pointer!

 Richard

  -- 
 Resources:
 - http://web2py.com
 - http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py (Source code)
 - https://code.google.com/p/web2py/issues/list (Report Issues)
 --- 
 You received this message because you are subscribed to the Google Groups 
 web2py-users group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to web2py+un...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/d/optout.




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] calling download function page by ajax

2014-03-18 Thread Limedrop
Posted to soon.  To clarify, the cookies need to be set in your download 
function:

  {{view}}
  
response.files.append(URL('static','jquery.fileDownload/jquery.fileDownload.js'))
  
  
  {{controller}}
  response.js = 
'$.fileDownload(http://127.0.0.1:8000/sgddms/label/download_func1?var1=2676var1=2673var1=2678;);'
  response.js += 
'$.fileDownload(http://127.0.0.1:8000/sgddms/label/download_func1?var1=2676var1=2673var1=2678;);'
  
  
  {{download_func1}}
  # these cookies are required by jQuery.fileDownload.js
  # to enable download via ajax
  response.cookies['fileDownload'] = 'true'
  response.cookies['fileDownload']['path'] = /



On Wednesday, March 19, 2014 6:18:11 PM UTC+13, Limedrop wrote:

 You might want to look at 
 http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/

 The only fiddly bit is to make sure you set the cookies correctly (see the 
 documentation for details).

 For example:

   {{view}}
   
 response.files.append(URL('static','js/jquery.fileDownload/jquery.fileDownload.js'))
   
   
   {{controller}}
   response.js = '$.fileDownload(
 http://127.0.0.1:8000/sgddms/label/download_func1?var1=2676var1=2673var1=2678
 );'
   response.js += '$.fileDownload(
 http://127.0.0.1:8000/sgddms/label/download_func1?var1=2676var1=2673var1=2678
 );'
   # these cookies are required by jQuery.fileDownload.js
   # to enable download via ajax
   response.cookies['fileDownload'] = 'true'
   response.cookies['fileDownload']['path'] = /








-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Force all requests to https - a pointer please

2014-02-27 Thread Limedrop
Try this:

session.secure()
if not request.is_https:
redirect('https://%s/%s' % (request.env.http_host, 
request.application))


On Friday, February 28, 2014 11:46:20 AM UTC+13, Cliff Kachinske wrote:

 I know I have read it somewhere, but I can't find it.

 Where can I find out how to force all requests to https?

 Thank you,m
 Cliff Kachinske


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Detecting OS issue

2014-01-13 Thread Limedrop
Have a look at python's platform module.  For example:

import platform
if platform.system() == 'Windows':   

elif platform.system() == 'Linux':



On Tuesday, January 14, 2014 7:26:09 AM UTC+13, Jon Smith wrote:

 Hello I am trying to figure out how to detect if a computer is running 
 Windows or Macintosh then load the appropriate files and if any other 
 system Linux/Mobile etc then load the other files

 The reason for this is I am using Google Earth in a project and I want to 
 load Google Maps if it is not available

 I am trying to do this


 {{if session._user_agent['os']['name'] == 'Macintosh' or 
 session._user_agent['os']['name'] == 'Windows':}}
 
  // do something

{{else:}}

 // do something

{{pass}}

 This however is creating an error if I try on my mobile device. I have not 
 had a chance to test on my Linux system yet.

 The error returned is: TypeError: 'NoneType' object has no attribute 
 '__getitem__'

 I am using the current stable release of web2py 2.8.2 (I think is the 
 version number) any suggestions in how I can do what I need?

 *Cheers


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Error uploading 60 character named .pptx file

2013-11-14 Thread Limedrop
Actually, the web2py setting you're looking for is 'length'.  Here's an 
example:


db.define_table('document',
Field('document_filename', writable=False, compute = lambda row: 
request.post_vars.document.filename),
Field('document','upload',autodelete=True,
  requires=IS_LENGTH(minsize=10, maxsize=9048576, 
error_message='Please select a file.')),
)

# Windows has a maximum length of 260 characters for a file's combined path 
and name
import platform
if platform.system() == 'Windows':
db.document.document.length = 100




On Friday, November 15, 2013 4:01:56 AM UTC+13, Loïc wrote:

 I had a similar issue some time ago, but Windows was my testing machine, 
 not the production server OS. So it was not very annoying...
 If you want to host on Windows, you may have to store the original 
 filename in the database, and change it on the disk : 

 http://web2py.com/books/default/chapter/29/07?search=uploads#Storing-the-original-filename



 Le jeudi 14 novembre 2013 11:03:05 UTC+1, Rahul a écrit :

 Okay - 
  So in my case the file name actually passed to DB is as highlighted 
 below - this is 229 characters long (still smaller than 260 limit). Can the 
 upload field handle such long file names ? Do you think that could be the 
 problem? How do we specify file name character limit in db.py when defining 
 files I know we can specify the size but how names of files ? Any idea? 

 in db.py I have  - 
  Field('attach_file','upload'))

 I am not using blob to store files- instead files are stored on server at 
 a specified path. 


 issues.attach_file.8ddd3149b14cb8e9.4d6f6e6579204d617474657273206578706f7365205072696d6172792041647669736f722066726f6d20436f6e7461637420746f20496e76204163636f756e74207669657720616e642064796e616d6963207265706f7274732e70707478.pptx
 Regards, Rahul

 On Thursday, November 14, 2013 2:11:13 PM UTC+5:30, Niphlod wrote:



 On Thursday, November 14, 2013 6:21:26 AM UTC+1, Rahul wrote:

 Hi Ricardo, 
  Thanks for the response, but I don't understand why it should 
 be a windows limit. I have many files with much larger names in windows, 
 never had such a problem. Besides this only occurs when we are uploading 
 it 
 in web2py. Could SQLite database be a constraint ? I am using sqlite for 
 this app.  What might cause this, for now I have reduced the file name and 
 it gets uploaded just fine. 

 Sincerely, Rahul D.


  
 There's no way  you can have a path with more than 260 characters in 
 windows. Any database has no issues on handling long paths, only the 
 underlying filesystem. If you choose to store files in your uploads folder, 
 and you are on windows, you need to limit the length of the filenames users 
 try to upload. Alternatively, you can store files in the database in a blob 
 field.



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Scheduler TIMEOUT

2013-11-12 Thread Limedrop
I've had this problem too.  I think it would be good if the scheduler had 
the option to retry timeouts, in the same way that retry_failed works.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Scheduler Namespace Gotcha

2013-08-25 Thread Limedrop
Thanks Niphlod. The scheduler really is a most excellent thing to use.

On Sunday, August 25, 2013 12:07:09 AM UTC+12, Niphlod wrote:

 Thanks for spotting this. Scheduler global variables are safe in the 
 scheduler module, but inside the function that creates the environment to 
 run the task, they may got overwritten, causing problems. I sent a PR on 
 github to fix the issue.

 On Saturday, August 10, 2013 12:03:10 AM UTC+2, Limedrop wrote:

 Hi,

 I was experiencing some strange results with the scheduler in one 
 particular application.  Tasks would successfully execute, but the 
 scheduler_task and scheduler_run records would stick on RUNNING.

 After some hair pulling I discovered that the app model was using this 
 variable:

 COMPLETED = 'Completed'

 And so task_report.status was being set as 'Completed'  whereas 
 scheduler.py expects:

 COMPLETED = 'COMPLETED'

 So if task_report.status == COMPLETED could never be True.

 Is this just something to work around or is it possible to make scheduler 
 play more nicely with the app namespace?

 Thanks







-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Scheduler Namespace Gotcha

2013-08-09 Thread Limedrop
Hi,

I was experiencing some strange results with the scheduler in one 
particular application.  Tasks would successfully execute, but the 
scheduler_task and scheduler_run records would stick on RUNNING.

After some hair pulling I discovered that the app model was using this 
variable:

COMPLETED = 'Completed'

And so task_report.status was being set as 'Completed'  whereas 
scheduler.py expects:

COMPLETED = 'COMPLETED'

So if task_report.status == COMPLETED could never be True.

Is this just something to work around or is it possible to make scheduler 
play more nicely with the app namespace?

Thanks





-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: web2py Safety discussion

2013-06-04 Thread Limedrop
I have often wondered if changing the names admin and appadmin would be 
an easy and simple way to add another layer of security?  In other words, 
add these as command-line arguments that can be set on startup?  In this 
way www.mysite.com/admin could be changed to something like 
www.mysite.com/secretadmin123.  After that access attempts to 
www.mysite.com/admin could either be handled using the normal invalid 
request methods or treated as a breach attempt.

I see that admin and appadmin are pretty much hard-coded into web2py, 
so I'm not sure if it would be worth the effort?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: SQLFORM add a second custom submit button

2013-04-21 Thread Limedrop
Ideally something like this will work for you...

def test_form():
 form = SQLFORM(db.table,
buttons = [INPUT(_type='Submit', _name='submit1', _value='Submit1'),
   INPUT(_type='Submit', _name='submit2', 
_value='Submit2')])
if form.accepts(request):
if form.vars.submit1:
pass
elif form.vars.submit2:
pass
return form 

Works in IE10, but this may not work in older browsers (such as IE7) so you 
might need to resort to a javascript solution as discussed here:

https://groups.google.com/forum/#!msg/web2py/D0S2-VsFjfU/YGsKiUf4wXkJ





On Monday, April 22, 2013 6:57:18 AM UTC+12, lucas wrote:

 hello one and all,

 working on a custom SQLFORM.  i use the form.custom.submit to display it 
 in the view and when it is pressed it properly updates that record in the 
 databse. good.  now i want to add a second custom button that will also 
 still update the fields to the proper record and then do a redirect to 
 another function in the controller.  i've read a few close posts and tried 
 them, but all unsuccessful.  how can i add a second custom button and a 
 method in the function to know when that other button was pushed, still 
 updating the record and then redirecting.

 thanx in advance.  lucas


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: need teaching advice (JS+jQuery)

2013-04-03 Thread Limedrop
What about the google maps jQuery plugin?
http://www.pittss.lv/jquery/gomap/solutions.php


On Thursday, April 4, 2013 6:47:15 AM UTC+13, Massimo Di Pierro wrote:

 Tomorrow I am starting teach a new class. I did not create the class, it 
 was assigned to me. The class is for undergraduate students who have little 
 or no programming experience but know HTML+CSS. No server-side programming 
 experience. The class should cover JS+jQuery but no server-side programming.

 What are some cool uses of JS/jQuery that do not involve server-side 
 programming? 
 I am thinking of hooking to some JSONP services. Is there any you would 
 suggest?

 Massimo


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Error when changing Postgresql password

2013-02-04 Thread Limedrop
(a) Because when you changed the DAL connection string, web2py thinks it 
might be a new database and tries to recreate the tables from scratch.

(b) You could try: 
db = DAL(...,fake_migrate_all=True)  
run the app and, if successful, then:
db = DAL(...,fake_migrate_all=False)  
But read the instructions in the book first  
http://web2py.com/books/default/chapter/29/06?search=fake_migrate



On Tuesday, February 5, 2013 7:08:27 AM UTC+13, Neil wrote:

 I've changed the user password for my Postgresql database. When I make the 
 update to the DAL connection string, I then get the following error:

 postgresql error ... class 'psycopg2.ProgrammingError'(relation 
 auth_user already exists)

 when going to the site. Notes:

- I've made no other changes to the database or model files
- I know the password is correct, because when I deliberately use the 
wrong password I get a different message (about not being able to connect 
to the database).
- When I revert to the old password (in both the connection string and 
the database), everything starts working again.

 Anyone know (a) what is causing this, and (b) how I can get around it?

 Neil


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Can't store query in session

2012-09-06 Thread Limedrop
Johann, you should look at this slice...

http://www.web2pyslices.com/slice/show/1489/save-query-in-session

Does it do what you want?


On Friday, September 7, 2012 12:40:44 AM UTC+12, Massimo Di Pierro wrote:

 You cannot store a query in a session. 

 On Thursday, 6 September 2012 04:26:57 UTC-5, Johann Spies wrote:

 I have been using session a lot to store queries.

 This morning with the following query:

 (((akb_doccenter.publication_date = '2012') AND (akb_doccenter_category.uuid 
 = akb_doccenter.category)) AND (akb_doccenter_location.uuid =akb_doccenter
 .location))



 I get the following when I try to do 
 session.query = query

 Traceback (most recent call last):
   File /home/js/web2py.20120810/gluon/main.py, line 545, in wsgibase
 session._try_store_on_disk(request, response)
   File /home/js/web2py.20120810/gluon/globals.py, line 683, in 
 _try_store_on_disk
 cPickle.dump(dict(self), response.session_file)
   File /usr/lib/python2.7/copy_reg.py, line 70, in _reduce_ex
 raise TypeError, can't pickle %s objects % base.__name__
 TypeError: can't pickle function objects


 What is causing this?  What is my alternatives?  Should I rather use 
 cache?

 Regards
 Johann



-- 





Re: [web2py] Re: SEO Friendly URLs and Page Titles

2012-08-27 Thread Limedrop

I don't know if you picked this up, but you don't seem to have row.id as 
part of the sqlfrom url.

Perhaps try: 
links = [lambda row: A('Details',_href=URL('default','equipment', 
args=[row.id, row.slug]))]


On Tuesday, August 28, 2012 10:28:39 AM UTC+12, SeamusSeamus wrote:

 Okay, but do  I leave everything else alone? All I want to do is make it 
 www.mysite.com/equipment/id/title
 currently, title is set up as slug in the DB. What am I doing wrong. 

  In my view:

 equipment_id = request.args(0)
 equipment_slug = request.args(1)
 query = (db.equipment.id == item_id)  (db.equipment.slug == 
 item_slug)
 item = db(query).select().first()
 
 try:
 equipment = db.equipment[int(request.args(0))]
 except:
 equipment = db.equipment(request.args(0)) or db(db.equipment.slug 
 == request.args(0)).select().first()


 and then my link in sqlform:

 links = [lambda row: A('Details',_href=URL('default','equipment', 
 args=[row.slug]))]





-- 





Re: [web2py] New version of bootstrap

2012-08-22 Thread Limedrop
Bootstrap would now seem to provide sufficient support for web2py menus:

- Submenu support on dropdowns.
- Disabled states on navs and dropdowns.

And the Affix JavaScript plugin is cool.

On Wednesday, August 22, 2012 11:27:03 PM UTC+12, Khalil KHAMLICHI wrote:

 Awesome!

 On Wed, Aug 22, 2012 at 11:10 AM, Alec Taylor 
 alec.t...@gmail.comjavascript:
  wrote:

 There's a new version of bootstrap available.

 Might be worth upgrading: https://github.com/web2py/web2py/pull/27

 --






-- 





[web2py] Re: LEFT JOIN query issues

2012-08-02 Thread Limedrop
This gets me every now and then...

In python it should be == rather than =

  left=db.mr_link.on(db.mr_link.recipID==db.recipient.id))


On Friday, August 3, 2012 8:08:38 AM UTC+12, Larry Wapnitsky wrote:

 I'm trying to take the following MySQL query

 SELECT recipient.emailAddress
 FROM recipient
 LEFT JOIN mr_link ON recipient.id = mr_link.recipID



 and turn it into a DAL query, but I keep running into 'keyword' issues

 My code is as such:

 rows = db().select(db.recipient.emailAddress, db.mr_link.ALL, left=db.
 mr_link.on(db.mr_link.recipID=db.recipient.id))

 but I keep receiving

 type 'exceptions.SyntaxError' keyword can't be an expression 
 (default.py, line 25)

 Assistance in solving this would be very helpful

 Thanks




-- 





[web2py] Re: Generating pdf using web2py-appreport (xhtmltopdf) in Python Web2py webapp

2012-07-09 Thread Limedrop
Hi Akash,

Your example controller code seems good and shouldwork.  The issue is that 
PISA is a bit sensitive and only supports a reduced subset of CSS.  The 
error suggests PISA does not know how to handle Alpha(Opacity=0).  You 
will need to somehow strip out the unsupported CSS from the html before it 
is rendered by REPORTPISA.  Note that images are also problematic (you will 
need PIL installed if you want anything other than JPG and even then they 
are rendered in separate paragraphs), so you might need to play with this 
too.

Cheers
Russell


On Saturday, July 7, 2012 5:40:29 PM UTC+12, Akash Kakkar wrote:

 *
 *

 I am from a non coding background so python, web2py is very new to me. I 
 am trying to send html content using json and then use that in controller 
 to generate pdf. If I am able to send json data and then use it in 
 controller function, i should be able to get the pdf. More details below. I 
 am missing out on correct json syntax , encoding and decoding.

 My app needs to export textarea content (using RTE redactor) to pdf. I get 
 html content from textarea (redactor), can you please advice me on how to 
 use pyfpdf to generate a pdf file on button click.

 I don't know how to get the html content (images and text) on button click 
 in view to generate pdf using appreport.

 I was able to use app-report to generate a pdf (using PISA, PYPDF does not 
 work) from an existing html file (without css) if html file has css it 
 throws an error,

 ***class 'sx.w3c.cssParser.CSSParseError' Terminal function expression 
 expected closing ')':: (u'Alpha(Opacity', u'=0); }\n\n\n\n.ui-state-')***

 This might be due to a mistake in the controller code:

 def myreport():
 html = response.render('myreport.html', dict())
 return plugin_appreport.REPORTPISA(html = html)

 --

 Another thing I tried was passing the html from my view to the controller 
 using ajax post (in Javascript). Redactor is the textarea RTE I am using 
 and alert gives me the desired html result.

 View:

 function getContent() {
 var t= jQuery('#redactor_content').getCode();
 alert(t);
 jQuery.ajax({ 
 type: POST, 
 url: http://127.0.0.1:8000/Test50/default/myreport2;, 
 data: {g : 'jQuery('#redactor_content').getCode()'} 

 }); 
  }

 Controller:

 def myreport2():
 g = request.get_vars
 html = response.render(g)
 return plugin_appreport.REPORTPISA(html = html)

 Due to my less knowledge in coding , I am not able to figure out and 
 correct my mistake. I will be thankful if anybody can help me with this 
 problem.

 Regards, Akash



[web2py] Re: How to Save Query in Session

2012-03-29 Thread Limedrop
What do you think about adding a serialization function to gluon.dal.Query? 
Eg, Query._as_dict()
We could also get the framework to automatically invoke it when saving a 
Query/Expression to session.

On Thursday, March 29, 2012 12:58:41 PM UTC+13, Massimo Di Pierro wrote:

 Let me know if you have a proposal to imporve the dal to make this easier.

 On Wednesday, 28 March 2012 17:29:49 UTC-5, Limedrop wrote:

 Sometimes that will be sufficient.  The issue is how you turn _lastsql 
 into a gluon.dal object that you can further manipulate.  

 For example, what if you want to do this:

 _lastsql  (db.person.name == 'John') 

 See the slice if you need to know how to do it.


 On Thursday, March 29, 2012 5:59:23 AM UTC+13, Cliff wrote:

 Doesn't db._lastsql return a string?  Can't you just save that in the 
 session?

 Or is that a naive question?




[web2py] Re: Storing class instances in sessions... or somewhere

2012-03-29 Thread Limedrop
If instances are pickable then you should be okay.  Have you tried saving 
them to the session and seeing what happens?  Note that sometimes you can 
pickle things okay but the unpickle throws the error.

Failing that have a look at the recipe near the bottom of this thread...
http://bytes.com/topic/python/answers/552476-why-cant-you-pickle-instancemethods

BTW, that's no good for web2py classes, which don't pickle because they are 
db connections.


On Friday, March 30, 2012 12:21:37 PM UTC+13, Web2py Newbie wrote:

 I have an existing application that I am trying to get running as AJAX 
 with web2py (locally, but eventually to run on GAE).  The application makes 
 use of class instances to store much of the data which would be used for 
 user sessions.  I understand that session can't be used to store class 
 instances but for the time being I want to keep the instances for each 
 session (about 200K of data).   Sooner or later I guess I will need to save 
 this data in the data store, but at the moment I'm trying to get a 
 prototype up and running and reworking the code to get the data into/out of 
 a database is more pain than I can face atm.   The instances are pickleable 
 (well, cPickle doesn't complain)

 My options seem to be:
 * cache in ram using the session id as a key and
 * dumping the instance to a string, saving the string to session  (on GAE 
 will this be the same as cache.ram?)

 Are there other approaches?  What's the best way to go about this?

 Also, in the next update of the documentation, this would be a useful 
 detail to include on the session related sections.

 Thanks in advance

 Brendan 



[web2py] Re: Storing class instances in sessions... or somewhere

2012-03-29 Thread Limedrop
M.  Picking might not be the issue.  I would try to take javascript out 
of the equation first.  What if you simulated the javascript in a second 
server-side controller?  See if it can retrieve, update and save the 
session?

On Friday, March 30, 2012 3:07:59 PM UTC+13, Web2py Newbie wrote:

 On Friday, 30 March 2012 12:04:05 UTC+11, Limedrop wrote:

 If instances are pickable then you should be okay.  Have you tried saving 
 them to the session and seeing what happens?  Note that sometimes you can 
 pickle things okay but the unpickle throws the error.

  Have you tried saving them to the session and seeing what happens? 

 I have - weird stuff happens.  The class I have been testing is supposed 
 to accumulate elements like a set.  The first one I add (in the controller 
 for the view for debugging) gets stored in the instance fine, and it seems 
 to persist when I save the instance to session.  However, when I add other 
 elements (in a separate function called by the javascript) to that instance 
 they get added while in the function, but don't seem to persist in the 
 object saved in the session.   

 It is like the instance is a local variable initialised from what is first 
 stored by the controller.  I can modify the original instance like it is a 
 local variable, but changes don't stay there to the next call. 

  

 Failing that have a look at the recipe near the bottom of this thread...

 http://bytes.com/topic/python/answers/552476-why-cant-you-pickle-instancemethods

 BTW, that's no good for web2py classes, which don't pickle because they 
 are db connections


 thanks for the link I will try to decipher it.  



[web2py] Re: How to Save Query in Session

2012-03-28 Thread Limedrop
Sometimes that will be sufficient.  The issue is how you turn _lastsql into 
a gluon.dal object that you can further manipulate.  

For example, what if you want to do this:

_lastsql  (db.person.name == 'John') 

See the slice if you need to know how to do it.


On Thursday, March 29, 2012 5:59:23 AM UTC+13, Cliff wrote:

 Doesn't db._lastsql return a string?  Can't you just save that in the 
 session?

 Or is that a naive question?




Re: [web2py] Re: Single error message for radio group

2012-03-28 Thread Limedrop
I've got the same issue (running 1.99.7).  Has anyone solved this?

On Sunday, February 26, 2012 6:12:41 PM UTC+13, Detectedstealth wrote:

 Hi Massimo,

 Your suggestion doesn't seem to be working: 
 LI(
 H5(self.T('What is your Age?')),
 INPUT( _type='radio', _name='age', _value='1', 
 _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing your 
 age')), value=self.request.vars['age']),
 LABEL(SPAN(self.T('Less than 20')), _for='age1'),
 INPUT( _type='radio', _name='age', 
 _value='2',_id='age2', hideerror=True, value=self.request.vars['age']), 
 LABEL(SPAN(self.T('20-35')), _for='age2'),
 INPUT( _type='radio', _name='age', _value='3', 
 _id='age3', hideerror=True, value=self.request.vars['age']), 
 LABEL(SPAN(self.T('35-50')), _for='age3'),
 INPUT( _type='radio', _name='age', _value='4', 
 _id='age4', hideerror=True, value=self.request.vars['age']),
 LABEL(SPAN(self.T('50-65')), _for='age4'),
 INPUT( _type='radio', _name='age', _value='5', 
 _id='age5', hideerror=True, value=self.request.vars['age']), 
 LABEL(SPAN(self.T('65 and never too old')), 
 _for='age5'),
 ),
 I still get an error on all radio fields.

 --
 Regards,
 Bruce
 On Sun, Feb 12, 2012 at 6:00 PM, Bruce Wade bruce.w...@gmail.com wrote:

 Thanks.


 On Sun, Feb 12, 2012 at 5:57 PM, Massimo Di Pierro 
 massimo.dipie...@gmail.com wrote:

 INPUT(,hideerror=True)

 On Feb 12, 6:33 pm, Bruce Wade bruce.w...@gmail.com wrote:
  Hi,
 
  Is it possible to show a single error message for a group of radio 
 buttons.
  See screen shot
 
  FORM(
  FIELDSET(
  H4(self.T('Personal Questions')),
  UL(
  LI(
  H5(self.T('What is your Age?')),
  INPUT( _type='radio', _name='age', _value='1',
  _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing your
  age'))),
  LABEL(SPAN(self.T('Less than 20')), 
 _for='age1'),
  INPUT( _type='radio', _name='age',
  _value='2',_id='age2'),
  LABEL(SPAN(self.T('20-35')), _for='age2'),
  INPUT( _type='radio', _name='age', _value='3',
  _id='age3'),
  LABEL(SPAN(self.T('35-50')), _for='age3'),
  INPUT( _type='radio', _name='age', _value='4',
  _id='age4'), LABEL(SPAN(self.T('50-65')), _for='age4'),
  INPUT( _type='radio', _name='age', _value='5',
  _id='age5'), LABEL(SPAN(self.T('65 and never too old')), _for='age5'),
  ),
 ),
 )
  )
 
  --
  --
  Regards,
  Bruce Wadehttp://
 ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com
 
   fit_errors.png
  371KViewDownload




 -- 
 -- 
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.fitnessfriendsfinder.com




 -- 
 -- 
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.fitnessfriendsfinder.com
  


Re: [web2py] Re: Single error message for radio group

2012-03-28 Thread Limedrop
Yes, tested and it now works!  Thanks Massimo.

On Thursday, March 29, 2012 3:01:41 PM UTC+13, Massimo Di Pierro wrote:

 I think there is a bug and I think I just fixed it in trunk. Please check 
 it.

 On Wednesday, 28 March 2012 20:38:08 UTC-5, Limedrop wrote:

 I've got the same issue (running 1.99.7).  Has anyone solved this?

 On Sunday, February 26, 2012 6:12:41 PM UTC+13, Detectedstealth wrote:

 Hi Massimo,

 Your suggestion doesn't seem to be working: 
 LI(
 H5(self.T('What is your Age?')),
 INPUT( _type='radio', _name='age', _value='1', 
 _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing your 
 age')), value=self.request.vars['age']),
 LABEL(SPAN(self.T('Less than 20')), _for='age1'),
 INPUT( _type='radio', _name='age', 
 _value='2',_id='age2', hideerror=True, value=self.request.vars['age']), 
 LABEL(SPAN(self.T('20-35')), _for='age2'),
 INPUT( _type='radio', _name='age', _value='3', 
 _id='age3', hideerror=True, value=self.request.vars['age']), 
 LABEL(SPAN(self.T('35-50')), _for='age3'),
 INPUT( _type='radio', _name='age', _value='4', 
 _id='age4', hideerror=True, value=self.request.vars['age']),
 LABEL(SPAN(self.T('50-65')), _for='age4'),
 INPUT( _type='radio', _name='age', _value='5', 
 _id='age5', hideerror=True, value=self.request.vars['age']), 
 LABEL(SPAN(self.T('65 and never too old')), 
 _for='age5'),
 ),
 I still get an error on all radio fields.

 --
 Regards,
 Bruce
 On Sun, Feb 12, 2012 at 6:00 PM, Bruce Wade bruce.w...@gmail.comwrote:

 Thanks.


 On Sun, Feb 12, 2012 at 5:57 PM, Massimo Di Pierro 
 massimo.dipie...@gmail.com wrote:

 INPUT(,hideerror=True)

 On Feb 12, 6:33 pm, Bruce Wade bruce.w...@gmail.com wrote:
  Hi,
 
  Is it possible to show a single error message for a group of radio 
 buttons.
  See screen shot
 
  FORM(
  FIELDSET(
  H4(self.T('Personal Questions')),
  UL(
  LI(
  H5(self.T('What is your Age?')),
  INPUT( _type='radio', _name='age', 
 _value='1',
  _id='age1', requires = IS_NOT_EMPTY(error_message=self.T('missing 
 your
  age'))),
  LABEL(SPAN(self.T('Less than 20')), 
 _for='age1'),
  INPUT( _type='radio', _name='age',
  _value='2',_id='age2'),
  LABEL(SPAN(self.T('20-35')), _for='age2'),
  INPUT( _type='radio', _name='age', 
 _value='3',
  _id='age3'),
  LABEL(SPAN(self.T('35-50')), _for='age3'),
  INPUT( _type='radio', _name='age', 
 _value='4',
  _id='age4'), LABEL(SPAN(self.T('50-65')), _for='age4'),
  INPUT( _type='radio', _name='age', 
 _value='5',
  _id='age5'), LABEL(SPAN(self.T('65 and never too old')), 
 _for='age5'),
  ),
 ),
 )
  )
 
  --
  --
  Regards,
  Bruce Wadehttp://
 ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com
 
   fit_errors.png
  371KViewDownload




 -- 
 -- 
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.fitnessfriendsfinder.com




 -- 
 -- 
 Regards,
 Bruce Wade
 http://ca.linkedin.com/in/brucelwade
 http://www.wadecybertech.com
 http://www.warplydesigned.com
 http://www.fitnessfriendsfinder.com
  


Re: [web2py] Re: Single error message for radio group

2012-03-28 Thread Limedrop
Thanks.  In my case default=None (and needs to be), so thankfully Massimo's 
fix does the trick.

On Thursday, March 29, 2012 3:27:40 PM UTC+13, Detectedstealth wrote:

 The solution I made was setting a default value for all my radio groups. 




[web2py] Re: Bug? The DAL gives different SQL when query is provided as string.

2012-03-26 Thread Limedrop
Hi Niphlod,

Thanks for your reply.  I'm running 1.99.7 and here's the model:

db.define_table('webpage',
Field('title'),
Field('body', 'text'))

db.define_table('comment',
Field('page_id', db.webpage),
Field('body', 'text'))

The issue is when you have an implicit inner join, but where you only
want one table in the output.
I've found a thread where Massimo says that support for stings in
queries is clanky and that
you need a db(db.table) or db(db.table.field) to determine which table
is needed.
http://groups.google.com/group/web2py/browse_thread/thread/2024f660a8981558/d4b0e90d701833bb

So I guess it isn't supported?


On Mar 27, 12:15 am, Niphlod niph...@gmail.com wrote:
 damn mobile phone screen
 I got it, seems a simple join, and for my simple model works without a
 hitch.

 can you please post your model and tell what web2py version are you running
 ?

 Il giorno lunedì 26 marzo 2012 01:58:31 UTC+2, Limedrop ha scritto:









  The difference is in the FROM clause.  In the second SQL the webpage
  table is missing.

  On Mar 26, 12:51 pm, Niphlod niph...@gmail.com wrote:
   is that because of the extra () ?
   every time you call db() the where clause gets encapsulated in a pair
  of
   parenthesis.

   db(db.auth_user.id0)(db.auth_​user.email==localhost)

   and

   db((db.auth_user.id0)  (db.auth_user.email==​localhost))

   give you different raw strings, but the same exact result.

   Il giorno sabato 24 marzo 2012 21:49:58 UTC+1, Limedrop ha scritto:

I've copied this from the bottom of another thread.

The DAL gives different SQL when a query is provided in string format.
Is this a bug, or should I not expect this to work?

See the example below, the first SQL works, the second SQL raises an
error.

from gluon.dal import Query
query = (db.comment.id  0)  (db.webpage.title == 'FAQ') 
(db.comment.page_id == db.webpage.id)
query_as_string = str(query)
query_from_string = Query(db, query_as_string)
print db(query)._select(db.comment.​​body)

SELECT  comment.body FROM comment, webpage WHERE (((comment.id  0)
AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id));

print db(query_from_string)._select(​​db.comment.body)

SELECT  comment.body FROM comment WHERE comment.id  0) AND
(webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)));

Why do this?  If the were possible it would enable you to easily save
a query in the session.  For example:

==Controller 1==
query1 = (db.comment.id  0)  (db.webpage.title == 'FAQ') 
(db.comment.page_id == db.webpage.id)
session.query = str(query1)

==Controller 2==
from gluon.dal import Query
query2 = Query(db, session.query)

This does NOT work because the DAL gives different SQL for query1 and
query2.


[web2py] How to Save Query in Session

2012-03-26 Thread Limedrop
Just in case any of you want to do this...I've written a routine that
enables you to save a Query/Expression object in the session.

I have a controller that uses a form to build a relatively complex
query and I want other controllers to use that query to generate
reports and graphs.  I initially explored saving the query in the
session as a string, but it just wasn't working for me so I bit the
bullet and wrote a seralization routine that takes a Query object and
extracts it into a dictionary strucuture.  There's another function
that does the reverse.

It's all here in this slice:
http://www.web2pyslices.com/slice/show/1489/save-query-in-session

It needs more testing for edge cases (I just don't know enough about
the DAL to do all of that).  I've written it as a module, but
ultimately it would be nice to have something like it as a method
within the gluon.dal.Query class itself?  Better yet, get the
framework to automatically invoke it when saving a Query/Expression to
session (like it does for rows).


[web2py] Re: How to Save Query in Session

2012-03-26 Thread Limedrop
Huh? I'm sorry but I don't understand.

On Mar 27, 4:28 pm, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 you cannot.







 On Monday, 26 March 2012 21:09:49 UTC-5, Limedrop wrote:

  Just in case any of you want to do this...I've written a routine that
  enables you to save a Query/Expression object in the session.

  I have a controller that uses a form to build a relatively complex
  query and I want other controllers to use that query to generate
  reports and graphs.  I initially explored saving the query in the
  session as a string, but it just wasn't working for me so I bit the
  bullet and wrote a seralization routine that takes a Query object and
  extracts it into a dictionary strucuture.  There's another function
  that does the reverse.

  It's all here in this slice:
 http://www.web2pyslices.com/slice/show/1489/save-query-in-session

  It needs more testing for edge cases (I just don't know enough about
  the DAL to do all of that).  I've written it as a module, but
  ultimately it would be nice to have something like it as a method
  within the gluon.dal.Query class itself?  Better yet, get the
  framework to automatically invoke it when saving a Query/Expression to
  session (like it does for rows).


[web2py] Re: Bug? The DAL gives different SQL when query is provided as string.

2012-03-25 Thread Limedrop
The difference is in the FROM clause.  In the second SQL the webpage
table is missing.

On Mar 26, 12:51 pm, Niphlod niph...@gmail.com wrote:
 is that because of the extra () ?
 every time you call db() the where clause gets encapsulated in a pair of
 parenthesis.

 db(db.auth_user.id0)(db.auth_user.email==localhost)

 and

 db((db.auth_user.id0)  (db.auth_user.email==localhost))

 give you different raw strings, but the same exact result.

 Il giorno sabato 24 marzo 2012 21:49:58 UTC+1, Limedrop ha scritto:









  I've copied this from the bottom of another thread.

  The DAL gives different SQL when a query is provided in string format.
  Is this a bug, or should I not expect this to work?

  See the example below, the first SQL works, the second SQL raises an
  error.

  from gluon.dal import Query
  query = (db.comment.id  0)  (db.webpage.title == 'FAQ') 
  (db.comment.page_id == db.webpage.id)
  query_as_string = str(query)
  query_from_string = Query(db, query_as_string)
  print db(query)._select(db.comment.​body)

  SELECT  comment.body FROM comment, webpage WHERE (((comment.id  0)
  AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id));

  print db(query_from_string)._select(​db.comment.body)

  SELECT  comment.body FROM comment WHERE comment.id  0) AND
  (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)));

  Why do this?  If the were possible it would enable you to easily save
  a query in the session.  For example:

  ==Controller 1==
  query1 = (db.comment.id  0)  (db.webpage.title == 'FAQ') 
  (db.comment.page_id == db.webpage.id)
  session.query = str(query1)

  ==Controller 2==
  from gluon.dal import Query
  query2 = Query(db, session.query)

  This does NOT work because the DAL gives different SQL for query1 and
  query2.


[web2py] Bug? The DAL gives different SQL when query is provided as string.

2012-03-24 Thread Limedrop
I've copied this from the bottom of another thread.


The DAL gives different SQL when a query is provided in string format.
Is this a bug, or should I not expect this to work?


See the example below, the first SQL works, the second SQL raises an
error.


from gluon.dal import Query
query = (db.comment.id  0)  (db.webpage.title == 'FAQ')  
(db.comment.page_id == db.webpage.id)
query_as_string = str(query)
query_from_string = Query(db, query_as_string)
print db(query)._select(db.comment.body)

SELECT  comment.body FROM comment, webpage WHERE (((comment.id  0)
AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id));


print db(query_from_string)._select(db.comment.body)

SELECT  comment.body FROM comment WHERE comment.id  0) AND
(webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)));



Why do this?  If the were possible it would enable you to easily save
a query in the session.  For example:

==Controller 1==
query1 = (db.comment.id  0)  (db.webpage.title == 'FAQ') 
(db.comment.page_id == db.webpage.id)
session.query = str(query1)

==Controller 2==
from gluon.dal import Query
query2 = Query(db, session.query)


This does NOT work because the DAL gives different SQL for query1 and
query2.


[web2py] Re: missing FROM-clause entry

2012-03-23 Thread Limedrop
Thanks for your suggestion...it pointed me in the right direction.

It turns out the issue is not with the query construction, but that
DAL handles string input differently to objects.  What I am trying to
do is take a Query and then convert it to a string so it can be saved
in the session.  The string can then be pulled from the session and
converted back into a Query.  This works for simple queries, but not
for queries with implicit joins.  See the difference:


from gluon.dal import Query
query = (db.comment.id  0)  (db.webpage.title == 'FAQ')  
(db.comment.page_id == db.webpage.id)
query_as_string = str(query)
query_from_string = Query(db, query_as_string)
db(query)._select(db.comment.body)
SELECT  comment.body FROM comment, webpage WHERE (((comment.id  0)
AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id));
db(query_from_string)._select(db.comment.body)
SELECT  comment.body FROM comment WHERE comment.id  0) AND
(webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)));

Does anyone know how to convert a Query to a string (so it can be
saved in the session) and then get it back again?


On Mar 24, 4:52 am, Wikus van de Merwe dupakrop...@googlemail.com
wrote:
 Just a blind guess but does this work any better?
 query = (comment.id  0)  (webpage.title == 'FAQ')  (comment.page_id ==
 webpage.id)  (comment.id == comment_tags.comment_id)  (tag.id ==
 comment_tags.tag_id)  (tag.label == 'Agree')
 db(query).select()


[web2py] Re: missing FROM-clause entry

2012-03-23 Thread Limedrop
Thanks for the information.  Unfortunately, in my case I really do
need to store the raw query in the session...and then convert it back
to a Query so I can then add a few more filters before the final
select(). Has anyone managed to store a representation of a query in
the session?

On Mar 24, 11:09 am, Anthony abasta...@gmail.com wrote:
 On Friday, March 23, 2012 5:36:28 PM UTC-4, monotasker wrote:

  I may be off target but I just recently noticed the .as_dict() method for
  rows objects. This converts the rows object to a regular dict (instead of a
  gluon storage object) which can be stored in session or cache (i.e., it's
  picklable). If you need the query (not the resulting rows object) to be
  stored this doesn't help, but if it works in your case to store the
  select() result this may actually be easier.

 There is also an .as_list() method, which converts to a list of
 dictionaries rather than a dictionary of dictionaries. You can also just
 store Rows objects directly in the session or cache -- the DAL defines a
 reduction function that calls the .as_list() method when a Rows object is
 pickled, so you don't have to call the method manually.

 Anthony


[web2py] Re: missing FROM-clause entry

2012-03-23 Thread Limedrop
An interesting suggestion...I can see how I could use it for some sort
of workaround.  What it would me is that I would have to use two
separate selects, when I was hoping you only do one.  Still it seems
to me that my initial approach is the correct one, and that the DAL
should be consistent in the way it generates SQL. Specifically:

==Controller 1==
query1 = (db.comment.id  0)  (db.webpage.title == 'FAQ') 
(db.comment.page_id == db.webpage.id)
session.query = str(query1)

==Controller 2==
from gluon.dal import Query
query2 = Query(db, session.query)

Should work, but does NOT work because the DAL gives different results
for query1 and query2.  Is this, then a bug?


On Mar 24, 3:28 pm, nick name i.like.privacy@gmail.com wrote:
 On Friday, March 23, 2012 10:09:07 PM UTC-4, Limedrop wrote:

  Thanks for the information.  Unfortunately, in my case I really do
  need to store the raw query in the session...and then convert it back
  to a Query so I can then add a few more filters before the final
  select(). Has anyone managed to store a representation of a query in
  the session?

 If you are using an SQL database, and the initial query is for a subset of
 records in a specific table, you might be able to use belongs, which can
 accept a query string; so:

 # compute complicated query; use _select instead of select
 sqlquery = db(table)(...)(...)._select(table.id)

 # store sqlquery in your string storage, etc; it is a string.
 #  e.g. put it in your session (but under no circumstance in a form/request
 # variable or a cookie - that would make your app vulnerable to SQL
 injection)

 # retrieve your sqlquery string from the secure storage

 # add additional conditions
 finalquery = db(table.id.belongs(sqlquery)  table.field1=='field1value')


[web2py] missing FROM-clause entry

2012-03-22 Thread Limedrop
Running Web2py 1.99.7 and using a model based on the wiki in the book
(http://web2py.com/books/default/chapter/29/3#A-wiki).  I want to
report a unique list of comments for a particular webpage, for a
particular tag (I've added a many-to-many tag table).  I use a form to
build a query, which ends up like this:

db_query = (comment.id  0) AND (webpage.title = 'FAQ')) AND
(comment.page_id = webpage.id)) AND (((comment.id =
comment_tags.comment_id) AND (tag.id = comment_tags.tag_id)) AND
(tag.label = 'Agree'

However, the select gives me an psycopg2.ProgrammingError: missing
FROM-clause entry because only one of the required tables has been
included in the SQL FROM clause:

db(db_query)._select(db.comment.body, distinct=True, orderby=db.comment.body)

SELECT DISTINCT comment.body FROM comment WHERE (comment.id  0)
AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)) AND
(((comment.id = comment_tags.comment_id) AND (tag.id =
comment_tags.tag_id)) AND (tag.label = 'Agree' ORDER BY
comment.body;


I can get rid of the error by including all the tables in the select,
but that gives me duplicates:

db(db_query)._select(db.comment.body, db.comment_tags.id, db.tag.id, 
db.webpage.id, distinct=True, orderby=db.comment.body)

SELECT DISTINCT comment.body, comment_tags.id, tag.id, webpage.id
FROM comment, comment_tags, tag, webpage WHERE (comment.id  0)
AND (webpage.title = 'FQA')) AND (comment.page_id = webpage.id)) AND
(((comment.id = comment_tags.comment_id) AND (tag.id =
comment_tags.tag_id)) AND (tag.label = 'Agree' ORDER BY
comment.body;

The SQL I want (which seems valid enough) is this:

SELECT DISTINCT comment.body FROM comment, comment_tags, tag, webpage
WHERE (comment.id  0) AND (webpage.title = 'FAQ')) AND
(comment.page_id = webpage.id)) AND (((comment.id =
comment_tags.comment_id) AND (tag.id = comment_tags.tag_id)) AND
(tag.label = 'Agree' ORDER BY comment.body;

How do I get the DAL to do this? What am I missing here?


[web2py] Re: transfer auth_group data with the app

2011-11-22 Thread Limedrop
Massimo's solution sure is cunning, but you might something like this
a bit more maintainable:

def install():
if db(db.auth_group.id  0).count() == 0:
db.auth_group.insert(role = 'edit')
db.auth_group.insert(role = 'moderate')
db.auth_group.insert(role = 'comment')
return

install()


On Nov 23, 11:28 am, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 yes because the file gets moved in a different folder after execution.
 It is a bit of a hack.
 We should think of a better way

 On Nov 22, 2:41 pm, petrasadi petras...@gmail.com wrote:



  thank you for this, but I have one more question: is this guarantied to
  execute only once (upon installation).- Hide quoted text -

 - Show quoted text -


[web2py] Re: lexical scanner

2011-11-09 Thread Limedrop
Sorry lucas, but I don't understand what you're trying to do.  Can you
explain further?

On Nov 9, 4:53 pm, lucas sjluk...@gmail.com wrote:
 ok, i have done so much using this really really cool technique.

 anyway, how do i pass a function reference to a global storage
 context so that the standard views that are stored under views are
 rendered properly, like in the above examples?

 lucas


[web2py] Re: lexical scanner

2011-11-09 Thread Limedrop
Okay, in that caseyou pass the function to the view as you would
any other variable.  For example:

return dict(form=form, rows=rows, file_lookup=file_lookup)


On Nov 10, 4:57 pm, lucas sjluk...@gmail.com wrote:
 yes, i wrote a function in main.py which is an added controller in my
 application.  under main.py, i have a function called file_lookup.  i
 am trying to use file_lookup in a view between the standard delimitors
 {{ and }}.  except that web2py is erroring out saying that file_lookup
 is not defined.  so i am thinking that i have to pass the function
 reference off to a global storage so that when web2py renders the
 view, it has a reference is file_lookup.  better?  lucas


[web2py] Re: SyntaxError: Set: no tables selected on select statement.

2011-11-07 Thread Limedrop
A couple of obvious thing.  First, the query goes with the db() not
the select().  Second, the reference to room is via room.id rather
than room.name.  So you could try:

reservations = db(db.reservation.room==room.id).select()


On Nov 8, 8:49 am, Matthew Young mab...@gmail.com wrote:
 Hello I am using the Version 1.99.3 (2011-11-07 17:41:19) dev version
 of web2py.

 I am having an issue with this view function:
 def check_room_availability():
     room = db.room(request.args(0)) or redirect(URL('view_rooms'))
     reservations = db().select(db.reservation.room.name==room.name)
     return dict(room=room, reservations=reservations)

 I get the following error when this page is viewed with a room number
 passed as an argument:
 Traceback (most recent call last):
   File /home/mattosaurus/web2py/gluon/restricted.py, line 194, in
 restricted
     in code it raises a RestrictedError containing the traceback.
 layer is
   File /home/mattosaurus/web2py/applications/roomReserve/controllers/
 default.py, line 121, in module
   File /home/mattosaurus/web2py/gluon/globals.py, line 149, in
 lambda
     self.files = []            # used by web2py_ajax.html
   File /home/mattosaurus/web2py/applications/roomReserve/controllers/
 default.py, line 85, in check_room_availability
     reservations = db().select(db.reservation.room.name==room.name)
   File /home/mattosaurus/web2py/gluon/dal.py, line 5697, in select
     db,
   File /home/mattosaurus/web2py/gluon/dal.py, line 1225, in select
     sql_t += ' %s %s' % (icommand, str(t))
   File /home/mattosaurus/web2py/gluon/dal.py, line 1128, in _select
     tablenames = self.tables(query)
 SyntaxError: Set: no tables selected

 My table definitions in db.py look like this:
 db.define_table('room',
     Field('name'),
     Field('description','text'),
     Field('location','text'),
     format='%(name)s')

 db.define_table('reservation',
     Field('room','references room'),
     Field('start_date','datetime'),
     Field('end_date','datetime'),
     Field('special_requirements','text'),
     Field('approved','boolean'),
     auth.signature)

 db.reservation.room.requires = IS_IN_DB(db,db.room.id,'%(name)s')
 db.room.name.requires = IS_NOT_EMPTY()
 db.room.description.requires = IS_NOT_EMPTY()
 db.room.location.requires = IS_NOT_EMPTY()
 db.reservation.start_date.requires = IS_NOT_EMPTY()
 db.reservation.end_date.requires = IS_NOT_EMPTY()

 Has anyone seen this error before? Is my select incorrect? I am
 finding the documentation a little confusing in this area.


[web2py] Re: SyntaxError: Set: no tables selected on select statement.

2011-11-07 Thread Limedrop
Well that's progress.  The error is somewhere in your view.

On Nov 8, 12:20 pm, Matthew Young mab...@gmail.com wrote:
 I get the following error with those changes:
 Traceback (most recent call last):
   File /home/mattosaurus/web2py/gluon/restricted.py, line 204, in
 restricted
     exec ccode in environment
   File /home/mattosaurus/web2py/applications/roomReserve/views/
 default/check_room_availability.html, line 84, in module
   File /home/mattosaurus/web2py/gluon/html.py, line 230, in URL
     function = f.__name__
 AttributeError: 'int' object has no attribute '__name__'

 On Nov 7, 2:39 pm, Limedrop russ...@holtrd.com wrote:



  A couple of obvious thing.  First, the query goes with the db() not
  the select().  Second, the reference to room is via room.id rather
  than room.name.  So you could try:

  reservations = db(db.reservation.room==room.id).select()

  On Nov 8, 8:49 am, Matthew Young mab...@gmail.com wrote:

   Hello I am using the Version 1.99.3 (2011-11-07 17:41:19) dev version
   of web2py.

   I am having an issue with this view function:
   def check_room_availability():
       room = db.room(request.args(0)) or redirect(URL('view_rooms'))
       reservations = db().select(db.reservation.room.name==room.name)
       return dict(room=room, reservations=reservations)

   I get the following error when this page is viewed with a room number
   passed as an argument:
   Traceback (most recent call last):
     File /home/mattosaurus/web2py/gluon/restricted.py, line 194, in
   restricted
       in code it raises a RestrictedError containing the traceback.
   layer is
     File /home/mattosaurus/web2py/applications/roomReserve/controllers/
   default.py, line 121, in module
     File /home/mattosaurus/web2py/gluon/globals.py, line 149, in
   lambda
       self.files = []            # used by web2py_ajax.html
     File /home/mattosaurus/web2py/applications/roomReserve/controllers/
   default.py, line 85, in check_room_availability
       reservations = db().select(db.reservation.room.name==room.name)
     File /home/mattosaurus/web2py/gluon/dal.py, line 5697, in select
       db,
     File /home/mattosaurus/web2py/gluon/dal.py, line 1225, in select
       sql_t += ' %s %s' % (icommand, str(t))
     File /home/mattosaurus/web2py/gluon/dal.py, line 1128, in _select
       tablenames = self.tables(query)
   SyntaxError: Set: no tables selected

   My table definitions in db.py look like this:
   db.define_table('room',
       Field('name'),
       Field('description','text'),
       Field('location','text'),
       format='%(name)s')

   db.define_table('reservation',
       Field('room','references room'),
       Field('start_date','datetime'),
       Field('end_date','datetime'),
       Field('special_requirements','text'),
       Field('approved','boolean'),
       auth.signature)

   db.reservation.room.requires = IS_IN_DB(db,db.room.id,'%(name)s')
   db.room.name.requires = IS_NOT_EMPTY()
   db.room.description.requires = IS_NOT_EMPTY()
   db.room.location.requires = IS_NOT_EMPTY()
   db.reservation.start_date.requires = IS_NOT_EMPTY()
   db.reservation.end_date.requires = IS_NOT_EMPTY()

   Has anyone seen this error before? Is my select incorrect? I am
   finding the documentation a little confusing in this area.- Hide quoted 
   text -

 - Show quoted text -


[web2py] Re: lexical scanner

2011-11-03 Thread Limedrop
if you use the web2py Storage class:

context = Storage()
context.auth = auth
render(content=content, context=context)


or in raw python:

context = {}
context['auth'] = auth
render(content=content, context=context)


On Nov 3, 8:43 pm, lucas sjluk...@gmail.com wrote:
 ok, something more complicated now.

 i have reference to auth in my text, for cross checking with
 permissions and stuff in an if statement.  how do i pass the auth
 pointer reference through to renderer so that when i use auth.* in the
 text it runs properly?

 thank you in advance.  lucas


[web2py] Re: lexical scanner

2011-11-01 Thread Limedrop
I think you want render.  For example:

from gluon.template import render
fields=Storage()
fields.first_name = John
content = Hello {{=first_name}}
rendered = render(content, context=fields)


On Nov 2, 9:02 am, lucas sjluk...@gmail.com wrote:
 ok, still stuck,

 i played with CODE(...) but that only displays the text in python or
 web2py syntax, it doesn't run it.  i tried exec(string), like in the
 web2py manual, under a function in index.py, but it failes to compile
 on that line saying invalid syntax.

 so i am still not sure, so how does view get processed and separated
 by html and python code and then the python code is interpreted and
 run as executable code?

 thank you in advance, lucas


[web2py] Re: nyroModal

2011-11-01 Thread Limedrop
This is what I do:

if form.accepts(request.vars, session):
return_script = ['parent.$.nyroModalRemove();']
return_script.append('parent.window.location.reload();')
return HTML(BODY(SCRIPT(''.join(return_script.xml()



On Nov 1, 8:19 pm, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 Hi,

 I'm using nyroModal to open a SQLFORM in a modal window. When I submit
 the form I want to the modal window to close and the parent window to
 refresh. Is this possible?

 Kenneth


[web2py] Re: lexical scanner

2011-11-01 Thread Limedrop
Render is the same function used to process the views.  So, as long as
you put all the variables in the namespace, your code will execute.
Something like this should work:

from gluon.template import render
context = Storage()
context.rows = rows
content = 
HTML
p
{{
for row in rows:
  ..something with rows..
for c in rows.colnames:
  ..something with colnames..
=A(some link text, =href=URL(index))

}}

/p
/HTML

rendered = render(content, context=context)



On Nov 2, 11:43 am, lucas sjluk...@gmail.com wrote:
 yes, but even more general then only fields, like you can have entire
 sections of blocked executable code in a view like

 HTML
 p
 {{
 for row in rows:
   ..something with rows..
 for c in rows.colnames:
   ..something with colnames..
 =A(some link text, =href=URL(index))}}

 /p
 /HTML

 that isn't so much a field as a big block of code, in a html/text
 file.  how do we get that to execute as python?  lucas


[web2py] Re: lexical scanner

2011-11-01 Thread Limedrop
Conceptually, this is the same as giving any module to access the
web2py helpers...you will need to make them available within the
namespace.  I did a quick test:

 content = {{from gluon.html import *}}{{=A('hello world')}}
 render(content=content)
'ahello world/a'

So it works!  Other things you might need are:

from gluon.http import *
from gluon.validators import *
from gluon.sqlhtml import *

As with the old local_import, if you want request, session, cache, T,
db(s) they will need to be passed in the context.  For example:

context.db = db
context.request = request

Hope that clarifies it for you.


On Nov 2, 3:25 pm, lucas sjluk...@gmail.com wrote:
 ok, i feel like i am on the right path, getting hot.  i have this
 sample code to break it down,

     q = iok dude, italic text./ibr /
     bthis is plain but bold text./bbr /
     {{=A('web2py code', _href=URL('http://fscj.edu'))}}
     from gluon.template import render
     from gluon.storage import Storage
     context = Storage()
     q4 = render(content=q, context=context)

 or more simpler

     q = iok dude, italic text./ibr /
     bthis is plain but bold text./bbr /
     {{=A('web2py code', _href=URL('http://fscj.edu'))}}
     from gluon.template import render
     q4 = render(content=q)

 i get the same error which ends in:

 File /opt/web-apps/web2py/gluon/template.py, line 916, in render
     exec(code) in context
   File string, line 2, in module
 NameError: name 'A' is not defined

 make sense?  suggestions, please?  lucas