[web2py] Re: Web2Py on GAE > very slow

2011-10-27 Thread Damjan Malis
Thanks, that would be much appreciated!

On Oct 27, 3:28 am, howesc  wrote:
> i will write something up for you soon


[web2py] AppReport using web2py view.

2011-10-27 Thread annet
In this thread: 
http://groups.google.com/group/web2py/browse_thread/thread/bb5abc07b692a554/
AppReport was mentioned. I downloaded the plugin and followed the
instructions in the Examples: 
https://github.com/lucasdavila/web2py-appreport/wiki/Docs-and-examples

This example results in an error:

def custom_report():
html = """





Author
Email
Twitter




Lucas Davila
lucass...@gmail.com
@lucadavila




"""

return plugin_appreport.REPORTPYFPDF(html = html, title = 'my
custom report using the plugin appreport')


Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py",
line 192, in restricted
exec ccode in environment
  File "/Library/Python/2.5/site-packages/web2py/applications/reports/
controllers/default.py", line 106, in 
  File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py",
line 145, in 
self._caller = lambda f: f()
  File "/Library/Python/2.5/site-packages/web2py/applications/reports/
controllers/default.py", line 51, in custom_report
return plugin_appreport.REPORTPYFPDF(html = html, title = 'my
custom report using the plugin appreport')
  File "/Library/Python/2.5/site-packages/web2py/applications/reports/
models/plugin_appreport.py", line 109, in REPORTPYFPDF
pdf_builder =
plugin_appreport_module.libs.appreport.pdf_builder.PdfBuilderPyfpdf(report
= self._get_report_instance(kargs))
AttributeError: PluginAppreport instance has no attribute
'_get_report_instance'


How would I use App Report when these are my function and view:


Controller:

def classtimesweek():
 
rows=db((db.lesrooster.bedrijf_id==1)&(db.lesrooster.dag_id==db.dag.id)&(db.lesrooster.level_id==db.level.id)).select(db.lesrooster.ALL,db.dag.dag,db.level.level,orderby=db.lesrooster.dag_id|
db.lesrooster.tijd)
return dict(rows=rows)

View:


  
...
  
  
...
  




Kind regards,

Annet


Re: [web2py] Dealing with arbitary user defined DAL fields

2011-10-27 Thread seongjoo

>
> A slight twist of my version is to use {"key": "value"} instead of "key: 
> value". The thought was to convert the string into dictionary-like datatype 
> more easily. 
>

Using {"key": "value"} format, the element of the field that has 
list:string type stores it as "{"key": "value"}". The problem is that an 
additional escape character proceeds the existing one when the key is 
non-ascii encoded as UTF-8. So the value becomes \\xab\\xcd\\xef instead of 
\xab\xcd\xef.

I need some help to figure out to avoid the additional escape character 
added in front of the existing one so the value is correctly stored.


[web2py] Re: AppReport using web2py view.

2011-10-27 Thread Paolo Caruccio
I have done it this way (code abstract not tested):

### model

db.define_table('t_persons',
Field('f_surname', type='string', notnull=True, label=T('Surname'), 
length=32),
Field('f_name', type='string', notnull=True, label=T('Name'), length=32),
)

### controller

def myreport():
persons = db(db.t_persons.id > 0).select()
logourl = URL('static','images/mylogo.jpg',host=True)
html = response.render('resources/myreport.html', dict(persons = persons, 
tdy=date.today(), logo=logourl))
return plugin_appreport.REPORTPISA(html = html)

### view myreport.html





@page {
margin: 1cm;
margin-bottom:2.5cm;
@frame footer {
-pdf-frame-content: footerContent;
/*-pdf-frame-border: 1;*/
bottom: 0cm;
margin-left: 1cm;
margin-right: 1cm;
height: 1cm;
}
}
h2 {font-width:bold;text-align:center;}
tr td{}
.section{border:1px solid #000;font-weight:bold;padding:4px 6px 0;}
.label{width:45%;}
.data{width:54%;}




Titolo
 


 
 
 



{{for p in persons:}}

 


SECTION TITLE
 


 


Surname
{{=p.f_surname}}
 


Given Name
{{=p.f_name}}
 

{{pass}}



page # printed on {{=tdy}}



### in view print_report.html

{{=A(SPAN(T('print report'), _class='printer_ico'), _href=URL('myreport'), 
_class="button")}}


Let me know if this works.

Ciao,

Paolo


[web2py] Offer a file for download, not from a request?

2011-10-27 Thread $p00ky
Dear all,

Is it possible to offer a file for downloading in web2py?

theFile = tempfile.NamedTemporaryFile()
with open(theFile.name, "wb") as myFile:
myFile.write("something")
return response.download(request, theFile)

For instance, when a user goes to "mysite.com/myapp/default/download/text", 
I return a file with "text" written in it.
I would like to use a tempfile for that.

There is no "request" here, so "return response.download(request, theFile)" 
does not work.
Any suggestion?


Re: [web2py] Dealing with arbitary user defined DAL fields

2011-10-27 Thread seongjoo
It seems that the problem is more of general python problem than of web2py.

Before using string:list type field to store user-defined field, I didn't 
experience having dict key values as non-ascii. Because of the new problem 
definition, I did experience it and learned something new.

For just clearing the problem out of web2py: The problem of extra escape 
character added can be reproduced as below.

>>> a_dict = { '\xec\x9d' : '\xed\x95' }

>>> str(a_dict)
"{ '\\xec\\x9d' : '\xed\\x95' }"



[web2py] Re: AppReport using web2py view.

2011-10-27 Thread annet
Hi Paolo,

Thanks for your reply, the code you provided works, I'll convert it
into my own app, hope that works too.


Kind regards,

Annet.


Re: [web2py] Re: sqlform.grid

2011-10-27 Thread Johann Spies
On 26 October 2011 21:20, peter  wrote:

>
>
> Adding in the css for grid actually spoilt things. I have managed to
> get a good looking grid for CDs with graphics using smartform.grid,
>

How did you get wrapping of the text in the 'Description' column in your
your grid (if http://ukjazz.net/store/albums is what you refer to)?

Regards
Johann

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


Re: [web2py] Re: SQLFORM.grid awesomeness and some questions

2011-10-27 Thread Johann Spies
On 26 October 2011 19:15, Cliff  wrote:

> So you need a column on the right for an "Add to Cart" button.
>
>

I have previously asked about custom edit buttons and this was the answer
(which works):

*links = [lambda row: A('Edit',_href=URL("controller","edit",
args=["update", tablename, a.id]))
and set editable, deletable, details  to False. **

**If you use jqueryui then the links are rendered as buttons

*The buttons created this way each appears in an extra column.

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


[web2py] Re: Offer a file for download, not from a request?

2011-10-27 Thread Anthony
There is a request in that case, it's just that response.download is 
expecting (a) the last argument in the URL to be the name of a file, and 
(b) its second argument to be a db object. In this case, instead of 
response.download, use response.stream(file, chunk_size, request). 
See http://web2py.com/book/default/chapter/04#response.

Anthony

On Thursday, October 27, 2011 6:21:16 AM UTC-4, $p00ky wrote:
>
> Dear all,
>
> Is it possible to offer a file for downloading in web2py?
>
> theFile = tempfile.NamedTemporaryFile()
> with open(theFile.name, "wb") as myFile:
> myFile.write("something")
> return response.download(request, theFile)
>
> For instance, when a user goes to "mysite.com/myapp/default/download/text", 
> I return a file with "text" written in it.
> I would like to use a tempfile for that.
>
> There is no "request" here, so "return response.download(request, 
> theFile)" does not work.
> Any suggestion?
>


[web2py] Re: Offer a file for download, not from a request?

2011-10-27 Thread $p00ky
Cheers,

Working code:
response.headers['Content-Type'] = "application/octet-stream"
response.headers['Content-Disposition'] = 'attachment; filename=%s' % 
filename
return content


[web2py] Multiple browser tabs and session

2011-10-27 Thread Cliff
What is the Web2py way of making session variables unique to one
browser tab?  This example illustrates the problem.

Model:
db.define_table('products', Field('quantity_on_hand', 'integer'))
db.define_table('jobs', Field('job_yield', 'integer'),
Field('product_id', db.products))

When a user updates the job_yield field, the jobs controller also
needs to update quantity on hand in the products table.  Usually one
would use a session variable something like this.

def edit():
# fetch current job yield
old_job_yield = db.jobs[request.vars(0)].job_yield
# save it in a session
session.old_job_yield= old_job_yield
...
if form.accepts(session,request):
  if request.post_vars.job_yield != session.old_job_yield:
   yield_delta = request.post_vars.job_yield -
session.old_job_yield
   # assume we magically fetch related product id, then
   old_quantity_on_hand =
db.products[product_id].quantity_on_hand
   new_quantity_on_hand = old_quantity_on_hand +
yield_delta
 
db(db.products.id==product_id).update(quantity_on_hand=new_quantity_on_hand)

The problem arises if the user edits a different job in a different
tab.  Because there is only one instance of session.old_job_yield, the
edit action in the other tab will overwrite it.

What is the Web2py way of handling this problem?

Thanks,
Cliff Kachinske



[web2py] Re: SSL Error

2011-10-27 Thread Ross Peoples
That is very odd. I have a production SSL site that I have been running for 
months without an issue. Even my development server (which runs trunk, but 
as of a week ago...haven't updated in a while) runs SSL only and it can run 
for weeks at a time.

I guess the usual questions apply: what version of web2py?

Also, I don't know if it matters, but with my command on the development 
server, I run with --no-cron (because I use the system's cron) and -l 
'/dev/null' to prevent logs from conflicting with other web2py instances 
that I run.

So my command looks like this:

python web2py.py -i 0.0.0.0 -a password -c my.crt -k my.key --no-cron -l 
'/dev/null'

I also run on Ubuntu Server 10.04 using the web2py trunk. So maybe this is 
a problem specific to the Rocket implementation on Windows? Or even the 
binary version of web2py?


Re: [web2py] Is it possible to compress the output html before rendering out?

2011-10-27 Thread Marco Tulio Cicero de M. Porto
like the uglifier on Ruby?

2011/10/21 Farsheed Ashouri 

> Is it possible to compress the output html before rendering out? I mean
> using tools like compressors or tiddy to clean/compress the output code
> automatically on output not on our source.
>
>


-- 
[]'s
Marco Tulio


Re: [web2py] Is it possible to compress the output html before rendering out?

2011-10-27 Thread Anthony
If you have a function that does the compressing, I suppose you could do 
something like:

def my_action():
[some code]
d = dict(...)
return compress_html(response.render(d))

Anthony

On Thursday, October 27, 2011 9:40:30 AM UTC-4, Marco Tulio wrote:
>
> like the uglifier on Ruby?
>
> 2011/10/21 Farsheed Ashouri 
>
>> Is it possible to compress the output html before rendering out? I mean
>> using tools like compressors or tiddy to clean/compress the output code
>> automatically on output not on our source.
>>
>>
>
>
> -- 
> []'s
> Marco Tulio
>


[web2py] trying to fix possible problem of migration...

2011-10-27 Thread Richard Vézina
Hello,

I suspect that I have a migration problem... There is some update function
that not working properly (not updating some fields and update others
correctly)...

I would like to know how to use correctly the migrate fake all at the DAL
level... In the book it says :

Migration problems can also be fixed for all tables at once:

1.

db = DAL 
(...,fake_migrate_all=True)


I would make sure if I can or not set the same way as de
fake_migrate_all=True, migrate=False or if I have to change all my table
(search/replace)??

Or says a other way can write this :


db = DAL(...,migrate=False, fake_migrate_all=True)


Thanks

Richard


Re: [web2py] trying to fix possible problem of migration...

2011-10-27 Thread Richard Vézina
Ok I just read a couple of lines above in book :

db = DAL(...,migrate_enabled=False)

Does it work in 1.98.2

Richard


On Thu, Oct 27, 2011 at 10:17 AM, Richard Vézina <
ml.richard.vez...@gmail.com> wrote:

> Hello,
>
> I suspect that I have a migration problem... There is some update function
> that not working properly (not updating some fields and update others
> correctly)...
>
> I would like to know how to use correctly the migrate fake all at the DAL
> level... In the book it says :
>
> Migration problems can also be fixed for all tables at once:
>
> 1.
>
> db = DAL 
> (...,fake_migrate_all=True)
>
>
> I would make sure if I can or not set the same way as de
> fake_migrate_all=True, migrate=False or if I have to change all my table
> (search/replace)??
>
> Or says a other way can write this :
>
>
> db = DAL(...,migrate=False, fake_migrate_all=True)
>
>
> Thanks
>
> Richard
>


Re: [web2py] trying to fix possible problem of migration...

2011-10-27 Thread Anthony
Since 1.95.1. See http://web2py.com/examples/default/changelog (which is 
accessible via the Download page).

Anthony

On Thursday, October 27, 2011 10:20:18 AM UTC-4, Richard wrote:
>
> Ok I just read a couple of lines above in book :
>
> db = DAL(...,migrate_enabled=False)
>
> Does it work in 1.98.2
>
> Richard
>
>
> On Thu, Oct 27, 2011 at 10:17 AM, Richard Vézina wrote:
>
>> Hello,
>>
>> I suspect that I have a migration problem... There is some update 
>> function that not working properly (not updating some fields and update 
>> others correctly)...
>>
>> I would like to know how to use correctly the migrate fake all at the DAL 
>> level... In the book it says :
>>
>> Migration problems can also be fixed for all tables at once:
>>  
>> 1.
>>
>> db = DAL 
>> (...,fake_migrate_all=True)
>>
>>
>> I would make sure if I can or not set the same way as de 
>> fake_migrate_all=True, migrate=False or if I have to change all my table 
>> (search/replace)??
>>
>> Or says a other way can write this :
>>
>>
>> db = DAL(...,migrate=False, fake_migrate_all=True)
>>
>>
>> Thanks 
>>
>> Richard
>>
>
>

Re: [web2py] Re: SSL Error

2011-10-27 Thread António Ramos
I´m using web2py 1.99.2 for windows

:(

2011/10/27 Ross Peoples 

> That is very odd. I have a production SSL site that I have been running for
> months without an issue. Even my development server (which runs trunk, but
> as of a week ago...haven't updated in a while) runs SSL only and it can run
> for weeks at a time.
>
> I guess the usual questions apply: what version of web2py?
>
> Also, I don't know if it matters, but with my command on the development
> server, I run with --no-cron (because I use the system's cron) and -l
> '/dev/null' to prevent logs from conflicting with other web2py instances
> that I run.
>
> So my command looks like this:
>
> python web2py.py -i 0.0.0.0 -a password -c my.crt -k my.key --no-cron -l
> '/dev/null'
>
> I also run on Ubuntu Server 10.04 using the web2py trunk. So maybe this is
> a problem specific to the Rocket implementation on Windows? Or even the
> binary version of web2py?
>


Re: [web2py] trying to fix possible problem of migration...

2011-10-27 Thread Richard Vézina
Thank you Anthony.

Richard

On Thu, Oct 27, 2011 at 10:24 AM, Anthony  wrote:

> Since 1.95.1. See http://web2py.com/examples/default/changelog (which is
> accessible via the Download page).
>
> Anthony
>
>
> On Thursday, October 27, 2011 10:20:18 AM UTC-4, Richard wrote:
>
>> Ok I just read a couple of lines above in book :
>>
>> db = DAL(...,migrate_enabled=False)
>>
>> Does it work in 1.98.2
>>
>> Richard
>>
>>
>> On Thu, Oct 27, 2011 at 10:17 AM, Richard Vézina 
>> wrote:
>>
>>> Hello,
>>>
>>> I suspect that I have a migration problem... There is some update
>>> function that not working properly (not updating some fields and update
>>> others correctly)...
>>>
>>> I would like to know how to use correctly the migrate fake all at the DAL
>>> level... In the book it says :
>>>
>>> Migration problems can also be fixed for all tables at once:
>>>
>>> 1.
>>>
>>> db = DAL 
>>> (...,fake_migrate_all=True)
>>>
>>>
>>> I would make sure if I can or not set the same way as de
>>> fake_migrate_all=True, migrate=False or if I have to change all my table
>>> (search/replace)??
>>>
>>> Or says a other way can write this :
>>>
>>>
>>> db = DAL(...,migrate=False, fake_migrate_all=True)
>>>
>>>
>>> Thanks
>>>
>>> Richard
>>>
>>
>>


Re: [web2py] Re: SSL Error

2011-10-27 Thread António Ramos
Also the same problem if i move my app to 1.982

The certficate was issued to apps.cires.pt but i´m acessing my app using the
ip and not the name

Can this be problem?



Em 27 de outubro de 2011 15:31, António Ramos escreveu:

> I´m using web2py 1.99.2 for windows
>
> :(
>
>
> 2011/10/27 Ross Peoples 
>
>> That is very odd. I have a production SSL site that I have been running
>> for months without an issue. Even my development server (which runs trunk,
>> but as of a week ago...haven't updated in a while) runs SSL only and it can
>> run for weeks at a time.
>>
>> I guess the usual questions apply: what version of web2py?
>>
>> Also, I don't know if it matters, but with my command on the development
>> server, I run with --no-cron (because I use the system's cron) and -l
>> '/dev/null' to prevent logs from conflicting with other web2py instances
>> that I run.
>>
>> So my command looks like this:
>>
>> python web2py.py -i 0.0.0.0 -a password -c my.crt -k my.key --no-cron -l
>> '/dev/null'
>>
>> I also run on Ubuntu Server 10.04 using the web2py trunk. So maybe this is
>> a problem specific to the Rocket implementation on Windows? Or even the
>> binary version of web2py?
>>
>
>


[web2py] Re: using lambda for represent a field - what I misunderstood?

2011-10-27 Thread TheSweetlink
Is there a reason for using represent to make redirection links?  You
may have an easier time creating redirection links with the A()
helper:

http://web2py.com/book/default/chapter/05?search=redirect

Apparently there is a new callback feature to the A helper which might
be helpful in your situation.

I couldn't tell you what's wrong without seeing more code.

Wish I could help more but one of the gurus will have a better "Why is
this so?" than I.

David

On Oct 26, 1:40 pm, Lazarof  wrote:
> ## The code ...
> from gluon.contrib.populate import populate
>
> db.define_table('product',
>     Field('field_n1'),
>     Field('field_n2'))
>
> if db(db.product).isempty():
>     populate(db.product, 17)
>
> some_function = 'function_n1'
> some_action = 'action_n1'
> some_table = 'table_n1'
> back_to = 'back_to_pt01'
> db.product.id.represent = lambda value,row: A('Ed',
> _href=URL(f=some_function, args=(some_action, some_table, back_to,
> value)))
>
> ## (1)
> ## when id=1 as a result I expect a link named Ed with href = '../app/
> default/function_n1/action_n1/table_n1/back_to_pt01/1'
>
> some_function = 'function_n2'
> some_action = 'action_n2'
> some_table = 'table_n2'
> back_to = 'back_to_pt02'
> db.product.field_n1.represent = lambda value,row: A(value,
> _href=URL(f=some_function, args=(some_action, some_table, back_to,
> row.id)))
>
> ## (2)
> ## when id=1 as a result I expect the content of field_n1 with href =
> '../app/default/function_n2/action_n2/table_n2/back_to_pt02/1'
>
> ## (3) and here is the question ...
> ## for both (1) and (2)
> ## I am geting href = '../app/default/function_n2/action_n2/table_n2/
> back_to_pt02/1'
> ## Is that correct?
>
> ## with this code I get what I am expecting
> ##xsome_function = 'function_n2'
> ##xsome_action = 'action_n2'
> ##xsome_table = 'table_n2'
> ##xback_to = 'back_to_pt02'
> ##db.product.field_n1.represent = lambda value,row: A(value,
> _href=URL(f=xsome_function, args=(xsome_action, xsome_table, xback_to,
> row.id)))
>
> Can someone switch on the light, please.
> Lazaro


[web2py] upload file to database using curl

2011-10-27 Thread thodoris
Hello,

I have been trying to find a way of how to upload a file in a database
using curl but i can't find any references. I have found a reference
that describes how to submit text  so i  guess that uploading a file
should possible as well. What i want to do is to upload a file from my
application that is written in C++ to the web server. I am new to
web2py so i would appreciate any advice.

Thodoris



[web2py] Re: Massimo Di Pierro talks about web2py on FLOSS Weekly

2011-10-27 Thread TheSweetlink
Very cool.  I especially enjoyed the tactful handling of web2py's
criticisms amongst the Python community as well as the fascinating
physics tangent.  M lattice quantum chromodynamics.

May this bring even more attention to web2py.

David

On Oct 26, 3:17 pm, Bruno Rocha  wrote:
> Massimo Di Pierro talks about web2py on FLOSS Weekly
>
> AUDIO:http://twit.cachefly.net/floss0188.mp3
>
> VIDEO:http://twit.tv/show/floss-weekly/188
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]


[web2py] Re: using lambda for represent a field - what I misunderstood?

2011-10-27 Thread Anthony
The lambda functions don't get called until the your data are actually 
rendered, which happens after the second set of assignments to 
some_function, some_action, etc. -- so both lambda functions end up using 
the same (second) set of values for those variables.

Anthony

On Wednesday, October 26, 2011 1:40:02 PM UTC-4, Lazarof wrote:
>
> ## The code ... 
> from gluon.contrib.populate import populate 
>
> db.define_table('product', 
> Field('field_n1'), 
> Field('field_n2')) 
>
> if db(db.product).isempty(): 
> populate(db.product, 17) 
>
> some_function = 'function_n1' 
> some_action = 'action_n1' 
> some_table = 'table_n1' 
> back_to = 'back_to_pt01' 
> db.product.id.represent = lambda value,row: A('Ed', 
> _href=URL(f=some_function, args=(some_action, some_table, back_to, 
> value))) 
>
> ## (1) 
> ## when id=1 as a result I expect a link named Ed with href = '../app/ 
> default/function_n1/action_n1/table_n1/back_to_pt01/1' 
>
> some_function = 'function_n2' 
> some_action = 'action_n2' 
> some_table = 'table_n2' 
> back_to = 'back_to_pt02' 
> db.product.field_n1.represent = lambda value,row: A(value, 
> _href=URL(f=some_function, args=(some_action, some_table, back_to, 
> row.id))) 
>
> ## (2) 
> ## when id=1 as a result I expect the content of field_n1 with href = 
> '../app/default/function_n2/action_n2/table_n2/back_to_pt02/1' 
>
> ## (3) and here is the question ... 
> ## for both (1) and (2) 
> ## I am geting href = '../app/default/function_n2/action_n2/table_n2/ 
> back_to_pt02/1' 
> ## Is that correct? 
>
>
> ## with this code I get what I am expecting 
> ##xsome_function = 'function_n2' 
> ##xsome_action = 'action_n2' 
> ##xsome_table = 'table_n2' 
> ##xback_to = 'back_to_pt02' 
> ##db.product.field_n1.represent = lambda value,row: A(value, 
> _href=URL(f=xsome_function, args=(xsome_action, xsome_table, xback_to, 
> row.id))) 
>
>
> Can someone switch on the light, please. 
> Lazaro



[web2py] Re: book 3.2ed

2011-10-27 Thread greenpoise
Need this one..cant wait..







On Oct 25, 10:04 am, Massimo Di Pierro 
wrote:
> One more update of the onlinebookposted:
>
>    http://web2py.com/book
>
> Includes:
>
> - italian translation
> - japanese translation
> - english (revised)
>
> The revised english version includes:
>
> [x] LICENSE CHANGE FROM GPLv2 to LGPLv3
> [x] new URL syntax
> [x] URL(...,scheme=,host=,port=), thanks Jonathan
> [x] URL(...,user_signature=True), LOAD(...,user_signature=True)
> [x] new T behavior
> [x] db(db.table), db(db.table.id) both suported and equivalent to
> db(db.table.id>0)
> [x] IS_DECIMAL_IN_RANGE and IS_FLOAT_IN_RANGE support dot="," (dot="."
> is default)
> [x] on_failed_authorization can be a function, thanks Niphold
> [x] SQLFORM.process()
> [x] SQLFORM.accepts(detect_record_change).record_changed
> [x] session.connect(separate=True) to handle many session files,
> thanks huaiyu wang
> [x] support for count(distinct=...)
> [x] IS_MATCH(...,strict=True)
> [x] No more Auth(globals(),db), just Auth(db). Same for Crud and
> Service.
> [x] efficient db(...).isempty()
> [x] "from gluon import *"
> [x] from mymodule import *
> [x] request.is_local
> [x] request.is_https
> [x] login_methods/loginza.py, thanks Vladimir
> [x] DAL(...,migrate_enabled=False) to disable all migrations
> [x] DAL(...,fake_migrate_all=True) to rebuild all corrupted metadata
> [x] messages in validators have default internationalization
> [x] web2py.py -J for running cron (thanks Jonathan Lundell)
> [x] bpython shell support, thanks Arun
> [x] response.toolbar()
> [x] db._timings contains database query timing info
> [x] web2py comet via gluon/contrib/comet_messaging.py (html5
> websockets)
> [x] new represent syntax
> [x] COL and COLGROUP helpers
> [x] auth.settings.login_after_registration=True
> [x] SQLFORM(...,separator=': ') now customizable
> [x] combined expressions print db.data.body.len().sum()
> [x] request.utcnow
> [x] web2py_ajax.html is more modular, thanks Anthony
> [x] current
> [x] dal expression.coalesce(*options)
> [x] response.include_meta() and response.include_files(), thanks
> Denes
> [x] dal auto-reconnect on time-out connections
> [x] DAL(...,adapter_arg={}) allows support for alternate drivers
> [x] new simpler API gluon.contrib.AuthorizeNet.procss(...)
> [x] upgraded to anytime
> [x] new alterante syntax for inner joins: db(...).select(join=...)
> [x] new syntax rows[i]('tablename.fieldname')
> [x] new DAL (complete rewrite of the web2py DAL is more modular)
> [x] new query syntax field.contains(list,all=True or False)
> [x] validate_and_update, thanks Bruno
> [x] web2py HTTP responses now set: "X-Powered-By: web2py", thanks
> Bruno
> [x] auth.settings.extra_fields['auth_user'].append(Field('country'))
> [x] A(...,callback=URL(...),larget='id') does Ajax
> [x] support for A(name,callback=url,target='id',delete='tr')
> [x] DAL 'request_tenant' fields are special, the altomatically filer
> all records based on their default value.
> [x] db._common_fields.append(Field('owner')) allows to add fields to
> ALL tables
> [x] experimental cubrid database support
> [x] better CAS with v2 support, thanks Olivier ROCH VILATO
> [x] all applications can delegate to login to external provider
>     Auth(...,cas_provider='http://.../other_app/default/user/cas')
> [x] isapiwsgihandler.py
> [x] setup-web2py-nginx-uwsgi-ubuntu.sh
> [x] DAL(..,auto_import=True) automatically imports tables from
> metadata  without need to db.define_table(...)s.
> [x] field.represent = lambda value,record:  (record is optional)
> [x] gluon/contrib/redis_cache.py
> [x] gluon/contrib/simplejsonrpc.py
> [x] expire_sessions.py respects expiration time, thanks iceberg
> [x] auth.settings.cas_actions
> [x] conditional models
> [x] x509 support (needs rocket upgrade, thanks Michele)
> [x] scripts/access.wsgi allows apache+mod_wsgi to delegate
>     authentication of any URL to any web2py app
> [x] DAL gotchas section
> [x] admin allow ``DEMO_MODE=True`` and ``FILTER_APPS=['welcome']``
> [x] admin has MULTI_USER_MODE (admin/models/0.py)
> [x] better mercual admin allows list of files, versions and retrieve
> [x] scripts/make_min_web2py.py
> [x] new cpdb.py, thanks Mart
> [x] experimental REST API
> [x] mentioned pyfpdf and added link to online docs, thanks Mariano
> [x] user_agent
> [x] web2py.py -K for running backgournd tasks
> [x] experimental gluon/scheduler.py
>
> TODO:
> - document wizard
> - document SQLFORM.grid and smartgrid
> - document GAE polymodel support
> - document new lazy virtual fields
> - rewrite acknowledgements
> - update screenshots
> - minor edits in chapter 1 and chapter 3
> - proofreading
> - republish!


[web2py] count file downloads

2011-10-27 Thread thodoris
Hi,

I am wondering what is the best way to count how many times a file has
been downloaded. I have the following:

db.define_table('image',
   Field('file', 'upload'),
   Field('downloads','integer', default=0,readable=False,
writable=False))

I have a view that has the following:

{{=A("Download", _href=URL('download', args=image.file))}}

So when Download is clicked the file file will be downloaded.

The function that is called is:

def download():
return response.download(request,db)

How can i increase the can increase the image.downloads each time a
file is downloaded.

I don't know how or if it is possible to pass the image.id in download
and increase the counter doing something like:

item = db.image[request.vars.id]
new_downloads = item.downloads + 1
item.update_record(downloads=new_downloads)

I tried passing more arguments to download like args=[image.file,
mage.id] but it fails. Any ideas


Re: [web2py] Re: SSL Error

2011-10-27 Thread Ross Peoples
I don't think so. I access my dev machine using the IP all the time. Can 
you try using the source code version instead of the binary and see if that 
makes a difference?

[web2py] Re: count file downloads

2011-10-27 Thread Anthony
response.download expects the last arg in the url to be the filename, so 
you might be able to pass the image.id as the first arg:

args=[image.id, image.file]

Anthony

On Thursday, October 27, 2011 11:39:22 AM UTC-4, thodoris wrote:
>
> Hi, 
>
> I am wondering what is the best way to count how many times a file has 
> been downloaded. I have the following: 
>
> db.define_table('image', 
>Field('file', 'upload'), 
>Field('downloads','integer', default=0,readable=False, 
> writable=False)) 
>
> I have a view that has the following: 
>
> {{=A("Download", _href=URL('download', args=image.file))}} 
>
> So when Download is clicked the file file will be downloaded. 
>
> The function that is called is: 
>
> def download(): 
> return response.download(request,db) 
>
> How can i increase the can increase the image.downloads each time a 
> file is downloaded. 
>
> I don't know how or if it is possible to pass the image.id in download 
> and increase the counter doing something like: 
>
> item = db.image[request.vars.id] 
> new_downloads = item.downloads + 1 
> item.update_record(downloads=new_downloads) 
>
> I tried passing more arguments to download like args=[image.file, 
> mage.id] but it fails. Any ideas



[web2py] SQLFORM.grid sorting dates

2011-10-27 Thread peter
If one clicks on 'data modified' in a windows folder, the files are
ordered with the most recent first.

In SQLFORM.grid if one has a column with a date in it, and one clicks
on the heading, they are sorted with the oldest first.

See www.ukjazz.net/store/albums

It would be nice if SQLFORM.grid acted the same as windows folders
here. Firstly for consistency, and secondly because usually one wants
to order things by the most recent first.

I realise that a second click on the heading does sort in this way

Peter


[web2py] Re: sqlform.grid

2011-10-27 Thread peter
Well, in theory with Web2py we have models controllers and views.
However I find that 50% of the view work I have to do in
the .represent of the model. Then there is a lot of trial and error.
So the division of responsibilites is not as clean as one would hope.
Another reason for doing things in represent is make the image and the
title links, so that the user views the album by clicking on them.

As I said earlier, if you use the css for the grid things dont work,
so delete the css for the grid, it still looks good.

db.albums.image.represent=lambda image,row:
A(IMG(_src=URL('store','download_image',args=[row.id]),_height="150",_width="150"),_href=URL('store','show_album',args=row.id,
vars=request.vars))

db.albums.description.represent=lambda
d,r:SPAN(A(H2(r.album_name),_href=URL('store','show_album',args=r.id),_style="text-
decoration:none"),H3(r.artist),XML(""+d[:
250]+".."+""))

As you see, I actually display the album name and and artist as part
of the description

The album name and artist columns contain blanks

Field('album_name', represent=lambda a,d:' '),
Field('artist',represent=lambda a,d:' '),

I do this so that I still have the columns present so that their
column headings can be used to sort on.

This is not ideal as the column headings are not in the right place,
however, I do not think there is a straightforward better solution.

Peter

On Oct 27, 1:28 pm, Johann Spies  wrote:
> On 26 October 2011 21:20, peter  wrote:
>
>
>
> > Adding in the css for grid actually spoilt things. I have managed to
> > get a good looking grid for CDs with graphics using smartform.grid,
>
> How did you get wrapping of the text in the 'Description' column in your
> your grid (ifhttp://ukjazz.net/store/albumsis what you refer to)?
>
> Regards
> Johann
>
> --
> Because experiencing your loyal love is better than life itself,
> my lips will praise you.  (Psalm 63:3)


[web2py] Re: Domain Masking and Internet Explorer

2011-10-27 Thread horridohobbyist
I agree with you, but just as a lark, I tried to add a P3P header to
the user() action:

response.headers['P3P'] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD
IVAi IVDi CONi HIS OUR IND CNT"'

In theory, this should work, but I still can't login. Check out
stressrelief.co.nr using IE and login as "richardeng2...@hotmail.com",
password "Ranger".

stressrelief.co.nr points to http://67.213.70.251/welcome/default/index
and if you use the latter URL, login is successful.

Interesting puzzle.

Richard

On Oct 26, 7:34 pm, Anthony  wrote:
> The way your domain masking works is that a frameset is set up at the
> masking URL (stressrelief.co.nr), and your actual site is placed inside a
> frame. In that case, apparently IE doesn't pass the session cookie back to
> your application. Seehttp://adamyoung.net/IE-Blocking-iFrame-Cookies.
>
> It's probably not a good idea to use domain masking anyway (the address bar
> won't show any of your internal URLs -- nothing can be bookmarked). Just
> set up the DNS for your domain to point to your server.
>
> Anthony
>
>
>
>
>
>
>
> On Wednesday, October 26, 2011 6:35:24 PM UTC-4, horridohobbyist wrote:
>
> > Okay, I've made it easier to investigate. I've obtained a free domain
> > name with domain masking...
>
> > stressrelief.co.nr points tohttp://67.213.70.251/welcome/default/index
>
> > The first URL prevents login. The second URL does not. It's the
> > standard web2py Welcome app -- login is "richard...@hotmail.com",
> > password "Ranger".
>
> > web2py is installed on Ubuntu with the usual Apache configuration:
>
> > 
> >   WSGIDaemonProcess web2py user=www-data group=www-data
> >   WSGIProcessGroup web2py
> >   WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py
>
> >   
> >     AllowOverride None
> >     Order Allow,Deny
> >     Deny from all
> >     
> >       Allow from all
> >     
> >   
>
> >   AliasMatch ^/([^/]+)/static/(.*) \
> >            /home/www-data/web2py/applications/$1/static/$2
> >   
> >     Options -Indexes
> >     Order Allow,Deny
> >     Allow from all
> >   
>
> >   
> >   Deny from all
> >   
>
> >   
> >   Deny from all
> >   
>
> >   CustomLog /var/log/apache2/access.log common
> >   ErrorLog /var/log/apache2/error.log
> > 
>
> > Richard
>
> > On Oct 26, 3:06 pm, horridohobbyist  wrote:
> > > I've discovered an issue, but I'm not sure if it is specific to
> > > web2py. It might be...
>
> > > I used domain forwarding with masking on stressrelief.drsommers.com to
> > > point tohttp://goodsexnetwork.com/stressrelief.  On Internet
> > > Explorer, this hinders the login function -- when you enter username/
> > > password, the browser simply throws you back to the login page (with
> > > no error message).
>
> > > I've gone back to domain forwarding without masking, and now it works
> > > fine.
>
> > > If you want to investigate, you should use domain forwarding with
> > > masking on the welcome app.
>
> > > Note that this issue is IE-specific. I've had no problem with Firefox,
> > > Chrome, Safari, or Opera.
>
> > > Richard


[web2py] Re: Domain Masking and Internet Explorer

2011-10-27 Thread horridohobbyist
Again, that's richardeng2005 @ hotmail . com

Richard

On Oct 27, 1:25 pm, horridohobbyist  wrote:
> I agree with you, but just as a lark, I tried to add a P3P header to
> the user() action:
>
>     response.headers['P3P'] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD
> IVAi IVDi CONi HIS OUR IND CNT"'
>
> In theory, this should work, but I still can't login. Check out
> stressrelief.co.nr using IE and login as "richardeng2...@hotmail.com",
> password "Ranger".
>
> stressrelief.co.nr points tohttp://67.213.70.251/welcome/default/index
> and if you use the latter URL, login is successful.
>
> Interesting puzzle.
>
> Richard
>
> On Oct 26, 7:34 pm, Anthony  wrote:
>
>
>
>
>
>
>
> > The way your domain masking works is that a frameset is set up at the
> > masking URL (stressrelief.co.nr), and your actual site is placed inside a
> > frame. In that case, apparently IE doesn't pass the session cookie back to
> > your application. Seehttp://adamyoung.net/IE-Blocking-iFrame-Cookies.
>
> > It's probably not a good idea to use domain masking anyway (the address bar
> > won't show any of your internal URLs -- nothing can be bookmarked). Just
> > set up the DNS for your domain to point to your server.
>
> > Anthony
>
> > On Wednesday, October 26, 2011 6:35:24 PM UTC-4, horridohobbyist wrote:
>
> > > Okay, I've made it easier to investigate. I've obtained a free domain
> > > name with domain masking...
>
> > > stressrelief.co.nr points tohttp://67.213.70.251/welcome/default/index
>
> > > The first URL prevents login. The second URL does not. It's the
> > > standard web2py Welcome app -- login is "richard...@hotmail.com",
> > > password "Ranger".
>
> > > web2py is installed on Ubuntu with the usual Apache configuration:
>
> > > 
> > >   WSGIDaemonProcess web2py user=www-data group=www-data
> > >   WSGIProcessGroup web2py
> > >   WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py
>
> > >   
> > >     AllowOverride None
> > >     Order Allow,Deny
> > >     Deny from all
> > >     
> > >       Allow from all
> > >     
> > >   
>
> > >   AliasMatch ^/([^/]+)/static/(.*) \
> > >            /home/www-data/web2py/applications/$1/static/$2
> > >   
> > >     Options -Indexes
> > >     Order Allow,Deny
> > >     Allow from all
> > >   
>
> > >   
> > >   Deny from all
> > >   
>
> > >   
> > >   Deny from all
> > >   
>
> > >   CustomLog /var/log/apache2/access.log common
> > >   ErrorLog /var/log/apache2/error.log
> > > 
>
> > > Richard
>
> > > On Oct 26, 3:06 pm, horridohobbyist  wrote:
> > > > I've discovered an issue, but I'm not sure if it is specific to
> > > > web2py. It might be...
>
> > > > I used domain forwarding with masking on stressrelief.drsommers.com to
> > > > point tohttp://goodsexnetwork.com/stressrelief.  On Internet
> > > > Explorer, this hinders the login function -- when you enter username/
> > > > password, the browser simply throws you back to the login page (with
> > > > no error message).
>
> > > > I've gone back to domain forwarding without masking, and now it works
> > > > fine.
>
> > > > If you want to investigate, you should use domain forwarding with
> > > > masking on the welcome app.
>
> > > > Note that this issue is IE-specific. I've had no problem with Firefox,
> > > > Chrome, Safari, or Opera.
>
> > > > Richard


[web2py] Re: Web2py won't connect to MSSQL

2011-10-27 Thread Massimo Di Pierro
check web2py/gluon/dal.py

there is a try: import pyodbc. remove the try and check whay it fails.
Must be a patch issue.

On Oct 25, 9:39 pm, Omi Chiba  wrote:
> CJM,
>
> Are you using apache using wsgi? if so, you're with me. You cannot
> import 
> pyodbc.http://ochiba77.blogspot.com/2011/10/how-to-setup-web2py-apache-wsgi
>
> If you're using rocket server, it should connect because I'm
> connecting without any problem. Only difference with your environment
> is that I'm using Windows 7. I use actual server(computer) name
> instead of localhost. You can try that to see if it makes any
> difference.
>
> db = DAL('mssql:// testUser:password1@ServerName/testDB')
>
> if it's mssql server express,
>
> db = DAL('mssql:// testUser:password1@ServerName\SQLEXPRESS/testDB')
>
> On 10月25日, 午後4:14, CJM  wrote:
>
>
>
>
>
>
>
> > It's a source code install. Hench the line:
>
> > > >  Web2py: source code install version 1.99.2 (2011-09-26 06:55:33)
>
> > :)
>
> > On Oct 25, 12:10 pm, Bruno Rocha  wrote:
>
> > > are you using source code or .exe version of web2py?
>
> > >http://zerp.ly/rochacbruno
> > > Em 25/10/2011 13:31, "CJM"  escreveu:
>
> > > > I'm unable to get web2py to connect to mssql.
>
> > > > (Failure to connect, tried 5 times:
> > > > 'NoneType' object has no attribute 'connect')
>
> > > > My connection string is: db = DAL('mssql://
> > > > testUser:password1@localhost/testDB')
>
> > > > Environment
> > > >  Windows Server 2008 R2, 64-bit operating system
> > > >  SQL Server 2008 R2, local.
> > > >  Web2py: source code install version 1.99.2 (2011-09-26 06:55:33)
> > > > stable.
> > > >  pyodbc
> > > >  Python 2.7.2
>
> > > > I've tested that I can connect using the pyodbc. The following code
> > > > works:
>
> > > > import pyodbc
> > > > cnxn = pyodbc.connect('DRIVER={SQL
> > > > Server};SERVER=localhost;DATABASE=testDB;UID=testUser;PWD=password1')
> > > > cursor = cnxn.cursor()
> > > > cursor.execute("select * from tbUsers")
> > > > rows = cursor.fetchall()
> > > > for row in rows:
> > > >  print row
>
> > > > Thanks for your time.
>
> > > > Corey.


[web2py] Re: Multiple browser tabs and session

2011-10-27 Thread Massimo Di Pierro
There is not one because this behavior is browser dependent and cannot
be controller by the server.
That said. If you know something we do not know let us know and we can
try improve it.

On Oct 27, 8:54 am, Cliff  wrote:
> What is the Web2py way of making session variables unique to one
> browser tab?  This example illustrates the problem.
>
> Model:
> db.define_table('products', Field('quantity_on_hand', 'integer'))
> db.define_table('jobs', Field('job_yield', 'integer'),
> Field('product_id', db.products))
>
> When a user updates the job_yield field, the jobs controller also
> needs to update quantity on hand in the products table.  Usually one
> would use a session variable something like this.
>
> def edit():
>     # fetch current job yield
>     old_job_yield = db.jobs[request.vars(0)].job_yield
>     # save it in a session
>     session.old_job_yield= old_job_yield
>     ...
>     if form.accepts(session,request):
>           if request.post_vars.job_yield != session.old_job_yield:
>                yield_delta = request.post_vars.job_yield -
> session.old_job_yield
>                # assume we magically fetch related product id, then
>                old_quantity_on_hand =
> db.products[product_id].quantity_on_hand
>                new_quantity_on_hand = old_quantity_on_hand +
> yield_delta
>
> db(db.products.id==product_id).update(quantity_on_hand=new_quantity_on_hand )
>
> The problem arises if the user edits a different job in a different
> tab.  Because there is only one instance of session.old_job_yield, the
> edit action in the other tab will overwrite it.
>
> What is the Web2py way of handling this problem?
>
> Thanks,
> Cliff Kachinske


[web2py] Re: SQLFORM.grid ondelete possible bug

2011-10-27 Thread Massimo Di Pierro
fixed


On Oct 26, 4:54 pm, Bob St John  wrote:
> using 1.99.2
>
> in gluon.sqlhtml.SQLFORM.grid:
>
> line 1489: return ondelete(table,request.args[-2],ret)
>
> I think it should be: return ondelete(table,request.args[-1],ret)
>
> As it is now, ondelete gets (table, table, ret), whereas I believe it
> should get (table, record_id, ret) to work properly...
>
> I like this grid method!


[web2py] Re: Room and Resource Reservation

2011-10-27 Thread Massimo Di Pierro
Please list the specs you need. Should not take much to do.

On Oct 26, 4:55 pm, Ismael Serratos  wrote:
> Looking for the same...
>
> 2011/10/6 António Ramos 
>
>
>
>
>
>
>
> > Hello, i´d like to suggest this app
>
> > Room and Resource(auto, projector etc) Reservation with a nice callendar
> > like fullcalendar.
>
> > IT think it would be very usefull for an intranet use
>
> > Does anyone have something like this in web2py?


[web2py] Re: SQLFORM.grid collection of posts

2011-10-27 Thread Massimo Di Pierro
Thanks this is useful! Mind that the API may still fluctuate a bit.

On Oct 26, 4:38 pm, Cliff  wrote:
> You can find a digest of posts about SQLFORM.grid here:
>
> https://docs.google.com/document/d/1p-OXDn75Nt2qmXQ0lvjqr4tYIf2PTIQx6...
>
> I know it is not complete, but it may help you get started.
>
> Also there is some good information in the source file: gluon/
> sqlhtml,  Just looking at the signature of the grid function is very
> instructive.
>
> If you find something I've missed, just let me know.
>
> Cliff Kachinske


[web2py] Re: SQLTABLE param headers=None bug - Web2py 1.99.2 (2011-09-26 06:55:33) stable

2011-10-27 Thread Massimo Di Pierro
fixed and uploading, thanks.

On Oct 26, 11:10 am, tg  wrote:
> At least for me to following is faster when reading...
>
> -        if not headers is None:
> +        if headers is None:
> +          headers={}
> +        else:
>             for c in columns:#new implement dict
> 
>
> regards
>
> thomas
>
>
>
>
>
>
>
> > I think I found a bug with the headers with the above version, which
> > when headers=None generates a unsubscriptable error at line 2061:
>
> > if isinstance(headers[colname],dict):
>
> > This error can be fixed by the following changes added to line 1966 of
> > sqlhtml.py:
>
> >         if not headers is None:
> >             for c in columns:#new implement dict
> >                 if isinstance(headers.get(c, c), dict):
> >                     coldict = headers.get(c, c)
> >                     attrcol = dict()
> >                     if coldict['width']!="":
> >                         attrcol.update(_width=coldict['width'])
> >                     if coldict['class']!="":
> >                         attrcol.update(_class=coldict['class'])
> >                     row.append(TH(coldict['label'],**attrcol))
> >                 elif orderby:
> >                     row.append(TH(A(headers.get(c, c),
> >                                     _href=th_link+'?orderby=' + c)))
> >                 else:
> >                     row.append(TH(headers.get(c, c)))
>
> >             if extracolumns:#new implement dict
> >                 for c in extracolumns:
> >                     attrcol = dict()
> >                     if c['width']!="":
> >                         attrcol.update(_width=c['width'])
> >                     if c['class']!="":
> >                         attrcol.update(_class=c['class'])
> >                     row.append(TH(c['label'],**attrcol))
>
> >             components.append(THEAD(TR(*row)))
> > +        else:
> > +          headers={}
>
> > Cheers
> > Calvin


[web2py] Re: curious DAL timeout issue

2011-10-27 Thread Massimo Di Pierro
Which version? Is the problem reproducible? Can you tell us more?
Perhaps open a ticket

On Oct 26, 11:24 am, Richard Bruskiewich
 wrote:
> I'm a recent fan of web2py, having adopted it for some major
> institutional projects in global agriculture. So far, so good - very
> happy - but I have a recurring curious low level database error which
> I'm not sure how to fix.
>
> I've already tried trapping my web2py data model in a try... except
> block, inside a loop to retry the database connection (about 20 times,
> or so I think), but this doesn't seem to help.  The database
> connection often works... it is just that when the MySQL connection is
> idle for too long, or when a fresh connection is requested for a new
> user session, something fails... DAL doesn't handle it.
>
> Here's the background: I'm running web2py in an NGINX server via uwsgi
> (which generally works fine - configured based on good advice online).
> However, this server runs within an Amazon Web Services (AWS) EC2
> server and accesses a MySQL instance running non-locally as a AWS
> Relational Database (RDB) server.
>
> I'm using a DAL pool_size of 10.
>
> Here's the error message:
>
> Operational Error: (2013, 'Lost connection to MySQL server during
> query')
>
> Traceback (most recent call last):
>   File "/opt/web2py/gluon/main.py", line 506, in wsgibase
>     BaseAdapter.close_all_instances('commit')
>   File "/opt/web2py/gluon/dal.py", line 373, in close_all_instances
>     getattr(instance,action)()
>   File "/opt/web2py/gluon/dal.py", line 1225, in commit
>     return self.connection.commit()
>   File "/opt/web2py/gluon/contrib/pymysql/connections.py", line 562,
> in commit
>     self.errorhandler(None, exc, value)
>   File "/opt/web2py/gluon/contrib/pymysql/connections.py", line 184,
> in defaulterrorhandler
>     raise errorclass, errorvalue
> OperationalError: (2013, 'Lost connection to MySQL server during
> query')
>
> I hope someone can suggest something here. Do I need to tweak some
> MySQL client parameter, or does someone have some advice about Amazon
> RDB usage practicalities in such a situation?
>
> Cheers
> Richard Bruskiewich
> Scientific Consultant,
> International Rice Research Institute (IRRI)


[web2py] Re: SQLFORM.grid collection of posts

2011-10-27 Thread Cliff
I'll try to keep an eye on it.

On Oct 27, 1:47 pm, Massimo Di Pierro 
wrote:
> Thanks this is useful! Mind that the API may still fluctuate a bit.
>
> On Oct 26, 4:38 pm, Cliff  wrote:
>
>
>
>
>
>
>
> > You can find a digest of posts about SQLFORM.grid here:
>
> >https://docs.google.com/document/d/1p-OXDn75Nt2qmXQ0lvjqr4tYIf2PTIQx6...
>
> > I know it is not complete, but it may help you get started.
>
> > Also there is some good information in the source file: gluon/
> > sqlhtml,  Just looking at the signature of the grid function is very
> > instructive.
>
> > If you find something I've missed, just let me know.
>
> > Cliff Kachinske


[web2py] Re: Found a bug: XMLRPC with basic authorization fails

2011-10-27 Thread Massimo Di Pierro
Can you help me debug? Look into gluon.tools.py. There is a function
basic() Add some print statements. Is it called? What does it return?

On Oct 23, 7:48 pm, Robert Clark  wrote:
> Hi Massimo
>
> Here are the steps to reproduce this problem in web2py 1.99.2 (these
> steps worked fine on 1.98.x versions)
>
> 1) In web2py admin create "New simple application" called "foo"
>
> 2) Add to db.py:
>     auth.settings.allow_basic_login = True
>
> 3) Decorate call() with @auth.requires_login in default.py:
>
>     @auth.requires_login()
>     def call():
>         ...
>
> 4) Add a simple XMLPRC method to default.py:
>
>     @service.xmlrpc
>     def multiply(a=1,b=1):
>         return dict(answer=int(a) * int(b))
>
> 5) Register a user with email "bob.sm...@foo.com" password "snowball"
>
> 6) From a python shell use ServerProxy to invoke the service
>
> > from xmlrpclib import ServerProxy
> > server = 
> > ServerProxy('http://bob.sm...@foo.com:snowball@localhost:8000/foo/default/call/xmlrpc',
> >  verbose=True)
> > server.multiply(2, 2)
>
> ...
> reply: 'HTTP/1.1 303 SEE OTHER\r\n'
> ...
>
> Cheers,
> Rob
>
> On Oct 22, 2:59 am, Massimo Di Pierro 
> wrote:
>
>
>
>
>
>
>
> > Can you provide an example to reproduce the problem?
>
> > On Oct 21, 12:38 am,RobinMarshall
> > wrote:
>
> > > Hi,
>
> > > Just wanted to say that we found a bug in 1.99.2 when using XMLRPC
> > > services with the @auth.requires_login decorator using basic
> > > authentication.
>
> > > It looks like some code was refactored out of requires_login into a
> > > generic requires method which might be the cause of the problem.
>
> > > A quick hack was to change the following code, but obviously that
> > > won't work very well for people who aren't using basic authentication.
>
> > >     def is_logged_in(self):
> > >         """
> > >         checks if the user is logged in and returns True/False.
> > >         if so user is in auth.user as well as in session.auth.user
> > >         """
> > >         if self.user:
> > >             return True
> > >         return False
>
> > > to:
>
> > >     def is_logged_in(self):
> > >         """
> > >         checks if the user is logged in and returns True/False.
> > >         if so user is in auth.user as well as in session.auth.user
> > >         """
> > >         if self.basic() and self.user:
> > >             return True
> > >         return False
>
> > > Cheers,
> > >Robin


[web2py] Re: gluon.storage.Storage interface discrepancy?

2011-10-27 Thread Massimo Di Pierro
Any suggestion for improvement?

On Oct 25, 3:32 pm, Jonathan Lundell  wrote:
> On Oct 25, 2011, at 1:18 PM, Anthony  wrote:
>
> > On Tuesday, October 25, 2011 4:08:20 PM UTC-4, pepper_bg wrote:
> > > You can do
> > > s.get(6,None)
>
> > Still have to anticipate what my keys are and write different code
> > accordingly. Which is fine in most cases I guess. Or may be I am
> > trying to be too generic here. Thanks for your input...
>
> > If you're not sure whether a key might be a string or integer, you can use 
> > the s.get() method in all cases.
>
> Still, it'd make sense for s['a'] to have the same semantics as s.a.


[web2py] Re: adjusting default select() behavior

2011-10-27 Thread Massimo Di Pierro
Sorry for the late response.

When you print a select() you get the default csv serialization.
For anything else I suggest you do it manually by looping over records
and columns. Or use the csv module if you need csv.


On Oct 25, 4:59 pm, lucas  wrote:
> hello one and all,
>
> here is the default behavior when i run the select statement like:
>
> d = db.news
> lst = db(d.id>0).select(d.id, d.event_date, d.permission, d.type,
> d.title, d.body, orderby=~d.event_date)
>
> news.id news.event_date news.permission news.type       news.title      
> news.body
> 29      2011-03-17              Equipment Con...        Tektronix       
> Tektronix has...
> 28      2011-01-14              Event   Research Hiat...        After a long 
> ...
>
> so you can see that i know how to change which fields display, but i
> would like to make news.body display say a character length of 30, and
> change the headers to remove the "news.".
>
> how do i do both of those customizations?  thank you in advance and
> have a great day.  lucas


Re: [web2py] Re: gluon.storage.Storage interface discrepancy?

2011-10-27 Thread Jonathan Lundell
Sure. On the road now, but shortly. 

On Oct 27, 2011, at 10:57 AM, Massimo Di Pierro  
wrote:

> Any suggestion for improvement?
> 
> On Oct 25, 3:32 pm, Jonathan Lundell  wrote:
>> On Oct 25, 2011, at 1:18 PM, Anthony  wrote:
>> 
>>> On Tuesday, October 25, 2011 4:08:20 PM UTC-4, pepper_bg wrote:
 You can do
 s.get(6,None)
>> 
>>> Still have to anticipate what my keys are and write different code
>>> accordingly. Which is fine in most cases I guess. Or may be I am
>>> trying to be too generic here. Thanks for your input...
>> 
>>> If you're not sure whether a key might be a string or integer, you can use 
>>> the s.get() method in all cases.
>> 
>> Still, it'd make sense for s['a'] to have the same semantics as s.a.


[web2py] Re: Multiple browser tabs and session

2011-10-27 Thread Anthony
How about:

yield_key = 'old_job_yield_%s' % request.args(0)
session[yield_key] = old_job_yield

That way, the session key is unique to the particular job being edited, and 
editing another job in a different tab won't overwrite the old_job_yield 
associated with this job. That won't protect against the user potentially 
editing the _same_ job in two different tabs (though to protect against 
that, you could use the SQLFORM detect_record_change argument), but should 
be OK for separate jobs. There is still a very small opportunity for a race 
condition in between reading the current value of quantity_on_hand and 
updating that value, but that would require two edit forms being submitted 
nearly simultaneously (actually, I think trunk now includes a feature 
allowing you to select a record for update, so it will remain locked until 
updated).

A few other issues:

   - Should be request.args(0), not request.vars(0) (request.vars is like a 
   dictionary -- access items with keys, not subscripts).
   - Should be form.accepts(request, session), not (session, request) -- 
   though, now, you should use form.process().accepted
   - After form acceptance, it's probably better to refer to form.vars 
   (i.e., the validated values) rather than request.post_vars.

Anthony

On Thursday, October 27, 2011 9:54:21 AM UTC-4, Cliff wrote:
>
> What is the Web2py way of making session variables unique to one 
> browser tab?  This example illustrates the problem. 
>
> Model: 
> db.define_table('products', Field('quantity_on_hand', 'integer')) 
> db.define_table('jobs', Field('job_yield', 'integer'), 
> Field('product_id', db.products)) 
>
> When a user updates the job_yield field, the jobs controller also 
> needs to update quantity on hand in the products table.  Usually one 
> would use a session variable something like this. 
>
> def edit(): 
> # fetch current job yield 
> old_job_yield = db.jobs[request.vars(0)].job_yield 
> # save it in a session 
> session.old_job_yield= old_job_yield 
> ... 
> if form.accepts(session,request): 
>   if request.post_vars.job_yield != session.old_job_yield: 
>yield_delta = request.post_vars.job_yield - 
> session.old_job_yield 
># assume we magically fetch related product id, then 
>old_quantity_on_hand = 
> db.products[product_id].quantity_on_hand 
>new_quantity_on_hand = old_quantity_on_hand + 
> yield_delta 
>   
> db(db.products.id==product_id).update(quantity_on_hand=new_quantity_on_hand) 
>
>
> The problem arises if the user edits a different job in a different 
> tab.  Because there is only one instance of session.old_job_yield, the 
> edit action in the other tab will overwrite it. 
>
> What is the Web2py way of handling this problem? 
>
> Thanks, 
> Cliff Kachinske 
>
>

[web2py] Re: curious DAL timeout issue

2011-10-27 Thread Richard Bruskiewich
Thank you Professor  Di Pierro for your direct reply.

Since I am new to the community, I'm not sure how to log a ticket.
I'll look into that but if you will bear with me, here is perhaps the
additional information you are asking for:

I've deployed Web2PY Version 1.98.2 (2011-08-04 00:47:09)

The error is routinely reproducible... on four different web browsers
(IE, FireFox, Chrome, Safari). Seems to be associated with starting a
new session after an old session times out(?).  Refreshing the web
browser clears the error, but the error always  recurs so is not
pretty for end users visiting the site, generating the anonymous, in
accessible Web2PY ticket URL which only Admin-privileged folks (i.e.
me) can view over an SSH tunnel.

I have web2py running behind NGINX via uswgi. This is installed on an
Amazon EC2 server using web recipes (e.g.
http://stackoverflow.com/questions/5335153/how-to-deply-web2py-using-nginx,
https://library.linode.com/web-servers/nginx/python-uwsgi/centos-5 and
other helpful sites - I have deployment notes available, if they'd be
needed).

I don't seem to see this problem at all while running the app on my
local machine (using the built in Rocket 1.2.2 server) only when in
production deployment on the Amazon cloud.

The back end database on the Amazon cloud is a remote MySQL image
running at Amazon (RDS - http://aws.amazon.com/rds/). I suspect that
mysql connections routinely time out in the cloud if they lay unused
for some period of time. Not sure how this might trip up the web2py
DAL.  You have the Traceback from my previous email (the same one
occurs each time...). The Traceback isn't too informative as to
exactly what part of my (model?) code is the one triggering the error.
Is it the DAL class __init__? I could, I suppose, try to chase this
down, but perhaps somebody more intimate with the code can better
suggest where to look.

Do let me know if any other information other than the above would be
of use to troubleshooting the problem.

I'll try to read up some more about Amazon RDS (and MySQL) to see if
there is anything I can do to tweak the MySQL installation to mitigate
timeouts.  Meanwhile, perhaps somebody out in the web2py community can
comment.

Thanks again for your direct reply.

Cheers
Richard Bruskiewich, PhD
Scientific Consultant,
International Rice Research Institute (IRRI)

On Oct 27, 10:51 am, Massimo Di Pierro 
wrote:
> Which version? Is the problem reproducible? Can you tell us more?
> Perhaps open a ticket
>
> On Oct 26, 11:24 am, RichardBruskiewich
>
>
>
>
>
>
>
>  wrote:
> > I'm a recent fan of web2py, having adopted it for some major
> > institutional projects in global agriculture. So far, so good - very
> > happy - but I have a recurring curious low level database error which
> > I'm not sure how to fix.
>
> > I've already tried trapping my web2py data model in a try... except
> > block, inside a loop to retry the database connection (about 20 times,
> > or so I think), but this doesn't seem to help.  The database
> > connection often works... it is just that when the MySQL connection is
> > idle for too long, or when a fresh connection is requested for a new
> > user session, something fails... DAL doesn't handle it.
>
> > Here's the background: I'm running web2py in an NGINX server via uwsgi
> > (which generally works fine - configured based on good advice online).
> > However, this server runs within an Amazon Web Services (AWS) EC2
> > server and accesses a MySQL instance running non-locally as a AWS
> > Relational Database (RDB) server.
>
> > I'm using a DAL pool_size of 10.
>
> > Here's the error message:
>
> > Operational Error: (2013, 'Lost connection to MySQL server during
> > query')
>
> > Traceback (most recent call last):
> >   File "/opt/web2py/gluon/main.py", line 506, in wsgibase
> >     BaseAdapter.close_all_instances('commit')
> >   File "/opt/web2py/gluon/dal.py", line 373, in close_all_instances
> >     getattr(instance,action)()
> >   File "/opt/web2py/gluon/dal.py", line 1225, in commit
> >     return self.connection.commit()
> >   File "/opt/web2py/gluon/contrib/pymysql/connections.py", line 562,
> > in commit
> >     self.errorhandler(None, exc, value)
> >   File "/opt/web2py/gluon/contrib/pymysql/connections.py", line 184,
> > in defaulterrorhandler
> >     raise errorclass, errorvalue
> > OperationalError: (2013, 'Lost connection to MySQL server during
> > query')
>
> > I hope someone can suggest something here. Do I need to tweak some
> > MySQL client parameter, or does someone have some advice about Amazon
> > RDB usage practicalities in such a situation?
>
> > Cheers
> > RichardBruskiewich
> > Scientific Consultant,
> > International Rice Research Institute (IRRI)


[web2py] Re: Multiple browser tabs and session

2011-10-27 Thread Cliff
This is what can be done in PHP.  It was easy to build names for
session variables by string concatenation because PHP variables begin
with a dollar sign.  So something like $_SESSION[$foobar] = 'hello,
world' would work. I'm not smart enough yet in Python to know if the
same thing is possible.

That said, here's a solution:

Look for a variable called tab_id to the query string.

if it's there, append it to the query string for the next request.

If it's missing assume it's either a brand new Web2py session or a
fresh browser tab.  In that case, append a new, unique to the query
string.

If you have to park something in the session, concat the tab_id to the
name of the session variable.  If you need to get it back, do the same
concatenation.

Maybe something like session.myvariable%s %tab_id would work.

Didn't depend on the browser at all.

I did not invent this, by the way, so credit belongs elsewhere.

On Oct 27, 1:41 pm, Massimo Di Pierro 
wrote:
> There is not one because this behavior is browser dependent and cannot
> be controller by the server.
> That said. If you know something we do not know let us know and we can
> try improve it.
>
> On Oct 27, 8:54 am, Cliff  wrote:
>
>
>
>
>
>
>
> > What is the Web2py way of making session variables unique to one
> > browser tab?  This example illustrates the problem.
>
> > Model:
> > db.define_table('products', Field('quantity_on_hand', 'integer'))
> > db.define_table('jobs', Field('job_yield', 'integer'),
> > Field('product_id', db.products))
>
> > When a user updates the job_yield field, the jobs controller also
> > needs to update quantity on hand in the products table.  Usually one
> > would use a session variable something like this.
>
> > def edit():
> >     # fetch current job yield
> >     old_job_yield = db.jobs[request.vars(0)].job_yield
> >     # save it in a session
> >     session.old_job_yield= old_job_yield
> >     ...
> >     if form.accepts(session,request):
> >           if request.post_vars.job_yield != session.old_job_yield:
> >                yield_delta = request.post_vars.job_yield -
> > session.old_job_yield
> >                # assume we magically fetch related product id, then
> >                old_quantity_on_hand =
> > db.products[product_id].quantity_on_hand
> >                new_quantity_on_hand = old_quantity_on_hand +
> > yield_delta
>
> > db(db.products.id==product_id).update(quantity_on_hand=new_quantity_on_hand 
> > )
>
> > The problem arises if the user edits a different job in a different
> > tab.  Because there is only one instance of session.old_job_yield, the
> > edit action in the other tab will overwrite it.
>
> > What is the Web2py way of handling this problem?
>
> > Thanks,
> > Cliff Kachinske


[web2py] Re: Multiple browser tabs and session

2011-10-27 Thread Cliff
Anthony, thank you.

I didn't know that something like session[myvar] would work.  I
thought it was only dot notation.

Thanks for the pointer on form.vars.

I'll look for more info on form.process().

I would be more worried about a record being left in a locked
condition than I would be about a race condition.  What happens if the
client goes away and never updates the record?

I know the code was sloppy.  I hope nobody uses it for an example.



On Oct 27, 2:18 pm, Anthony  wrote:
> How about:
>
> yield_key = 'old_job_yield_%s' % request.args(0)
> session[yield_key] = old_job_yield
>
> That way, the session key is unique to the particular job being edited, and
> editing another job in a different tab won't overwrite the old_job_yield
> associated with this job. That won't protect against the user potentially
> editing the _same_ job in two different tabs (though to protect against
> that, you could use the SQLFORM detect_record_change argument), but should
> be OK for separate jobs. There is still a very small opportunity for a race
> condition in between reading the current value of quantity_on_hand and
> updating that value, but that would require two edit forms being submitted
> nearly simultaneously (actually, I think trunk now includes a feature
> allowing you to select a record for update, so it will remain locked until
> updated).
>
> A few other issues:
>
>    - Should be request.args(0), not request.vars(0) (request.vars is like a
>    dictionary -- access items with keys, not subscripts).
>    - Should be form.accepts(request, session), not (session, request) --
>    though, now, you should use form.process().accepted
>    - After form acceptance, it's probably better to refer to form.vars
>    (i.e., the validated values) rather than request.post_vars.
>
> Anthony
>
>
>
>
>
>
>
> On Thursday, October 27, 2011 9:54:21 AM UTC-4, Cliff wrote:
>
> > What is the Web2py way of making session variables unique to one
> > browser tab?  This example illustrates the problem.
>
> > Model:
> > db.define_table('products', Field('quantity_on_hand', 'integer'))
> > db.define_table('jobs', Field('job_yield', 'integer'),
> > Field('product_id', db.products))
>
> > When a user updates the job_yield field, the jobs controller also
> > needs to update quantity on hand in the products table.  Usually one
> > would use a session variable something like this.
>
> > def edit():
> >     # fetch current job yield
> >     old_job_yield = db.jobs[request.vars(0)].job_yield
> >     # save it in a session
> >     session.old_job_yield= old_job_yield
> >     ...
> >     if form.accepts(session,request):
> >           if request.post_vars.job_yield != session.old_job_yield:
> >                yield_delta = request.post_vars.job_yield -
> > session.old_job_yield
> >                # assume we magically fetch related product id, then
> >                old_quantity_on_hand =
> > db.products[product_id].quantity_on_hand
> >                new_quantity_on_hand = old_quantity_on_hand +
> > yield_delta
>
> > db(db.products.id==product_id).update(quantity_on_hand=new_quantity_on_hand 
> > )
>
> > The problem arises if the user edits a different job in a different
> > tab.  Because there is only one instance of session.old_job_yield, the
> > edit action in the other tab will overwrite it.
>
> > What is the Web2py way of handling this problem?
>
> > Thanks,
> > Cliff Kachinske


Re: [web2py] sqlform.grid

2011-10-27 Thread Richard Vézina
Hello Bruno,

I am giving a ride to new SQLFORM.grid actually... And I wonder if there is
a way to have a scroll bar for big table (large table)? Do I have to use
jQuery UI?

If so is there a predefined way of doing it?

Richard

On Tue, Oct 25, 2011 at 4:53 PM, Bruno Rocha  wrote:

> The grid css is in base.css, but if you do not want to mess your own css,
> open the file and copy only the grid part. it is commented.
>
>
> On Tue, Oct 25, 2011 at 6:46 PM, peter  wrote:
>
>> I am using and enjoying sqlform.grid. I have the latest version of
>> web2py, however, I think that the css files within my application have
>> become out of date.
>>
>> If I have ten pages, then the page numbers appear vertically rather
>> than horizontally at the bottom of the table.
>>
>> What css files do I need to copy into my application to keep the css
>> up to date for the grid?
>>
>> Thanks
>> Peter
>
>
>
>
>
>


Re: [web2py] sqlform.grid

2011-10-27 Thread Bruno Rocha
On Thu, Oct 27, 2011 at 5:51 PM, Richard Vézina  wrote:

> Hello Bruno,
>
> I am giving a ride to new SQLFORM.grid actually... And I wonder if there is
> a way to have a scroll bar for big table (large table)? Do I have to use
> jQuery UI?
>
> If so is there a predefined way of doing it?
>

Include this in your css rules.

.web2py_grid .web2py_table {

   1. overflow: scroll;

}


[web2py] Re: curious DAL timeout issue

2011-10-27 Thread Anthony
On Thursday, October 27, 2011 2:37:19 PM UTC-4, Richard Bruskiewich wrote:
>
> I'm not sure how to log a ticket. 
>

FYI: http://code.google.com/p/web2py/issues/list 


Re: [web2py] Re: Room and Resource Reservation

2011-10-27 Thread António Ramos
Does this help?
http://www.youtube.com/watch?v=ntkxvNxEKXk



2011/10/27 Massimo Di Pierro 

> Please list the specs you need. Should not take much to do.
>
> On Oct 26, 4:55 pm, Ismael Serratos  wrote:
> > Looking for the same...
> >
> > 2011/10/6 António Ramos 
> >
> >
> >
> >
> >
> >
> >
> > > Hello, i´d like to suggest this app
> >
> > > Room and Resource(auto, projector etc) Reservation with a nice
> callendar
> > > like fullcalendar.
> >
> > > IT think it would be very usefull for an intranet use
> >
> > > Does anyone have something like this in web2py?
>


Re: [web2py] sqlform.grid

2011-10-27 Thread Richard Vézina
Many thanks Bruno I was digging into the appadmin trying to get the overflow
stuff and putting it into my test view function.

With Datatables I didn't use overflow since a wild...

Thanks again.

Richard

On Thu, Oct 27, 2011 at 4:04 PM, Bruno Rocha  wrote:

>
>
> On Thu, Oct 27, 2011 at 5:51 PM, Richard Vézina <
> ml.richard.vez...@gmail.com> wrote:
>
>> Hello Bruno,
>>
>> I am giving a ride to new SQLFORM.grid actually... And I wonder if there
>> is a way to have a scroll bar for big table (large table)? Do I have to use
>> jQuery UI?
>>
>> If so is there a predefined way of doing it?
>>
>
> Include this in your css rules.
>
> .web2py_grid .web2py_table {
>
>1. overflow: scroll;
>
> }
>


[web2py] customized the id field in sqlite

2011-10-27 Thread Chris
I a noob to web2py; so much so I'm not sure if I'm asking the right 
question! 

I'm trying to change the default behavior of the id field in my table. 
 Instead of an auto-increment of 1, 2, 3, etc...I need it to auto-increment 
11-01, 11-02, 11-03, etc. Even better it would be nice to have 
it start at a number like 11-102999

I've been attempting to do this Models/mydb.py when defining my table and 
fields.




[web2py] Re: Contribution

2011-10-27 Thread Triquetra
I don't think web2py supports this currently, but I think you are on
the right track.

I think what I would suggest is an extension to auth.add_permission.

Something like auth.add_permission(group.id, 'name', 'object',
record_id, 'column_name', state_bool) where column_name is the name of
the table column(field) and NULL or unspecified equals all columns;
and where state_bool is any expression returning a boolean value such
that a "true" value means the permission is active, and a "false"
value means it is not (e.g. db.articles.published == true; or time.now
- db.articles.date > 30 days) and NULL or unspecified equals all/any
states.

Of course this would also require respective extensions to
auth.has_permission.

On Oct 26, 1:17 pm, Richard Vézina 
wrote:
> I just read the doc... Not sure what I suggest is possible... According to
> the doc it would need something like this to work:
>
> auth.has_permission(group_id, 'read', 'table123', field123 == 'something')
>
> This would lead to check if a user as the permission read on table123 when
> field123 has the value something...
>
> It would be great if it is possible...
>
> Richard
>
> On Wed, Oct 26, 2011 at 2:03 PM, Richard Vézina 
>
>
>
>
>
>
> > wrote:
> > And why the object could not be a query that can return a list of records
> > having the state you are looking for??
>
> > Richard
>
> > On Mon, Oct 24, 2011 at 8:25 PM, Triquetra <
> > trique...@triquetradevelopment.com> wrote:
>
> >> No, I don't think this helps, unless I'm misunderstanding something
> >> (which is possible).
>
> >> When using "auth.add_permission(group_id, 'name', 'object',
> >> record_id)" the CRUD permissions are only enforced if the object is a
> >> table (according to the book).  So, even assuming one could pass a
> >> column as the object (to enable field based access control), the
> >> web2py access system will not automatically enforce CRUD permissions
> >> on this object (like it would with tables or records).  This level of
> >> access control would require additional manual enforcement in the
> >> controllers.
>
> >> This doesn't help with state based permissions either.  The issue here
> >> is that permissions may change depending upon the state of the
> >> object.  Workflows are a good example.  If A is in group author and E
> >> is in group editor, a workflow may demand that A has full CRUD rights
> >> until the article is submitted for editing, then A only has read
> >> rights over the SAME record and editor group gets read and update
> >> rights only after submission of the article for editing.  Same record,
> >> same groups, same users -- different permissions based on the state of
> >> the record (which could be indicated by the content of a field).
>
> >> > On Friday, October 21, 2011 3:54:26 PM UTC-4, Triquetra wrote:
>
> >> > > I'd like to see
> >> > > web2py's access control beefed up (thus permitting easy development of
> >> > > workflows, among other things).  Specifically, the current web2py RBAC
> >> > > has two levels of granularity: table and record (row). This should be
>
> >> > extended to include field(column), type(controller), and
>
> >> > > context(state).
>
> >> > auth.add_permission(group_id, 'name', 'object', record_id)
>
> >> > In the above, 'object' can be any user-defined object, not just a DB
> >> table
> >> > (record_id is only relevant if the object is a table). Does that help?
>
> >> > > Although the type(controller) access control is currently implemented
> >> > > via decorators in web2py, this is restricted to coders.
>
> >> > You don't have to use decorators. You can directly check for permissions
> >> via
> >> > auth.has_membership() and auth.has_permission().


[web2py] Re: Contribution

2011-10-27 Thread Triquetra
I'm sure assistance with documentation would be appreciated by all!

On Oct 26, 10:16 am, Hong-Khoan Quach 
wrote:
> I want to thank you all for your suggestions so far and please
> post further suggestions :).
>
> Massimo, Anthony or other contributors/committers, do you
> have anything on your TODO list ?
>
> Regards
>
> Hong-Khoan
>
> Am 21.10.2011 12:52, schrieb Hong-Khoan Quach:
>
>
>
>
>
>
>
> > Hi there.
>
> > We would like to contribute to web2py for a university open source
> > practical course. Does anyone have an idea for an important/cool feature
> > that we could propose to our supervisor?
> > Furthermore, are there any low hanging fruits, we can start with?
>
> > Regards
>
> > Matteo and Hong-Khoan
>
>
>
>  signature.asc
> < 1KViewDownload


[web2py] Re: count file downloads

2011-10-27 Thread thodoris
Thanx Antony! I can't believe it was as simple as that...

On Oct 27, 5:50 pm, Anthony  wrote:
> response.download expects the last arg in the url to be the filename, so
> you might be able to pass the image.id as the first arg:
>
> args=[image.id, image.file]
>
> Anthony
>
>
>
>
>
>
>
> On Thursday, October 27, 2011 11:39:22 AM UTC-4, thodoris wrote:
>
> > Hi,
>
> > I am wondering what is the best way to count how many times a file has
> > been downloaded. I have the following:
>
> > db.define_table('image',
> >    Field('file', 'upload'),
> >    Field('downloads','integer', default=0,readable=False,
> > writable=False))
>
> > I have a view that has the following:
>
> > {{=A("Download", _href=URL('download', args=image.file))}}
>
> > So when Download is clicked the file file will be downloaded.
>
> > The function that is called is:
>
> > def download():
> >     return response.download(request,db)
>
> > How can i increase the can increase the image.downloads each time a
> > file is downloaded.
>
> > I don't know how or if it is possible to pass the image.id in download
> > and increase the counter doing something like:
>
> > item = db.image[request.vars.id]
> > new_downloads = item.downloads + 1
> > item.update_record(downloads=new_downloads)
>
> > I tried passing more arguments to download like args=[image.file,
> > mage.id] but it fails. Any ideas


[web2py] Re: upload file to database using curl

2011-10-27 Thread howesc
i don't know the answer, but i would go about finding the answer by:
 - creating a form that lets me upload the file to web2py (see the book for 
examples)
 - run it in a browser while using tools that track the request sent to the 
server with the file (chrome has this built in with the network tab of the 
developer toolbar, or httpfox on FF, or charles)
 - figure out how to send the right headers and data to the server from 
cURL.

there may be a better way to glean this info, but that is the steps i'd 
take.


[web2py] Re: Auth in MongoDB

2011-10-27 Thread Francisco Costa
any insight?

On Oct 20, 5:51 pm, Francisco Costa  wrote:
> Hi,
> we are in the process of converting our MySQL DB toMongoDB(via
> pymongo).
>
> We have already convert the auth_user table.
> Now we want to change theauthconnection fromauth=Auth(globals(), db)
> toauth=Auth(globals(), mongo)
>
> but we get this error:
> TypeError: 'Collection' object is not callable. If you meant to call
> the 'Table' method on a 'Database' object it is failing because no
> such method exists.
>
> Is there any way that theauthsupports Collections and not only
> tables?


Re: [web2py] Re: Found a bug: XMLRPC with basic authorization fails

2011-10-27 Thread Hong-Khoan Quach
Hi Massimo,

we already have fixed the bug and we sent you a patch. Didn't you
receive our mail?

Regards

Matteo and Hong-Khoan


Am 27.10.2011 19:56, schrieb Massimo Di Pierro:
> Can you help me debug? Look into gluon.tools.py. There is a function
> basic() Add some print statements. Is it called? What does it return?
> 
> On Oct 23, 7:48 pm, Robert Clark  wrote:
>> Hi Massimo
>>
>> Here are the steps to reproduce this problem in web2py 1.99.2 (these
>> steps worked fine on 1.98.x versions)
>>
>> 1) In web2py admin create "New simple application" called "foo"
>>
>> 2) Add to db.py:
>> auth.settings.allow_basic_login = True
>>
>> 3) Decorate call() with @auth.requires_login in default.py:
>>
>> @auth.requires_login()
>> def call():
>> ...
>>
>> 4) Add a simple XMLPRC method to default.py:
>>
>> @service.xmlrpc
>> def multiply(a=1,b=1):
>> return dict(answer=int(a) * int(b))
>>
>> 5) Register a user with email "bob.sm...@foo.com" password "snowball"
>>
>> 6) From a python shell use ServerProxy to invoke the service
>>
>>> from xmlrpclib import ServerProxy
>>> server = 
>>> ServerProxy('http://bob.sm...@foo.com:snowball@localhost:8000/foo/default/call/xmlrpc',
>>>  verbose=True)
>>> server.multiply(2, 2)
>>
>> ...
>> reply: 'HTTP/1.1 303 SEE OTHER\r\n'
>> ...
>>
>> Cheers,
>> Rob
>>
>> On Oct 22, 2:59 am, Massimo Di Pierro 
>> wrote:
>>
>>
>>
>>
>>
>>
>>
>>> Can you provide an example to reproduce the problem?
>>
>>> On Oct 21, 12:38 am,RobinMarshall
>>> wrote:
>>
 Hi,
