[web2py] Re: Select filled with years

2017-04-18 Thread Juan Carlos Quesada


def getyears(anyo): 
from datetime import datetime, date
option = []
option.append(OPTION(T('Año'), _value=''))
year = datetime.today().year
ryear = range(2015, int(year+1))
for r in ryear:
if anyo == r:
selected = True
else:
selected = None
option.append(OPTION(r, _value=r, _selected=selected))
return SELECT(*option, _name='anyo', _id='anyo', _class="form-control 
input-md")


El domingo, 16 de abril de 2017, 23:07:08 (UTC+2), Winter Kryz escribió:
>
> Hello everybody,
>
> I have a table like this
>
> db.define_table('Report',
> Field('person', 'reference Person'),
> Field('year', 'integer'),
> Field('letter', 'string'),
>)
>
> and I use SQLFORM to create a form with that table
>
> form=SQLFORM(db.Report)
>
> I want to know if instead a 'year' field where I have to write the year, I 
> can fill a select with years from 1989 to 2017 so the user can pick one 
> from that list. I don't know how to do that because I'm using a sqlform. 
>
> Any ideas would be appreciate.
>
> 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] Removing item from list:Reference

2017-04-18 Thread Sharjeel Ali Shaukat
I have company table in which projects information is stored in 
list:reference , now i want to remove the project id from company table 
reference field without using loop , simple by DAL update query

*Company Table*
|  *id*  |  *name*  |  *projects*  |
|  1   |  Com1  |  |1|2| |

So after update my table should become


*Company Table*
|  *id*  |  *name*  |  *projects*  |
|  1   |  Com1  |  |2| |



I need to write a update query that will remove project id from list 
reference without using select query and for loop first
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: Python 2.7 mock library and web2py

2017-04-18 Thread Marlysson Silva
Do you have a file called db in your modules folder in your application?

Em domingo, 16 de abril de 2017 11:37:11 UTC-3, Robin Bryce escreveu:
>
> Hi,
>
> I'm attempting to use the python mock library with some unittest based 
> tests for a web2py application. It feels like I'm going against the grain. 
>
> General question: Is it generally a pain to use mock with web2py 
> applications or am I missing some trick to get it working ?
>
> Specifically, in models/db.py I have
>
> from gluon.contrib.login_methods.ldap_auth import ldap_auth
>
> in a unittest implementation I have
>
> def mock_ldap_auth(*args,**kw):
> return True
>
> mock_ldap_auth = mock.patch(
> 'db.ldap_auth',
> side_effect=mock_ldap_auth)
>
>
> I'm using web2py_utils and webtest to drive unittest.
>
> class TestSomething(unittest.TestCase):
> # __init__ method which intialises webtest
>
> def setUp(self):
> p = mock_ldap_auth.start()
> self.addCleanup(p.stop)
>
> The call to 'mock_ldap_auth.start()' produces this traceback::
>
> Traceback (most recent call last):
>   File "C:\Projects\web2py\applications\icss/tests\sign_infra.py", line 
> 49, in setUp
> p = mock_ldap_auth.start()
>   File "C:\Projects\pyenvs\icss\lib\site-packages\mock\mock.py", line 
> 1500, in start
> result = self.__enter__()
>   File "C:\Projects\pyenvs\icss\lib\site-packages\mock\mock.py", line 
> 1353, in __enter__
> self.target = self.getter()
>   File "C:\Projects\pyenvs\icss\lib\site-packages\mock\mock.py", line 
> 1523, in 
> getter = lambda: _importer(target)
>   File "C:\Projects\pyenvs\icss\lib\site-packages\mock\mock.py", line 
> 1206, in _importer
> thing = __import__(import_path)
>   File "C:\Projects\web2py\gluon\custom_import.py", line 89, in 
> custom_importer
> raise ImportError, 'Cannot import module %s' % str(e)
> ImportError: Cannot import module 'applications.icss.modules.db'
>
> Note: My purpose in asking this question is to avoid ugly and unnecessary 
> case specific work arounds.
>
> Thanks,
>
> Robin
>
>

