[web2py] Populate a simple form (without a database)

2011-06-25 Thread Martin Weissenboeck
Hi,

let's say I have a simple form like the following:

def one():

form = FORM(_name='n')

if form.accepts(request.vars, session):

# do something
redirect(URL('two'))

else:

*# what I want to do is something like*

*form.vars.n = 'MY DYNAMIC VALUE'*


return dict(form=form)


Regards, Martin


[web2py] how to round the number of seconds

2011-06-25 Thread dorasan
Hello everyone.

Could you tell me how to round the number of seconds which
'request.now' represents like this

'2011-06-25 15:26:55.881000'   =  '2011-06-25 15:26:55' or
'2011-06-25 15:26:56'

thank you

dorasan


[web2py] how to round the number of seconds

2011-06-25 Thread portable dora
Im sorry. I missed the tag '[web2py]'

-- Forwarded message --
From: dorasan portabled...@gmail.com
Date: 2011/6/25
Subject: how to round the number of seconds
To: web2py-users web2py@googlegroups.com


Hello everyone.

Could you tell me how to round the number of seconds which
'request.now' represents like this

'2011-06-25 15:26:55.881000'   =  '2011-06-25 15:26:55' or
'2011-06-25 15:26:56'

thank you

dorasan


Re: [web2py] how to round the number of seconds

2011-06-25 Thread Bruno Rocha
mydate = request.now()
mydate.strftime('%Y-%m-%d %H:%M:%S')



--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]



On Sat, Jun 25, 2011 at 3:36 AM, dorasan portabled...@gmail.com wrote:

 Hello everyone.

 Could you tell me how to round the number of seconds which
 'request.now' represents like this

 '2011-06-25 15:26:55.881000'   =  '2011-06-25 15:26:55' or
 '2011-06-25 15:26:56'

 thank you

 dorasan


[web2py] Re: dict.__getitem__(self, key) KeyError: 'nombre'

2011-06-25 Thread Juan Antonio
Ok, I have the reason why i got this KeyError.

The problem was not on table 'fab_lote', the problem was in table
'db.fabricacion'.

The argument 'format' in definition of table db.fabricacion was wrong
and the field 'nombre' does not exis in this table:

db.define_table('fabricacion',
   Field('escandallo', db.escandallo, writable=False),
   Field('cantidad', 'double'),
   Field('fecha_alta', 'date', default=datetime.date.today(),
writable=False),
   Field('fecha_mod', 'date',  writable=False),
   Field('cerrado', writable=False, default='no'),
   Field('lote_fabricado', db.lote, writable=False),
   Field('observaciones', widget=SQLFORM.widgets.text.widget),
format='%(nombre)s'))

So that's it.

Juan A.


On 24 jun, 17:44, Juan Antonio juanr...@gmail.com wrote:
 Hello,

 Together with others tables I have this in my db.py file:
 ...
 db.define_table('fab_lote',
    Field('fabricacion', db.fabricacion),
    Field('lote', db.lote),
    Field('cantidad_orden', 'double'),
    Field('cantidad_gastado', 'double'),
    Field('coste_unitario', 'double'))
 

 when I click on 'db.fab_lote ' in the database admin api I get:
 Traceback (most recent call last):
   File /home/jaromero/juan/programacion/web2py/gluon/restricted.py,
 line 192, in restricted
     exec ccode in environment
   File /home/jaromero/juan/programacion/web2py/applications/
 librefactory/views/appadmin.html, line 161, in module
     strong{{=%02d % ram['oldest'][1]}}/strong minutes
   File /home/jaromero/juan/programacion/web2py/gluon/sqlhtml.py,
 line 1366, in __init__
     r = A(field.represent(r), _href=str(href))
   File /home/jaromero/juan/programacion/web2py/gluon/dal.py, line
 3631, in repr_ref
     def repr_ref(id, r=referenced, f=ff): return f(r, id)
   File /home/jaromero/juan/programacion/web2py/gluon/dal.py, line
 3604, in ff
     return r._format % row
   File /home/jaromero/juan/programacion/web2py/gluon/dal.py, line
 3697, in __getitem__
     return dict.__getitem__(self, key)
 KeyError: 'nombre'

 But field 'nombre' is not anymore in this table.

 I get the same in some controllers.

 From the shell I can get the data from this table with select()
 without any problem. why do I get this KeyError?


[web2py] LessCSS -- really interesting CSS compiler

2011-06-25 Thread Joe Barnhart
http://lescss.org/

The crux of this js library is to preprocess your CSS files so you can
use a few carefully-chosen extensions to make your CSS files smaller
and more powerful (kind of like web2py).

For example, VARIABLES.  How many times have you wished you could just
assign a name to a color and then use it over and over and over inside
your CSS file?  Another example, NESTING.  You can actually use a
class, id, or element definition within another and its definition
nests.  And you can even pass parameters to tailor the nested CSS.

For something as simple in concept, it's a little overwhelming at how
it can transform a complicated CSS file.  I'm still wrapping my head
around it.

-- Joe B.


[web2py] Re: LessCSS -- really interesting CSS compiler

2011-06-25 Thread Joe Barnhart
That's http://lesscss.org/  Sheesh.

On Jun 25, 7:50 pm, Joe  Barnhart joe.barnh...@gmail.com wrote:
 http://lescss.org/


Re: [web2py] Re: LessCSS -- really interesting CSS compiler

