[web2py][recipe] Unique constraint over 2+ fields for form validation of SQL UNIQUE (f1, f2,...);

2015-01-15 Thread Richard
Hello,

I just found a way to avoid _before_insert and _before_update callbacks and 
implement at the form level the unique constraint apply at backend level 
over 2 fields like so : 

ALTER TABLE table_name
  ADD CONSTRAINT unique_f1_and_f2
  UNIQUE (f1, f2);

What works for me in my picilar use case is to use IS_NOT_IN_DB() with set 
like this :

fields_combination_set = db(db.table_name.f2 == request.vars.fk_id)
db.table_name.f1.requires = IS_NOT_IN_DB(fields_combination_set, 
'table_name.f1')

My f2 field is a foreign key and I get the value from another form that 
redirect on the form where the IS_NOT_IN_DB() validators will be used...

What I want to acheive is avoid combination of multiples revision number 
for a given parent record... So my f1 field is a revision number and my f2 
is the parent record id for which the revision number applies.

Hope it could help some and if I need that again in the future I may found 
this email quickly...

:)

Richard

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


Re: [web2py] Exporting from a SQLFORM.grid with customized search queries

2015-01-15 Thread Dexter Hadley
Thx to both of you!  There is also the google code issue here: 
https://code.google.com/p/web2py/issues/detail?id=2006 
https://code.google.com/p/web2py/issues/detail?id=2006

dex*


 On Jan 15, 2015, at 8:48 AM, Prasad Muley pmmu...@gmail.com wrote:
 
 Hi Massimo,
 
Thanks for reply. I've sent you the pull request on github. Let me 
 know if you get any errors :)
 
 
 On Thu, Jan 15, 2015 at 9:26 PM, Massimo Di Pierro 
 massimo.dipie...@gmail.com mailto:massimo.dipie...@gmail.com wrote:
 Thanks. I will merge this patch!
 
 
 On Thursday, 15 January 2015 04:01:24 UTC-6, Prasad Muley wrote:
 Hello Massimo and Dexter,
 
 I've a fix for this issue. I've tested it and attached the diff file. 
 PFA. 
 
 Let me know if I missed anything. 
 
 Btw Can I send pull request?
 
 On Saturday, October 25, 2014 at 5:17:24 AM UTC+5:30, Massimo Di Pierro wrote:
 Hello Dexter, I think your are right. I will review this asap. Meanwhile, 
 would you be able to open an issue with a link to this thread so we can more 
 easily keep track. Thanks!.
 
 Massimo
 
 On Thursday, 23 October 2014 13:23:16 UTC-5, Dexter Hadley wrote:
 Hi All,
 
 This is my first time posting a question, so thanks to Massimo and they whole 
 community for making web2py.  Its great!
 
 I am trying to export results from a customized full-text search using 
 SQLFORM.grid.  My backend is a Postgres db, and I successfully define 
 search_widget and searchable functions that are passed to the 
 SQLFORM.grid to do the full-text search.  It will works pretty well on the 
 web app.  However, once I click the export button, SQLFORM.grid apparently 
 recreates the query using the default SQLFORM.build_query and ignores the 
 correct query which I define in searchable.  After poking around in 
 sqlhtml.py, I found this is so because the exporter only conditions on 
 request.vars.keywords before calling  SQLFORM.build_query, and it does not 
 check for callable(searchable) which I think it should do.  In fact, I fixed 
 it by editing sqlhtml.py to force the exporter to condition on 
 (request.vars.keywords and callable(searchable)) before setting up the rows 
 object to export.  The code I added is in bold below (on line 2298 of 
 sqlhtml.py):
 
 if request.vars.keywords and callable(searchable):
 try:
 #the query should be constructed using searchable 
 fields but not virtual fields
 sfields = reduce(lambda a, b: a + b,
 [[f for f in t if f.readable and not 
 isinstance(f, Field.Virtual)] for t in tables])
 dbset = dbset(SQLFORM.build_query(
 sfields, request.vars.get('keywords', '')))
 rows = dbset.select(left=left, orderby=orderby,
 cacheable=True, 
 *selectable_columns)
 except Exception, e:
 response.flash = T('Internal Error')
 rows = []
 else:
 rows = dbset.select(left=left, orderby=orderby,
 cacheable=True, *selectable_columns)
 
 Is this a bug or is there a better way to do an export of customized search 
 results using SQLFORM.grid?  I'm using the current version of everything 
 (web2py 2.9.11, Postgres 9.3, Python 2.7.8).  Thx again,
 
 dex*
 
 -- 
 Resources:
 - http://web2py.com http://web2py.com/
 - http://web2py.com/book http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py http://github.com/web2py/web2py (Source 
 code)
 - https://code.google.com/p/web2py/issues/list 
 https://code.google.com/p/web2py/issues/list (Report Issues)
 --- 
 You received this message because you are subscribed to a topic in the Google 
 Groups web2py-users group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/web2py/Td58YKBAaMo/unsubscribe 
 https://groups.google.com/d/topic/web2py/Td58YKBAaMo/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 web2py+unsubscr...@googlegroups.com 
 mailto:web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout 
 https://groups.google.com/d/optout.
 
 
 
 -- 
 Thanks and Regards
 Prasad M. Muley
 
 -- 
 Resources:
 - http://web2py.com http://web2py.com/
 - http://web2py.com/book http://web2py.com/book (Documentation)
 - http://github.com/web2py/web2py http://github.com/web2py/web2py (Source 
 code)
 - https://code.google.com/p/web2py/issues/list 
 https://code.google.com/p/web2py/issues/list (Report Issues)
 --- 
 You received this message because you are subscribed to a topic in the Google 
 Groups web2py-users group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/web2py/Td58YKBAaMo/unsubscribe 
 https://groups.google.com/d/topic/web2py/Td58YKBAaMo/unsubscribe.
 To unsubscribe from this group and all its 

[web2py] Re: What is the best way to add an extra input on the client side?

2015-01-15 Thread Derek
I would suggest that you do something similar to what I've done here...

http://www.web2pyslices.com/slice/show/1612/ajax-adding-child-records-to-parent