>>
 Just wanted to say that we found a bug in 1.99.2 when using XMLRPC
 services with the @auth.requires_login decorator using basic
 authentication.
>>
 It looks like some code was refactored out of requires_login into a
 generic requires method which might be the cause of the problem.
>>
 A quick hack was to change the following code, but obviously that
 won't work very well for people who aren't using basic authentication.
>>
 def is_logged_in(self):
 """
 checks if the user is logged in and returns True/False.
 if so user is in auth.user as well as in session.auth.user
 """
 if self.user:
 return True
 return False
>>
 to:
>>
 def is_logged_in(self):
 """
 checks if the user is logged in and returns True/False.
 if so user is in auth.user as well as in session.auth.user
 """
 if self.basic() and self.user:
 return True
 return False
>>
 Cheers,
 Robin



signature.asc
Description: OpenPGP digital signature


[web2py] New questions about the book

2011-10-27 Thread Archibald Linx
Dear Web2py users,

I have started playing around with Web2py. I am reading various parts
of the book. I am very satisfied with the framework and I find the
atmosphere of this mailing list very friendly. Thanks.

I have some more questions about the book.

1) Sometimes I see in the documentation "if form.process().accepted:"
and sometimes "if form.accepts(request.vars, session):". What's the
difference between the two ?