2011-06-25 Thread Stef Mientki
On 25-06-2011 13:51, Joe Barnhart wrote:
 That's http://lesscss.org/  Sheesh.

 On Jun 25, 7:50 pm, Joe  Barnhart joe.barnh...@gmail.com wrote:
 http://lescss.org/
thanks Joe,

I've looking for such a tool for years.

cheers,
Stef


Re: [web2py] Re: I created a little app to be able to share some files over the net without authentication

2011-06-25 Thread szimszon
Okay. I put a GPL3 in it. Is that okay? :) I not really care. :) This is 
just for fun.

So fork it! Submit pull requests! Make it more fun! And tell me if you like 
it :-D



[web2py] Re: Populate a simple form (without a database)

2011-06-25 Thread Massimo Di Pierro
form=SQLFORM.factory(Field('n',default='MY DYNAMIC VALUE'))
if form.acepts(request,session): redirect(URL('two))
retur dict(form=form)

On Jun 25, 1:15 am, Martin Weissenboeck mweis...@gmail.com wrote:
 Hi,

 let's say I have a simple form like the following:

 def one():

 form = FORM(_name='n')

 if form.accepts(request.vars, session):

 # do something
 redirect(URL('two'))

 else:

 *# what I want to do is something like*

 *form.vars.n = 'MY DYNAMIC VALUE'*

 return dict(form=form)

 Regards, Martin


[web2py] Re: Populate a simple form (without a database)

2011-06-25 Thread Anthony
First, I think you want FORM(INPUT(_name='n')), otherwise you'll have an 
empty form.
 
If you want to pre-populate a form using form.vars.fieldname=somevalue, you 
have to do that after the form is created, but *before* you call 
form.accepts (the form.accepts method adds the form.vars value to the INPUT 
element). See 
http://web2py.com/book/default/chapter/07#Pre-populating-the-form.
 
If you only want to pre-populate the field after a failed form submission 
(but not when the form is initially loaded), then you could use an 
alternative method:
 
form.element(_name='n').update(_value='MY DYNAMIC VALUE')
 
That updates the html INPUT element directly instead of relying on 
form.accepts to add the form.vars value to the element.
 
Anthony

On Saturday, June 25, 2011 2:15:57 AM UTC-4, mweissen wrote:

 Hi, 

 let's say I have a simple form like the following:

 def one():

 form = FORM(_name='n')

  if form.accepts(request.vars, session):

  # do something
 redirect(URL('two'))

 else:

  *# what I want to do is something like*

  *form.vars.n = 'MY DYNAMIC VALUE'*


 return dict(form=form)


  Regards, Martin



Re: [web2py] web2py and postgresql schema

2011-06-25 Thread Massimiliano
I've the same problem.
Take a look here.

http://groups.google.com/group/web2py/browse_thread/thread/8b5e166b7b27edc7?pli=1


On Fri, Jun 24, 2011 at 3:11 PM, Camil Ghircoias
ghircoiasca...@yahoo.comwrote:

 Hi,

 I am now reading some documnentation about web2py.
 Does web2py support postgresql schemas ?
 I have my tables grouped in postgresql into scheme inside same
 database.
 So I can have same tables into the same databases but in different
 schemas.

 Like

 schema1.mytable
 schema2.mytable

 How can I work with web2py without renaming tables or changing the
 database logic ?

 I write here because on internbet there was not a clear answer if you
 can work with it or not.



Ciao
-- 
Massimiliano


Re: [web2py] how to round the number of seconds

2011-06-25 Thread portable dora
THANK YOU!!!


2011/6/25 Bruno Rocha rochacbr...@gmail.com

 mydate = request.now()
 mydate.strftime('%Y-%m-%d %H:%M:%S')



 --
 Bruno Rocha
 [ About me: http://zerp.ly/rochacbruno ]



 On Sat, Jun 25, 2011 at 3:36 AM, dorasan portabled...@gmail.com wrote:

 Hello everyone.

 Could you tell me how to round the number of seconds which
 'request.now' represents like this

 '2011-06-25 15:26:55.881000'   =  '2011-06-25 15:26:55' or
 '2011-06-25 15:26:56'

 thank you

 dorasan





[web2py] let eclipse find global functions defined in model folder

2011-06-25 Thread Sebastian E. Ovide
Hi All,

I've add a bunch of imports into my plugin controller and model which fixed
all my eclipse errors. Now I've added a function into my plugin model but it
is not seen by Eclipse in my plugin controller.

any ideas ?

-- 
Sebastian E. Ovide


[web2py] Re: Speed of rendering html data (10,000+ rows)

2011-06-25 Thread Vineet
I tried doing like this:--

In controller--

def get_data():
custdata = db.executesql(qry, as_dict=True)
return response.json(custdata)

And in View,

other code is as earlier (hence omitted)
sAjaxSource: {{=URL('MIS','get_data')}},


Still, the dataTable is blank.
Pl. help.

---Vineet

On Jun 24, 5:56 pm, Vineet vineet.deod...@gmail.com wrote:
 As suggested by the community, I am trying to export json data to
 dataTable.
 But only blank dataTable is rendered (with desired formatting, search
 box, etc.)
 Pl. introspect into my code as to where I have a mistake.
 Data is not displayed (as returned by get_data method).
 I have made sure that the tables in MySQL have been populated.

 ---
 Controller
 ---
 def show_data():
     return dict()

 def get_data():
     custdata = db.executesql(qry, as_dict=True)
     return dict(mydata=custdata)

 # For testing purpose, I returned response.json(custdata) in a
 separate method  validated the output on jsonlint.com.
 It is valid json.
 But, here the returned value is dict(mydata=custdata).
 How do I reference the custdata object in View?
 Already tried {{=mydata}} in script tag in View

 ---
 View (show_data.html)
 ---
 {{extend 'layout.html'}}

 script
 $(document).ready(function() {
     var oTable = $('.smarttable').dataTable( {
         sScrollY: 200px,
         sAjaxSource: {{=URL('MIS','get_data.json')}},
         sDom: frtiS,
         bDeferRender: true
     } );} );

 /script

 # html table tags go here

 h1Customer Database/h1
 br /
 table class=smarttable
 thead
 tr
     thCustomer Name/ththVehicle No/thetc.
 /tr
 /thead
 tbody

 /tbody
 /table

 # This link is for testing json data returned.
 a href='{{=URL('MIS','get_rows.json')}}'my_json/a

 Thanks,
 Vineet

 On Jun 22, 1:51 am, contatogilson...@gmail.com



 contatogilson...@gmail.com wrote:
  It can paginate data?
  _
  *Gilson Filho*
  *Web Developerhttp://gilsondev.com*- Hide quoted text -

 - Show quoted text -


Re: [web2py] Re: Speed of rendering html data (10,000+ rows)

2011-06-25 Thread Vasile Ermicioi
try

def get_data():
   custdata = db.executesql(qry, as_dict=True)
   return response.json(custdata.as_list())

also go to this link   http://yoururl/app/controller/get_data
you should see a json response


Re: [web2py] Re: Speed of rendering html data (10,000+ rows)

2011-06-25 Thread Anthony
On Saturday, June 25, 2011 1:07:39 PM UTC-4, elffikk wrote: 


 try

 def get_data():
custdata = db.executesql(qry, as_dict=True)
return response.json(custdata.as_list())

 
He's already using as_dict=True in the executesql call, so doing 
custdata.as_list() shouldn't be necessary.
 


[web2py] Re: Speed of rendering html data (10,000+ rows)

2011-06-25 Thread Anthony
Is MIS your app name, or the controller name? If it's the app name, your URL 
call also needs the controller name, or it will think MIS is the controller 
and the Ajax call will fail.

On Saturday, June 25, 2011 1:02:50 PM UTC-4, Vineet wrote:

 I tried doing like this:-- 

 In controller-- 

 def get_data(): 
 custdata = db.executesql(qry, as_dict=True) 
 return response.json(custdata) 

 And in View, 

 other code is as earlier (hence omitted) 
 sAjaxSource: {{=URL('MIS','get_data')}}, 


 Still, the dataTable is blank. 
 Pl. help. 

 ---Vineet 

 On Jun 24, 5:56 pm, Vineet vineet@gmail.com wrote: 
  As suggested by the community, I am trying to export json data to 
  dataTable. 
  But only blank dataTable is rendered (with desired formatting, search 
  box, etc.) 
  Pl. introspect into my code as to where I have a mistake. 
  Data is not displayed (as returned by get_data method). 
  I have made sure that the tables in MySQL have been populated. 
  
  --- 
  Controller 
  --- 
  def show_data(): 
  return dict() 
  
  def get_data(): 
  custdata = db.executesql(qry, as_dict=True) 
  return dict(mydata=custdata) 
  
  # For testing purpose, I returned response.json(custdata) in a 
  separate method  validated the output on jsonlint.com. 
  It is valid json. 
  But, here the returned value is dict(mydata=custdata). 
  How do I reference the custdata object in View? 
  Already tried {{=mydata}} in script tag in View 
  
  --- 
  View (show_data.html) 
  --- 
  {{extend 'layout.html'}} 
  
  script 
  $(document).ready(function() { 
  var oTable = $('.smarttable').dataTable( { 
  sScrollY: 200px, 
  sAjaxSource: {{=URL('MIS','get_data.json')}}, 
  sDom: frtiS, 
  bDeferRender: true 
  } );} ); 
  
  /script 
  
  # html table tags go here 
  
  h1Customer Database/h1 
  br / 
  table class=smarttable 
  thead 
  tr 
  thCustomer Name/ththVehicle No/thetc. 
  /tr 
  /thead 
  tbody 
  
  /tbody 
  /table 
  
  # This link is for testing json data returned. 
  a href='{{=URL('MIS','get_rows.json')}}'my_json/a 
  
  Thanks, 
  Vineet 
  
  On Jun 22, 1:51 am, contatog...@gmail.com 
  
  
  
  contatog...@gmail.com wrote: 
   It can paginate data? 
   _ 
   *Gilson Filho* 
   *Web Developerhttp://gilsondev.com*- Hide quoted text - 
  
  - Show quoted text -



[web2py] Error on upgrading to 1.96.4

2011-06-25 Thread Kenneth Lundström

Environment:
Centos 5.5, Apache 2.something, mod_wsgi, MySQL

Version 1.95.something worked nice


[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] mod_wsgi 
(pid=23210): Target WSGI script '/data/domains/web2py/wsgihandler.py' 
cannot be loaded as Python module.
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] mod_wsgi 
(pid=23210): Exception occurred processing WSGI script 
'/data/domains/web2py/wsgihandler.py'.
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] Traceback (most 
recent call last):
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File 
/data/domains/web2py/wsgihandler.py, line 31, in module
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] import 
gluon.main
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File 
/data/domains/web2py/gluon/__init__.py, line 15, in module
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] from 
globals import current
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File 
/data/domains/web2py/gluon/globals.py, line 21, in module
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] from html 
import xmlescape, TABLE, TR, PRE
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File 
/data/domains/web2py/gluon/html.py, line 29, in module
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] from utils 
import web2py_uuid, hmac_hash
[Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] ImportError: 
cannot import name hmac_hash




