misc: factor check for postgresql usage
This commit is contained in:
parent
38d45fad3d
commit
f19d6b9375
|
@ -29,7 +29,7 @@ def setup_module(module):
|
|||
cleanup()
|
||||
|
||||
pub = create_temporary_pub()
|
||||
pub.has_site_option = lambda x: True
|
||||
pub.is_using_postgresql = lambda: True
|
||||
|
||||
conn = psycopg2.connect(user=os.environ['USER'])
|
||||
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||
|
|
|
@ -374,7 +374,7 @@ class FormDefPage(Directory):
|
|||
'Overwrite with new import')
|
||||
r += htmltext('<li><a href="export">%s</a></li>') % _('Export')
|
||||
r += htmltext('<li><a href="anonymise">%s</a></li>') % _('Anonymise forms')
|
||||
if not (get_publisher().has_site_option('postgresql') and get_cfg('postgresql', {})):
|
||||
if not get_publisher().is_using_postgresql():
|
||||
r += htmltext('<li><a href="archive">%s</a></li>') % _('Archive')
|
||||
if self.formdef.roles:
|
||||
r += htmltext('<li><a href="invite">%s</a></li>') % _('Invites')
|
||||
|
@ -957,7 +957,7 @@ class FormDefPage(Directory):
|
|||
return '<?xml version="1.0" encoding="iso-8859-15"?>\n' + ET.tostring(x)
|
||||
|
||||
def archive(self):
|
||||
if get_publisher().has_site_option('postgresql') and get_cfg('postgresql', {}):
|
||||
if get_publisher().is_using_postgresql():
|
||||
raise TraversalError()
|
||||
|
||||
if get_request().form.get('job'):
|
||||
|
|
|
@ -193,7 +193,7 @@ class UserFieldsFormDef(FormDef):
|
|||
users_cfg['formdef'] = ET.tostring(xml_export)
|
||||
get_publisher().cfg['users'] = users_cfg
|
||||
get_publisher().write_cfg()
|
||||
if get_publisher().has_site_option('postgresql') and get_cfg('postgresql', {}):
|
||||
if get_publisher().is_using_postgresql():
|
||||
import sql
|
||||
sql.do_user_table()
|
||||
|
||||
|
|
|
@ -343,8 +343,7 @@ class UsersDirectory(Directory):
|
|||
other_roles = [str(x) for x in checked_roles if x not in ('admin', 'none')]
|
||||
if other_roles:
|
||||
other_roles_set = set(other_roles)
|
||||
if not (get_publisher().has_site_option('postgresql') and
|
||||
get_cfg('postgresql', {})):
|
||||
if not get_publisher().is_using_postgresql():
|
||||
# with pickle storage we have to duplicate all roles as
|
||||
# they may have been stored as integers
|
||||
for other_role in other_roles:
|
||||
|
|
|
@ -298,8 +298,7 @@ class RootDirectory(BackofficeRootDirectory):
|
|||
counts[formdef.id] = len(values)
|
||||
|
||||
do_graphs = False
|
||||
if get_publisher().has_site_option('postgresql') and \
|
||||
misc.get_cfg('postgresql', {}) and \
|
||||
if get_publisher().is_using_postgresql() and \
|
||||
get_publisher().get_site_option('postgresql_views') != 'false':
|
||||
do_graphs = True
|
||||
|
||||
|
@ -544,13 +543,13 @@ class FormPage(Directory):
|
|||
if limit:
|
||||
r += htmltext('<input type="hidden" name="limit" value="%s"/>') % limit
|
||||
|
||||
if get_publisher().has_site_option('postgresql') and misc.get_cfg('postgresql', {}):
|
||||
if get_publisher().is_using_postgresql():
|
||||
if order_by is None:
|
||||
order_by = ''
|
||||
r += htmltext('<input type="hidden" name="order_by" value="%s"/>') % order_by
|
||||
|
||||
waitpoint_status = self.formdef.workflow.get_waitpoint_status()
|
||||
if get_publisher().has_site_option('postgresql') and misc.get_cfg('postgresql', {}):
|
||||
if get_publisher().is_using_postgresql():
|
||||
r += htmltext('<h3>%s</h3>') % _('Search')
|
||||
if get_request().form.get('q'):
|
||||
q = get_request().form.get('q')
|
||||
|
@ -643,7 +642,7 @@ class FormPage(Directory):
|
|||
fields = self.get_fields_from_query()
|
||||
selected_filter = self.get_filter_from_query()
|
||||
|
||||
if get_publisher().has_site_option('postgresql') and misc.get_cfg('postgresql', {}):
|
||||
if get_publisher().is_using_postgresql():
|
||||
# only enable pagination in SQL mode, as we do not have sorting in
|
||||
# the other case.
|
||||
limit = get_request().form.get('limit', 20)
|
||||
|
|
|
@ -171,9 +171,7 @@ class FormDef(StorableObject):
|
|||
# formdef
|
||||
if data_class._formdef is self:
|
||||
return data_class
|
||||
if (get_publisher().has_site_option('postgresql') and
|
||||
get_cfg('postgresql', {}) and
|
||||
not mode == 'files') or mode == 'sql':
|
||||
if (get_publisher().is_using_postgresql() and not mode == 'files') or mode == 'sql':
|
||||
import sql
|
||||
table_name = sql.get_formdef_table_name(self)
|
||||
cls = new.classobj(self.url_name.title(), (sql.SqlFormData,),
|
||||
|
@ -233,7 +231,7 @@ class FormDef(StorableObject):
|
|||
else:
|
||||
self.last_modification_user_id = None
|
||||
t = StorableObject.store(self)
|
||||
if get_publisher().has_site_option('postgresql') and get_cfg('postgresql', {}):
|
||||
if get_publisher().is_using_postgresql():
|
||||
import sql
|
||||
sql.do_formdef_tables(self, rebuild_views=True)
|
||||
return t
|
||||
|
|
|
@ -41,7 +41,7 @@ class FormDefUI(object):
|
|||
|
||||
get_response().add_javascript(['jquery.js'])
|
||||
if not partial_display:
|
||||
if not (get_publisher().has_site_option('postgresql') and misc.get_cfg('postgresql', {})):
|
||||
if not get_publisher().is_using_postgresql():
|
||||
get_response().add_javascript(['tablesorter/jquery.tablesorter.min.js'])
|
||||
else:
|
||||
include_form = False
|
||||
|
|
|
@ -110,6 +110,9 @@ class WcsPublisher(StubWcsPublisher):
|
|||
"missing_appdir_redirect")
|
||||
configure = classmethod(configure)
|
||||
|
||||
def is_using_postgresql(self):
|
||||
return bool(self.has_site_option('postgresql') and self.cfg.get('postgresql', {}))
|
||||
|
||||
def set_config(self, request = None):
|
||||
QommonPublisher.set_config(self, request = request)
|
||||
filename = os.path.join(self.app_dir, 'config.pck')
|
||||
|
@ -130,7 +133,7 @@ class WcsPublisher(StubWcsPublisher):
|
|||
import wcs.workflows
|
||||
wcs.workflows.load_extra()
|
||||
|
||||
if self.has_site_option('postgresql') and get_cfg('postgresql', {}):
|
||||
if self.is_using_postgresql():
|
||||
import sql
|
||||
self.user_class = sql.SqlUser
|
||||
self.tracking_code_class = sql.TrackingCode
|
||||
|
@ -205,7 +208,7 @@ class WcsPublisher(StubWcsPublisher):
|
|||
return QommonPublisher.try_publish(self, request)
|
||||
|
||||
def cleanup(self):
|
||||
if self.has_site_option('postgresql') and get_cfg('postgresql', {}):
|
||||
if self.is_using_postgresql():
|
||||
import sql
|
||||
sql.cleanup_connection()
|
||||
|
||||
|
|
Loading…
Reference in New Issue