Actually the book I am reading is a few months old, and it seems that
since it was published, it has been quite modified.

I have seen that in chapter 3, all "if form.accepts(request.vars,
session):" have been replaced by "if form.process().accepted:". What's
the reason for that ?

2) On page 109 ( http://www.web2py.com/book/default/chapter/03#An-Image-Blog
), I have not really understood the following sentence :

"Line 9 processes the submitted form (the submitted form variables are
in request.vars) within the current session (the session is used to
prevent double submissions, and to enforce navigation)."

Line 9 refers to : "form.accepts(request.vars, session):"

Would it be different if I would just write :
"form.accepts(request.vars):" ?

I think I understand why using the session prevents double submissions
but I am not sure.

3) On page 108 ( http://www.web2py.com/book/default/chapter/03#An-Image-Blog
), there is written  :

if form.process().accepted:
response.flash = 'your comment is posted'

On page 112 ( http://www.web2py.com/book/default/chapter/03#Adding-CRUD
), there is written :

form = SQLFORM(table)
if form.process().accepted:
session.flash = '...'

Why is it sometimes "response.flash" and sometimes "session.flash" ?


Thanks in advance,
Archibald


Re: [web2py] Re: gluon.storage.Storage interface discrepancy?

2011-10-27 Thread Jonathan Lundell
On Oct 27, 2011, at 10:57 AM, Massimo Di Pierro wrote:

> Any suggestion for improvement?

I'm not sure when I'll have time to get around to it, but my idea is to 
implement both Storage.__getattr__ and .__getitem__ in terms of 
super(get(whatever, None)). (That's not quite the syntax, but you get the 
idea.) I don't suppose that __setattr__ needs any special attention.

> 
> On Oct 25, 3:32 pm, Jonathan Lundell  wrote:
>> On Oct 25, 2011, at 1:18 PM, Anthony  wrote:
>> 
>>> On Tuesday, October 25, 2011 4:08:20 PM UTC-4, pepper_bg wrote:
 You can do
 s.get(6,None)
>> 
>>> Still have to anticipate what my keys are and write different code
>>> accordingly. Which is fine in most cases I guess. Or may be I am
>>> trying to be too generic here. Thanks for your input...
>> 
>>> If you're not sure whether a key might be a string or integer, you can use 
>>> the s.get() method in all cases.
>> 
>> Still, it'd make sense for s['a'] to have the same semantics as s.a.




Re: [web2py] Re: gluon.storage.Storage interface discrepancy?

2011-10-27 Thread Jonathan Lundell
On Oct 27, 2011, at 5:03 PM, Jonathan Lundell wrote:

> On Oct 27, 2011, at 10:57 AM, Massimo Di Pierro wrote:
> 
>> Any suggestion for improvement?
> 
> I'm not sure when I'll have time to get around to it, but my idea is to 
> implement both Storage.__getattr__ and .__getitem__ in terms of 
> super(get(whatever, None)). (That's not quite the syntax, but you get the 
> idea.) I don't suppose that __setattr__ needs any special attention.