[web2py] Re: Error on upgrading to 1.96.4

2011-06-25 Thread Massimo Di Pierro
Something is wrong with your upgrade. The gluon/utils.py did not get
updated.

On Jun 25, 1:14 pm, Kenneth Lundström kenneth.t.lundst...@gmail.com
wrote:
 Environment:
 Centos 5.5, Apache 2.something, mod_wsgi, MySQL

 Version 1.95.something worked nice

 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] mod_wsgi
 (pid=23210): Target WSGI script '/data/domains/web2py/wsgihandler.py'
 cannot be loaded as Python module.
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] mod_wsgi
 (pid=23210): Exception occurred processing WSGI script
 '/data/domains/web2py/wsgihandler.py'.
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] Traceback (most
 recent call last):
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File
 /data/domains/web2py/wsgihandler.py, line 31, in module
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]     import
 gluon.main
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File
 /data/domains/web2py/gluon/__init__.py, line 15, in module
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]     from
 globals import current
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File
 /data/domains/web2py/gluon/globals.py, line 21, in module
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]     from html
 import xmlescape, TABLE, TR, PRE
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File
 /data/domains/web2py/gluon/html.py, line 29, in module
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]     from utils
 import web2py_uuid, hmac_hash
 [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] ImportError:
 cannot import name hmac_hash


