1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Traceback (most recent call last):
File "/home/mau/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/home/mau/web2py/applications/Hesty/controllers/e_default.py", line 708, in <module>
File "/home/mau/web2py/gluon/globals.py", line 421, in <lambda>
self._caller = lambda f: f()
File "/home/mau/web2py/gluon/tools.py", line 3868, in f
return action(*a, **b)
File "/home/mau/web2py/applications/Hesty/controllers/e_default.py", line 649, in sleep_chart
gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 24}])
IndexError: list index out of range
I have a code that works OK except when there is no data in the database.
gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 24}])gauge.add('Light Sleep', [{'value':[i.light_sleep for i in data][-1], 'max_value': 24}])gauge.add('Deep Sleep', [{'value':[i.deep_sleep for i in data][-1], 'max_value': 24}])return gauge.render()
[...]
gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 24}])
IndexError: list index out of rangeExpectation:I want to have a default figure in the database. I have tried having "default=0" but the int only appears in the form text area. So the error persists.
Is there a way to have a default figure in the database or a way to catch this errors and let the new user to input int figure?
if len(data):
gauge.add('Awake', [{'value':[i.awake for i in data][-1], 'max_value': 24}])
gauge.add('Light Sleep', [{'value':[i.light_sleep for i in data][-1], 'max_value': 24}])
gauge.add('Deep Sleep', [{'value':[i.deep_sleep for i in data][-1], 'max_value': 24}])
else:
gauge.add('Unknown', [{'value':[0], 'max_value': 24}])
--
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/9mI7-ZkpA_0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Notice that, it seems you are using [-1] because