@request.restful()
@cors_allow
def save_transaction():
response.view = 'generic.json'
def POST(**data):
# Creating the parent transaction
parent = {'parent_transaction' : None,
'transaction_date': '01/01/2019',
'transaction_label' : 'label',
'transaction_type' : data['transaction_type'],
'treatment': data['selected_treatment'],
'transaction_value': data['total_value'],
'paid': data['allpaid'],
'payment_method': None
}
return db.transactions.validate_and_insert(**parent)
return locals()
db.define_table('transactions',
Field('parent_transaction', type='reference transactions', requires=IS_EMPTY_OR(IS_IN_DB(db, 'transactions.id', '%(transaction_label)s'))),
Field('transaction_date', 'date', requires=IS_DATE(format='%d/%m/%Y',error_message='Coloque uma data no formato DD/MM/AAAA')),
Field('transaction_label', 'string'),
Field('transaction_type', 'string', requires=IS_IN_SET(['Receita','Despesa'])),
Field('treatment', type='reference contact_treatment', requires=IS_EMPTY_OR(IS_IN_DB(db, 'contact_treatment.id', '%(description)s'))),
Field('description', 'string', requires=IS_NOT_EMPTY(error_message='Preencha com uma descrição')),
Field('transaction_by', 'reference contacts', requires=IS_EMPTY_OR(IS_IN_DB(db, 'contacts.id', '%(name)s',))),
Field('transaction_value', 'float', requires=IS_FLOAT_IN_RANGE(None, None, dot=","), default=0),
Field('paid', 'boolean', default=False),
Field('payment_method', type='reference payment_methods', requires=IS_EMPTY_OR(IS_IN_DB(db, 'payment_methods.id', '%(name)s'))),
)
{'parent_transaction': None, 'transaction_date': '01/01/2019', 'transaction_label': 'label', 'transaction_type': 'Receita', 'treatment': 1, 'transaction_value': 250, 'paid': False, 'payment_method': None}
Hi!I am trying to call a POST method from a Vue.js frontend. My backend is web2py serving a REST API:
[...]
This is the Data sent:{'parent_transaction': None, 'transaction_date': '01/01/2019', 'transaction_label': 'label', 'transaction_type': 'Receita', 'treatment': 1, 'transaction_value': 250, 'paid': False, 'payment_method': None}This is the response:
Any idea what is wrong? What does mean "iderrors"?
{"id": 2345, "errors": None}
ERROR:Rocket.Errors.Thread-2:Traceback (most recent call last):
File "/Users/titogarridoogando/Documents/Projetos/web2py/controle/web2py/gluon/rocket.py", line 1797, in run_app
sections = len(output)
TypeError: object of type 'Reference' has no len()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/titogarridoogando/Documents/Projetos/web2py/controle/web2py/gluon/rocket.py", line 1288, in run
self.run_app(conn)
File "/Users/titogarridoogando/Documents/Projetos/web2py/controle/web2py/gluon/rocket.py", line 1819, in run_app
output.close()
TypeError: 'NoneType' object is not callable
--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/daa835f7-e232-494c-9bbc-def2a249869f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No entry in the database...I could execute the post from postman... but if I try from axios in vue I am even getting a web2py server error:ERROR:Rocket.Errors.Thread-2:Traceback (most recent call last):
File "/Users/titogarridoogando/Documents/Projetos/web2py/controle/web2py/gluon/rocket.py", line 1797, in run_app
sections = len(output)
TypeError: object of type 'Reference' has no len()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/titogarridoogando/Documents/Projetos/web2py/controle/web2py/gluon/rocket.py", line 1288, in run
self.run_app(conn)
File "/Users/titogarridoogando/Documents/Projetos/web2py/controle/web2py/gluon/rocket.py", line 1819, in run_app
output.close()
TypeError: 'NoneType' object is not callableNo idea what it means...
On Wednesday, July 17, 2019 at 11:02:59 AM UTC-7, Tito Garrido wrote:No entry in the database...I could execute the post from postman... but if I try from axios in vue I am even getting a web2py server error:ERROR:Rocket.Errors.Thread-2:Traceback (most recent call last):
File "/Users/titogarridoogando/Documents/Projetos/web2py/controle/web2py/gluon/rocket.py", line 1797, in run_app
sections = len(output)
TypeError: object of type 'Reference' has no len()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/titogarridoogando/Documents/Projetos/web2py/controle/web2py/gluon/rocket.py", line 1288, in run
self.run_app(conn)
File "/Users/titogarridoogando/Documents/Projetos/web2py/controle/web2py/gluon/rocket.py", line 1819, in run_app
output.close()
TypeError: 'NoneType' object is not callableNo idea what it means...Which version of web2py are you using? Is this with Python2 or Python3?
--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/f2b43605-f028-4293-8093-41243a9c4331%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I just figured out that the error:is because of:return db.transactions.validate_and_insert(**parent)seems that db.transactions.validate_and_insert(**parent) is causing an error during the return.. if I return a string it works...
To unsubscribe from this group and stop receiving emails from it, send an email to web...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/f2b43605-f028-4293-8093-41243a9c4331%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.