[web2py] Re: belongs handle if there is only one value

2017-07-29 Thread 黄祥
if test0 != None and type(test0) == str:
query = (db.test1.test0 == test0)
elif test0 != None and type(test0) == list:
query = (db.test1.test0.belongs(test0) )
else:
query = (db.test1.id > 0)

return error traceback when access 
http://127.0.0.1:8000/a/default/test1?test0=None#
*ValueError: invalid literal for long() with base 10: 'None'*

this works
if test0 != 'None' and type(test0) == str:
query = (db.test1.test0 == test0)
elif test0 != 'None' and type(test0) == list:
query = (db.test1.test0.belongs(test0) )
else:
query = (db.test1.id > 0)

sometime i confuse the null value (None or '') in web2py, what works in 
models or database side and what works in controllers and views side is 
different.
like example above, when i put the code in models None is works but as an 
example above i put it on controllers or view side, it should be 'None'
another thing is for query or update value to set null value assign it into 
None or ''

thanks and best regards,
stifan

-- 
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: Execution error of script sessions2trash

2017-07-29 Thread domezzzz


El viernes, 28 de julio de 2017, 17:07:21 (UTC-3), dome escribió:
>
> Version: 2.15.2-stable+timestamp.2017.07.19.12.18.41 
> 
>  web2py.exe for windows
>
> Start logging--
>File "c:\web2py_sitio\gluon\shell.py", line 268, in run 
>  execfile(startfile, _env)
>File "scripts/sessions2trash.py", line 90
>  print 'key: %s' % str(item)
>^
>SyntaxError: invalid syntax
> End logging--
>
> Adding any print '.' or print('...) or print sys.argv, gives error.
> And also, in any source that is launched in cmd mode.
> It looks like a web2py.exe problem
> In version 2.14.6 works.
>
> Regards.
> -
> 29.07.2017
> ¡ups!
> Apologies, I did not do all the relevant tests.
> You had to change ALL the print to py3 form.
>

-- 
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: Weird problems generating menu from database

2017-07-29 Thread Massimo Di Pierro
Let me assume there is only one level and this cannot be arbitrarily 
nested. Also I assume the initial model of this thread:

db.define_table('store_catalog',
Field('maincategory', 'string'),
Field('subcategory', 'string'),
Field('description', 'text'))

t = store_catalog
rows = db(t).select()
from collections import defaultdict
d=defaultdict(list)
for row in rows: d[row.maincategory].append(row.subcategory)
response.menu = [
[T(key), False, None, [[T(sub), False, 'link'] for sub in 
sorted(d[key])]] for key in sorted(d)
]

On Saturday, 29 July 2017 08:00:40 UTC-5, Вячеслав Анатольевич wrote:
>
> Hi!
>
> Paraphrase the question, can anyone explain how to create 
> a drop-down menu from a database table or show a working example?
>
>

-- 
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: belongs handle if there is only one value

2017-07-29 Thread Massimo Di Pierro
shouldn't this be:

if test0 != None and type(test0) == str:
query = (db.test1.test0 == test0)
elif test0 != None and type(test0) == list:
query = (db.test1.test0.belongs(test0) )
else:
query = (db.test1.id > 0)

On Saturday, 29 July 2017 02:27:41 UTC-5, 黄祥 wrote:
>
> thx 4 the way out massimo, another way is to use if condition that check 
> the data type
> *e.g.*
> if test0 != 'None' and type(test0) == 'str':
> query = (db.test1.test0 == test0)
> elif test0 != 'None' and type(test0) == 'list':
> query = (db.test1.test0.belongs(test0) )
> else:
> query = (db.test1.id > 0)
>
> thanks and best regards,
> stifan
>

-- 
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: IMPORTANT - WEB2PY CONSULTING

2017-07-29 Thread Oasis Agano
Hello,

Can you add me too?
Name: Oasis AGANO

Software developer/consultant & Digital Nomad.
I've been using web2py since 2014.

I will share my site later(work in progress).
meanwhile my email is oasisag...@gmail.com.


kr,
Oasis

On Monday, February 16, 2015 at 12:21:36 AM UTC+2, Massimo Di Pierro wrote:
>
> We need to update the list of companies that provide web2py consulting.
> This list is obsolete:
>
> http://web2py.com/init/default/support
>
> Some links are broke. Most pages do not even mention web2py. Some of them 
> have a design that is simply not acceptable for a web development company.
>
> That list will be eliminated. IF YOU WANT TO BE LISTED please update your 
> page to have a decent design and MENTION WEB2PY on the main site. Then 
> respond to this thread by providing an updated link and the country were 
> you incorporated. If you have a self-employed individual list your country 
> of residence.
>
>

-- 
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: Weird problems generating menu from database

2017-07-29 Thread Вячеслав Анатольевич
Hi!

Paraphrase the question, can anyone explain how to create 
a drop-down menu from a database table or show a working example?

-- 
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] Datatables Query String Parsing

2017-07-29 Thread villas
Thanks for responses and José that code will be a good help.

In my case, parsing the query is quite trivial to extract a search string 
and the sort order,  which is all I needed just now.