[web2py] Re: Error on upgrading to 1.96.4

2011-06-25 Thread Kenneth
Interesting, I did the upgrade with Upgrade button in admin and web2py
crasched when updating, not sure at what point.

I did a manual upgrade and now everything works again.

Thank You Massimo.


On Jun 25, 9:28 pm, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 Something is wrong with your upgrade. The gluon/utils.py did not get
 updated.

 On Jun 25, 1:14 pm, Kenneth Lundström kenneth.t.lundst...@gmail.com
 wrote:







  Environment:
  Centos 5.5, Apache 2.something, mod_wsgi, MySQL

  Version 1.95.something worked nice

  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] mod_wsgi
  (pid=23210): Target WSGI script '/data/domains/web2py/wsgihandler.py'
  cannot be loaded as Python module.
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] mod_wsgi
  (pid=23210): Exception occurred processing WSGI script
  '/data/domains/web2py/wsgihandler.py'.
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] Traceback (most
  recent call last):
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File
  /data/domains/web2py/wsgihandler.py, line 31, in module
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]     import
  gluon.main
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File
  /data/domains/web2py/gluon/__init__.py, line 15, in module
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]     from
  globals import current
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File
  /data/domains/web2py/gluon/globals.py, line 21, in module
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]     from html
  import xmlescape, TABLE, TR, PRE
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]   File
  /data/domains/web2py/gluon/html.py, line 29, in module
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10]     from utils
  import web2py_uuid, hmac_hash
  [Sat Jun 25 21:51:17 2011] [error] [client 93.106.44.10] ImportError:
  cannot import name hmac_hash


[web2py] redirect(URL())

2011-06-25 Thread Kenneth
I tried to make a redirect to my frontpage and didn´t remember how to
do that so I tried with redirect(URL()). That leads to a endless loop.
In my case Firefox stopped after trying to redirect. Maybe web2py
should detect this stupid programming error or is there a case when
URL() is needed?

Now I know that the adress of the frontpage is URL('default', 'index')


Kenneth


[web2py] Re: redirect(URL())

2011-06-25 Thread Massimo Di Pierro
In the general case it is not possible to detect loops. Alan Turing
proved it.;-0
There are cases when you want to redirect(URL()) once and that should
be allowed.

On Jun 25, 4:43 pm, Kenneth kenneth.t.lundst...@gmail.com wrote:
 I tried to make a redirect to my frontpage and didn´t remember how to
 do that so I tried with redirect(URL()). That leads to a endless loop.
 In my case Firefox stopped after trying to redirect. Maybe web2py
 should detect this stupid programming error or is there a case when
 URL() is needed?

 Now I know that the adress of the frontpage is URL('default', 'index')

 Kenneth


[web2py] Re: experimental in trunk... common_fields and precints

2011-06-25 Thread Chris S
This is great, I've been away from web2py for about a year now and
this feature is exactly what I was trying to do quite some time ago by
manually storing and filtering by a SiteId.

A couple of questions.
1 - Is there a way to over ride the filter if you do not want it, for
say Administration?
2 - Can you define tables that are 'global' which always over ride the
feature?  In this case I'm thinking a read-only table that all sites
retrieve information from.