__setitem__, I meant.

> 
>> 
>> On Oct 25, 3:32 pm, Jonathan Lundell  wrote:
>>> On Oct 25, 2011, at 1:18 PM, Anthony  wrote:
>>> 
 On Tuesday, October 25, 2011 4:08:20 PM UTC-4, pepper_bg wrote:
> You can do
> s.get(6,None)
>>> 
 Still have to anticipate what my keys are and write different code
 accordingly. Which is fine in most cases I guess. Or may be I am
 trying to be too generic here. Thanks for your input...
>>> 
 If you're not sure whether a key might be a string or integer, you can use 
 the s.get() method in all cases.
>>> 
>>> Still, it'd make sense for s['a'] to have the same semantics as s.a.
> 
> 




[web2py] Re: New questions about the book

2011-10-27 Thread Anthony
On Thursday, October 27, 2011 7:57:31 PM UTC-4, Archibald Linx wrote:
>
>
> 1) Sometimes I see in the documentation "if form.process().accepted:" 
> and sometimes "if form.accepts(request.vars, session):". What's the 
> difference between the two ?
>

form.process() was added very recently and is now preferred over 
form.accepts (though the latter is still perfectly fine). 
See http://web2py.com/book/default/chapter/07#The-process-and-validate-methods. 
form.process() does the same thing (it actually calls form.accepts()), but 
returns the form itself (hence the need to add .accepted if you want to see 
if it was accepted).
 