After playing around more,  it seems to me that Web2py would be really 
improved with something like Datatables (as well as the sqlform grid).

   - For small datasets you can feed in all the data at once and use js 
   pagination and searching etc.  It's quick and avoids a lot of queries.
   - For large datasets,  the ajax interaction is great.


The number of queries that the sqlform grid produces is very inefficient,  
and that is why I have been experimenting with Datatables in the first 
place.

Indeed Datatables seems to fit really well with Massimo's ideas for the 
future (I mean making better use of the client-side and reducing 
bandwidth).  

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: belongs handle if there is only one value

2017-07-29 Thread 黄祥
thx 4 the way out massimo, another way is to use if condition that check 
the data type
*e.g.*
if test0 != 'None' and type(test0) == 'str':
query = (db.test1.test0 == test0)
elif test0 != 'None' and type(test0) == 'list':
query = (db.test1.test0.belongs(test0) )
else:
query = (db.test1.id > 0)

thanks and best regards,
stifan

-- 
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: belongs handle if there is only one value

2017-07-29 Thread Massimo Di Pierro
if not isinstance(test0, (tuple, list)): test0 = [test0]
query = (db.test1.test0.belongs(test0) )


On Friday, 28 July 2017 20:31:25 UTC-5, 黄祥 wrote:
>
> is it possible belongs to handle if there is only one value?
> e.g.
> *models/db.py*
> db.define_table('test0', 
> Field('name'),
> format = '%(name)s')
> db.define_table('test1', 
> Field('name'),
> Field('test0', 'reference test0'),
> format = '%(name)s')
>
> *controllers/default.py*
> def install():
> if db(db.test0).isempty() and db(db.test1).isempty():
> db.test0.bulk_insert([{'name' : 'test0 - a'}, {'name' : 'test0 - b'}, ] )
> db.test1.bulk_insert([{'name' : 'test1 - a', 'test0' : 1}, {'name' : 
> 'test1 - b', 'test0' : 2}, ] )
> def test0():
> form = SQLFORM.factory(
> Field("test0", "list:reference test0", 
>  requires = IS_EMPTY_OR(IS_IN_DB(db, db.test0.id, db.test0._format, 
>multiple = True) ) ) )
> if form.process().accepted:
> redirect(URL('test1', vars = form.vars) )
> elif form.errors:
> response.flash = T('Form has errors')
> return dict(form = form)
> def test1():
> test0 = request.vars.test0
> query = (db.test1.test0.belongs(test0) )
> rows = db(query).select()
> return dict(test0 = test0, query = query, rows = rows)
>
> *result:*
> http://127.0.0.1:8000/a/default/test1?test0=1#
> query : 
> 
> rows : 
> test0 : 
> 1
>
> http://127.0.0.1:8000/a/default/test1?test0=1=2#
> query : 
> 
> rows : 
> test1.idtest1.nametest1.test0
> 1 test1 - a test0 - a
> 2 test1 - b test0 - b
> test0 : 
> 1
> 2
>
> *question:*
> why belongs cannot handle if the value of dict is only one value? how can 
> achieve it using web2py way?
>
> thanks and best regards,
> stifan
>

-- 
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: MySQL and web2py error 1103

2017-07-29 Thread Massimo Di Pierro
 Is this with the latest version? 2.15.2?

On Friday, 28 July 2017 11:13:23 UTC-5, Jorgeluis Ortega wrote:
>
> Hi, I'm working with web2py for some months, which seems to be a very 
> interesting tool. 
> I want to know if there is the possibility of manipulating MySQL data from my 
> app inventor through web2py. 
> I have tried a few methods but it gives me an error 1103 unable to post or 
> put the text. I want to do as it does snugly from php. 
> I hope you understand me and if you can help me I would appreciate it a lot
>
>

-- 
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: MS-SQL DAL Problem

2017-07-29 Thread Massimo Di Pierro

This seems like a serious issue. Are you available to help us debug via 
chat?