On May 26, 10:38 am, villas villa...@gmail.com wrote:
 Thanks, that sounds like a solution and I will experiment a little.
 I like thisfeaturevery much!

 On May 26, 4:30 pm, Massimo Di Pierro massimo.dipie...@gmail.com
 wrote:







  You can do what you ask

  db.define_table('tenant',Field('name'))
  # somehow store a tenant.id in session.tenant_id
  # use tenant id for all other tables but the one above
  db._common_fields=[Field('request_tenant',default=session.tenant_id,writabl 
  e=False,readable=False)]

  On May 26, 9:52 am, villas villa...@gmail.com wrote:

   Hi Massimo

   My thought/suggestions are:

   Almost everyone using thisfeaturewill also wish to keep data
   relating to the tenant,  e.g. they will have a 'tenant' table with
   information about 'harvard.school.org'.

   The foreign key relating to the 'tenant' table under your system would
   therefore be using the string 'harvard.school.org' rather than an id
   integer.  Is that a good idea?

   Many webservers will accept any sub-domain and this could lead to the
   field 'request_tenant' being populated with misspellings etc,
   e.g.   'harvd.school.org' or 'harverd.school.org',
   'harvhard.school.org'.  This would be difficult to relate to a
   'tenant' table.

   To stop those problems,  you might still consider to use the ideas in
   my original suggestion,  i.e.
   * lookup the sub-domain when the request is received and allocate an
   id reference.
   * specify what to do if the sub-domain is not recognised i.e. provide
   a default value or raise an error (maybe 404).
   * to save time when it is a single tenant system,  set a global
   constant to avoid the overhead of the multi-tenant lookup.

   Regards,
   David

   On May 26, 3:10 pm, Massimo Di Pierro massimo.dipie...@gmail.com
   wrote:

I changed 'request_precinct' to 'request_tenant' since this is more
appropriate. We are talking about buildig multi-tenant apps.

db._common_fields=[Field('request_tenant',default=request.env.http_host,w
ritable=False,readable=False)]

Notice you can also do

db._common_fields=[auth.signature]

and all tables will have created_by, modified_by, created_on,
modified_on, etc.

On May 26, 7:17 am, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:

 yes.

 On May 25, 11:37 pm, mattgorecki m...@goelephant.com wrote:

  So in this example request_precinct would equal 
  harvard.anyschool.org?

  Matt

  On May 25, 9:47 pm, Massimo Di Pierro massimo.dipie...@gmail.com
  wrote:

   There are two more features in trunk that I could use some testing
   with (commonfieldsand precints)

   Imagine you have created an app school designed to manage one
   school. It has one database and many tables. You wrote it with one
   school in mind. Now you want to turn it into a service so that
   multiple schools can register and use it. You want to identify the
   school for example by the urlhttp://harvard.anyschool.organdeach
   school should ONLY see its own users, groups, records, etc. etc.

   Before today to do this you would have to rewrite all your tables 
   and
   queries.

   Today you can do it without changing your code at all. You just 
   have
   to add this line after db=DAL(...)

   db._common_fields=[Field('request_precinct',default=request.env.http_host,w
ritable=False,readable=False)]

   Yes. That is it!

   How does it work?

   1) db._common_fields is a list offieldsthat you want to add to all
   tables.
   2) The field called 'request_precinct' is special. Every query
   involving a table having this field is automatically filtered 
   byfield
   value == field default. In our example the default is
   request.env.http_host, i.e. the hostname in the http request which
   identifies the school.
   3) The field is hidden (writable=False,readable=False) but has a
   default therefore it is automatically set for all inserts.

   There is nothing special about schools here. You can use it with 
   any
   other app.

   Give it a try and let me know.

   I could use some help in writing some documentation about thenew
   features added today. ;-)

   Massimo


[web2py] Re: experimental in trunk... common_fields and precints

2011-06-25 Thread Chris S
Ah there was one other scenario I meant to as.

Can you have an entry in the table which, when filtered, always
passes?
Here I'm thinking about a cross-site admin that could register a
single time and be retrieved from any of the accessing URL's.

On Jun 25, 7:08 pm, Chris S sanders.ch...@gmail.com wrote:
 This is great, I've been away from web2py for about a year now and
 thisfeatureis exactly what I was trying to do quite some time ago by
 manually storing and filtering by a SiteId.

 A couple of questions.
 1 - Is there a way to over ride the filter if you do not want it, for
 say Administration?
 2 - Can you define tables that are 'global' which always over ride 
 thefeature?  In this case I'm thinking a read-only table that all sites
 retrieve information from.

 On May 26, 10:38 am, villas villa...@gmail.com wrote:







  Thanks, that sounds like a solution and I will experiment a little.
  I like thisfeaturevery much!

  On May 26, 4:30 pm, Massimo Di Pierro massimo.dipie...@gmail.com
  wrote:

   You can do what you ask

   db.define_table('tenant',Field('name'))
   # somehow store a tenant.id in session.tenant_id
   # use tenant id for all other tables but the one above
   db._common_fields=[Field('request_tenant',default=session.tenant_id,writabl
e=False,readable=False)]

   On May 26, 9:52 am, villas villa...@gmail.com wrote:

Hi Massimo

My thought/suggestions are:

Almost everyone using thisfeaturewill also wish to keep data
relating to the tenant,  e.g. they will have a 'tenant' table with
information about 'harvard.school.org'.

The foreign key relating to the 'tenant' table under your system would
therefore be using the string 'harvard.school.org' rather than an id
integer.  Is that a good idea?

Many webservers will accept any sub-domain and this could lead to the
field 'request_tenant' being populated with misspellings etc,
e.g.   'harvd.school.org' or 'harverd.school.org',
'harvhard.school.org'.  This would be difficult to relate to a
'tenant' table.

To stop those problems,  you might still consider to use the ideas in
my original suggestion,  i.e.
* lookup the sub-domain when the request is received and allocate an
id reference.
* specify what to do if the sub-domain is not recognised i.e. provide
a default value or raise an error (maybe 404).
* to save time when it is a single tenant system,  set a global
constant to avoid the overhead of the multi-tenant lookup.

Regards,
David

