import os
import datetime as dt
from datetime import datetime, timedelta, date
from py4web import action, request, DAL, Field, Session, Cache, user_in
from py4web.utils.auth import Auth
from py4web import action, request, abort, redirect, URL, Field
from py4web.utils.form import Form, FormStyleBulma
from py4web.utils.publisher import Publisher, ALLOW_ALL_POLICY
from pydal.validators import * #IS_NOT_EMPTY, IS_INT_IN_RANGE, IS_IN_SET, IS_IN_DB, IS_EMAIL, IS_MATCH
from pydal.validators import *
from . common import db, session, T, cache, authenticated, unauthenticated, Field
from pydal.validators import *
### Define your table below
# exposes services necessary to access the db.thing via ajax
publisher = Publisher(db, policy=ALLOW_ALL_POLICY)
# define session and cache objects
session = Session(secret="some secret")
cache = Cache(size=1000)
# define database and tables
#connection = sqlite.connect('cache.db', timeout=10)
db = DAL("sqlite://xstorage.db", folder=os.path.join(os.path.dirname(__file__), "databases"))#db = DAL("sqlite://storage.db", folder=os.path.join(os.path.dirname(__file__), "databases"))
#db = DAL( "postgres://mauricewaka:b3th32dau2a##@localhost:5432/py4db", migrate=False)
auth = Auth(session, db)
# (configure here)
auth.enable()
db.define_table('answers',
Field('author', 'reference auth_user', default=auth.user_id, writable=False, readable=False),
Field("message", 'text', requires=IS_NOT_EMPTY(), notnull=False),
auth.signature
)
@authenticated()
@action.uses(auth.user)
def index():
...some code...
yesterday = dt.datetime.utcnow() - dt.timedelta(days=1)
db(db.answers.modified_on < yesterday).delete()
...some more code....
Traceback (most recent call last):
File "/home/maurice/py4web/py4web/core.py", line 551, in wrapper
ret = func(*func_args, **func_kwargs)
File "/home/maurice/py4web/py4web/core.py", line 512, in wrapper
ret = func(*args, **kwargs)
File "/home/maurice/py4web/py4web/core.py", line 512, in wrapper
ret = func(*args, **kwargs)
File "apps/scaffoldx/controllers.py", line 571, in index
db(db.answers.modified_on < yesterday).delete()
File "/home/maurice/.local/lib/python3.6/site-packages/pydal/base.py", line 763, in __getattr__
return BasicStorage.__getattribute__(self, key)
AttributeError: 'DAL' object has no attribute 'answers'
What could be wrong here and how can I solve it?
N/B
I have tried to define the table inside the controller code with an error coming as : 'table already defined'. When I remove the definition then the above error comes.
Regards
from ..common import db, session, T, cache, auth, logger
@action.uses("applications/index.html", session, db, T, auth.user)
def index():
page['sub_title'] = A('MENU', _href=URL('index'))
return dict(page=page)
import os
import datetime as dt
from datetime import datetime, timedelta, date
from py4web import action, request, DAL, Field, Session, Cache, user_in
from py4web.utils.auth import Auth
from py4web import action, request, abort, redirect, URL, Field
from py4web.utils.form import Form, FormStyleBulma
from py4web.utils.publisher import Publisher, ALLOW_ALL_POLICY
from pydal.validators import * #IS_NOT_EMPTY, IS_INT_IN_RANGE, IS_IN_SET, IS_IN_DB, IS_EMAIL, IS_MATCH
from pydal.validators import *
from . common import db, session, T, cache, authenticated, unauthenticated, Field
from pydal.validators import *
# exposes services necessary to access the db.thing via ajax
publisher = Publisher(db, policy=ALLOW_ALL_POLICY)
# define session and cache objects
session = Session(secret="some secret")
cache = Cache(size=1000)
# define database and tables
db = DAL("sqlite://xstorage.db", folder=os.path.join(os.path.dirname(__file__), "databases"))
auth = Auth(session, db)
# (configure here)
auth.enable()
db.define_table('answers',
Field('author', 'reference auth_user', default=auth.user_id, writable=False, readable=False),
Field("message", 'text', requires=IS_NOT_EMPTY(), notnull=False),
auth.signature
)
--
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/wn6mmXVPlC0/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/95f5b7fa-e68e-4f7b-9174-d5eea3448456%40googlegroups.com.