[web2py] TEXT data type deprecated in future MSSQL?

2012-03-16 Thread Joaquin Orbe
Hi Massimo,

I've took a look into dal.py and found that text data type for
MSSQLAdapter and MSSQL2Adapter is mapped to TEXT and NTEXT
respectively. According to this article[0], these ones should be
replaced by varchar(max) and nvarchar(max) due to will be deprecated
in future versions (maybe SQL Server 2012? I couldn't find it).

How do you handle this situations?

Regards,
Joaquin.

[0] http://msdn.microsoft.com/en-us/library/ms187993.aspx


Re: [web2py] Re: TEXT data type deprecated in future MSSQL?

2012-03-16 Thread Joaquin Orbe
On Fri, Mar 16, 2012 at 5:45 PM, Massimo Di Pierro
massimo.dipie...@gmail.com wrote:
 P.S. Please open a google code ticket about it.

Done:
http://code.google.com/p/web2py/issues/detail?id=722

Regards,
Joaco.


[web2py] error when insert record in appadmin

2011-03-05 Thread Joaquin Orbe
Hi all,

I have a strange behaviour in appadmin trying to insert a record. It
happens with all my tables except for auth's (auth_user, auth_group,
etc). This is the error message:

class 'pyodbc.ProgrammingError'(('42000', [42000] [Microsoft][ODBC
SQL Server Driver][SQL Server]Incorrect syntax near ')'. (102)
(SQLExecDirectW)))

I tried to understand the ticket created and could find this at
gluon\dal.py in insert at line 717:
locals
query   : 'INSERT INTO my_table() VALUES ();'

Does it means it created an empty query?

I'm on win7, python 2.6, web2py 1.92.1 from sources.

Thanks in advance,
Joaquin.


[web2py] Re: error when insert record in appadmin

2011-03-05 Thread Joaquin Orbe
Update: I've tried SQLite and it's the same problem:

class 'sqlite3.OperationalError'(near ): syntax error)
 locals
 query   : 'INSERT INTO my_table() VALUES ();'

Any kind of help will be appreciated.

Joaquin.

On Sat, Mar 5, 2011 at 3:09 PM, Joaquin Orbe joaquino...@gmail.com wrote:
 Hi all,

 I have a strange behaviour in appadmin trying to insert a record. It
 happens with all my tables except for auth's (auth_user, auth_group,
 etc). This is the error message:

 class 'pyodbc.ProgrammingError'(('42000', [42000] [Microsoft][ODBC
 SQL Server Driver][SQL Server]Incorrect syntax near ')'. (102)
 (SQLExecDirectW)))

 I tried to understand the ticket created and could find this at
 gluon\dal.py in insert at line 717:
 locals
 query   : 'INSERT INTO my_table() VALUES ();'

 Does it means it created an empty query?

 I'm on win7, python 2.6, web2py 1.92.1 from sources.

 Thanks in advance,
 Joaquin.



[web2py] non redirection when authentication fails

2011-03-15 Thread Joaquin Orbe
Hi All,

I have two kind of users in my application: admins and users. Each
of them has different index function which I've decored, that's why I
get these URLs when trying to login:

* admins login through
http://127.0.0.1:8000/myapp/default/user/login?_next=/myapp/admin/index
* common users login through
http://127.0.0.1:8000/myapp/default/user/login?_next=/myapp/default/index

Everything work as I expected, but when authentication fails both
groups are redirect to http://127.0.0.1:8000/myapp/default/user/login.
Is it possible to have non-redirection when authentication fails? I've
been playing with auth.settings.on_failed_authorization and
auth.settings.on_failed_authentication but couldn't get it work.
Any help will be appreciated.


Joaquin.


[web2py] Re: non redirection when authentication fails

2011-03-19 Thread Joaquin Orbe
Hi,

a workaround for this (and I like it) is:
auth = Auth(globals(),db, request.controller)

With this I redirect to the login page for the correct controller when
authentication fails.

Regards,
Joaquin.

On Tue, Mar 15, 2011 at 12:15 PM, Joaquin Orbe joaquino...@gmail.com wrote:
 Hi All,

 I have two kind of users in my application: admins and users. Each
 of them has different index function which I've decored, that's why I
 get these URLs when trying to login:

 * admins login through
 http://127.0.0.1:8000/myapp/default/user/login?_next=/myapp/admin/index
 * common users login through
 http://127.0.0.1:8000/myapp/default/user/login?_next=/myapp/default/index

 Everything work as I expected, but when authentication fails both
 groups are redirect to http://127.0.0.1:8000/myapp/default/user/login.
 Is it possible to have non-redirection when authentication fails? I've
 been playing with auth.settings.on_failed_authorization and
 auth.settings.on_failed_authentication but couldn't get it work.
 Any help will be appreciated.


 Joaquin.