On May 26, 3:10 pm, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:

 I changed 'request_precinct' to 'request_tenant' since this is more
 appropriate. We are talking about buildig multi-tenant apps.

 db._common_fields=[Field('request_tenant',default=request.env.http_host,w
 ritable=False,readable=False)]

 Notice you can also do

 db._common_fields=[auth.signature]

 and all tables will have created_by, modified_by, created_on,
 modified_on, etc.

 On May 26, 7:17 am, Massimo Di Pierro massimo.dipie...@gmail.com
 wrote:

  yes.

  On May 25, 11:37 pm, mattgorecki m...@goelephant.com wrote:

   So in this example request_precinct would equal 
   harvard.anyschool.org?

   Matt

   On May 25, 9:47 pm, Massimo Di Pierro massimo.dipie...@gmail.com
   wrote:

There are two more features in trunk that I could use some 
testing
with (commonfieldsand precints)

Imagine you have created an app school designed to manage one
school. It has one database and many tables. You wrote it with 
one
school in mind. Now you want to turn it into a service so that
multiple schools can register and use it. You want to identify 
the
school for example by the urlhttp://harvard.anyschool.organdeach
school should ONLY see its own users, groups, records, etc. etc.

Before today to do this you would have to rewrite all your 
tables and
queries.

Today you can do it without changing your code at all. You just 
have
to add this line after db=DAL(...)

db._common_fields=[Field('request_precinct',default=request.env.http_host,w
 ritable=False,readable=False)]

Yes. That is it!

How does it work?

1) db._common_fields is a list offieldsthat you want to add to 
all
tables.
2) The field called 'request_precinct' is special. Every query
involving a table having this field is automatically filtered 
byfield
value == field default. In our example the default is
request.env.http_host, i.e. the hostname in the http request 
which
identifies the school.
3) The field is hidden (writable=False,readable=False) but has a
default therefore it is automatically set for all inserts.

There is nothing special about 

Re: [web2py] Re: It makes duplicate records on datastore

2011-06-25 Thread Anthony

On Saturday, June 25, 2011 8:34:13 PM UTC-4, dorasan wrote: 

 Anthony 

 Thank you for your reply.
 The way to use  'customforms' solved my problem!!!
 But adding a hidden _formkey field didn't solve it as it still calls 
 double submission somehow.
 I added a hidden _formkey field like this.

  input value=9038845529 type=hidden name=_formkey /
 input type=hidden name=_formname value=article_works /

 
Can you show the code for how you're creating and adding the _formkey value?
 


Re: [web2py] Re: It makes duplicate records on datastore

2011-06-25 Thread portable dora
Just random...
I'm sorry I actually dont understand what _formkey value is..

dorasan

2011/6/26 Anthony abasta...@gmail.com


 On Saturday, June 25, 2011 8:34:13 PM UTC-4, dorasan wrote:

 Anthony

 Thank you for your reply.
 The way to use  'customforms' solved my problem!!!
 But adding a hidden _formkey field didn't solve it as it still calls
 double submission somehow.
 I added a hidden _formkey field like this.

  input value=9038845529 type=hidden name=_formkey /
 input type=hidden name=_formname value=article_works /


 Can you show the code for how you're creating and adding the _formkey
 value?




Re: [web2py] Re: It makes duplicate records on datastore

2011-06-25 Thread Anthony
When you call form.accepts, the accepts method will create the formkey for 
you and add it to the session and as an attribute of the form. After calling 
form.accepts, the key will be stored in form.formkey -- so you could pass 
that value to the view and insert it as the _formkey field value. I think 
that would work. I suppose you could also create your own token, but then 
you'd have to add it to the session yourself, with the name 
'_formkey[formname]' (you're probably better off letting form.accepts handle 
it, though).
 
Anthony
 

On Saturday, June 25, 2011 9:38:50 PM UTC-4, dorasan wrote:

 Just random... 
 I'm sorry I actually dont understand what _formkey value is..

 dorasan

 2011/6/26 Anthony abas...@gmail.com


 On Saturday, June 25, 2011 8:34:13 PM UTC-4, dorasan wrote: 

 Anthony 

 Thank you for your reply.
 The way to use  'customforms' solved my problem!!!
 But adding a hidden _formkey field didn't solve it as it still calls 
 double submission somehow.
 I added a hidden _formkey field like this.

  input value=9038845529 type=hidden name=_formkey /
 input type=hidden name=_formname value=article_works /

  
 Can you show the code for how you're creating and adding the _formkey 
 value?
  




[web2py] Re: Speed of rendering html data (10,000+ rows)

2011-06-25 Thread Vineet
a='MyWheels', c='MIS', f='get_data'.
So, {{=URL('MIS','get_data')}} should work.
But I do not get the data in dataTable.
---Vineet

