Re: [web2py] Re: auth.signature not working

2021-02-15 Thread António Ramos
I didnt because the problem was not in that table.
I was looking to the wrong table.
Thk u

Kevin Keller  escreveu em seg., 15/02/2021 às 18:58 :

> How did you solve it?
>
> On Mon, Feb 15, 2021, 17:33 António Ramos  wrote:
>
>> Thank you Jim but i found the problem.
>> My fault this time.
>> Thank you again.
>>
>> PS. Its just me or this forum is abandoned? Should i go elsewhere for
>> help ?
>>
>> Em seg., 15 de fev. de 2021 às 15:46, António Ramos 
>> escreveu:
>>
>>> Hi Jim
>>> Sorry but dont understand your suggestion.
>>> You mean auth.requires_login() on my restful function like this
>>> @auth.requires_login() ?
>>> @request.restful()
>>> def uploadInvoice():
>>> Does it make sense? Its going to be called by external script.
>>> Inside my  uploadInvoice i have
>>> user = auth.login_bare("myuser", "pwd") and i can check that it returns
>>> the myuser ID. so before inserting a record it should know who the user is.
>>>
>>> I also have this code that i suspect that could get auth.signature in
>>> trouble.
>>> Please comment .
>>>
>>>
>>> db.entities._after_update.append(lambda s, f
>>> : wfFields().update_readers(db, 'entities', s, f))
>>> db.entities._after_update.append(lambda s, f
>>> : wfFields().update_authors(db, 'entities', s, f))
>>> db.entities._after_update.append(lambda s, f: extrafields_sync(s, f))
>>> db.entities._after_insert.append(lambda f, id: extrafields_sync(db(
>>> db.entities.id==id), f))
>>>
>>> Em seg., 15 de fev. de 2021 às 15:33, Jim S 
>>> escreveu:
>>>
 Have you tried with an auth decorator?  Maybe auth.requires_login()?

 -Jim

 On Saturday, February 13, 2021 at 3:33:01 PM UTC-6 Ramos wrote:

> Anybody here?
>
> Em sex., 12 de fev. de 2021 às 23:57, António Ramos <
> ramst...@gmail.com> escreveu:
>
>> hello this is my model
>> db.define_table(
>> 'entities',
>> Field('uuid', length=64, default=lambda: str(uuid.uuid4())),
>> Field('entity', 'string',length=70,required=True, label=T(
>> "Entity")),
>> Field('description', length=100,label=T("Description"), default=
>> ""),
>> Field('status', db.status),
>> Field('type', 'reference dbentities', label=T("Type")),
>> Field('sub_type', "reference subtypes", label=T("Type")),
>> Field('event','string',length=10),
>> Field('trailevent', 'list:integer'),
>> Field("last_error", default=""),
>> Field('extrareaders', 'list:reference auth_user'),
>> Field('extrafield', db.extrafields, requires=IS_EMPTY_OR(
>> IS_IN_DB(db, 'extrafields.id', '%(extrafield)s'))),
>> Field('relatedto', 'reference entities', requires=IS_EMPTY_OR(
>> IS_IN_DB(db, 'entities.id', '%(entity)s'))),
>> Field('file', 'upload', label="Ficheiro"),
>> Field('valstart', 'date', label="Válido de",
>>   default=datetime.datetime.utcnow()),
>> Field('valend', 'date', label="Válido até",
>>   default=datetime.datetime.utcnow()),
>> Field('orderedat', 'float'),
>> Field('question','string'),
>> Field('qt','double'),
>> Field('units','string',length=5),
>> Field('readers', 'list:string', default=[""]),#friend uuid
>> Field('details','json'),
>> auth.signature,
>> format='%(type)s %(entity)s',
>> )
>>
>>
>> I have auth.signature but  this code
>>
>> @request.restful()
>> def uploadInvoice():
>> import random
>> import string
>> response.view = 'generic.json'
>>
>> def POST(*args, **kw):
>> try:
>> user = auth.login_bare("userxxx", "") # so it has a
>> user
>> uploaded_file = kw['file']
>> filename =
>>  db.entities.file.store(uploaded_file, uploaded_file.filename)
>> id = db.entities.insert(
>> entity="Invoice",
>> type=db.dbentities(entity="Invoice")["id"],
>> status=DBTools().setStatus(db,"Draft", "Invoice"),
>> file=filename,
>> created_by=4, # even with this line it saves as None
>> modified_by=4, # even with this line it saves as None
>> description="")
>> if id:
>> eventid = db.events.insert(
>> event="Invoice", relatedto=id,  type=
>> "Document added", receipts={},linktodoc=id
>> )
>> db.entities[id]=dict(event=eventid)
>> return "ok"
>>
>> except Exception as e:
>> raise Exception('Error on line {}{}{}'.format(
>> sys.exc_info()[-1].tb_lineno, str(e), request.vars))
>> return locals()
>>
>> does not fills the created_by and modified_by field. They have None
>>
>> Any help ???
>> Regards