[web2py] in-line select for counting purpose

2011-03-26 Thread Joaquin Orbe
Hi all,

I'm trying to get a result for this query:

select vendor.id, vendor.Name,
(select count(*) from sales_order where [Status] = 1 and vendor.id =
sales_order.VendorID),
(select count(*) from sales_order where [Status] = 2 and vendor.id =
sales_order.VendorID),
(select count(*) from sales_order where [Status] = 3 and vendor.id =
sales_order.VendorID)
from vendor

and for it I do:

countOpen = db((db.sales_order.Status==1)(db.sales_order.VendorID ==
db.vendor.id)).count()
countProg = db((db.sales_order.Status==2)(db.sales_order.VendorID ==
db.vendor.id)).count()
countClosed = db((db.sales_order.Status==3)(db.sales_order.VendorID
== db.vendor.id)).count()

rows = db().select(db.vendor.id, db.vendor.Name,countOpen,countProg,countClosed)

but it's not working because I get

(1, vendor1, 1, 4, 1)
(2, vendor2, 1, 4, 1)

instead of

(1, vendor1, 1, 4, 1)
(2, vendor2, 0, 0, 0)

It seems the result of vendor1 is also applied to vendor2 (vendor2
does not have records in sales_order table).

Does someone know how to solve it?

Thanks in advance,
Joaquin.


Re: [web2py] Re: in-line select for counting purpose

2011-03-30 Thread Joaquin Orbe
On Sat, Mar 26, 2011 at 6:30 PM, Massimo Di Pierro
massimo.dipie...@gmail.com wrote:
 You an have a nested select in place of a field.

 I think you want:
 count = db.sales_order.id.count()
 query = db.sales_order.VendorID == db.vendor.id
 rows1 = db(query)
 (db.sales_order.Status==1).select(db.vendor.id,db.vendor.Name,count)
 rows2 = db(query)
 (db.sales_order.Status==2).select(db.vendor.id,db.vendor.Name,count)
 rows3 = db(query)
 (db.sales_order.Status==3).select(db.vendor.id,db.vendor.Name,count)





 On Mar 26, 3:57 pm, Joaquin Orbe joaquino...@gmail.com wrote:
 Hi all,

 I'm trying to get a result for this query:

 select vendor.id, vendor.Name,
 (select count(*) from sales_order where [Status] = 1 and vendor.id =
 sales_order.VendorID),
 (select count(*) from sales_order where [Status] = 2 and vendor.id =
 sales_order.VendorID),
 (select count(*) from sales_order where [Status] = 3 and vendor.id =
 sales_order.VendorID)
 from vendor

 and for it I do:

 countOpen = db((db.sales_order.Status==1)(db.sales_order.VendorID ==
 db.vendor.id)).count()
 countProg = db((db.sales_order.Status==2)(db.sales_order.VendorID ==
 db.vendor.id)).count()
 countClosed = db((db.sales_order.Status==3)(db.sales_order.VendorID
 == db.vendor.id)).count()

 rows = db().select(db.vendor.id, 
 db.vendor.Name,countOpen,countProg,countClosed)

 but it's not working because I get

 (1, vendor1, 1, 4, 1)
 (2, vendor2, 1, 4, 1)

 instead of

 (1, vendor1, 1, 4, 1)
 (2, vendor2, 0, 0, 0)

 It seems the result of vendor1 is also applied to vendor2 (vendor2
 does not have records in sales_order table).

 Does someone know how to solve it?

 Thanks in advance,
 Joaquin.


Hi Massimo,
sorry for my late answer.

How should I applied your suggestion? As I can understand, your code
seems to have three row results, and in my case I need only one. Is it
correct my understanding?

Thanks,
Joaquin.


Re: [web2py] Re: in-line select for counting purpose