-- 
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] update_or_insert only returns id if created not updated

2017-04-18 Thread António Ramos
why?
https://github.com/web2py/pydal/blob/4b30558e7d75da152ac6a003991e9add1b68c235/pydal/objects.py#L795

I could and need to use the id in case of update...


Sem
vírus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

-- 
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: Removing item from list:Reference

2017-04-18 Thread Alfonso Serra
Will this work for you?

company = db(db.companies.id==1).select().first()
company.projects.remove(1)

use db.commit() afterwards if this is ran in a console instead a controller.

Ideally you could use foreign keys to delete related projects data or 
dependencies. Have in mind that list fields are web2py feature, not a 
database one.

-- 
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: Using validate_and_insert with a computed field

2017-04-18 Thread Alfonso Serra
Hi Chris, why do you use requires IS_NOT_EMPTY in a computed field?, if you 
do, you have to supply a value before is computed, isnt it?

-- 
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: Using validate_and_insert with a computed field

2017-04-18 Thread Christopher L
Hi Alfonso,

I think the original reason was that sometimes I would end up with a
computed field without a value. Inserts should automatically compute rows,
but for some reason that wasn't happening here.

On Apr 18, 2017 8:04 AM, "Alfonso Serra"  wrote:

Hi Chris, why do you use requires IS_NOT_EMPTY in a computed field?, if you
do, you have to supply a value before is computed, isnt it?

-- 
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/Kqfg-MG5K44/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.


Re: [web2py] Re: Using validate_and_insert with a computed field

2017-04-18 Thread Alfonso Serra
As per the docs, they say they are stored in db but not computed on 
retrieval. i guess this applies to updates. 
Does this calculate_field function does not return a value in some case? 
for example total = unit * price may be None if the operation fails because 
either unit or price is None or the function does not return any value.



-- 
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] requires option on field does't work

2017-04-18 Thread Andrea Fae'
I have this table

db.define_table('materia',
Field('nome', 
requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'materia.nome')]),
Field('docente','reference auth_user'),

auth.signature,singular="Materia",plural="Materie",migrate='materia.table',
format='%(nome)s')
db.materia.nome.requires=IS_NOT_IN_DB(db(db.materia.docente==request.vars.docente),db.materia.nome)

I have this function
def materie_docente():
# recupero l'id del docente
docente = request.args(0)
# query per recuperare il nome  del docente
query_nome_docente = db.auth_user.id == docente
# recupero nome e cognome del docente
row = 
db(query_nome_docente).select(db.auth_user.first_name,db.auth_user.last_name).first()
#materie del docente
query = (db.materia.docente == docente)
db.materia.docente.default = docente
db.materia.docente.readable = True
db.materia.docente.writable = False
# imposto la grid per far vedere le materie di quel docente
exportcls = dict(csv_with_hidden_cols=False, html=False, json=False, 
tsv_with_hidden_cols=False, tsv=False)
form = SQLFORM.grid(query, args=[docente], 
fields=[db.materia.nome],create=True, details=True, editable=True, 
deletable=True, maxtextlength=60, exportclasses = exportcls)

return locals()


When I insert a new "materia" it can be inserted duplicated... it doesn't 
control is the materia.nome is still in the database.
I know maybe the reasonbecause request.vars.docente is not managed in 
the form. If I change db.materia.docente.writable from False to True is 
working but I don't want that the user change the field "docente". How to 
solve this problem?
Thank you

-- 
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] delete record confirmation dialog

2017-04-18 Thread Andrea Fae'
How to change customized message in the confirmation dialog about delete a 
record using grid or smartgrid? (depending on the situation)
Any examples?


-- 
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: Using validate_and_insert with a computed field

2017-04-18 Thread Anthony
You should not set "requires" on a computed field -- when you use 
validate_and_insert, the validation will be run before the computed value 
is generated. However, you can instead set required=True. In that case, any 
time you do an insert or update, if the fields needed by the computed field 
are missing, the computed field will trigger an exception (you'll have to 
catch the exception). Alternatively, you could add IS_NOT_EMPTY validators 
to the fields that are needed by the computed field -- as long as those 
fields are not empty, neither will the computed field be.