Re: [web2py] Re: auth.signature not working

2021-02-15 Thread Kevin Keller
How did you solve it?

On Mon, Feb 15, 2021, 17:33 António Ramos  wrote:

> Thank you Jim but i found the problem.
> My fault this time.
> Thank you again.
>
> PS. Its just me or this forum is abandoned? Should i go elsewhere for help
> ?
>
> Em seg., 15 de fev. de 2021 às 15:46, António Ramos 
> escreveu:
>
>> Hi Jim
>> Sorry but dont understand your suggestion.
>> You mean auth.requires_login() on my restful function like this
>> @auth.requires_login() ?
>> @request.restful()
>> def uploadInvoice():
>> Does it make sense? Its going to be called by external script.
>> Inside my  uploadInvoice i have
>> user = auth.login_bare("myuser", "pwd") and i can check that it returns
>> the myuser ID. so before inserting a record it should know who the user is.
>>
>> I also have this code that i suspect that could get auth.signature in
>> trouble.
>> Please comment .
>>
>>
>> db.entities._after_update.append(lambda s, f
>> : wfFields().update_readers(db, 'entities', s, f))
>> db.entities._after_update.append(lambda s, f
>> : wfFields().update_authors(db, 'entities', s, f))
>> db.entities._after_update.append(lambda s, f: extrafields_sync(s, f))
>> db.entities._after_insert.append(lambda f, id: extrafields_sync(db(
>> db.entities.id==id), f))
>>
>> Em seg., 15 de fev. de 2021 às 15:33, Jim S 
>> escreveu:
>>
>>> Have you tried with an auth decorator?  Maybe auth.requires_login()?
>>>
>>> -Jim
>>>
>>> On Saturday, February 13, 2021 at 3:33:01 PM UTC-6 Ramos wrote:
>>>
 Anybody here?

 Em sex., 12 de fev. de 2021 às 23:57, António Ramos 
 escreveu:

> hello this is my model
> db.define_table(
> 'entities',
> Field('uuid', length=64, default=lambda: str(uuid.uuid4())),
> Field('entity', 'string',length=70,required=True, label=T("Entity"
> )),
> Field('description', length=100,label=T("Description"), default=""
> ),
> Field('status', db.status),
> Field('type', 'reference dbentities', label=T("Type")),
> Field('sub_type', "reference subtypes", label=T("Type")),
> Field('event','string',length=10),
> Field('trailevent', 'list:integer'),
> Field("last_error", default=""),
> Field('extrareaders', 'list:reference auth_user'),
> Field('extrafield', db.extrafields, requires=IS_EMPTY_OR(
> IS_IN_DB(db, 'extrafields.id', '%(extrafield)s'))),
> Field('relatedto', 'reference entities', requires=IS_EMPTY_OR(
> IS_IN_DB(db, 'entities.id', '%(entity)s'))),
> Field('file', 'upload', label="Ficheiro"),
> Field('valstart', 'date', label="Válido de",
>   default=datetime.datetime.utcnow()),
> Field('valend', 'date', label="Válido até",
>   default=datetime.datetime.utcnow()),
> Field('orderedat', 'float'),
> Field('question','string'),
> Field('qt','double'),
> Field('units','string',length=5),
> Field('readers', 'list:string', default=[""]),#friend uuid
> Field('details','json'),
> auth.signature,
> format='%(type)s %(entity)s',
> )
>
>
> I have auth.signature but  this code
>
> @request.restful()
> def uploadInvoice():
> import random
> import string
> response.view = 'generic.json'
>
> def POST(*args, **kw):
> try:
> user = auth.login_bare("userxxx", "") # so it has a
> user
> uploaded_file = kw['file']
> filename =
>  db.entities.file.store(uploaded_file, uploaded_file.filename)
> id = db.entities.insert(
> entity="Invoice",
> type=db.dbentities(entity="Invoice")["id"],
> status=DBTools().setStatus(db,"Draft", "Invoice"),
> file=filename,
> created_by=4, # even with this line it saves as None
> modified_by=4, # even with this line it saves as None
> description="")
> if id:
> eventid = db.events.insert(
> event="Invoice", relatedto=id,  type=
> "Document added", receipts={},linktodoc=id
> )
> db.entities[id]=dict(event=eventid)
> return "ok"
>
> except Exception as e:
> raise Exception('Error on line {}{}{}'.format(
> sys.exc_info()[-1].tb_lineno, str(e), request.vars))
> return locals()
>
> does not fills the created_by and modified_by field. They have None
>
> Any help ???
> 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