2011-03-31 Thread Joaquin Orbe
On Wed, Mar 30, 2011 at 6:56 PM, Massimo Di Pierro
massimo.dipie...@gmail.com wrote:
 yes. I do not know how to do it with one query.

 On Mar 30, 3:18 pm, Joaquin Orbe joaquino...@gmail.com wrote:
 On Sat, Mar 26, 2011 at 6:30 PM, Massimo Di Pierro









 massimo.dipie...@gmail.com wrote:
  You an have a nested select in place of a field.

  I think you want:
  count = db.sales_order.id.count()
  query = db.sales_order.VendorID == db.vendor.id
  rows1 = db(query)
  (db.sales_order.Status==1).select(db.vendor.id,db.vendor.Name,count)
  rows2 = db(query)
  (db.sales_order.Status==2).select(db.vendor.id,db.vendor.Name,count)
  rows3 = db(query)
  (db.sales_order.Status==3).select(db.vendor.id,db.vendor.Name,count)

  On Mar 26, 3:57 pm, Joaquin Orbe joaquino...@gmail.com wrote:
  Hi all,

  I'm trying to get a result for this query:

  select vendor.id, vendor.Name,
  (select count(*) from sales_order where [Status] = 1 and vendor.id =
  sales_order.VendorID),
  (select count(*) from sales_order where [Status] = 2 and vendor.id =
  sales_order.VendorID),
  (select count(*) from sales_order where [Status] = 3 and vendor.id =
  sales_order.VendorID)
  from vendor

  and for it I do:

  countOpen = db((db.sales_order.Status==1)(db.sales_order.VendorID ==
  db.vendor.id)).count()
  countProg = db((db.sales_order.Status==2)(db.sales_order.VendorID ==
  db.vendor.id)).count()
  countClosed = db((db.sales_order.Status==3)(db.sales_order.VendorID
  == db.vendor.id)).count()

  rows = db().select(db.vendor.id, 
  db.vendor.Name,countOpen,countProg,countClosed)

  but it's not working because I get

  (1, vendor1, 1, 4, 1)
  (2, vendor2, 1, 4, 1)

  instead of

  (1, vendor1, 1, 4, 1)
  (2, vendor2, 0, 0, 0)

  It seems the result of vendor1 is also applied to vendor2 (vendor2
  does not have records in sales_order table).

  Does someone know how to solve it?

  Thanks in advance,
  Joaquin.

 Hi Massimo,
 sorry for my late answer.

 How should I applied your suggestion? As I can understand, your code
 seems to have three row results, and in my case I need only one. Is it
 correct my understanding?

 Thanks,
 Joaquin.

It's ok Massimo, thanks anyway. I've solved it with an executesql
statement for the moment.

BTW, I've been playing with dql.py trying to support this scenario but
the code is a bit messy to publish here. I could get it work but I
don't know if this could have impact in another place (I'm still a
newbie). I'll post it here once I apply a cleaning on it.


Thanks for all,
Joaquin.


Re: [web2py] Re: Attribute Error

2011-04-10 Thread Joaquin Orbe
On Sun, Apr 10, 2011 at 11:07 AM, Anthony abasta...@gmail.com wrote:
 It works for me. Are you sure you're problem is with {{=n.name}}. The error
 message you got looks like a NameError, not an AttributeError. Are you
 referring to a variable 'name' somewhere in your view (or controller)? Can
 you show your full controller and view code?

 Anthony
 On Sunday, April 10, 2011 9:48:26 AM UTC-4, David J wrote:

 I am passing a list of employees

 so in my view I have

 {{ for n in employees:}

 {{= n.name }}

 {{pass}}

Try something like this.

In your controller:

create your list of employees, ie:

employees = []
class  Employee:
   pass

john  =  Employee()  # Create an empty employee record

# Fill the fields of the record
john.name  =  'John Doe'
john.dept  =  'computer lab'
john.salary  =  1000

employees.append(john)

return (employees=employees)

In your view, your code should work:

{{ for n in employees:}}

{{= n.name }}

{{pass}}


Hope it works for you.

Joaquin.


Re: [web2py] About auth.requires_membership()

2011-06-06 Thread Joaquin Orbe
On Mon, Jun 6, 2011 at 2:03 PM, Cesar Bustios cesarbust...@gmail.com wrote:
 Hi, is there a way to use this decorator with more than one group? For
 example if i need function X to be use with groups A and B:

 @auth.requires_membership('A', 'B')
 def X(): ...

 That doesn't work. How can I do that?

 Thanks

Hi,
try this:

@auth.requires(auth.requires_membership('A') or auth.requires_membership('B'))
def X(): ...


Joaquin.


Re: [web2py] export data to OOO and Excel

2011-07-20 Thread Joaquin Orbe
On Wed, Jul 20, 2011 at 5:45 AM, Vineet vineet.deod...@gmail.com wrote:
 I was looking for a library to export data to OpenOffice  Excel.
 I found 2 such open source projects.

 For OOO ---
 http://ooolib.sourceforge.net/

 For Excel ---
 http://www.python-excel.org/

 What I intend to do is, keep the classes in web2py folder, import the
 classes in controller, then parse the result fetched from MySQL and
 export the data to OOO or Excel.

 Reasons as to why I am posting it here are--

 1] Whether anybody has tried these and knows if these are mostly bug-
 free (may not be 100%)
 2] Whether anybody knows any other (better suited, may be) projects
 like these (considering integration into w2p, feature-rich, tested,
 etc.)
 3] To share my findings with the list (might be useful to someone
 new).

 Cheers
 :-)