Anthony

On Tuesday, April 18, 2017 at 10:35:06 AM UTC-4, Alfonso Serra wrote:
>
> As per the docs, they say they are stored in db on insert but not computed 
> on retrieval. i guess this applies to updates. 
> Does this calculate_field function does not return a value in some case? 
> for example total = unit * price may be None if the operation fails because 
> either unit or price is None or the function does not return any value.
>
>
>
>

-- 
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: requires option on field does't work

2017-04-18 Thread Anthony

>
>
> db.materia.nome.requires=IS_NOT_IN_DB(db(db.materia.docente==request.vars.docente),db.materia.nome)
>

There is no request.vars.docente. Based on your controller code, it appears 
you are passing the "docente" value via request.args(0), so the above 
should probably be db.materia.docente==request.args(0).

Anthony

-- 
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: Removing item from list:Reference

2017-04-18 Thread Anthony
On Tuesday, April 18, 2017 at 7:54:21 AM UTC-4, Alfonso Serra wrote:
>
> Will this work for you?
>
> company = db(db.companies.id==1).select().first()
> company.projects.remove(1)
>

The above will remove the value from the Row object but will not update the 
database. To do the latter, you must then call:

company.update_record()

Anthony

-- 
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] list of dates into database

2017-04-18 Thread R U
I am trying to insert many dates into a field.  Currently I am only getting
1 date inserted.
my overall goal is to insert many (semi random) dates into the database;
each user will have his/her own unique list.  Then later iterate over the
list having the date trigger some event if it equals today's date.

controller:
from datetime import date, datetime, timedelta
import random
from random import randint
dog = randint(3,25)
def perdelta(start, end, delta):
curr = start
while curr < end:
yield curr
curr += delta

for result in perdelta(date(2017, 11, 11), date(2018, 12, 12),
timedelta(days=dog)):
print str(result)

fun.zipdip.insert(infom=result)

model:
fun = DAL('sqlite://storage.sqlite')
fun.define_table('zipdip',
Field('infom')),

result in dal is:
3 selected
zipdip.id

zipdip.infom

1 
2018-11-30
2 
2018-12-07
3 
2018-11-30

but if the code is run for example in repl.it the result is the outcome I
am looking for

2017-11-11
2017-11-24
2017-12-07
2017-12-20
2018-01-02
2018-01-15
2018-01-28
2018-02-10
2018-02-23
2018-03-08
2018-03-21
2018-04-03
2018-04-16
2018-04-29
2018-05-12
2018-05-25
2018-06-07
2018-06-20
2018-07-03
2018-07-16
2018-07-29
2018-08-11
2018-08-24
2018-09-06
2018-09-19
2018-10-02
2018-10-15
2018-10-28
2018-11-10
2018-11-23
2018-12-06

-- 
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: Select filled with years

2017-04-18 Thread Dave S