Re: [web2py] Re: auth.signature not working

2021-02-15 Thread António Ramos
Once again thank you Jim for your patience :)
Regards from Portugal

António

Em seg., 15 de fev. de 2021 às 16:59, Jim S  escreveu:

> No, this forum has not been abandoned.  I think the issue may be that most
> of us are now spending a much greater amount of time with py4web.  That,
> and in my case anyway, I shied away from this question because I haven't
> used web2py in a restful manner before so wasn't sure I had anything to
> offer.
>
> -Jim
>
> On Monday, February 15, 2021 at 10:33:12 AM UTC-6 Ramos wrote:
>
>> Thank you Jim but i found the problem.
>> My fault this time.
>> Thank you again.
>>
>> PS. Its just me or this forum is abandoned? Should i go elsewhere for
>> help ?
>>
>> Em seg., 15 de fev. de 2021 às 15:46, António Ramos 
>> escreveu:
>>
>>> Hi Jim
>>> Sorry but dont understand your suggestion.
>>> You mean auth.requires_login() on my restful function like this
>>> @auth.requires_login() ?
>>> @request.restful()
>>> def uploadInvoice():
>>> Does it make sense? Its going to be called by external script.
>>> Inside my  uploadInvoice i have
>>> user = auth.login_bare("myuser", "pwd") and i can check that it returns
>>> the myuser ID. so before inserting a record it should know who the user is.
>>>
>>> I also have this code that i suspect that could get auth.signature in
>>> trouble.
>>> Please comment .
>>>
>>>
>>> db.entities._after_update.append(lambda s, f
>>> : wfFields().update_readers(db, 'entities', s, f))
>>> db.entities._after_update.append(lambda s, f
>>> : wfFields().update_authors(db, 'entities', s, f))
>>> db.entities._after_update.append(lambda s, f: extrafields_sync(s, f))
>>> db.entities._after_insert.append(lambda f, id: extrafields_sync(db(
>>> db.entities.id==id), f))
>>>
>>> Em seg., 15 de fev. de 2021 às 15:33, Jim S 
>>> escreveu:
>>>
 Have you tried with an auth decorator?  Maybe auth.requires_login()?

 -Jim

 On Saturday, February 13, 2021 at 3:33:01 PM UTC-6 Ramos wrote:

> Anybody here?
>
> Em sex., 12 de fev. de 2021 às 23:57, António Ramos <
> ramst...@gmail.com> escreveu:
>
>> hello this is my model
>> db.define_table(
>> 'entities',
>> Field('uuid', length=64, default=lambda: str(uuid.uuid4())),
>> Field('entity', 'string',length=70,required=True, label=T(
>> "Entity")),
>> Field('description', length=100,label=T("Description"), default=
>> ""),
>> Field('status', db.status),
>> Field('type', 'reference dbentities', label=T("Type")),
>> Field('sub_type', "reference subtypes", label=T("Type")),
>> Field('event','string',length=10),
>> Field('trailevent', 'list:integer'),
>> Field("last_error", default=""),
>> Field('extrareaders', 'list:reference auth_user'),
>> Field('extrafield', db.extrafields, requires=IS_EMPTY_OR(
>> IS_IN_DB(db, 'extrafields.id', '%(extrafield)s'))),
>> Field('relatedto', 'reference entities', requires=IS_EMPTY_OR(
>> IS_IN_DB(db, 'entities.id', '%(entity)s'))),
>> Field('file', 'upload', label="Ficheiro"),
>> Field('valstart', 'date', label="Válido de",
>>   default=datetime.datetime.utcnow()),
>> Field('valend', 'date', label="Válido até",
>>   default=datetime.datetime.utcnow()),
>> Field('orderedat', 'float'),
>> Field('question','string'),
>> Field('qt','double'),
>> Field('units','string',length=5),
>> Field('readers', 'list:string', default=[""]),#friend uuid
>> Field('details','json'),
>> auth.signature,
>> format='%(type)s %(entity)s',
>> )
>>
>>
>> I have auth.signature but  this code
>>
>> @request.restful()
>> def uploadInvoice():
>> import random
>> import string
>> response.view = 'generic.json'
>>
>> def POST(*args, **kw):
>> try:
>> user = auth.login_bare("userxxx", "") # so it has a
>> user
>> uploaded_file = kw['file']
>> filename =
>>  db.entities.file.store(uploaded_file, uploaded_file.filename)
>> id = db.entities.insert(
>> entity="Invoice",
>> type=db.dbentities(entity="Invoice")["id"],
>> status=DBTools().setStatus(db,"Draft", "Invoice"),
>> file=filename,
>> created_by=4, # even with this line it saves as None
>> modified_by=4, # even with this line it saves as None
>> description="")
>> if id:
>> eventid = db.events.insert(
>> event="Invoice", relatedto=id,  type=
>> "Document added", receipts={},linktodoc=id
>> )
>> db.entities[id]=dict(event=eventid)
>> return "ok"
>>
>> except Exception as 

Re: [web2py] Re: auth.signature not working

2021-02-15 Thread Jim S
No, this forum has not been abandoned.  I think the issue may be that most 
of us are now spending a much greater amount of time with py4web.  That, 
and in my case anyway, I shied away from this question because I haven't 
used web2py in a restful manner before so wasn't sure I had anything to 
offer.

-Jim

On Monday, February 15, 2021 at 10:33:12 AM UTC-6 Ramos wrote:

> Thank you Jim but i found the problem.
> My fault this time.
> Thank you again.
>
> PS. Its just me or this forum is abandoned? Should i go elsewhere for help 
> ?
>
> Em seg., 15 de fev. de 2021 às 15:46, António Ramos  
> escreveu:
>
>> Hi Jim
>> Sorry but dont understand your suggestion.
>> You mean auth.requires_login() on my restful function like this 
>> @auth.requires_login() ?
>> @request.restful()
>> def uploadInvoice():
>> Does it make sense? Its going to be called by external script. 
>> Inside my  uploadInvoice i have 
>> user = auth.login_bare("myuser", "pwd") and i can check that it returns 
>> the myuser ID. so before inserting a record it should know who the user is.
>>
>> I also have this code that i suspect that could get auth.signature in 
>> trouble. 
>> Please comment .
>>  
>>
>> db.entities._after_update.append(lambda s, f
>> : wfFields().update_readers(db, 'entities', s, f))
>> db.entities._after_update.append(lambda s, f
>> : wfFields().update_authors(db, 'entities', s, f))
>> db.entities._after_update.append(lambda s, f: extrafields_sync(s, f))
>> db.entities._after_insert.append(lambda f, id: extrafields_sync(db(
>> db.entities.id==id), f))
>>
>> Em seg., 15 de fev. de 2021 às 15:33, Jim S  escreveu:
>>
>>> Have you tried with an auth decorator?  Maybe auth.requires_login()?
>>>
>>> -Jim
>>>
>>> On Saturday, February 13, 2021 at 3:33:01 PM UTC-6 Ramos wrote:
>>>
 Anybody here?

 Em sex., 12 de fev. de 2021 às 23:57, António Ramos  
 escreveu:

> hello this is my model
> db.define_table(
> 'entities',
> Field('uuid', length=64, default=lambda: str(uuid.uuid4())),
> Field('entity', 'string',length=70,required=True, label=T("Entity"
> )),
> Field('description', length=100,label=T("Description"), default=""
> ),
> Field('status', db.status),
> Field('type', 'reference dbentities', label=T("Type")),
> Field('sub_type', "reference subtypes", label=T("Type")),
> Field('event','string',length=10),
> Field('trailevent', 'list:integer'),
> Field("last_error", default=""),
> Field('extrareaders', 'list:reference auth_user'),
> Field('extrafield', db.extrafields, requires=IS_EMPTY_OR(
> IS_IN_DB(db, 'extrafields.id', '%(extrafield)s'))),
> Field('relatedto', 'reference entities', requires=IS_EMPTY_OR(
> IS_IN_DB(db, 'entities.id', '%(entity)s'))),
> Field('file', 'upload', label="Ficheiro"),
> Field('valstart', 'date', label="Válido de",
>   default=datetime.datetime.utcnow()),
> Field('valend', 'date', label="Válido até",
>   default=datetime.datetime.utcnow()),
> Field('orderedat', 'float'),
> Field('question','string'),
> Field('qt','double'),
> Field('units','string',length=5),
> Field('readers', 'list:string', default=[""]),#friend uuid
> Field('details','json'),
> auth.signature,
> format='%(type)s %(entity)s',
> )
>
>
> I have auth.signature but  this code
>
> @request.restful()
> def uploadInvoice():
> import random
> import string
> response.view = 'generic.json'
>
> def POST(*args, **kw):
> try:
> user = auth.login_bare("userxxx", "") # so it has a 
> user
> uploaded_file = kw['file']
> filename =
>  db.entities.file.store(uploaded_file, uploaded_file.filename)
> id = db.entities.insert(
> entity="Invoice",
> type=db.dbentities(entity="Invoice")["id"],
> status=DBTools().setStatus(db,"Draft", "Invoice"),
> file=filename,
> created_by=4, # even with this line it saves as None
> modified_by=4, # even with this line it saves as None
> description="")
> if id:
> eventid = db.events.insert(
> event="Invoice", relatedto=id,  type=
> "Document added", receipts={},linktodoc=id
> )
> db.entities[id]=dict(event=eventid)
> return "ok"
>
> except Exception as e:
> raise Exception('Error on line {}{}{}'.format(
> sys.exc_info()[-1].tb_lineno, str(e), request.vars))
> return locals()
>
> does not fills the created_by and modified_by field. They have None 
>
> Any help ???

Re: [web2py] Re: auth.signature not working

2021-02-15 Thread António Ramos
Thank you Jim but i found the problem.
My fault this time.
Thank you again.

PS. Its just me or this forum is abandoned? Should i go elsewhere for help ?

Em seg., 15 de fev. de 2021 às 15:46, António Ramos 
escreveu:

> Hi Jim
> Sorry but dont understand your suggestion.
> You mean auth.requires_login() on my restful function like this
> @auth.requires_login() ?
> @request.restful()
> def uploadInvoice():
> Does it make sense? Its going to be called by external script.
> Inside my  uploadInvoice i have
> user = auth.login_bare("myuser", "pwd") and i can check that it returns
> the myuser ID. so before inserting a record it should know who the user is.
>
> I also have this code that i suspect that could get auth.signature in
> trouble.
> Please comment .
>
>
> db.entities._after_update.append(lambda s, f
> : wfFields().update_readers(db, 'entities', s, f))
> db.entities._after_update.append(lambda s, f
> : wfFields().update_authors(db, 'entities', s, f))
> db.entities._after_update.append(lambda s, f: extrafields_sync(s, f))
> db.entities._after_insert.append(lambda f, id: extrafields_sync(db(
> db.entities.id==id), f))
>
> Em seg., 15 de fev. de 2021 às 15:33, Jim S 
> escreveu:
>
>> Have you tried with an auth decorator?  Maybe auth.requires_login()?
>>
>> -Jim
>>
>> On Saturday, February 13, 2021 at 3:33:01 PM UTC-6 Ramos wrote:
>>
>>> Anybody here?
>>>
>>> Em sex., 12 de fev. de 2021 às 23:57, António Ramos 
>>> escreveu:
>>>
 hello this is my model
 db.define_table(
 'entities',
 Field('uuid', length=64, default=lambda: str(uuid.uuid4())),
 Field('entity', 'string',length=70,required=True, label=T("Entity"
 )),
 Field('description', length=100,label=T("Description"), default=""
 ),
 Field('status', db.status),
 Field('type', 'reference dbentities', label=T("Type")),
 Field('sub_type', "reference subtypes", label=T("Type")),
 Field('event','string',length=10),
 Field('trailevent', 'list:integer'),
 Field("last_error", default=""),
 Field('extrareaders', 'list:reference auth_user'),
 Field('extrafield', db.extrafields, requires=IS_EMPTY_OR(
 IS_IN_DB(db, 'extrafields.id', '%(extrafield)s'))),
 Field('relatedto', 'reference entities', requires=IS_EMPTY_OR(
 IS_IN_DB(db, 'entities.id', '%(entity)s'))),
 Field('file', 'upload', label="Ficheiro"),
 Field('valstart', 'date', label="Válido de",
   default=datetime.datetime.utcnow()),
 Field('valend', 'date', label="Válido até",
   default=datetime.datetime.utcnow()),
 Field('orderedat', 'float'),
 Field('question','string'),
 Field('qt','double'),
 Field('units','string',length=5),
 Field('readers', 'list:string', default=[""]),#friend uuid
 Field('details','json'),
 auth.signature,
 format='%(type)s %(entity)s',
 )


 I have auth.signature but  this code

 @request.restful()
 def uploadInvoice():
 import random
 import string
 response.view = 'generic.json'

 def POST(*args, **kw):
 try:
 user = auth.login_bare("userxxx", "") # so it has a
 user
 uploaded_file = kw['file']
 filename =
  db.entities.file.store(uploaded_file, uploaded_file.filename)
 id = db.entities.insert(
 entity="Invoice",
 type=db.dbentities(entity="Invoice")["id"],
 status=DBTools().setStatus(db,"Draft", "Invoice"),
 file=filename,
 created_by=4, # even with this line it saves as None
 modified_by=4, # even with this line it saves as None
 description="")
 if id:
 eventid = db.events.insert(
 event="Invoice", relatedto=id,  type=
 "Document added", receipts={},linktodoc=id
 )
 db.entities[id]=dict(event=eventid)
 return "ok"

 except Exception as e:
 raise Exception('Error on line {}{}{}'.format(
 sys.exc_info()[-1].tb_lineno, str(e), request.vars))
 return locals()

 does not fills the created_by and modified_by field. They have None

 Any help ???
 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.
>> To view this discussion on the web visit
>> 

Re: [web2py] Re: Programatically create Row

2021-02-15 Thread Jacinto Parga
So, do you want to storage a dummy row to be proccessed in the same 
controler or to be passed to another controller or function?. I mean, if 
you want to use it in the same controller why not a local variable to 
storage it.. 

If you have used a SQLFORM. factory to get the values they are storaged in 
form.vars object.

What do you mean with a dummy row? Is it like a structure of a db row? 

El sábado, 13 de febrero de 2021 a las 17:45:09 UTC+1, david...@gmail.com 
escribió:

> Thanks for the suggestion. I don't need to create the form 
> programmatically - the factory is great for that. I've already got code to 
> create the form but want to create a dummy row on the server side to 
> populate a display example form. 
>
> Cheers, 
> David
>
> On Sat, 13 Feb 2021, 08:37 Jacinto Parga,  wrote:
>
>>
>> http://www.web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM-factory
>>
>> El viernes, 12 de febrero de 2021 a las 18:26:42 UTC+1, 
>> david...@gmail.com escribió:
>>
>>> I have a controller that displays confidential data from a table but 
>>> want to be able to show the form publicly with some dummy data. The 
>>> controller makes use of field representation and references so I basically 
>>> need a Row.
>>>
>>> I can create the object I need using the table.insert() methods and then 
>>> db.rollback() to avoid committing the dummy data but is there a better 
>>> method. I've had a look at the internals of Row and suspect that trying to 
>>> create a Row object by hand would be pretty fraught, but is there a better 
>>> way than just using insert() and rollback()? It feels like using a 
>>> sledgehammer to crack a nut.
>>>
>>> Cheers,
>>> David
>>>
>> -- 
>> 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/FSHPxYTxr24/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> web2py+un...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/web2py/5ce7ca44-d5d7-4854-96c9-99b78b14fcdcn%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/85137da9-e4a0-4fb0-9c7b-291fbb3c40a1n%40googlegroups.com.