On Sunday, January 11, 2015 at 11:18:56 PM UTC-7, Przemysław wrote:

 Partially solved. Manually added field of the reference type now has a 
 drop down list. The field is defined and set properly before 
 SLQFORM.factory in this way:
 pt = Field('phone_type', 'reference phone_types')
 pt.requires=IS_IN_DB(db, db.phone_types.id, '%(type)s')
 Then it is used in SQLFORM.factory.

 Still I have no concept how to multiply this field according to the phone 
 number field multiplication.I've tried tu use 'show_if' function but I 
 really don't know how to point many phone 'number' input objects which are 
 created runtime.
 I'll be grateful for any help or advise.
 Przemek



 W dniu niedziela, 11 stycznia 2015 22:46:48 UTC+1 użytkownik Przemysław 
 Loesch napisał:

 Massimo, thank you very much for your answer. List type widget works just 
 great. I didn't know web2py already has the feature which I tried to 
 implement in the complicated way. I'm wondering how many such goodies are 
 waiting for me to discover in this great framework.

 Now going back to forms. The logic is no problem because I insert data 
 myself using additional values - the form contains only some of the fields 
 of the whole table. Anyway insert is manual after form validation. The 
 'phones' table is separate from 'institutions' because it contains also 
 phone type, description, and reference to a person. This is the reason of 
 my next question. Is it possible in some way to multiply a set of fields? 
 In my form I actually multiply the whole row of the 'phones' table. The 
 thing I cannot achieve so far is the manually added reference field working 
 like the one created by SQLFORM with the db.phones.phone_type as an 
 argument. Manually added Field('phone_type', 'reference db.phone_type' ) 
 doesn't have a drop down list with phone types. Is it a way to solve this?
 Thanks a lot!
 Przemek




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


[web2py] error connecting two applications on different computers

2015-01-15 Thread Luis Díaz
greetings.
excuse me I'm using google translator (my language is Spanish)
location:
a control system for assistance.
* A central computer where managers come and go down the reports.
* Some stations where the person registers its input and output (such
equipment may or may not be connected to the network)

for computers that are not connected, a download of care in a text
file that is then loaded into the central computer. (this works)

for computers that are connected, the idea is that the core team, make
the request for the past attendance records.

path query:
http://192.168.0.10:8000/welcome/default/call/json/get_data/

if I test from the browser to that route, the system throws the form
corect information in json.

but if from the central computer, from a web2py controller, run the
following instruction (I can not find another way .. I see
documentation for applications to communicate, I see only external
examples)


def import_data():
import pycurl, urllib
from StringIO import StringIO
from gluon.serializers import json, loads_json

buffer = StringIO()
c = pycurl.Curl()

url_eq = 'http://%s/welcome/default/call/json/get_data/' %
'192.168.0.10:8000'

c.setopt(c.URL, url_eq)
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()
data_new = loads_json(buffer.getvalue())



ERROR
type 'exceptions.TypeError' invalid arguments to setopt


anyone can help me?
I need the data request web2py make it.
and hoping to eventually be automated using cron

-- 
http://diazluis.com
Analista Programador
User Linux 532223

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


[web2py] Re: Gig: web2py nut needed for remote scheduling/membership site

2015-01-15 Thread Massimo Di Pierro
I recently had a similar discussion on the topic with a friend. It is 
nearly impossible to find a good developer in a modern agile technology 
(web2py or other) for $15/hr anywhere. Most people I work with charge from 
$50/hr for a long term contract with guaranteed number of hours to $150 for 
an occasional gig. A top developer and/or a project with a strict close 
deadline can charge even more per hour.

The point is that web2py+python allows to build apps at least 10x faster 
than other systems, let's say Java. This means that a developer can deliver 
an app much faster but you have to pay them more per hour for an equivalent 
product. You can find $15 Java developers but not a web2py/python 
developers.

People who are skilled with the latest technologies (any modern technology) 
are people who make a huge investment in their own time into learning and 
experimenting. This has a cost. This is what you pay for. Your edge is the 
short time to market and lower maintenance costs. If you think of saving on 
development, you end up with poor quality software.

Anyway, when hiring somebody, always ask them to show you them what they 
have built with the tools in question. If they haven't built anything, they 
do not know how to use those tools.

Massimo





On Thursday, 15 January 2015 07:38:39 UTC-6, Leonel Câmara wrote:

 You expect people to be your dev lead, do all the admin work, basically 
 have all the responsibility for the success of this project, and you're 
 paying 15 bucks an hour?


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


Re: [web2py] Re: lazy question: does anyone have a simple backbone.js/web2py example or tutorial?

2015-01-15 Thread Massimo Di Pierro
I like handsontable a lot. It allows cut and paste to and from Excel. It 
can customized in HTML down to the single cells.

On Thursday, 15 January 2015 02:21:01 UTC-6, Tim Richardson wrote:

 Backgrid.js looks promising. Getting web2py to populate a backbone 
 collection was pretty easy. 
 On 15/01/2015 5:18 PM, Tim Richardson t...@tim-richardson.net wrote:



 On Thursday, 15 January 2015 11:19:04 UTC+11, Derek wrote:

 I suppose you haven't seen 'DataTables.net' ?



 I looked at it a while ago. It looks very nice, but it's only partially 
 open source (the edit plugin is not) 

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



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


[web2py] Re: numba jit fails in web2py environment

2015-01-15 Thread Massimo Di Pierro
Define the function in a module and import the function from the module. Do 
not put it in a model or controller. Those are not normal python modules 
and who knows what goes on. Anyway, your function would be re-compiled at 
every iteration.

I wrote this (https://github.com/mdipierro/ocl) works like numba (less 
powerful probably) and it would have the same problem.

Massimo