On Tuesday, April 18, 2017 at 2:23:14 AM UTC-7, Juan Carlos Quesada wrote:
>
> def getyears(anyo): 
> from datetime import datetime, date
> option = []
> option.append(OPTION(T('Año'), _value=''))
> year = datetime.today().year
> ryear = range(2015, int(year+1))
> for r in ryear:
> if anyo == r:
> selected = True
> else:
> selected = None
> option.append(OPTION(r, _value=r, _selected=selected))
> return SELECT(*option, _name='anyo', _id='anyo', _class="form-control 
> input-md")
>
>
>
Doesn't this duplicate a lof of IS_IN_SET() and SQLFORM() ? 

/dps

El domingo, 16 de abril de 2017, 23:07:08 (UTC+2), Winter Kryz escribió:
>>
>> Hello everybody,
>>
>> I have a table like this
>>
>> db.define_table('Report',
>> Field('person', 'reference Person'),
>> Field('year', 'integer'),
>> Field('letter', 'string'),
>>)
>>
>> and I use SQLFORM to create a form with that table
>>
>> form=SQLFORM(db.Report)
>>
>> I want to know if instead a 'year' field where I have to write the year, 
>> I can fill a select with years from 1989 to 2017 so the user can pick one 
>> from that list. I don't know how to do that because I'm using a sqlform. 
>>
>> Any ideas would be appreciate.
>>
>> 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: list of dates into database

2017-04-18 Thread Dave S


On Tuesday, April 18, 2017 at 12:02:28 PM UTC-7, R U wrote:
>
> I am trying to insert many dates into a field.  Currently I am only 
> getting 1 date inserted.
> my overall goal is to insert many (semi random) dates into the database; 
> each user will have his/her own unique list.  Then later iterate over the 
> list having the date trigger some event if it equals today's date.
>
> controller:
> from datetime import date, datetime, timedelta
> import random
> from random import randint
> dog = randint(3,25)
> def perdelta(start, end, delta):
> curr = start
> while curr < end:
> yield curr
> curr += delta
>
> for result in perdelta(date(2017, 11, 11), date(2018, 12, 12), 
> timedelta(days=dog)):
> print str(result)
> 
> fun.zipdip.insert(infom=result)
>
> model: 
> fun = DAL('sqlite://storage.sqlite')
> fun.define_table('zipdip',
> Field('infom')),
>
> result in dal is: 
> 3 selected
> zipdip.id 
> 
> zipdip.infom 
> 
> 1  
> 2018-11-30
> 2  
> 2018-12-07
> 3  
> 2018-11-30
>
>

If your indentation is as shown above, I'm surprised you get 3, because it 
looks like you're only inserting the last one.

/dps
 

> but if the code is run for example in repl.it the result is the outcome I 
> am looking for
>
> 2017-11-11
> 2017-11-24
> 2017-12-07
> 2017-12-20
> 2018-01-02
> 2018-01-15
> 2018-01-28
> 2018-02-10
> 2018-02-23
> 2018-03-08
> 2018-03-21
> 2018-04-03
> 2018-04-16
> 2018-04-29
> 2018-05-12
> 2018-05-25
> 2018-06-07
> 2018-06-20
> 2018-07-03
> 2018-07-16
> 2018-07-29
> 2018-08-11
> 2018-08-24
> 2018-09-06
> 2018-09-19
> 2018-10-02
> 2018-10-15
> 2018-10-28
> 2018-11-10
> 2018-11-23
> 2018-12-06
>
>

-- 
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: delete record confirmation dialog

2017-04-18 Thread Paolo Valleri
At the moment is not possible to change it directly in grid or smartgrid.
This is because the javascript variable is fixed, assigned 
in 
https://github.com/web2py/web2py/blob/master/applications/welcome/views/web2py_ajax.html
and then used 
in 
https://github.com/web2py/web2py/blob/master/applications/welcome/static/js/web2py.js#L186

Depending on your use case you can either translate the sentence defined in 
web2py_ajax.html or add your custom logic in order to change the content of 
the w2p_ajax_confirm_message javascript variable.

Paolo

On Tuesday, April 18, 2017 at 6:00:21 PM UTC+2, Andrea Fae' wrote:
>
> How to change customized message in the confirmation dialog about delete a 
> record using grid or smartgrid? (depending on the situation)
> Any examples?
>
>
>

-- 
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: Removing item from list:Reference

2017-04-18 Thread Anthony
list:-type fields are a DAL abstraction (they are simply stored as 
pipe-delimited strings in the database), so it would be complicated to get 
the database to directly manipulate the contents of such fields. If you 
have the entire contents of the field, you can update the field without a 
select:

new_list = old_list.remove(some_id) # Somehow, you must already have 
old_list
db(db.company.id == company_id).update(projects=new_list)

Otherwise, you'll have to select and loop (though, note that you can select 
only the records that need to change):

rows = db(db.company.projects.contains(some_id)).select(db.company.id, db.
company.projects)
[r.update_record(projects=r.projects.remove(some_id)) for r in rows]