>
> 2) On page 109 ( 
> http://www.web2py.com/book/default/chapter/03#An-Image-Blog 
> ), I have not really understood the following sentence : 
>
> "Line 9 processes the submitted form (the submitted form variables are 
> in request.vars) within the current session (the session is used to 
> prevent double submissions, and to enforce navigation)." 
>
> Line 9 refers to : "form.accepts(request.vars, session):" 
>
> Would it be different if I would just write : 
> "form.accepts(request.vars):" ? 
>

Yes, if you leave out the session, it won't create a hidden _formkey field 
and store the value in the session. This is the mechanism web2py uses to 
prevent double form submission and CSRF attacks. 
See http://web2py.com/book/default/chapter/07#Hidden-fields.
 

> 3) On page 108 ( 
> http://www.web2py.com/book/default/chapter/03#An-Image-Blog 
> ), there is written  : 
>
> if form.process().accepted: 
> response.flash = 'your comment is posted' 
>
> On page 112 ( http://www.web2py.com/book/default/chapter/03#Adding-CRUD 
> ), there is written : 
>
> form = SQLFORM(table) 
> if form.process().accepted: 
> session.flash = '...' 
>
> Why is it sometimes "response.flash" and sometimes "session.flash" ?
>

response.flash if the form page will be reloading; session.flash if you are 
redirecting to a new page. 
See http://web2py.com/book/default/chapter/07#Forms-and-redirection.

