from gluon.tools import Auth, Crud, Service, PluginManager, prettydate, Wiki
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()
wiki = Wiki(auth=auth, render='html')
auth.define_tables(username=True, migrate=False)
media=db.tables(db.wiki_media)
media.fields.append(Field('filedata', 'blob'))
media.filedata.represent = lambda value,row: \
A('get it', _href=URL('download', args=value))
db.wiki_media.filename.uploadfield='filedata'
from gluon import DAL
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate, Wiki
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()
## create all tables needed by auth if not custom tables
auth.define_tables(username=True, migrate=False)
auth.wiki(resolve=False)
.
.
.
media=db.wiki_media
media.fields.append(Field('filedata', 'blob'))
media.filedata.represent = lambda value,row: \
A('get it', _href=URL('download', args=value))
db.wiki_media.filename.uploadfield='filedata'
Traceback (most recent call last):
File "C:\web2py\gluon\restricted.py", line 209, in restricted
exec ccode in environment
File "C:/web2py/applications/TAMOTO/models/db.py", line 103, in <module>
media.filedata.represent = lambda value,row: \
File "C:\web2py\gluon\dal.py", line 7626, in __getitem__
return ogetattr(self, str(key))
AttributeError: 'Table' object has no attribute 'filedata'
AttributeError: 'Table' object has no attribute 'filedata'
So I think I'm close. Just not aware of how to add that field yet.
# before auth.wiki()
auth.settings.extra_fields["wiki_page"] = [Field("filedata", "blob"),]
I didn't expect you wanted to add a field to the table after calling .,,
<type 'exceptions.AttributeError'>('DAL' object has no attribute 'wiki_media') but when commented out the appadmin displays all the tables except the wiki_ tables.
from gluon import DAL
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate, Wiki
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()
## create all tables needed by auth if not custom tables
auth.settings.extra_fields['auth_user']= [
Field('business_unit', length=15),
Field('default_charge_number', length=15),
Field('location', length=15),
Field('phone', length=12)]
auth.settings.extra_fields["wiki_media"] = [Field("filedata", "blob"),]
auth.define_tables(username=True, migrate=False)
#
# db.wiki_media.filename.uploadfield='filedata'
# db.wiki_page.filedata.represent = lambda value,row: \
# A('get it', _href=URL('download', args=value))I tried your patch but the tables were not defined. Is my db.py code correct? The commented out code causes an error<type 'exceptions.AttributeError'>('DAL' object has no attribute 'wiki_media') but when commented out the appadmin displays all the tables except the wiki_ tables.
db.wiki_media.filename.uploadfield='filedata'
db.wiki_page.filedata.represent = lambda value,row: \
A('get it', _href=URL('download', args=value))Traceback (most recent call last):
File "C:\web2py\gluon\restricted.py", line 209, in restricted
exec ccode in
environment
File "C:/web2py/applications/TAMOTO/models/db.py", line 68, in <module>
db.wiki_page.filedata.represent = lambda value,row: \
File "C:\web2py\gluon\dal.py", line 7626, in __getitem__
return ogetattr(self, str(key))
AttributeError: 'Table' object has no attribute 'filedata'
db = DAL(settings.database_uri, check_reserved=['oracle'], migrate_enabled=False, fake_migrate_all=True)
session.secure()
session.connect(request, response, db)
.
.
.
from gluon import DAL
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate, Wiki
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()
## create all tables needed by auth if not custom tables
auth.settings.extra_fields['auth_user']= [
Field('business_unit', length=15),
Field('default_charge_number', length=15),
Field('location', length=15),
Field('phone', length=12)]
auth.settings.extra_fields["wiki_media"] = [Field("filedata", "blob"),]
auth.wiki(resolve=False)
db.wiki_media.filename.uploadfield='filedata'
db.wiki_page.filedata.represent = lambda value,row: \
A('get it', _href=URL('download', args=value))
auth.define_tables(username=True, migrate=False, fake_migrate=True)
.
.
.
#code now looks like this, put the represent= inside the
# call to extra_fileds
.
.
.
auth.settings.extra_fields["wiki_media"] = [
Field("filedata", "blob",
represent = lambda value,row: \
A('get it', _href=URL('download', args=value))),]
auth.define_tables(username=True, migrate=False, fake_migrate=True)
auth.wiki(resolve=False)
db.wiki_media.filename.uploadfield='filedata'Traceback (most recent call last):
File "C:\web2py\gluon\restricted.py", line 209, in restricted
exec ccode in
environment
File "C:/web2py/applications/TAMOTO/models/db.py", line 70, in <module>
auth.wiki(resolve=False)
File "C:\web2py\gluon\tools.py", line 3192, in wiki
env=env)
File "C:\web2py\gluon\tools.py", line 4597, in __init__
args.append(field)
UnboundLocalError: local variable 'args' referenced before assignment
the index displays the login page but after logging in returns the login page without logging in the user (user is in db)
if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
db = DAL(settings.database_uri, check_reserved=['oracle'])
## store sessions and tickets there
session.connect(request, response, db=db, migrate='db.web2py_session_tamoto')
else:
.
.
.
## create all tables needed by auth if not custom tables
auth.define_tables(username=True, signature=False, migrate=False)
Traceback (most recent call last):
File "C:\web2py_src_2.1.1\web2py\gluon\restricted.py", line 209, in restricted
exec ccode in environment
File "C:/web2py_src_2.1.1/web2py/applications/TAMOTO/models/db.py", line 16, in <module>
session.connect(request, response, db=db, migrate='db.web2py_session_tamoto')
File "C:\web2py_src_2.1.1\web2py\gluon\globals.py", line 581, in connect
migrate=table_migrate,
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 7092, in define_table
table = self.lazy_define_table(tablename,*fields,**args)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 7124, in lazy_define_table
polymodel=polymodel)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 920, in create_table
self.create_sequence_and_triggers(query,table)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 2865, in create_sequence_and_triggers
self.execute(query)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 2856, in execute
return self.log_execute(command, args)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 1687, in log_execute
ret = self.cursor.execute(*a, **b)
DatabaseError: ORA-00955: name is already used by an existing object
Thought I might give writing a patch a try so I tried catching and ignoring the exception in the OracleAdaptor but it does not work.
After setting migrate_enabled to False:
db = DAL(settings.database_uri, check_reserved=['oracle'], migrate_enabled=False)
I get this error:
Traceback (most recent call last):
File "C:\web2py_src_2.1.1\web2py\gluon\main.py", line 541, in wsgibase
session._try_store_in_db(request, response)
File "C:\web2py_src_2.1.1\web2py\gluon\globals.py", line 670, in _try_store_in_db
record_id = table.insert(**dd)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 7812, in insert
return ret
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 1160, in insert
raise e
IntegrityError: ORA-01400: cannot insert NULL into ("UWAVEDAT"."WEB2PY_SESSION_TAMOTO"."ID")
Thought I'd start over with a brand new application & get the wiki working but I am running into difficulty before I even get to the wiki part.
I created a brand new app and started by moving my 0.py file into models then edited db.py like so:
if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
db = DAL(settings.database_uri, check_reserved=['oracle'])
## store sessions and tickets there
session.connect(request, response, db=db, migrate='db.web2py_session_tamoto')
else:
.
.
.
## create all tables needed by auth if not custom tables
auth.define_tables(username=True, signature=False, migrate=False)
Of course I get an Oracle Error:
Traceback (most recent call last):
File "C:\web2py_src_2.1.1\web2py\gluon\restricted.py", line 209, in restricted
exec ccode in environment
File "C:/web2py_src_2.1.1/web2py/applications/TAMOTO/models/db.py", line 16, in <module>
session.connect(request, response, db=db, migrate='db.web2py_session_tamoto')
File "C:\web2py_src_2.1.1\web2py\gluon\globals.py", line 581, in connect
migrate=table_migrate,
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 7092, in define_table
table = self.lazy_define_table(tablename,*fields,**args)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 7124, in lazy_define_table
polymodel=polymodel)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 920, in create_table
self.create_sequence_and_triggers(query,table)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 2865, in create_sequence_and_triggers
self.execute(query)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 2856, in execute
return self.log_execute(command, args)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 1687, in log_execute
ret = self.cursor.execute(*a, **b)
DatabaseError: ORA-00955: name is already used by an existing object
Thought I might give writing a patch a try so I tried catching and ignoring the exception in the OracleAdaptor but it does not work.
After setting migrate_enabled to False:
db = DAL(settings.database_uri, check_reserved=['oracle'], migrate_enabled=False)
I get this error:
Traceback (most recent call last):
Variables
session <Storage {'auth': None, '_user_agent': {'os': {'...ser': {'version': '15.0.1', 'name': 'Firefox'}}}>
request <Storage {'function': 'index', 'body': <cStringI...lications\\TAMOTO\\', 'post_vars': <Storage {}>}>
session._try_store_in_db <bound method Session._try_store_in_db of <Stora...er': {'version': '15.0.1', 'name': 'Firefox'}}}>>
response <Storage {'body': <cStringIO.StringO object at 0...a> at 0x03FE8F30>, 'view': 'default/index.html'}>
Traceback (most recent call last):
File "C:\web2py_src_2.1.1\web2py\gluon\restricted.py", line 209, in restricted
exec ccode in environment
File "C:/web2py_src_2.1.1/web2py/applications/TAMOTO/controllers/default.py", line 240, in <module>
File "C:\web2py_src_2.1.1\web2py\gluon\globals.py", line 187, in <lambda>
self._caller = lambda f: f()
File "C:/web2py_src_2.1.1/web2py/applications/TAMOTO/controllers/default.py", line 20, in index
return auth.wiki()
File "C:\web2py_src_2.1.1\web2py\gluon\tools.py", line 3227, in wiki
return self._wiki.read(slug)['content'] if slug else self._wiki()
File "C:\web2py_src_2.1.1\web2py\gluon\tools.py", line 4697, in __call__
return self.edit(request.args(1) or 'index')
File "C:\web2py_src_2.1.1\web2py\gluon\tools.py", line 4791, in edit
formstyle='table2cols',showid=False).process()
File "C:\web2py_src_2.1.1\web2py\gluon\html.py", line 2135, in process
self.validate(**kwargs)
File "C:\web2py_src_2.1.1\web2py\gluon\html.py", line 2075, in validate
if self.accepts(**kwargs):
File "C:\web2py_src_2.1.1\web2py\gluon\sqlhtml.py", line 1441, in accepts
self.vars.id = self.table.insert(**fields)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 7808, in insert
ret = self._db._adapter.insert(self,self._listify(fields))
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 1160, in insert
raise e
DatabaseError: ORA-04098: trigger 'UWAVEDAT.WIKI_PAGE_TRIGGER' is invalid and failed re-validation
CREATE SEQUENCE "SCHEMANAME"."WIKI_PAGE_SEQUENCE" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 2001 CACHE 2000 ORDER NOCYCLE ;
CREATE OR REPLACE TRIGGER "SCHEMANAME"."WIKI_PAGE_TRIGGER" BEFORE
INSERT ON wiki_page FOR EACH ROW BEGIN
SELECT wiki_page_sequence.nextval INTO :NEW.id FROM DUAL;
END;
/
ALTER TRIGGER "SCHEMANAME"."WIKI_PAGE_TRIGGER" ENABLE;
Note for future searchers & people as foolish as I am to try and use Oracle for web site backend.
....
I did not have this issue with tables created by web2py.
Traceback (most recent call last):
File "C:\web2py_src_2.1.1\web2py\gluon\restricted.py", line 209, in restricted
exec ccode in environment
File "C:/web2py_src_2.1.1/web2py/applications/TAMOTO/controllers/default.py", line 240, in <module>
File "C:\web2py_src_2.1.1\web2py\gluon\globals.py", line 187, in <lambda>
self._caller = lambda f: f()
File "C:/web2py_src_2.1.1/web2py/applications/TAMOTO/controllers/default.py", line 20, in index
return auth.wiki()
File "C:\web2py_src_2.1.1\web2py\gluon\tools.py", line 3227, in wiki
return self._wiki.read(slug)['content'] if slug else self._wiki()
File "C:\web2py_src_2.1.1\web2py\gluon\tools.py", line 4705, in __call__
return self.search()
File "C:\web2py_src_2.1.1\web2py\gluon\tools.py", line 4990, in search
content.append(self.cloud()['content'])
File "C:\web2py_src_2.1.1\web2py\gluon\tools.py", line 5001, in cloud
orderby = ~count, limitby=(0,20))
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 8790, in select
return adapter.select(self.query,fields,attributes)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 1615, in select
return self._select_aux(sql,fields,attributes)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 1580, in _select_aux
self.execute(sql)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 2856, in execute
return self.log_execute(command, args)
File "C:\web2py_src_2.1.1\web2py\gluon\dal.py", line 1687, in log_execute
ret = self.cursor.execute(*a, **b)
DatabaseError: ORA-00904: "WIKI_TAG"."WIKI_PAGE": invalid identifier
DatabaseError: ORA-00904: "WIKI_TAG"."WIKI_PAGE": invalid identifier