There are ways to do what you want via raw SQL (that would vary based on 
the RDBMS), but it may not be worth pursuing that optimization unless you 
find the above becomes a bottleneck in your application.

Anthony

On Tuesday, April 18, 2017 at 6:06:02 AM UTC-4, Sharjeel Ali Shaukat wrote:
>
> I have company table in which projects information is stored in 
> list:reference , now i want to remove the project id from company table 
> reference field without using loop , simple by DAL update query
>
> *Company Table*
> |  *id*  |  *name*  |  *projects*  |
> |  1   |  Com1  |  |1|2| |
>
> So after update my table should become
>
>
> *Company Table*
> |  *id*  |  *name*  |  *projects*  |
> |  1   |  Com1  |  |2| |
>
>
>
> I need to write a update query that will remove project id from list 
> reference without using select query and for loop first
> 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: update_or_insert only returns id if created not updated

2017-04-18 Thread Anthony
I think the reason is so you can determine whether an insert was done or 
not (otherwise there would be no way to distinguish). Anyway, it's a fairly 
simple function, so if you need the id of updated records, just write your 
own version.

Anthony

On Tuesday, April 18, 2017 at 6:58:22 AM UTC-4, Ramos wrote:
>
> why?
>
> https://github.com/web2py/pydal/blob/4b30558e7d75da152ac6a003991e9add1b68c235/pydal/objects.py#L795
>  
> 
>
> I could and need to use the id in case of update...
>
>
> 
>  Sem 
> vírus. www.avast.com 
> 
>  
> <#CAEM0BxPk8LJQyTpKvT5vkn4FBchbB1cMx=YGN=iwjW7Aw2cG4w@mail.gmail.com_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>

-- 
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: update_or_insert only returns id if created not updated

2017-04-18 Thread Paolo Valleri
It should work. Try to open an issue on https://github.com/web2py/pydal or 
a pull request with the necessary change
it could be something like, 

 new_id = record[self._id.name]

Paolo

On Tuesday, April 18, 2017 at 12:58:22 PM UTC+2, Ramos wrote:
>
> why?
>
> https://github.com/web2py/pydal/blob/4b30558e7d75da152ac6a003991e9add1b68c235/pydal/objects.py#L795
>
> I could and need to use the id in case of update...
>
>
> 
>  Sem 
> vírus. www.avast.com 
> 
>  
> <#CAEM0BxPk8LJQyTpKvT5vkn4FBchbB1cMx=YGN=iwjW7Aw2cG4w@mail.gmail.com_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>

-- 
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] decode/encode password

2017-04-18 Thread lucas
hello one and all,

what about this 
for https://groups.google.com/forum/#!topic/web2py/4eWj_BlGWjc and I 
started this new thread because I think it is different subject then the 
latter link.

what if I sent the password as straight text in the form?  meaning it is 
decoded from the database, sent to and from as straight text, displayed as 
straight text, and then encoded before it is stored back in the database. 
 see I am setting up managers for each firm in my model.  and a manager 
works at the firm and can insert and update new logins/users for only their 
own firm.  so I don't believe it is necessary for the managers to see the 
 for the password.  the managers are allowed to change the passwords of 
the other users.

if you think is really a terrible idea for security reasons, please let me 
know and why.

if you think it is fine to setup managers with this level of control, then 
please tell me how to decode and encode the passwords under web2py.

thank you and sincerely, Lucas

-- 
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: Using validate_and_insert with a computed field

2017-04-18 Thread Christopher L
Thanks for the info Anthony! I'll try one of those approaches.

Why is validation run before compute?

On Apr 18, 2017 2:50 PM, "Anthony"  wrote:

You should not set "requires" on a computed field -- when you use
validate_and_insert, the validation will be run before the computed value
is generated. However, you can instead set required=True. In that case, any
time you do an insert or update, if the fields needed by the computed field
are missing, the computed field will trigger an exception (you'll have to
catch the exception). Alternatively, you could add IS_NOT_EMPTY validators
to the fields that are needed by the computed field -- as long as those
fields are not empty, neither will the computed field be.