Re: [web2py] Re: auth.signature not working

2021-02-15 Thread António Ramos
Hi Jim
Sorry but dont understand your suggestion.
You mean auth.requires_login() on my restful function like this
@auth.requires_login() ?
@request.restful()
def uploadInvoice():
Does it make sense? Its going to be called by external script.
Inside my  uploadInvoice i have
user = auth.login_bare("myuser", "pwd") and i can check that it returns the
myuser ID. so before inserting a record it should know who the user is.

I also have this code that i suspect that could get auth.signature in
trouble.
Please comment .


db.entities._after_update.append(lambda s, f: wfFields().update_readers(db,
'entities', s, f))
db.entities._after_update.append(lambda s, f: wfFields().update_authors(db,
'entities', s, f))
db.entities._after_update.append(lambda s, f: extrafields_sync(s, f))
db.entities._after_insert.append(lambda f, id: extrafields_sync(db(
db.entities.id==id), f))

Em seg., 15 de fev. de 2021 às 15:33, Jim S  escreveu:

> Have you tried with an auth decorator?  Maybe auth.requires_login()?
>
> -Jim
>
> On Saturday, February 13, 2021 at 3:33:01 PM UTC-6 Ramos wrote:
>
>> Anybody here?
>>
>> Em sex., 12 de fev. de 2021 às 23:57, António Ramos 
>> escreveu:
>>
>>> hello this is my model
>>> db.define_table(
>>> 'entities',
>>> Field('uuid', length=64, default=lambda: str(uuid.uuid4())),
>>> Field('entity', 'string',length=70,required=True, label=T("Entity"
>>> )),
>>> Field('description', length=100,label=T("Description"), default=""),
>>> Field('status', db.status),
>>> Field('type', 'reference dbentities', label=T("Type")),
>>> Field('sub_type', "reference subtypes", label=T("Type")),
>>> Field('event','string',length=10),
>>> Field('trailevent', 'list:integer'),
>>> Field("last_error", default=""),
>>> Field('extrareaders', 'list:reference auth_user'),
>>> Field('extrafield', db.extrafields, requires=IS_EMPTY_OR(
>>> IS_IN_DB(db, 'extrafields.id', '%(extrafield)s'))),
>>> Field('relatedto', 'reference entities', requires=IS_EMPTY_OR(
>>> IS_IN_DB(db, 'entities.id', '%(entity)s'))),
>>> Field('file', 'upload', label="Ficheiro"),
>>> Field('valstart', 'date', label="Válido de",
>>>   default=datetime.datetime.utcnow()),
>>> Field('valend', 'date', label="Válido até",
>>>   default=datetime.datetime.utcnow()),
>>> Field('orderedat', 'float'),
>>> Field('question','string'),
>>> Field('qt','double'),
>>> Field('units','string',length=5),
>>> Field('readers', 'list:string', default=[""]),#friend uuid
>>> Field('details','json'),
>>> auth.signature,
>>> format='%(type)s %(entity)s',
>>> )
>>>
>>>
>>> I have auth.signature but  this code
>>>
>>> @request.restful()
>>> def uploadInvoice():
>>> import random
>>> import string
>>> response.view = 'generic.json'
>>>
>>> def POST(*args, **kw):
>>> try:
>>> user = auth.login_bare("userxxx", "") # so it has a user
>>> uploaded_file = kw['file']
>>> filename =
>>>  db.entities.file.store(uploaded_file, uploaded_file.filename)
>>> id = db.entities.insert(
>>> entity="Invoice",
>>> type=db.dbentities(entity="Invoice")["id"],
>>> status=DBTools().setStatus(db,"Draft", "Invoice"),
>>> file=filename,
>>> created_by=4, # even with this line it saves as None
>>> modified_by=4, # even with this line it saves as None
>>> description="")
>>> if id:
>>> eventid = db.events.insert(
>>> event="Invoice", relatedto=id,  type=
>>> "Document added", receipts={},linktodoc=id
>>> )
>>> db.entities[id]=dict(event=eventid)
>>> return "ok"
>>>
>>> except Exception as e:
>>> raise Exception('Error on line {}{}{}'.format(
>>> sys.exc_info()[-1].tb_lineno, str(e), request.vars))
>>> return locals()
>>>
>>> does not fills the created_by and modified_by field. They have None
>>>
>>> Any help ???
>>> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/022388a0-7a1a-405a-93e2-86498f18e334n%40googlegroups.com
> 
> .
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- 

