"""Definitions of the App tables """ from .callbacks import INHIBIT_CASCADE_DELETE from gluon import current from gluon.storage import Storage from plugin_dbui import (INHIBIT_DELETE_UNDEF, INHIBIT_UPDATE_UNDEF) from pydal import Field class App(object): """Create tables to steer the application. """ @staticmethod def _protect(table): """protect the content of the table. * Record containing the UNDEF string can not be update or delete. * Inhibit cascade delte for foreign elements Args: table (pyDAL.Table): database table """ table._before_delete.append(INHIBIT_CASCADE_DELETE) table._before_delete.append(INHIBIT_DELETE_UNDEF) table._before_update.append(INHIBIT_UPDATE_UNDEF) @staticmethod def define_tables(db, T): """define tables to steer the application. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator """ App.preferences(db, T) @staticmethod def preferences(db, T): """preferences table Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: pyDAL.Table """ table = db.define_table( "preferences", Field("property", "string", length=255, notnull=True, unique=True), Field("value", "json", length=255), Field("definition", "text", notnull=True), migrate="preferences.table") table.value.requires = None # load preference for a later use app = Storage() for row in db(db.preferences).select(): app[row.property] = row.value # add local variable app.cfgPreferences = None app.reg_institute = "" app.institute = None current.app = app return table