Anthony

On Tuesday, April 18, 2017 at 10:35:06 AM UTC-4, Alfonso Serra wrote:
>
> As per the docs, they say they are stored in db on insert but not computed
> on retrieval. i guess this applies to updates.
> Does this calculate_field function does not return a value in some case?
> for example total = unit * price may be None if the operation fails because
> either unit or price is None or the function does not return any value.
>
>
>
> --
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/Kqfg-MG5K44/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.


Re: [web2py] Re: web2py and python3

2017-04-18 Thread JorgeH
Please consider adding support for GraphQL, if I may suggest

On Sunday, April 16, 2017 at 9:51:11 AM UTC-5, Massimo Di Pierro wrote:
>
> The main goal is to make it as close as possible to web2py but faster, 
> allow more flexibility and move more logic client-size. It will be smaller 
> than web2py.
>
> admin will look different but have similar functionality.
> the request/response objects will be the bottlepy ones. 
> dal & templates are the same as in web2py, therefore most of the logic 
> will be similar.
> routing will be done with decorators like bottlepy and flask.
> scaffolding app will promote single page apps with vue.js and auth0 
> instead of native template system.
> nothing (except apps themselves) will be store on filesystem because we 
> found that to be a scalability bottleneck.
> thinking about integrating websockets ot http push notification or 
> integration...
> the folder structure will be similar to web2py's (applications, 
> applications/databases, etc) but it will use import not execfile and will 
> give more flexibility to organize individual apps internally.
> apps will be able to import each other modules and models.
>
>

-- 
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: decode/encode password

2017-04-18 Thread Dave S


On Tuesday, April 18, 2017 at 2:19:30 PM UTC-7, lucas wrote:
>
> hello one and all,
>
> what about this for 
> https://groups.google.com/forum/#!topic/web2py/4eWj_BlGWjc and I started 
> this new thread because I think it is different subject then the latter 
> link.
>
> what if I sent the password as straight text in the form?  meaning it is 
> decoded from the database, sent to and from as straight text, displayed as 
> straight text, and then encoded before it is stored back in the database. 
>  see I am setting up managers for each firm in my model.  and a manager 
> works at the firm and can insert and update new logins/users for only their 
> own firm.  so I don't believe it is necessary for the managers to see the 
>  for the password.  the managers are allowed to change the passwords of 
> the other users.
>
> if you think is really a terrible idea for security reasons, please let me 
> know and why.
>
> if you think it is fine to setup managers with this level of control, then 
> please tell me how to decode and encode the passwords under web2py.
>
>
most password reset schemes only allow managers (or helpdeskians) to force 
a new password.  In some schemes, they don't know what the new password is, 
just that a new one has been forced (temporary passwords can be random, and 
are often cut-and-pasted by the email recipient).  

This  (manager blindness) is good for users because users have a tendency  
to reuse passwords.  It's one thing for a manager to know what the 
temporary password is when it may expire in hours and won't work on other 
sign-ins the user does, it's another thing for them to see that Joe always 
uses NCC-1701.

Furthermore, the encryption functions web2py uses are essentially one-way.  
There is no easy way to decrypt.  web2py, during logins, only encrypts the 
submitted password and then compares encrypted versions.  Of course, if you 
have a spare GPU around, you can try brute-force attacks.

/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] Re: update_or_insert only returns id if created not updated

2017-04-18 Thread Anthony
On Tuesday, April 18, 2017 at 3:33:31 PM UTC-4, Paolo Valleri wrote:
>
> It should work. Try to open an issue on https://github.com/web2py/pydal 
> or a pull request with the necessary change
> it could be something like, 
>
>  new_id = record[self._id.name]
>

We can't do that, as it would break backward compatibility. I suppose you 
could add an option or create an alternative method.

Anthony
 

-- 
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: Using validate_and_insert with a computed field