[web2py] Re: auth.signature not working

2021-02-15 Thread Jim S
Have you tried with an auth decorator?  Maybe auth.requires_login()?

-Jim

On Saturday, February 13, 2021 at 3:33:01 PM UTC-6 Ramos wrote:

> Anybody here?
>
> Em sex., 12 de fev. de 2021 às 23:57, António Ramos  
> escreveu:
>
>> hello this is my model
>> db.define_table(
>> 'entities',
>> Field('uuid', length=64, default=lambda: str(uuid.uuid4())),
>> Field('entity', 'string',length=70,required=True, label=T("Entity")),
>> Field('description', length=100,label=T("Description"), default=""),
>> Field('status', db.status),
>> Field('type', 'reference dbentities', label=T("Type")),
>> Field('sub_type', "reference subtypes", label=T("Type")),
>> Field('event','string',length=10),
>> Field('trailevent', 'list:integer'),
>> Field("last_error", default=""),
>> Field('extrareaders', 'list:reference auth_user'),
>> Field('extrafield', db.extrafields, requires=IS_EMPTY_OR(
>> IS_IN_DB(db, 'extrafields.id', '%(extrafield)s'))),
>> Field('relatedto', 'reference entities', requires=IS_EMPTY_OR(
>> IS_IN_DB(db, 'entities.id', '%(entity)s'))),
>> Field('file', 'upload', label="Ficheiro"),
>> Field('valstart', 'date', label="Válido de",
>>   default=datetime.datetime.utcnow()),
>> Field('valend', 'date', label="Válido até",
>>   default=datetime.datetime.utcnow()),
>> Field('orderedat', 'float'),
>> Field('question','string'),
>> Field('qt','double'),
>> Field('units','string',length=5),
>> Field('readers', 'list:string', default=[""]),#friend uuid
>> Field('details','json'),
>> auth.signature,
>> format='%(type)s %(entity)s',
>> )
>>
>>
>> I have auth.signature but  this code
>>
>> @request.restful()
>> def uploadInvoice():
>> import random
>> import string
>> response.view = 'generic.json'
>>
>> def POST(*args, **kw):
>> try:
>> user = auth.login_bare("userxxx", "") # so it has a user
>> uploaded_file = kw['file']
>> filename =
>>  db.entities.file.store(uploaded_file, uploaded_file.filename)
>> id = db.entities.insert(
>> entity="Invoice",
>> type=db.dbentities(entity="Invoice")["id"],
>> status=DBTools().setStatus(db,"Draft", "Invoice"),
>> file=filename,
>> created_by=4, # even with this line it saves as None
>> modified_by=4, # even with this line it saves as None
>> description="")
>> if id:
>> eventid = db.events.insert(
>> event="Invoice", relatedto=id,  type="Document added"
>> , receipts={},linktodoc=id
>> )
>> db.entities[id]=dict(event=eventid)
>> return "ok"
>>
>> except Exception as e:
>> raise Exception('Error on line {}{}{}'.format(
>> sys.exc_info()[-1].tb_lineno, str(e), request.vars))
>> return locals()
>>
>> does not fills the created_by and modified_by field. They have None 
>>
>> Any help ???
>> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/022388a0-7a1a-405a-93e2-86498f18e334n%40googlegroups.com.