Basically, things should hopefully clear up when you read the forms chapter.

Anthony



Re: [web2py] Auth in MongoDB

2011-10-27 Thread ~redShadow~
On Thu, 2011-10-20 at 09:51 -0700, Francisco Costa wrote: 
> Hi,
> we are in the process of converting our MySQL DB to MongoDB (via
> pymongo).
> 
> We have already convert the auth_user table.
> Now we want to change the auth connection from
> auth = Auth(globals(), db)
> to
> auth = Auth(globals(), mongo)
> 
> but we get this error:
> TypeError: 'Collection' object is not callable. If you meant to call
> the 'Table' method on a 'Database' object it is failing because no
> such method exists.
> 
> Is there any way that the auth supports Collections and not only
> tables?

You will be able to do that using DAL with the mongodb adapter (once it
is finished); you get that error since Auth() expects a DAL object as
the second argument to constructor, in order to access the database;
instead, you are passing a pymongo.Collection object that Auth doesn't
know how to use..

For now, the two solutions I see are:
- temporarily use a sqlite database just to store users/auth stuff
- write a custom (maybe inheriting) "MongoAuth" object that acts like
Auth but uses mongodb collections to store data

-- 
Samuele ~redShadow~ Santi

 redshadow[at]hackzine.org - redshadowhack[at]gmail.com

  Blog: http://hackzine.org

  GPG Key signature:
   050D 3E9F 6E0B 44CE C008 D1FC 166C 3C7E EB26 4933

/me recommends:
Squadra Informatica - http://www.squadrainformatica.com

 - Proud ThinkPad T-Series owner
 - Registered Linux-User: #440008
  * GENTOO User since 1199142000 (2008-01-01)
  * former DEBIAN SID user

  "Software is like sex: it's better when it's free!"
  -- Linus Torvalds



signature.asc
Description: This is a digitally signed message part


[web2py] Suggestions for multiple files upload in form

2011-10-27 Thread Paolo Caruccio
I wasn't able to find in the web, even in this group, a multiple files 
upload system with the followings requirements:

- upload the files together with form submit
- no frame, no flash, no ajax form submit but only jquery and python
- give a title to the uploading files
- simple to integrate and control in web2py 

so, inspired by 
http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/,
 