2017-04-18 Thread Anthony
On Tuesday, April 18, 2017 at 5:41:38 PM UTC-4, Chris wrote:
>
> Thanks for the info Anthony! I'll try one of those approaches.
>
> Why is validation run before compute?
>

In terms of implementation, compute is handled in the .insert() method, 
which must necessarily run after validation. I suppose we could add code to 
calculate computed values before validation in the .validate_and_ methods, 
but I don't think that really makes sense. Computed fields should not need 
to be validated, as they are in control of generating their own values. You 
should instead validate the inputs to the computed field.

Anthony

-- 
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: table already exists; 'Rows' object has no attribute 'fields'

2017-04-18 Thread pbreit
models were in the regular models.py file

On Monday, April 17, 2017 at 4:18:26 PM UTC-7, Dave S wrote:
>
>
>
> On Monday, April 17, 2017 at 3:58:38 PM UTC-7, pbreit wrote:
>>
>> Sqlite. These are fresh installs with just a table defined and no other 
>> edits.
>>
>> I've noticed that I can get it to work if I quickcreate the new app, call 
>> it up in a browser so the initial tables get created, add my own models and 
>> the call it up again.
>>
>
> What did you name your model files?
>
> /dps
>  
>
>>
>>
>> On Monday, April 17, 2017 at 1:29:09 PM UTC-7, Dave S wrote:
>>>
>>> On Sunday, April 16, 2017 at 12:31:04 AM UTC-7, pbreit wrote:

 I'm a long time web2py user running into some problems I haven't seen 
 before and cannot resolve.

 First, I am getting this error a lot even when I create a brand new 
 project from scratch:

 OperationalError: table "auth_user" already exists


 Another error I am getting consistently is:

 AttributeError: 'Rows' object has no attribute 'fields'


>>>
>>> What database?  What does your connection string look like?
>>>  
>>>
 All I am doing is going to /appadmin and trying to view a simple table:

 http://127.0.0.1:8000/payouts/appadmin/select/db?query=db.contact.id>0


 db.define_table('contact',
 Field('user_id', 'reference auth_user', default=auth.user_id),
 Field('name'),
 Field('address'),
 Field('city'),
 Field('province'),
 Field('zip'),
 Field('country'),
 Field('status', default='new'),
 Field('tax_id'),
 Field('phone'),
 Field('entity'),
 Field('business_type'),
 Field('bank_name'),
 Field('bank_id'),
 Field('bank_account_id'),
 Field('bank_currency'),
 auth.signature)



>>>
>>> /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] list of dates into database

2017-04-18 Thread Marlysson Silva
You already tried populate method in built in contribuiu methods?

The populate function do that to some table of system , it generate some fake 
data in some large dataset .. Example

populate(db.mytable, 20)

The lib use the bayesian classifier to generate data based in type of field..

-- 
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: table already exists; 'Rows' object has no attribute 'fields'

2017-04-18 Thread Wabbajack

Similar problem here i have downloaded the latest version.
enable username = true
add 1 user thru the webapp

then go appadmin click db.auth_user [to view my newly created user]
then the error occurs  'Rows' object has 
no attribute 'fields'

Also i view the database and confirmed that it already added 1 user also 
update the group, event, membership table


-- 
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: Removing item from list:Reference

2017-04-18 Thread Sharjeel Ali Shaukat

Thanks ! how  it will response  when i used it in put service of web2py

-- 
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: table already exists; 'Rows' object has no attribute 'fields'

2017-04-18 Thread Dave S


On Tuesday, April 18, 2017 at 7:54:32 PM UTC-7, Wabbajack wrote:
>
>
> Similar problem here i have downloaded the latest version.
>

Windows?  Source?  Packaged or GitHub?

 

> enable username = true
> add 1 user thru the webapp
>
> then go appadmin click db.auth_user [to view my newly created user]
> then the error occurs  'Rows' object 
> has no attribute 'fields'
>
> Also i view the database and confirmed that it already added 1 user also 
> update the group, event, membership table
>
>
Are you also using sqlite?
 

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