cubicweb #343624 access to ORM and views outside web engine. [resolved]

here is what is necessary in one of my scripts to get it to use ORM objects and views with a dbapi connection but without running in the web engine.

from cubicweb.web.request import CubicWebRequestBase as cwrb
dbapi.DBAPIRequest.build_ajax_replace_url = cwrb.build_ajax_replace_url.im_func
dbapi.DBAPIRequest.list_form_param = cwrb.list_form_param.im_func

def fake_unicode(self, *args, **kwargs):
    return u''

def fake_list(self, *args, **kwargs):
    return []

def prop(self, name):
    try:
        return super(dbapi.DBAPIRequest, self).property_value(name)
    except KeyError:
        return ''

dbapi.DBAPIRequest.property_value = prop
dbapi.DBAPIRequest.next_tabindex = count().next

def fake(self, *args, **kwargs):
    pass
dbapi.DBAPIRequest.form = {}
dbapi.DBAPIRequest.relative_path = fake
dbapi.DBAPIRequest.url = fake
dbapi.DBAPIRequest.next_tabindex = fake
dbapi.DBAPIRequest.data = {}
dbapi.DBAPIRequest.add_js = fake #cwrb.add_js.im_func
dbapi.DBAPIRequest.add_css = fake #cwrb.add_css.im_func

cnxprops = None
if options.log:
    cnxprops = dbapi.ConnectionProperties(log=True)
try:
    self.cnx = dbapi.connect(database=self.appid, user=user, password=password,
                             host=dbserver, port=options.dbport, cnxprops=cnxprops)
except:
    user, password = self.HACK[user]
    print 'cannot connect to',self.appid,'with',options.dbuser,'trying',user,
    self.cnx = dbapi.connect(database=self.appid, user=user, password=password,
                             host=dbserver, port=options.dbport, cnxprops=cnxprops)

self.cnx.vreg.config.set_option('base-url', URLMAP[self.appid])
self.cnx.vreg['propertydefs']['ui.site-title'] = {'default': self.appid}
self.cnx.load_vobjects(apptemplate, force_reload=False)
self.cursor = self.cnx.cursor()

it would be nice if the above code was reduced to a minimum.

prioritynormal
typeenhancement
done in3.4.0
load0.500
load left0.000
closed by<not specified>