I wrote one by my self.
It's minimalist and the code isn't optimized (I'm not a programmer), but it 
works for my purposes.

If you would like to test it in default welcome web2py app:
 - put jquery.multiuploads.js in static/js folder
 - put multiuploads.css in static/css folder
 - append the functions to default.py in controllers folder
 - append the table definition to db.py in models folder
 - put upload_documents.html in views folder

You'll find some comments in the code and also many errors.

I look forward to your suggestions and opinions.

Ciao.

Paolo
{{response.files.extend([URL('static','css/multiuploads.css'),URL('static','js/jquery.multiuploads.js')])}}
{{extend 'layout.html'}}

{{=form}}




jquery.multiuploads.js
Description: JavaScript source
/* CAUTION: essential rules don't remove */
div.multiupload_widget 
{
	display:inline-block; /* fix the div.error issue */
}

ul.mw_list
{
	display:block;
}

input.mw_fileTitle
{
	float:left;
}

div.mw_fileBrowserWrapper
{
	float:left;
}

a.mw_addBtn
{
	display:block;
	position:relative;
	overflow:hidden;
	max-width:70px;
	min-height:22px;
	text-align:center;
	margin-right:2px;
}

a.mw_clearBtn
{
	float:left;
	max-width:70px;
	min-height:22px;
	text-align:center;
	margin-left:2px;
}

a.mw_delItem
{
	display:block;
	float:right;
}

ul.mw_list ul
{
	width:90%; /* to avoid elastic when we slide it */
}
li.mw_group
{
	cursor:pointer;
}

/* CUSTOMIZATION */

div.multiupload_widget
{
width:280px;
margin: 2px 15px 2px 5px;
padding:0 1px;
}

ul.mw_list
{
margin:0 0 4px 0;
padding:0;
min-height:32px;
border:1px solid #e1e1e1;
border-radius:2px;
overflow:auto;
list-style:none;
}

ul.mw_list>li
{
font-weight:bold;
display:block;
margin:2px 0;
}

ul.mw_list li:hover
{
background-color:lightyellow;
}

ul.mw_list ul
{
list-style:none;
margin-top:2px;
margin-left:22px;
width:256px; /*div.multiupload_widget - (margin-left + 2*(border width)) => 280-(22+2) */
}

ul.mw_list ul li
{
font-weight:normal;
}

ul.mw_list span
{
word-wrap:break-word;
display:inline-block;
width:80%;
margin:0 0 0 10px;
}

li.mw_group
{

}

li.mw_group span
{

}

div.mw_bar{}

input[type="text"].mw_fileTitle
{
width:69%;
padding-left:3px;
}

div.mw_fileBrowserWrapper{}

a.mw_addBtn, a.mw_clearBtn
{
width:24px;
height:22px;
background:#EAEAEA;
border:1px solid #DEDEDE;
border-radius:2px;
margin:0 2px 0 2px;
font-size:16px;
font-weight:bold;
line-height:22px;
}

a.mw_addBtn
{
line-height:24px;
}

a.mw_addBtn:hover, a.mw_clearBtn:hover
{
text-decoration:none;
}

a.mw_addBtn > span {}
a.mw_clearBtn > span {}

a.mw_delItem
{
width:16px;
height:16px;
background-color:silver;
color:white;
font-weight:bold;
border-radius:10px;
text-align:center;
font-size:13px;
line-height:13px;
text-decoration:none;
margin:2px 4px 0 0;
}

a.mw_delItem:hover
{
text-decoration:none;
color:#275B90;
background-color:#aaa;
}

/*--*/
/* FILE ICON - based on http://nicolasgallagher.com/pure-css-gui-icons/
/*--*/

ul.mw_list i
{
display: block;
float: left;
width: 12px;
height: 17px;
background: #eee;
margin-left: 4px;
margin-top: 2px;
position: relative;
}

ul.mw_list b
{
	z-index:1;
	overflow:hidden;
	padding:0;
}

ul.mw_list b em
{
	border-bottom: 1px solid #275B90;
	color: #275B90;
	display: block;
}

ul.mw_list b em::before, ul.mw_list b em::after
{
margin: -8px 0 0;
background: #275B90;
}

ul.mw_list b em::before
{
left: 5px;
width: 8px;
height: 12px;
border: 2px solid #275B90;
background: transparent;
}

ul.mw_list b em::after
{
left: 4px;
border-width: 3px;
border-style: solid;
border-color: white #275B90 #275B90 white;
margin-top: -9px;
background: transparent;
}

ul.mw_list b::before, ul.mw_list b::after, ul.mw_list b em::before, ul.mw_list b em::after 
{
	content:"";
	position:absolute;
	top:50%;
	left:0;
}

/*--*/def check(form):
# check if file list is empty. We, indeed, set notnull=False for f_document Field 
for var in request.vars:
if var.startswith('f_document') and request.vars[var] != '': return
form.errors.f_document = T("file list is empty")


def upload_documents():
# only SQLFORM.factory tested
form=SQLFORM.factory(db.t_documents)

if form.accepts(request, session, onvalidation=lambda form:check(form)): # Is it possible to use onvalidation with form.process() syntax ?
nfiles = 0
for var in 

[web2py] Re: Web2py won't connect to MSSQL

2011-10-27 Thread chris_g
I recently had a similar problem where I could import pyodbc at the
python shell, but I was getting a DLL error when I tried to import
pyodbc under mod_wsgi.
I suggest that you put "import pyodbc" inside your wsgihandler.py (or
at the top of db.py) and see what errors are being produced.
I had recently had this problem and resolved it by following the steps
described here:
http://code.google.com/p/pyodbc/issues/detail?id=214

Chris Guest


[web2py] SQLFORM.grid behavior with an empty table

2011-10-27 Thread Bob St John
using 1.99.2

SQLFORM.grid...

I don't see the need for this statement...

line 1641: if not searchable and not rows: return DIV(T('No records
found'))

If it was removed a user would see an empty grid rather than just a
div, no matter what the value of 'searchable' was.

An empty grid allows the user to add a record, which seems more usable
than the 'No records found' result when searchable=False


Re: [web2py] Suggestions for multiple files upload in form

2011-10-27 Thread Bruno Rocha
Thanks for this, I am using another jquery library for upload and I am going
o test this.

Can you provide a packed .w2p web2py application?

On Thu, Oct 27, 2011 at 10:40 PM, Paolo Caruccio  wrote:

> I wasn't able to find in the web, even in this group, a multiple files
> upload system with the followings requirements:
>
> - upload the files together with form submit
> - no frame, no flash, no ajax form submit but only jquery and python
> - give a title to the uploading files
> - simple to integrate and control in web2py
>
> so, inspired by
> http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/,
> I wrote one by my self.
> It's minimalist and the code isn't optimized (I'm not a programmer), but it
> works for my purposes.
>
> If you would like to test it in default welcome web2py app:
>  - put jquery.multiuploads.js in static/js folder
>  - put multiuploads.css in static/css folder
>  - append the functions to default.py in controllers folder
>  - append the table definition to db.py in models folder
>  - put upload_documents.html in views folder
>
> You'll find some comments in the code and also many errors.
>
> I look forward to your suggestions and opinions.
>
> Ciao.
>
> Paolo
>



-- 

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


[web2py] Re: db events trigger

2011-10-27 Thread Igor
Any progress on this feature?
This could be really nice.


Re: [web2py] Suggestions for multiple files upload in form

2011-10-27 Thread Ovidio Marinho
  I got was this, it seems not to be carrying it. js

http://www.diigo.com/item/image/1iw09/9pki


   Ovidio Marinho Falcao Neto
Web Developer
 ovidio...@gmail.com
  ovidiomari...@itjp.net.br
 ITJP - itjp.net.br
   83   8826 9088 - Oi
   83   9334 0266 - Claro
Brasil



2011/10/27 Bruno Rocha 

>
>
> Thanks for this, I am using another jquery library for upload and I am
> going o test this.
>
> Can you provide a packed .w2p web2py application?
>
> On Thu, Oct 27, 2011 at 10:40 PM, Paolo Caruccio <
> paolo.carucci...@gmail.com> wrote:
>
>> I wasn't able to find in the web, even in this group, a multiple files
>> upload system with the followings requirements:
>>
>> - upload the files together with form submit
>> - no frame, no flash, no ajax form submit but only jquery and python
>> - give a title to the uploading files
>> - simple to integrate and control in web2py
>>
>> so, inspired by
>> http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/,
>> I wrote one by my self.
>> It's minimalist and the code isn't optimized (I'm not a programmer), but
>> it works for my purposes.
>>
>> If you would like to test it in default welcome web2py app:
>>  - put jquery.multiuploads.js in static/js folder
>>  - put multiuploads.css in static/css folder
>>  - append the functions to default.py in controllers folder
>>  - append the table definition to db.py in models folder
>>  - put upload_documents.html in views folder
>>
>> You'll find some comments in the code and also many errors.
>>
>> I look forward to your suggestions and opinions.
>>
>> Ciao.
>>
>> Paolo
>>
>
>
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>


[web2py] Re: MongoDB testing and development

2011-10-27 Thread Mark Breedveld
Found another error, but I can't figure out an solution.
But it must be rather simple.

I use the following model and without auth ofcourse
if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
dbp = DAL('mysql://root:MerMB#2#@192.168.2.29/performance') <--
this one doesn't matter right know
tdb = DAL('mongodb://mb1/db') <-- Connects perfectly, but

tdb.define_table('blog',
Field('name','string'))
tdb.define_table('category',
Field('name',"string"))
tdb.define_table('post',
Field('category',tdb.category),
Field('blog',tdb.blog),
Field('title',"string"),
Field('createdt',"datetime",default=datetime.datetime.now))
tdb.define_table('comment',
Field('content', "text"),
Field('createdt',"datetime",default=datetime.datetime.now))
tdb.define_table('likepost',
Field('likescomment','boolean'),
Field('comment',tdb.comment))
tdb.define_table('postgps',
Field('latitude',"double"),
Field('longitude',"double"),
Field('post',tdb.post))

#Modifications too DAL

def insert(self,table,fields):
ctable = self.connection[table._tablename]
values = dict((k,self.represent(v,table[k].type)) for k,v in
fields) <-- This doesn't work
ctable.insert(values)
return uuid2int(id)

def create_table(self, table, migrate=True, fake_migrate=False,
polymodel=None):
capped=0 # 100 or capped < 1:
"""
#TODO throw new Error that this is an illigal
size?
#http://api.mongodb.org/python/current/api/pymongo/
database.html (create_collection())
If I understood well, then capped collections are
quite limited in size
But they also clean themselves, so maybe we could
implement a general log structure on this type of collections
This part of the method cant't be reached right
now, since we can not implement the capped argument
"""
pass
else:
self.connection.create_collection(table,
size=capped, capped=True)
except CollectionInvalid:
pass
#TODO converted uncapped collection to capped
collection
#create capped tables with a fixed length for performance


Traceback (most recent call last):
  File "/home/beheerder/web2py/gluon/restricted.py", line 204, in
restricted
exec ccode in environment
  File "/home/beheerder/web2py/applications/pt/controllers/
default.py", line 112, in 
  File "/home/beheerder/web2py/gluon/globals.py", line 149, in

self._caller = lambda f: f()
  File "/home/beheerder/web2py/applications/pt/controllers/
default.py", line 73, in add_blog
tdb.blog.insert(name=request.vars.name)
  File "/home/beheerder/web2py/gluon/dal.py", line 5091, in insert
return self._db._adapter.insert(self,self._listify(fields))
  File "/home/beheerder/web2py/gluon/dal.py", line 3754, in insert
values = dict((k,self.represent(v,table[k].type)) for k,v in
fields)
  File "/home/beheerder/web2py/gluon/dal.py", line 3754, in 
values = dict((k,self.represent(v,table[k].type)) for k,v in
fields)
  File "/home/beheerder/web2py/gluon/dal.py", line 4976, in
__getitem__
return dict.__getitem__(self, str(key))
KeyError: 'blog.name'

Any idea? My suggestion is that the fields are not loaded some how,
because of the create function?

On 21 okt, 17:01, Massimo Di Pierro 
wrote:
> yes.
>
> On Oct 21, 2:55 am,MarkBreedveld  wrote:
>
>
>
>
>
>
>
> > Dear Massimo,
>
> > I downloaded the trunk and I am currently testing the MongoDB Adapter
> > and I can tell that inserting currently isn't working. Also the
> > creation of tables doesn't work.
>
> > First question, shall I put the bugs and improvements that I find in
> > the Issue list or just in this discussion?
>
> > Secondly, the create_table method, is it possible to just skip the
> > function with a pass command? Cause collection in mongodb are created
> > on first insert of an document. There are capped collections in
> > MongoDB which offer better performance, but there data size is fixed.
> > My advise would be that by default the model is just passed(if not
> > needed somewhere else in web2py) and we could later implement the
> > capped collections. Because I want to have the adapter working first.
>
> > def create_table(self, table, migrate=True, fake_migrate=False,
> > polymodel=None):
> >         pass
> >                 #May capped collection 
> > here?http://www.mongodb.org/display/DOCS/Capped+Collections
> >                 #because pymongo create collection on first insert 
> > (inserting a
> > document)http://api.mongodb.org/python/2.0/tutorial.html
>
> > RegardsMark,