On Wednesday, 26 July 2017 09:41:58 UTC-5, Jaco wrote:
>
> Hi all,
> since updating from 2.14.6 to 2.15.2 I have a problem with accessing a 
> remote MS-SQL Database. It does not recognize certain fields and always 
> gives me an "incorrect syntax" error.
>
> This is the test with the "old" gluon:
> >>> from gluon2146 import DAL, Field
> >>> py = 
> DAL("mssql://DRIVER={FreeTDS};SERVER=SERVERNAME\\INSTANCE;DATABASE=DATABASE;UID=USER;PWD=PASSWORD")
> >>> py.define_table('quelle',
> ... Field('quelleID', type='id', writable=False, 
> readable=False, rname='Id',label = 'Quelle ID'),
> ... Field('QName', readable=False, 
> writable=False,rname='Name'),
> ... Field('quelle_datum', type = 'date',comment='Datum der 
> Quelle', label = 'Quellendatum'),
> ... Field('bemerkung','text', comment='Bemerkung zur 
> Quelle', label = 'Bemerkung'),
> ... rname = 'tQuelle',
> ... fake_migrate=True
> ...)
> 
> >>>
> ... rows = py().select(py.quelle.ALL)
> >>> for row in rows[0:5]:
> ... print row.quelleID
> ...
> 4514
> 4515
> 4516
> 4517
> 4518
> >>> for row in rows[0:5]:
> ... print row.quelle_datum
> ...
> 2016-09-16
> 2016-09-16
> 2016-11-14
> 2016-09-16
> 2016-10-18
> >>>
>
> and this is with the new one:
> >>> from gluon import DAL, Field
> >>> py = 
> DAL("mssql://DRIVER={FreeTDS};SERVER=SERVERNAME\\INSTANCE;DATABASE=DATABASE;UID=USER;PWD=PASSWORD")
> >>> py.define_table('quelle',
> ... Field('quelleID', type='id', writable=False, 
> readable=False, rname='Id',label = 'Quelle ID'),
> ... Field('QName', readable=False, 
> writable=False,rname='Name'),
> ... Field('quelle_datum', type = 'date',comment='Datum der 
> Quelle', label = 'Quellendatum'),
> ... Field('bemerkung','text', comment='Bemerkung zur 
> Quelle', label = 'Bemerkung'),
> ... rname = 'tQuelle',
> ... fake_migrate=True
> ...)
> 
> >>> rows = py().select(py.quelle.ALL)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/home/jacob/gluon/packages/dal/pydal/objects.py", line 2211, in 
> select
> return adapter.select(self.query, fields, attributes)
>   File "/home/jacob/gluon/packages/dal/pydal/adapters/base.py", line 760, 
> in select
> return self._select_aux(sql, fields, attributes, colnames)
>   File "/home/jacob/gluon/packages/dal/pydal/adapters/base.py", line 716, 
> in _select_aux
> rows = self._select_aux_execute(sql)
>   File "/home/jacob/gluon/packages/dal/pydal/adapters/base.py", line 710, 
> in _select_aux_execute
> self.execute(sql)
>   File "/home/jacob/gluon/packages/dal/pydal/adapters/__init__.py", line 
> 67, in wrap
> return f(*args, **kwargs)
>   File "/home/jacob/gluon/packages/dal/pydal/adapters/base.py", line 410, 
> in execute
> rv = self.cursor.execute(command, *args[1:], **kwargs)
> pyodbc.ProgrammingError: ('42000', "[42000] [FreeTDS][SQL Server]Incorrect 
> syntax near 'quelle_datum'. (102) (SQLExecDirectW)")
> >>>
>
> The table already exists and I am just trying to access the Data. 
> If am am trying to only access the ID Field, it works.
>
> >>> rows = py().select(py.quelle.quelleID)
> >>> for row in rows:
> ... print row.quelleID
> ...
> 4514
> 4515
> 4516
>
> Does anyone know a workaround?
>
> Thanks in advance :)
>

-- 
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 use sum() in grid

2017-07-29 Thread Massimo Di Pierro
There is no easy way but I just made a commit that fixes your problem. If 
you use trunk or wait for a next web2py version (within days) and you can 
do:

def stck_issue_manage():
#form = SQLFORM.smartgrid(db.t_stck_issue,onupdate=auth.archive)
grid = SQLFORM.grid(db.t_stck_issue)
if grid.dbset:
 myrow=grid.dbset.select(db.t_stck_issue.f_sub_total.sum())[0]
 answer=myrow._extra['SUM(t_stck_issue.f_sub_total)']
else: answer = None
return locals()
VIEW
{{extend 'layout.html'}}

Manage stck_issue{{=grid}}
All Issue Totals: {{=answer}}


On Wednesday, 26 July 2017 08:27:33 UTC-5, kesh wrote:
>
> hello sir
> i hope you are ok, well i have been having a problem with some code here 
> and have searched all over the internet but i was not able to get a solution
> MODEL
> db.define_table('t_stck_issue',
> Field('f_name', type='reference t_items',
>   label=T('Name')),
> Field('f_stck_client', type='reference t_clients',
>   label=T('Client Assgn')),
> Field('f_stck_quantity', type='integer',
>   label=T('Stock Quantity')),
> Field('f_unit_price', type='double',
>   label=T('Unit Price')),
> Field('f_sub_total',type='double', compute=lambda 
> r:r['f_unit_price']*r['f_stck_quantity'],
>   label=T('Sub Total')),
> auth.signature,
> format='%(f_name)s',
> migrate=settings.migrate)
>
> db.define_table('t_stck_issue_archive',db.t_stck_issue,Field('current_record','reference
>  
> t_stck_issue',readable=False,writable=False))
> CONTROLLER
> def stck_issue_manage():
> #form = SQLFORM.smartgrid(db.t_stck_issue,onupdate=auth.archive)
> form = SQLFORM.grid(db.t_stck_issue)
> myrow=db().select(db.t_stck_issue.f_sub_total.sum())[0]
> answer=myrow._extra['SUM(t_stck_issue.f_sub_total)']
> return locals()
> VIEW
> {{extend 'layout.html'}}
>
> Manage stck_issue{{=form}}
> All Issue Totals: {{=answer}}
>
> well it calculates the sub total field for all properly, but i would like 
> it to change when i filter by client to do the sub total for that 
> particular client only
>

-- 
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.