On Jun 25, 11:13 pm, Anthony abasta...@gmail.com wrote:
 Is MIS your app name, or the controller name? If it's the app name, your URL
 call also needs the controller name, or it will think MIS is the controller
 and the Ajax call will fail.







 On Saturday, June 25, 2011 1:02:50 PM UTC-4, Vineet wrote:
  I tried doing like this:--

  In controller--

  def get_data():
      custdata = db.executesql(qry, as_dict=True)
      return response.json(custdata)

  And in View,

  other code is as earlier (hence omitted)
  sAjaxSource: {{=URL('MIS','get_data')}},

  Still, the dataTable is blank.
  Pl. help.

  ---Vineet

  On Jun 24, 5:56 pm, Vineet vineet@gmail.com wrote:
   As suggested by the community, I am trying to export json data to
   dataTable.
   But only blank dataTable is rendered (with desired formatting, search
   box, etc.)
   Pl. introspect into my code as to where I have a mistake.
   Data is not displayed (as returned by get_data method).
   I have made sure that the tables in MySQL have been populated.

   ---
   Controller
   ---
   def show_data():
       return dict()

   def get_data():
       custdata = db.executesql(qry, as_dict=True)
       return dict(mydata=custdata)

   # For testing purpose, I returned response.json(custdata) in a
   separate method  validated the output on jsonlint.com.
   It is valid json.
   But, here the returned value is dict(mydata=custdata).
   How do I reference the custdata object in View?
   Already tried {{=mydata}} in script tag in View

   ---
   View (show_data.html)
   ---
   {{extend 'layout.html'}}

   script
   $(document).ready(function() {
       var oTable = $('.smarttable').dataTable( {
           sScrollY: 200px,
           sAjaxSource: {{=URL('MIS','get_data.json')}},
           sDom: frtiS,
           bDeferRender: true
       } );} );

   /script

   # html table tags go here

   h1Customer Database/h1
   br /
   table class=smarttable
   thead
   tr
       thCustomer Name/ththVehicle No/thetc.
   /tr
   /thead
   tbody

   /tbody
   /table

   # This link is for testing json data returned.
   a href='{{=URL('MIS','get_rows.json')}}'my_json/a

   Thanks,
   Vineet

   On Jun 22, 1:51 am, contatog...@gmail.com

   contatog...@gmail.com wrote:
It can paginate data?
_
*Gilson Filho*
*Web Developerhttp://gilsondev.com*-Hide quoted text -

   - Show quoted text -


[web2py] Re: Speed of rendering html data (10,000+ rows)

2011-06-25 Thread Anthony
What happens if you go to /MyWheels/MIS/get_data? Do you get the proper JSON 
returned? If so, then the problem is probably in your client-side JS code. 
Also, on the client side, check in Firebug (or similar) to see if the Ajax 
call is getting made properly, and if it is returning the JSON. You may need 
to work on debugging the client-side JS/DataTables code.
 
Anthony

On Saturday, June 25, 2011 10:57:23 PM UTC-4, Vineet wrote:

 a='MyWheels', c='MIS', f='get_data'. 
 So, {{=URL('MIS','get_data')}} should work. 
 But I do not get the data in dataTable. 
 ---Vineet 

 On Jun 25, 11:13 pm, Anthony abas...@gmail.com wrote: 
  Is MIS your app name, or the controller name? If it's the app name, your 
 URL 
  call also needs the controller name, or it will think MIS is the 
 controller 
  and the Ajax call will fail. 
  
  
  
  
  
  
  
  On Saturday, June 25, 2011 1:02:50 PM UTC-4, Vineet wrote: 
   I tried doing like this:-- 
  
   In controller-- 
  
   def get_data(): 
   custdata = db.executesql(qry, as_dict=True) 
   return response.json(custdata) 
  
   And in View, 
  
   other code is as earlier (hence omitted) 
   sAjaxSource: {{=URL('MIS','get_data')}}, 
  
   Still, the dataTable is blank. 
   Pl. help. 
  
   ---Vineet 
  
   On Jun 24, 5:56 pm, Vineet vinee...@gmail.com wrote: 
As suggested by the community, I am trying to export json data to 
dataTable. 
But only blank dataTable is rendered (with desired formatting, search 

box, etc.) 
Pl. introspect into my code as to where I have a mistake. 
Data is not displayed (as returned by get_data method). 
I have made sure that the tables in MySQL have been populated. 
  
--- 
Controller 
--- 
def show_data(): 
return dict() 
  
def get_data(): 
custdata = db.executesql(qry, as_dict=True) 
return dict(mydata=custdata) 
  
# For testing purpose, I returned response.json(custdata) in a 
separate method  validated the output on jsonlint.com. 
It is valid json. 
But, here the returned value is dict(mydata=custdata). 
How do I reference the custdata object in View? 
Already tried {{=mydata}} in script tag in View 
  
--- 
View (show_data.html) 
--- 
{{extend 'layout.html'}} 
  
script 
$(document).ready(function() { 
var oTable = $('.smarttable').dataTable( { 
sScrollY: 200px, 
sAjaxSource: {{=URL('MIS','get_data.json')}}, 
sDom: frtiS, 
bDeferRender: true 
} );} ); 
  
/script 
  
# html table tags go here 
  
h1Customer Database/h1 
br / 
table class=smarttable 
thead 
tr 
thCustomer Name/ththVehicle No/thetc. 
/tr 
/thead 
tbody 
  
/tbody 
/table 
  
# This link is for testing json data returned. 
a href='{{=URL('MIS','get_rows.json')}}'my_json/a 
  
Thanks, 
Vineet 
  
On Jun 22, 1:51 am, conta...@gmail.com 
  
conta...@gmail.com wrote: 
 It can paginate data? 
 _ 
 *Gilson Filho* 
 *Web Developerhttp://gilsondev.com*-Hide quoted text - 
  
- Show quoted text -



[web2py] Re: Speed of rendering html data (10,000+ rows)