On Thursday, 15 January 2015 05:10:36 UTC-6, Leopold Haimberger wrote:

 Hi

 I am using the numba just in time compiler (version 0.16) for speeding up 
 numerical calculations under python.

 For testing it I have slightly modified the standard web2py welcome 
 application such that the index controller function calls a tiny function 
 numba_add which
 adds 2 numbers. 



 from numba import *

 #@jit
 def numba_add(x,y):
 z=x+y
 return z

 def index():
 
 example action using the internationalization operator T and flash
 rendered by views/default/index.html or views/generic.html

 if you need a simple wiki simply replace the two lines below with:
 return auth.wiki()
 
 response.flash = T(7+4={}.format(numba_add(7.0,4.0)))
 return dict(message=T('Hello World {}'.format(numba_add(7.0,4.0


 When running it,  numba is imported and if I comment out the @jit 
 decorator the application works well. However if I use the @jit decorator 
 to compile it I get the error ticket below.
 Does anyone have a clue what could be wrong. I have now idea what the 
 error message means.

 Leo Haimberger

 Error ticket for welcomeTicket ID

 131.130.157.11.2015-01-15.10-57-59.c400457e-a478-49cf-b014-acde33d01266
 type 'exceptions.KeyError' Failed at object mode 
 backend\n'__restricted__'Versionweb2py™Version 
 2.9.11-stable+timestamp.2014.09.15.23.35.11Traceback

 1.
 2.
 3.
 4.
 5.
 6.
 7.
 8.
 9.
 10.
 11.
 12.
 13.
 14.
 15.
 16.
 17.
 18.
 19.
 20.
 21.
 22.
 23.
 24.
 25.
 26.

 Traceback (most recent call last):
   File /fio/srvx7/leo/python/web2py/gluon/restricted.py, line 224, in 
 restricted
 exec ccode in environment
   File 
 /fio/srvx7/leo/python/web2py/applications/welcome/controllers/default.py 
 http://localhost:8000/admin/default/edit/welcome/controllers/default.py, 
 line 79, in module
   File /fio/srvx7/leo/python/web2py/gluon/globals.py, line 392, in lambda
 self._caller = lambda f: f()
   File 
 /fio/srvx7/leo/python/web2py/applications/welcome/controllers/default.py 
 http://localhost:8000/admin/default/edit/welcome/controllers/default.py, 
 line 26, in index
 response.flash = T(7+4={}.format(numba_add(7.0,4.0)))
   File 
 /opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/dispatcher.py,
  line 153, in _compile_for_args
 return self.jit(sig)
   File 
 /opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/dispatcher.py,
  line 144, in jit
 return self.compile(sig, **kws)
   File 
 /opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/dispatcher.py,
  line 279, in compile
 flags=flags, locals=locs)
   File 
 /opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
  line 552, in compile_extra
 return pipeline.compile_extra(func)
   File 
 /opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
  line 263, in compile_extra
 return self.compile_bytecode(res.result, func_attr=self.func_attr)
   File 
 /opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
  line 275, in compile_bytecode
 return self._compile_bytecode()
   File 
 /opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
  line 501, in _compile_bytecode
 return self._run_pipeline(pipelines)
   File 
 /opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
  line 526, in _run_pipeline
 raise _raise_error(msg, res.exception)
 KeyError: Failed at object mode backend\n'__restricted__'

 In file: 
 /fio/srvx7/leo/python/web2py/applications/welcome/controllers/default.py

 1.
 2.
 3.
 4.
 5.
 6.
 7.
 8.
 9.
 10.
 11.
 12.
 13.
 14.
 15.
 16.
 17.
 18.
 19.
 20.
 21.
 22.
 23.
 24.
 25.
 26.
 27.
 28.
 29.
 30.
 31.
 32.
 33.
 34.
 35.
 36.
 37.
 38.
 39.
 40.
 41.
 42.
 43.
 44.
 45.
 46.
 47.
 48.
 49.
 50.
 51.
 52.
 53.
 54.
 55.
 56.
 57.
 58.
 59.
 60.
 61.
 62.
 63.
 64.
 65.
 66.
 67.
 68.
 69.
 70.
 71.
 72.
 73.
 74.
 75.
 76.
 77.
 78.
 79.
 80.

 # -*- coding: utf-8 -*-
 # this file is released under public domain and you can use without 
 limitations

 #
 ## This is a sample controller
 ## - index is the default action of any application
 ## - user is required for authentication and authorization
 ## - download is for downloading files uploaded in the db (does streaming)
 ## - api is an example of Hypermedia API 

Re: [web2py] Re: Exporting from a SQLFORM.grid with customized search queries

2015-01-15 Thread Prasad Muley
Hi Massimo,

   Thanks for reply. I've sent you the pull request on github. Let
me know if you get any errors :)


On Thu, Jan 15, 2015 at 9:26 PM, Massimo Di Pierro 
massimo.dipie...@gmail.com wrote:

 Thanks. I will merge this patch!


 On Thursday, 15 January 2015 04:01:24 UTC-6, Prasad Muley wrote:

 Hello Massimo and Dexter,

 I've a fix for this issue. I've tested it and attached the diff
 file. PFA.

 Let me know if I missed anything.

 Btw Can I send pull request?

 On Saturday, October 25, 2014 at 5:17:24 AM UTC+5:30, Massimo Di Pierro
 wrote:

 Hello Dexter, I think your are right. I will review this asap.
 Meanwhile, would you be able to open an issue with a link to this thread so
 we can more easily keep track. Thanks!.

 Massimo

 On Thursday, 23 October 2014 13:23:16 UTC-5, Dexter Hadley wrote:

 Hi All,

 This is my first time posting a question, so thanks to Massimo and they
 whole community for making web2py.  Its great!

 I am trying to export results from a customized full-text search using
 SQLFORM.grid.  My backend is a Postgres db, and I successfully define
 search_widget and searchable functions that are passed to the
 SQLFORM.grid to do the full-text search.  It will works pretty well on the
 web app.  However, once I click the export button, SQLFORM.grid apparently
 recreates the query using the default SQLFORM.build_query and ignores the
 correct query which I define in searchable.  After poking around in
 sqlhtml.py, I found this is so because the exporter only conditions on
 request.vars.keywords before calling  SQLFORM.build_query, and it does not
 check for callable(searchable) which I think it should do.  In fact, I
 fixed it by editing sqlhtml.py to force the exporter to condition on
 (request.vars.keywords *and callable(searchable)*) before setting up
 the rows object to export.  The code I added is in bold below (on line 2298
 of sqlhtml.py):

 if request.vars.keywords *and callable(searchable)*:
 try:
 #the query should be constructed using
 searchable fields but not virtual fields
 sfields = reduce(lambda a, b: a + b,
 [[f for f in t if f.readable and not
 isinstance(f, Field.Virtual)] for t in tables])
 dbset = dbset(SQLFORM.build_query(
 sfields, request.vars.get('keywords', '')))
 rows = dbset.select(left=left, orderby=orderby,
 cacheable=True,
 *selectable_columns)
 except Exception, e:
 response.flash = T('Internal Error')
 rows = []
 else:
 rows = dbset.select(left=left, orderby=orderby,
 cacheable=True,
 *selectable_columns)

 Is this a bug or is there a better way to do an export of customized
 search results using SQLFORM.grid?  I'm using the current version of
 everything (web2py 2.9.11, Postgres 9.3, Python 2.7.8).  Thx again,

 dex*

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




-- 
Thanks and Regards
Prasad M. Muley

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


[web2py] Possible error in book about jquery (already corrected in online book)

2015-01-15 Thread Carlos Kitu
I was trying to implement the jquery code example to conditionally show or 
hide part of the page (see page 505 in 
https://dl.dropboxusercontent.com/u/18065445/web2py/web2py_manual_5th.pdf).

It didn't work because it was using the attr function as: 
 if(jQuery('#taxpayer_married').attr('checked'))

Looking at the functions of jQuery, I realized that I should use .prop() 
function instead of .attr().

Later, I discovered that the online version of the book 
(http://www.web2py.com/books/default/chapter/29/11/jquery-and-ajax) used 
the right function:

if(jQuery('#taxpayer_married').prop('checked'))

I suppose  it will get corrected in the next version of the pdf.

Best regards.

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


[web2py] Re: [OT] HTML to PDF

2015-01-15 Thread Ariya Owam-aram
Hi Bruno,

I install wkhtmltopdf and integrate with web2py by using subprocess.call, 
it work very well on my macbook (rocket server). But I can't success 
running subprocess.call on production server (Ngix). I also test 
subprocess.call wkthtmltopdf from web2py's shell (admin) it return non-zero 
number as output. (nothing comeout)

But suprocess.call wkhtmltopdf is working well in the web2py shell (python 
web2py.py -S app -M).

Now I don't know where to go next?

Can you please tell me what I missing.

Thank you in advanced.
Ariya 

On Thursday, December 6, 2012 at 3:36:50 AM UTC+7, rochacbruno wrote:

 I found this excellent command line tool: 
 http://code.google.com/p/wkhtmltopdf/

 It generates the PDF qith a very nice quality and I see it is easy to 
 integrate on web2py applications using pysh or subprocess.

 http://code.google.com/p/wkhtmltopdf/


 *Bruno Cezar Rocha** - @rochacbruno*
 rocha...@gmail.com javascript: | Mobile: +55 (11) 99210-8821
 www.CursoDePython.com.br | www.rochacbruno.com.br
 Blog: microblog app http://rochacbruno.com.br/microblog-app/
   Get a signature like this. 
 http://r1.wisestamp.com/r/landing?promo=18dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_18
  Click 
 here. 
 http://r1.wisestamp.com/r/landing?promo=18dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_18


  

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


[web2py] numba jit fails in web2py environment

2015-01-15 Thread Leopold Haimberger
Hi

I am using the numba just in time compiler (version 0.16) for speeding up 
numerical calculations under python.

For testing it I have slightly modified the standard web2py welcome 
application such that the index controller function calls a tiny function 
numba_add which
adds 2 numbers. 



from numba import *

#@jit
def numba_add(x,y):
z=x+y
return z

def index():

example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html

if you need a simple wiki simply replace the two lines below with:
return auth.wiki()

response.flash = T(7+4={}.format(numba_add(7.0,4.0)))
return dict(message=T('Hello World {}'.format(numba_add(7.0,4.0


When running it,  numba is imported and if I comment out the @jit decorator 
the application works well. However if I use the @jit decorator to compile 
it I get the error ticket below.
Does anyone have a clue what could be wrong. I have now idea what the error 
message means.

Leo Haimberger

Error ticket for welcomeTicket ID

131.130.157.11.2015-01-15.10-57-59.c400457e-a478-49cf-b014-acde33d01266
type 'exceptions.KeyError' Failed at object mode 
backend\n'__restricted__'Versionweb2py™Version 
2.9.11-stable+timestamp.2014.09.15.23.35.11Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.

Traceback (most recent call last):
  File /fio/srvx7/leo/python/web2py/gluon/restricted.py, line 224, in 
restricted
exec ccode in environment
  File 
/fio/srvx7/leo/python/web2py/applications/welcome/controllers/default.py 
http://localhost:8000/admin/default/edit/welcome/controllers/default.py, line 
79, in module
  File /fio/srvx7/leo/python/web2py/gluon/globals.py, line 392, in lambda
self._caller = lambda f: f()
  File 
/fio/srvx7/leo/python/web2py/applications/welcome/controllers/default.py 
http://localhost:8000/admin/default/edit/welcome/controllers/default.py, line 
26, in index
response.flash = T(7+4={}.format(numba_add(7.0,4.0)))
  File 
/opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/dispatcher.py,
 line 153, in _compile_for_args
return self.jit(sig)
  File 
/opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/dispatcher.py,
 line 144, in jit
return self.compile(sig, **kws)
  File 
/opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/dispatcher.py,
 line 279, in compile
flags=flags, locals=locs)
  File 
/opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
 line 552, in compile_extra
return pipeline.compile_extra(func)
  File 
/opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
 line 263, in compile_extra
return self.compile_bytecode(res.result, func_attr=self.func_attr)
  File 
/opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
 line 275, in compile_bytecode
return self._compile_bytecode()
  File 
/opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
 line 501, in _compile_bytecode
return self._run_pipeline(pipelines)
  File 
/opt/anaconda/lib/python2.7/site-packages/numba-0.16.0-py2.7-linux-x86_64.egg/numba/compiler.py,
 line 526, in _run_pipeline
raise _raise_error(msg, res.exception)
KeyError: Failed at object mode backend\n'__restricted__'

In file: 
/fio/srvx7/leo/python/web2py/applications/welcome/controllers/default.py

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.

# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations

#
## This is a sample controller
## - index is the default action of any application
## - user is required for authentication and authorization
## - download is for downloading files uploaded in the db (does streaming)
## - api is an example of Hypermedia API support and access control
#
from numba import *

@jit
def numba_add(x,y):
z=x+y
return z

def index():

example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html

if you need a simple wiki simply replace the two lines below with:
return auth.wiki()

response http://localhost:8000/examples/global/vars/response.flash = T 
http://localhost:8000/examples/global/vars/T(7+4={}.format(numba_add(7.0,4.0)))
return dict(message=T http://localhost:8000/examples/global/vars/T('Hello 

[web2py] Re: Exporting from a SQLFORM.grid with customized search queries

2015-01-15 Thread Massimo Di Pierro
Thanks. I will merge this patch!

On Thursday, 15 January 2015 04:01:24 UTC-6, Prasad Muley wrote:

 Hello Massimo and Dexter,

 I've a fix for this issue. I've tested it and attached the diff 
 file. PFA. 

 Let me know if I missed anything. 

 Btw Can I send pull request?

 On Saturday, October 25, 2014 at 5:17:24 AM UTC+5:30, Massimo Di Pierro 
 wrote:

 Hello Dexter, I think your are right. I will review this asap. Meanwhile, 
 would you be able to open an issue with a link to this thread so we can 
 more easily keep track. Thanks!.

 Massimo

 On Thursday, 23 October 2014 13:23:16 UTC-5, Dexter Hadley wrote:

 Hi All,

 This is my first time posting a question, so thanks to Massimo and they 
 whole community for making web2py.  Its great!

 I am trying to export results from a customized full-text search using 
 SQLFORM.grid.  My backend is a Postgres db, and I successfully define 
 search_widget and searchable functions that are passed to the 
 SQLFORM.grid to do the full-text search.  It will works pretty well on the 
 web app.  However, once I click the export button, SQLFORM.grid apparently 
 recreates the query using the default SQLFORM.build_query and ignores the 
 correct query which I define in searchable.  After poking around in 
 sqlhtml.py, I found this is so because the exporter only conditions on 
 request.vars.keywords before calling  SQLFORM.build_query, and it does not 
 check for callable(searchable) which I think it should do.  In fact, I 
 fixed it by editing sqlhtml.py to force the exporter to condition on 
 (request.vars.keywords *and callable(searchable)*) before setting up 
 the rows object to export.  The code I added is in bold below (on line 2298 
 of sqlhtml.py):

 if request.vars.keywords *and callable(searchable)*:
 try:
 #the query should be constructed using 
 searchable fields but not virtual fields
 sfields = reduce(lambda a, b: a + b,
 [[f for f in t if f.readable and not 
 isinstance(f, Field.Virtual)] for t in tables])
 dbset = dbset(SQLFORM.build_query(
 sfields, request.vars.get('keywords', '')))
 rows = dbset.select(left=left, orderby=orderby,
 cacheable=True, 
 *selectable_columns)
 except Exception, e:
 response.flash = T('Internal Error')
 rows = []
 else:
 rows = dbset.select(left=left, orderby=orderby,
 cacheable=True, 
 *selectable_columns)

 Is this a bug or is there a better way to do an export of customized 
 search results using SQLFORM.grid?  I'm using the current version of 
 everything (web2py 2.9.11, Postgres 9.3, Python 2.7.8).  Thx again,

 dex*



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


[web2py] Using whoosh for in-built wiki

2015-01-15 Thread Ben Lawrence
HI
I have installed Massimo's Haystack for Whoosh (
https://github.com/mdipierro/web2py-haystack) and it works and passes the 
tests that are included there.
Now I am trying to use it for the tables in the in-built wiki. 
However, it doesn't find the search string in the wiki body fields. Has 
anyone used whoosh for the in-built wiki?

IN db.py
# Make sure this is called after the auth instance is created
auth.wiki(resolve=False)

IN default.py
def wiki():
return auth.wiki()

# whoosh_haystack.py is a module that contains the code 
in plugin_haystack.py (for some reason the plugin doesn't install as a 
plugin. works as a module tho)
from whoosh_haystack import *

def search():
index = 
Haystack(db.wiki_page,backend=WhooshBackend,indexdir='wiki-whoosh')
index.indexes('title','body')

answers=[]
a='none'
form = SQLFORM.factory(
Field('search', 'string'))
if form.process(keepvalues=True).accepted:
a = form.vars.search
answers=db(index.search(body=a)).select()
return dict(form=form,answers=answers)

IN default/search.html :
{{extend 'layout.html'}}
{{=form}}
{{=answers}}


thanks.

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


[web2py] Re: Don't use 64 bit ODBC with Web2Py and SQL Server

2015-01-15 Thread Pbop
We of course changed source to 32 bit when we went to 32 bit ODBC drivers. 
Did not try pypyodbc and did not know about pytds, which is cool to know! 
Thanks. For now we have a solution so my message is to just try and save 
folks a lot of time and grief. 


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


[web2py] Re: Error in Eclipse kepler for Web2py source: generics.xml

2015-01-15 Thread Massimo Di Pierro
To rephrase what Niphlod is saying. generic.xml contains code (web2py 
template language) used to generate XML but it does not contain XML. 
Eclipse thinks it should contain XML and complains. I guess there is some 
Eclipse settings to make it ignore this file validation.

On Wednesday, 14 January 2015 13:51:32 UTC-6, Niphlod wrote:

 if you have set up eclipse to be foolish you can't follow the warnings it 
 outputs. It's treating generic.xml as something with valid XML markup 
 inside, while web2py's generic.xml is filled with templating functions that 
 are NOT static xml. 

 On Tuesday, January 13, 2015 at 10:38:00 AM UTC+1, Carl Hunter Roach wrote:

 In today's Web2py source I get a  for the contents of 
 applications/x/views/generic.xml
 with the default content: {{from gluon.serializers import 
 xml}}{{=XML(xml(response._vars,quote=False))}}

 The error is: Content is not allowed in prolog

 This error doesn't prevent the application from working but I'd like to 
 get to the IDE to a zero error, zero warning state.

 Any suggestions?



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


[web2py] Re: How to add a column to SQLFORM.smartgrid that contains the row count?

2015-01-15 Thread Dave S


On Thursday, January 15, 2015 at 11:47:07 AM UTC-8, César Bustíos Benites 
wrote:

 Hello all, I have a simple SQLFORM.smartgrid using two tables: tramites 
 and tramites_procesos:



Is your view anything different  from
{{=form}}

I would assume, without having actually gotten to smartgrids yet, that a 
virtual field would be part of the answer.
URL:http://web2py.com/books/default/chapter/29/07/forms-and-validators#Virtual-fields-in-SQLFORM-grid-and-smartgrid

Sorry for the vague answer.

/dps


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


[web2py] How to add a column to SQLFORM.smartgrid that contains the row count?

2015-01-15 Thread César Bustíos Benites
Hello all, I have a simple SQLFORM.smartgrid using two tables: tramites 
and desarrollo_tramites:

https://lh6.googleusercontent.com/-n3RmEWYCkP0/VLgYJVm42TI/YAI/FQU8KmqkrLQ/s1600/tramites.png
This is how the code looks like:

@auth.requires_login()
def consulta_tramite():
user_id = auth.user.id
user_area = auth.user.area
db.tramites.estado.writable = False
db.tramites_procesos.tramite.writable = False
db.tramites_procesos.usuario.default = user_id
db.tramites_procesos.usuario.writable = False
form = SQLFORM.smartgrid(
db.tramites,
linked_tables = ['tramites_procesos'],
divider=' ⇒',
fields=[
db.tramites.id,
db.tramites.tiempo,
db.tramites.documento_generado,
db.tramites_procesos.id,
db.tramites_procesos.tiempo,
db.tramites_procesos.indicacion,
db.tramites_procesos.usuario,
db.tramites_procesos.area_destino,
db.tramites_procesos.usuario_destino,
db.tramites_procesos.comentarios
],
editable=False,
deletable=False,
create=False,
details=False,
exportclasses=dict(xml=False, html=False, json=False, tsv=False, 
tsv_with_hidden_cols=False),
maxtextlength=100,
formstyle='bootstrap'
)


if form.element('.web2py_table table'):
form.element('.web2py_table table')['_class'] = 'table 
table-bordered'
for tr in form.element('.web2py_table table tbody'):
for td in tr.components:
if 'Urgente' in td.components:
td.add_class('warning warning-message')
elif 'Muy Urgente' in td.components:
td.add_class('danger danger-message')
return dict(form=form)

I want to add an extra column at the beginning of the table that shows the 
row count, something like this:

# | Nº trámite | Fecha | ...
===
1 | ...
2 | ...
3 | ...
4 | ...

How can I achieve such thing?

Thank you,
César B.

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


[web2py] Why can I peek but not edit some existing files?

2015-01-15 Thread Tom Campbell
I created a file called default/view.html using the web interface. It looks 
as expected when I peek at it:

{{extend 'layout.html'}}
h1This is the default/view.html template/h1
{{=BEAUTIFY(response._vars)}}


However, when I choose to edit that file using the web interface I get a 
blank, uneditable page. This happens with several view files I created. 

Browser console shows this error originating from comment-fold.js: 

TypeError: lineText is undefined


Running web2py with this info in the VERSION file: Version 
2.9.5-stable+timestamp.2014.03.16.02.35.39

python.exe is on a local drive, web2py and Application directory are on 
Dropbox drive.

How can I get access to these files?

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


[web2py] Re: Why can I peek but not edit some existing files?

2015-01-15 Thread Dave S


On Thursday, January 15, 2015 at 2:42:39 PM UTC-8, Tom Campbell wrote:

 I created a file called default/view.html using the web interface. It 
 looks as expected when I peek at it:

 {{extend 'layout.html'}}
 h1This is the default/view.html template/h1
 {{=BEAUTIFY(response._vars)}}


 However, when I choose to edit that file using the web interface I get a 
 blank, uneditable page. This happens with several view files I created. 

 Browser console shows this error originating from comment-fold.js: 

 TypeError: lineText is undefined


 Running web2py with this info in the VERSION file: Version 
 2.9.5-stable+timestamp.2014.03.16.02.35.39

 python.exe is on a local drive, web2py and Application directory are on 
 Dropbox drive.

 How can I get access to these files?


I've had a few times when I've used right-click-Open Link In New Tab to 
edit a file related to the one I've already had open,
and the new tab has the framework but no visible file contents.  Refreshing 
the page (F5) makes the contents visible.

But starting at the Edit page (the name in the Navbar), and opening a 
file there, has worked for me.

On this machine, I'm still on Version 
2.9.5-stable+timestamp.2014.03.16.02.35.39

 Host is Fedora (16, still) with FF 33.1.1 as the browser.

/dps

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


Re: [web2py] Re: lazy question: does anyone have a simple backbone.js/web2py example or tutorial?

2015-01-15 Thread Tim Richardson
Backgrid.js looks promising. Getting web2py to populate a backbone
collection was pretty easy.
On 15/01/2015 5:18 PM, Tim Richardson t...@tim-richardson.net wrote:



 On Thursday, 15 January 2015 11:19:04 UTC+11, Derek wrote:

 I suppose you haven't seen 'DataTables.net' ?



 I looked at it a while ago. It looks very nice, but it's only partially
 open source (the edit plugin is not)

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


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


[web2py] Re: Error: Exporting CSV file in SQLFORM.grid

2015-01-15 Thread Tim Richardson
A quick question: if you try the standard Tab Separated Value export, does 
it work? (you can refer back to your stack overflow link to see why I ask).



On Thursday, 15 January 2015 04:31:56 UTC+11, Prasad Muley wrote:

 Hello All,

I've used a SQLFORM.grid for displaying table content. I've 
 provided export to CSV option in grid.

 My app settings are as below:

 *models/db.py*

 db.define_table('company',
 Field('name', 'string', length=128, notnull=True, 
 unique=True),
 Field('address', 'string'), format='%(name)s')


 db.define_table('document',
   Field('name', 'string', length=128, 
 notnull=True),
   Field('type', 'string', notnull=True),
   Field('company', db.company, format='%(name)s') 
   

 Here, 
 document table has company as a reference key,
 *Exported CSV should contain the company names not ids*

 So I've defined a class *CSVExporter* according to anthony 
 http://www.quora.com/Anthony-Bastardi  solution for 
 web2pygrid-csv-exports-shows-ids-not-values-for-reference-fields 
 http://stackoverflow.com/questions/17337290/web2pygrid-csv-exports-shows-ids-not-values-for-reference-fields

 *modules/doc_utils.py*
 from cStringIO import StringIO


 class CSVExporter(object):
 This class is used when grid's table contains reference key id.
Exported CSV should contain reference key name of reference 
key not ids
 file_ext = csv
 content_type = text/csv

 def __init__(self, rows):
 self.rows = rows

 def export(self):
 if self.rows:
 s = StringIO()
 self.rows.export_to_csv_file(s, represent=True)
 return s.getvalue()
 else:
 return ''

 *#Grid uses Custom search for string*


 def search_query(fields, keywords):
  Custom search for doc grid
 if isinstance(keywords, (tuple, list)):
 keywords = keywords[0]
 request.vars.keywords = keywords
 key = keywords.strip()
 if key and not '' in key and not ' in key and key:
 SEARCHABLE_TYPES = ('string', 'text', 'list:string')
 words = key.split(' ') if key else []
 filters = []
 for field in fields:
 #apply search on company_name also
 if field.name == portfolio_company:
 #get db from current module
 db = current.db
 #get company name from record
 company_ids = [company.id for company in db(
 db.company.name.contains(words)).select(db.company.id
 )]
 if company_ids:
 filters.append(field.belongs(company_ids))
 continue
 if field.type in SEARCHABLE_TYPES:
 all_words_filters = []
 for word in words:
 all_words_filters.append(field.contains(word))
 filters.append(reduce(lambda a, b: (a  b), 
 all_words_filters))
 parts = filters
 else:
 parts = None
 if parts:
 return reduce(lambda a, b: a | b, parts)
 else:
 return None

 *controllers/documents.py*
 from applications.asdf.doc_utils import CSVExporter, search_query


 def docs():
 export_csv = False
 export_classes = None
 query = valid_db_query_here
 if auth.has_membership('manager'): 
  export_csv = True
  export_classes = dict(csv=(CSVExporter, 'CSV'), 
 xml=False, html=False,
 json=False, 
 csv_with_hidden_cols=False,
 tsv=False, 
 tsv_with_hidden_cols=False)

 grid = SQLFORM.grid(query, orderby=~db.document.created_on,
  showbuttontext=False, 
 csv=export_csv, deletable=False,
  searchable=search_query, 
 exportclasses=export_classes)

 
return (grid=grid)

 If I search single keyword like Google or MicroSoft in then export works 
 as expected.

 if I search multiple keywords like Google India Private Limited or Redhat 
 India Pvt Ltd then it shows expected rows in grid

 But If I click on export button then it gives me *Following error*


 *Ticket ID*
 *127.0.0.1.2015-01-14.21-56-57.34fb2b60-2857-4c1a-9626-a854630fc9c7*

 *type 'exceptions.AttributeError' 'list' object has no attribute 
 'colnames'*

 *Version*
 *web2py™ Version 2.9.5-stable+timestamp.2014.03.16.02.35.39*
 *Traceback*
 *1.*
 *2.*
 *3.*
 *4.*
 *5.*
 *6.*
 *7.*
 *8.*
 *9.*
 *10.*
 *11.*
 *12.*
 *13.*
 *14.*
 *15.*
 *16.*
 *Traceback (most recent call last):*
 *  File /home/prasad/Rootpy/web2py_2.9/gluon/restricted.py, line 220, in 
 restricted*
 *exec ccode in environment*
 *  File 
 /home/prasad/Rootpy/web2py_2.9/applications/asdf/controllers/documents.py, 
 line 137, in 

Re: [web2py] Re: Error: Exporting CSV file in SQLFORM.grid

2015-01-15 Thread Prasad Muley
Hi Tim,

  Export format should be CSV file. I am getting that error because of
the custom search in grid.

I got some clues from Exporting from a SQLFORM.grid with customized search
queries https://groups.google.com/forum/#!topic/web2py/Td58YKBAaMo

I'll try TSV once I fix this issue.


On Thu, Jan 15, 2015 at 1:32 PM, Tim Richardson t...@tim-richardson.net
wrote:

 A quick question: if you try the standard Tab Separated Value export, does
 it work? (you can refer back to your stack overflow link to see why I ask).



 On Thursday, 15 January 2015 04:31:56 UTC+11, Prasad Muley wrote:

 Hello All,

I've used a SQLFORM.grid for displaying table content. I've
 provided export to CSV option in grid.

 My app settings are as below:

 *models/db.py*

 db.define_table('company',
 Field('name', 'string', length=128, notnull=True,
 unique=True),
 Field('address', 'string'), format='%(name)s')


 db.define_table('document',
   Field('name', 'string', length=128,
 notnull=True),
   Field('type', 'string', notnull=True),
   Field('company', db.company, format='%(name)s')


 Here,
 document table has company as a reference key,
 *Exported CSV should contain the company names not ids*

 So I've defined a class *CSVExporter* according to anthony
 http://www.quora.com/Anthony-Bastardi  solution for
 web2pygrid-csv-exports-shows-ids-not-values-for-reference-fields
 http://stackoverflow.com/questions/17337290/web2pygrid-csv-exports-shows-ids-not-values-for-reference-fields

 *modules/doc_utils.py*
 from cStringIO import StringIO


 class CSVExporter(object):
 This class is used when grid's table contains reference key id.
Exported CSV should contain reference key name of reference
key not ids
 file_ext = csv
 content_type = text/csv

 def __init__(self, rows):
 self.rows = rows

 def export(self):
 if self.rows:
 s = StringIO()
 self.rows.export_to_csv_file(s, represent=True)
 return s.getvalue()
 else:
 return ''

 *#Grid uses Custom search for string*


 def search_query(fields, keywords):
  Custom search for doc grid
 if isinstance(keywords, (tuple, list)):
 keywords = keywords[0]
 request.vars.keywords = keywords
 key = keywords.strip()
 if key and not '' in key and not ' in key and key:
 SEARCHABLE_TYPES = ('string', 'text', 'list:string')
 words = key.split(' ') if key else []
 filters = []
 for field in fields:
 #apply search on company_name also
 if field.name == portfolio_company:
 #get db from current module
 db = current.db
 #get company name from record
 company_ids = [company.id for company in db(
 db.company.name.contains(words)).select(db.company.id
 )]
 if company_ids:
 filters.append(field.belongs(company_ids))
 continue
 if field.type in SEARCHABLE_TYPES:
 all_words_filters = []
 for word in words:
 all_words_filters.append(field.contains(word))
 filters.append(reduce(lambda a, b: (a  b),
 all_words_filters))
 parts = filters
 else:
 parts = None
 if parts:
 return reduce(lambda a, b: a | b, parts)
 else:
 return None

 *controllers/documents.py*
 from applications.asdf.doc_utils import CSVExporter, search_query


 def docs():
 export_csv = False
 export_classes = None
 query = valid_db_query_here
 if auth.has_membership('manager'):
  export_csv = True
  export_classes = dict(csv=(CSVExporter, 'CSV'),
 xml=False, html=False,
 json=False,
 csv_with_hidden_cols=False,
 tsv=False,
 tsv_with_hidden_cols=False)

 grid = SQLFORM.grid(query, orderby=~db.document.created_on,
  showbuttontext=False,
 csv=export_csv, deletable=False,
  searchable=search_query,
 exportclasses=export_classes)


return (grid=grid)

 If I search single keyword like Google or MicroSoft in then export works
 as expected.

 if I search multiple keywords like Google India Private Limited or Redhat
 India Pvt Ltd then it shows expected rows in grid

 But If I click on export button then it gives me *Following error*


 *Ticket ID*
 *127.0.0.1.2015-01-14.21-56-57.34fb2b60-2857-4c1a-9626-a854630fc9c7*

 *type 'exceptions.AttributeError' 'list' object has no attribute
 'colnames'*

 *Version*
 *web2py™ Version 2.9.5-stable+timestamp.2014.03.16.02.35.39*
 *Traceback*
 *1.*
 *2.*
 *3.*
 *4.*
 *5.*
 

[web2py] Re: Exporting from a SQLFORM.grid with customized search queries

2015-01-15 Thread Prasad Muley
Hello Massimo and Dexter,

I've a fix for this issue. I've tested it and attached the diff 
file. PFA. 

Let me know if I missed anything. 

Btw Can I send pull request?

On Saturday, October 25, 2014 at 5:17:24 AM UTC+5:30, Massimo Di Pierro 
wrote:

 Hello Dexter, I think your are right. I will review this asap. Meanwhile, 
 would you be able to open an issue with a link to this thread so we can 
 more easily keep track. Thanks!.

 Massimo

 On Thursday, 23 October 2014 13:23:16 UTC-5, Dexter Hadley wrote:

 Hi All,

 This is my first time posting a question, so thanks to Massimo and they 
 whole community for making web2py.  Its great!

 I am trying to export results from a customized full-text search using 
 SQLFORM.grid.  My backend is a Postgres db, and I successfully define 
 search_widget and searchable functions that are passed to the 
 SQLFORM.grid to do the full-text search.  It will works pretty well on the 
 web app.  However, once I click the export button, SQLFORM.grid apparently 
 recreates the query using the default SQLFORM.build_query and ignores the 
 correct query which I define in searchable.  After poking around in 
 sqlhtml.py, I found this is so because the exporter only conditions on 
 request.vars.keywords before calling  SQLFORM.build_query, and it does not 
 check for callable(searchable) which I think it should do.  In fact, I 
 fixed it by editing sqlhtml.py to force the exporter to condition on 
 (request.vars.keywords *and callable(searchable)*) before setting up the 
 rows object to export.  The code I added is in bold below (on line 2298 of 
 sqlhtml.py):

 if request.vars.keywords *and callable(searchable)*:
 try:
 #the query should be constructed using searchable 
 fields but not virtual fields
 sfields = reduce(lambda a, b: a + b,
 [[f for f in t if f.readable and not 
 isinstance(f, Field.Virtual)] for t in tables])
 dbset = dbset(SQLFORM.build_query(
 sfields, request.vars.get('keywords', '')))
 rows = dbset.select(left=left, orderby=orderby,
 cacheable=True, 
 *selectable_columns)
 except Exception, e:
 response.flash = T('Internal Error')
 rows = []
 else:
 rows = dbset.select(left=left, orderby=orderby,
 cacheable=True, 
 *selectable_columns)

 Is this a bug or is there a better way to do an export of customized 
 search results using SQLFORM.grid?  I'm using the current version of 
 everything (web2py 2.9.11, Postgres 9.3, Python 2.7.8).  Thx again,

 dex*



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py
index 28c3761..6e32aa2 100644
--- a/gluon/sqlhtml.py
+++ b/gluon/sqlhtml.py
@@ -2326,7 +2326,7 @@ class SQLFORM(FORM):
  expcolumns.append(str(field))
 
 if export_type in exportManager and exportManager[export_type]:
-if keywords:
+if keywords and not callable(searchable):
 try:
 #the query should be constructed using searchable
 #fields but not virtual fields
@@ -2339,6 +2339,19 @@ class SQLFORM(FORM):
 except Exception, e:
 response.flash = T('Internal Error')
 rows = []
+elif callable(searchable):
+#use custom_query using searchable
+try:
+#the query should be constructed using searchable
+#fields but not virtual fields
+sfields = reduce(lambda a, b: a + b,
+[[f for f in t if f.readable and not isinstance(f, 
Field.Virtual)] for t in tables])
+dbset = dbset(searchable(sfields, keywords))
+rows = dbset.select(left=left, orderby=orderby,
+cacheable=True, 
*selectable_columns)
+except Exception, e:
+response.flash = T('Internal Error')
+rows = []
 else:
 rows = dbset.select(left=left, orderby=orderby,
 cacheable=True, 

[web2py] Re: Gig: web2py nut needed for remote scheduling/membership site

2015-01-15 Thread Leonel Câmara
You expect people to be your dev lead, do all the admin work, basically 
have all the responsibility for the success of this project, and you're 
paying 15 bucks an hour?

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


Re: [web2py] Re: Gig: web2py nut needed for remote scheduling/membership site

2015-01-15 Thread António Ramos
Now i understand the subject
Web2py is severelly underrated
Em 15/01/2015 13:38, Leonel Câmara leonelcam...@gmail.com escreveu:

 You expect people to be your dev lead, do all the admin work, basically
 have all the responsibility for the success of this project, and you're
 paying 15 bucks an hour?

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


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