Hi Vineet,
I used xlwt for a non-production site and worked fine for me (just a
very simple report with a small formatting).
This is a quick example:

def excel_report():
from datetime import datetime
import xlwt
tmpfilename=os.path.join(request.folder,'private',str(uuid4()))

font0 = xlwt.Font()
font0.name = 'Arial'
font0.bold = True

style0 = xlwt.XFStyle()
style0.font = font0

style1 = xlwt.XFStyle()
style1.num_format_str = 'DD--'

wb = xlwt.Workbook()
ws = wb.add_sheet('Sample report')

ws.write(0, 0, 'Text here', style0)
ws.write(0, 6, 'More text here', style0)
ws.write(0, 7, datetime.now(), style1)

wb.save(tmpfilename)

data = open(tmpfilename,rb).read()
os.unlink(tmpfilename)
response.headers['Content-Type']='application/vnd.ms-excel'
return data


Hope it helps you.

Joaco.


Re: [web2py] export data to OOO and Excel

2011-07-21 Thread Joaquin Orbe
On Thu, Jul 21, 2011 at 3:40 PM, Dave davidramsayreinh...@gmail.com wrote:
 This works great, but when i download the file it is missing the extension.
 Is there an easy way to add '.xls' to the file name?

 Thanks,
 Dave

Hi Dave,
how do you download the file? This method is an action in one controller, ie:

http://127.0.0.1:8000/myapp/printer/excel_report

and the file is downloaded as XLS.

Joaco.


Re: [web2py] web2py.com/poweredby / Quality Systems

2011-07-29 Thread Joaquin Orbe
On Fri, Jul 29, 2011 at 6:11 AM, JmiXIII sylvn.p...@gmail.com wrote:
 Hello,

 I was just having a look at web2py.com/poweredby and in particular Quality
 Systems Tool:
 http://www.qualitysystems.com

 It seems to me this tool is made with Plone instead of web2py  did I
 miss something ?



Hello,
why do you think so? I take a look into code and can see this:
.
function web2py_ajax_init() {
  jQuery('.hidden').hide();
.

I don't know if this means that is or not made with web2py.


Joaco.


Re: [web2py] setting blank date in new widget

2011-09-27 Thread Joaquin Orbe
On Tue, Sep 27, 2011 at 4:55 PM, apple simo...@gmail.com wrote:
 The new date/time widgets do not seem to have an option to set a blank
 date/time. Once you have clicked on the date field you have to set a
 date. Backspace and delete keys have no effect.

 Is there a way to leave the date field blank or to delete a date?

Try this in your model:

IS_EMPTY_OR(IS_DATE())

Joaco.


Re: [web2py] processing upload field.

2012-02-06 Thread Joaquin Orbe
On Fri, Feb 3, 2012 at 11:58 AM, VP vtp2...@gmail.com wrote:
 I have the following situation.

 There is a field A of type upload (image).

 There is another field B of type compute, which depends on A.

 I want to be able to process the image uploaded in field A and save
 it, but before the compute in field B is executed.  In other words,
 field B will be computed after the image in field A is processed.

 What is the best way to do this?

 Thanks.

Hi,
once I did something like this but without computed fields. It could help you:

def uploadfile():
form = SQLFORM.factory(
Field('field1',),
Field('uploadField', 'upload',
uploadfolder='applications/your_app/your_folder'),
table_name='test_table',
labels={your_labels}
)

if request.vars.uploadFile!=None:
do_whatever_with_your_file(request.vars.uploadField.file)

if form.process().accepted:
response.flash = 'upload OK'
elif form.errors:
response.flash = 'form has errors'
return dict(form=form)


Regards,
Joaco.