2011-06-25 Thread Anthony
Note, you might also check out PowerTable (
https://bitbucket.org/rochacbruno/powertable), which is a web2py plugin for 
DataTables. There's also a jqGrid widget that's part of plugin_wiki (you can 
use it even on non-wiki pages) -- see 
http://web2py.com/book/default/chapter/13#Current-Widgets.

On Saturday, June 25, 2011 11:53:52 PM UTC-4, Anthony wrote:

 Looks like DataTables requires your JSON to include a few special 
 parameters (http://datatables.net/usage/server-side), so you'll probably 
 need to manipulate the JSON on the server side before returning it to the 
 client.
  
 Anthony



Re: [web2py] how to download an audio file

2011-06-25 Thread Bruno Rocha
{{=A(_src=URL('static','files', args='longfilename.mp3'))}}

Does not works?


--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]




On Sun, Jun 26, 2011 at 1:38 AM, weheh richard_gor...@verizon.net wrote:

 I want to click on a link and have a jpeg or an mp3 file downloaded
 from the server to my local machine as though I had done a right-mouse-
 click and selected the Save Link As ... menu entry. In other words,
 when I click on the link I want to get a popup asking where to save
 the file. Any thoughts as to how to do this? My feeble attempts so far
 have failed miserably. The file is stored on the server under C:/
 web2py/applications/myapp/static/files/mytable.name/xy/long filename.


[web2py] Re: how to download an audio file

2011-06-25 Thread Massimo Di Pierro
http://.../myapp/static/files/mytable.name/xy/long filename?
attachment

notice the ?attachment after filename

On Jun 25, 11:38 pm, weheh richard_gor...@verizon.net wrote:
 I want to click on a link and have a jpeg or an mp3 file downloaded
 from the server to my local machine as though I had done a right-mouse-
 click and selected the Save Link As ... menu entry. In other words,
 when I click on the link I want to get a popup asking where to save
 the file. Any thoughts as to how to do this? My feeble attempts so far
 have failed miserably. The file is stored on the server under C:/
 web2py/applications/myapp/static/files/mytable.name/xy/long filename.


[web2py] Formatting SQLFORM.factory

2011-06-25 Thread alex
Hi all,

In a SQLFORM.factory generated form I want to have the labels on top
of the fields.

form=SQLFORM.factory( Field('address', label=T('Address')),)

Any idea?
Thank you


[web2py] Re: how to download an audio file [closed]

2011-06-25 Thread weheh


On Jun 26, 1:02 am, weheh richard_gor...@verizon.net wrote:
 Super! Thank you Massimo. @Bruno, thanks for the response, but please
 note that A(_src= ... will not work. It must be A(_href= ... Probably
 just an oversight on your part.

 On Jun 26, 12:55 am, Massimo Di Pierro massimo.dipie...@gmail.com
 wrote:







 http://.../myapp/static/files/mytable.name/xy/long filename?
  attachment

  notice the ?attachment after filename

  On Jun 25, 11:38 pm, weheh richard_gor...@verizon.net wrote:

   I want to click on a link and have a jpeg or an mp3 file downloaded
   from the server to my local machine as though I had done a right-mouse-
   click and selected the Save Link As ... menu entry. In other words,
   when I click on the link I want to get a popup asking where to save
   the file. Any thoughts as to how to do this? My feeble attempts so far
   have failed miserably. The file is stored on the server under C:/
   web2py/applications/myapp/static/files/mytable.name/xy/long filename.


[web2py] How to download multiple files with one click?

2011-06-25 Thread weheh
Imagine an album with multiple songs and you want to download all the
songs at once by clicking on the album download link. Is there a
simple way to get a link to download multiple files with one click?

I suppose it could be done by zipping all the songs together into a
single file, but I haven't implemented it that way. I also suppose it
could be done with iterative jQuery calls, but this would probably
mean having to save each file one at a time. Anyway, just thought I
would ask and see if someone had a good idea about this or knew the
simple answer. Thanks.


[web2py] Re: Formatting SQLFORM.factory

2011-06-25 Thread Massimo Di Pierro
Try

form=SQLFORM.factory( Field('address', label=T('Address')),
formstyle='table2cols')




On Jun 25, 11:59 pm, alex a22...@gmail.com wrote:
 Hi all,

 In a SQLFORM.factory generated form I want to have the labels on top
 of the fields.

 form=SQLFORM.factory( Field('address', label=T('Address')),)

 Any idea?
 Thank you


Re: [web2py] Re: Formatting SQLFORM.factory

2011-06-25 Thread al ex
Thank you. It worked,


On Sun, Jun 26, 2011 at 11:22 AM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 Try

 form=SQLFORM.factory( Field('address', label=T('Address')),
 formstyle='table2cols')




 On Jun 25, 11:59 pm, alex a22...@gmail.com wrote:
  Hi all,
 
  In a SQLFORM.factory generated form I want to have the labels on top
  of the fields.
 
  form=SQLFORM.factory( Field('address', label=T('Address')),)
 
  Any idea?
  Thank you



[web2py] Re: How to download multiple files with one click?

2011-06-25 Thread Massimo Di Pierro
I do not believe this is possible at all (except by downloading a
zipped file). The JS in the browser is not allowed to initiate
downloads because it has no access to local filesystem. Downloads must
explicitly initiated by the user by clicking and approving the save.
This is a security feature of all browsers.

On Jun 26, 12:06 am, weheh richard_gor...@verizon.net wrote:
 Imagine an album with multiple songs and you want to download all the
 songs at once by clicking on the album download link. Is there a
 simple way to get a link to download multiple files with one click?

 I suppose it could be done by zipping all the songs together into a
 single file, but I haven't implemented it that way. I also suppose it
 could be done with iterative jQuery calls, but this would probably
 mean having to save each file one at a time. Anyway, just thought I
 would ask and see if someone had a good idea about this or knew the
 simple answer. Thanks.