class PytisCryptoEncryptUsingKey(Base_PyFunction): name = 'pytis_crypto_encrypt_using_key' arguments = ( sql.Column('', pytis.data.String()), sql.Column('', pytis.data.String()), ) result_type = pytis.data.String() multirow = False stability = 'VOLATILE' depends_on = () access_rights = () @staticmethod def pytis_crypto_encrypt_using_key(public, text): public, text = args import Crypto.PublicKey.RSA import base64 rsa = Crypto.PublicKey.RSA.importKey(public) encrypted = rsa.encrypt(text, None)[0] return base64.encodestring(encrypted)
class RowSelectFunc(sql.SQLFunction): name = 'row_select_func' arguments = (sql.Argument('min_n', pytis.data.Integer()), ) result_type = ( sql.Column('foo', pytis.data.String()), sql.Column('n', pytis.data.Integer()), sql.Column('b', pytis.data.Boolean()), ) multirow = True stability = 'stable' execution_cost = 10 expected_rows = 4 def body(self): foo = sql.t.Foo return sqlalchemy.select(self._exclude(foo, foo.c.id, foo.c.description), whereclause=(foo.c.n >= ival('$1'))) depends_on = (Foo, )
class XChanges(sql.SQLTable): """Sloupečky zaznamenávající uživatele a časy vytvoření a změn údajů. Je určena k tomu, aby ji dědily všechny ostatní tabulky.""" name = '_changes' fields = ( sql.Column('vytvoril', pytis.data.Name(not_null=True), default=sqlalchemy.text('user')), sql.Column('vytvoreno', pytis.data.DateTime(not_null=True), default=sqlalchemy.text('now()')), sql.Column('zmenil', pytis.data.Name(not_null=True), default=sqlalchemy.text('user')), sql.Column('zmeneno', pytis.data.DateTime(not_null=True), default=sqlalchemy.text('now()')), ) depends_on = () access_rights = default_access_rights.value(globals())
class CmsMenuStructureTreeOrder(sql.SQLFunction): """Generate a sortable string representing the hierarchical position of given menu item.""" schemas = cms_schemas.value(globals()) name = 'cms_menu_structure_tree_order' arguments = (sql.Column('', pytis.data.Integer()), ) external = True result_type = pytis.data.LTree() multirow = False stability = 'VOLATILE' depends_on = (CmsMenuStructure, ) access_rights = ()
class CmsRoles(sql.SQLTable): """CMS roles.""" name = '_cms_roles' external = True schemas = cms_schemas.value(globals()) fields = ( sql.PrimaryColumn('role_id', pytis.data.Serial()), sql.Column('name', pytis.data.String(not_null=True)), sql.Column('system_role', pytis.data.String(not_null=False), unique=True), sql.Column('description', pytis.data.String(not_null=False)), ) depends_on = () access_rights = cms_rights.value(globals()) init_columns = ('system_role', 'name') init_values = ( ('ANYONE', 'Anyone'), ('USER', 'Logged user'), )
class Foo(sql.SQLTable): """Foo table.""" name = 'foo' fields = ( sql.PrimaryColumn('id', pytis.data.LargeSerial()), sql.Column('foo', pytis.data.String(), doc='some string', index=dict(method='hash')), sql.Column('n', pytis.data.Integer(not_null=True), check='n<1000', doc='some number'), sql.Column('b', pytis.data.Boolean(), default=True), sql.Column('description', pytis.data.String()), ) inherits = () tablespace = None init_columns = ( 'foo', 'n', ) init_values = ( ( 'abc', 10, ), ( 'def', 20, ), ) unique = (( 'foo', 'n', ), ) with_oids = False access_rights = (( 'ALL', 'foo-users', ), )
class CmsUserRoleAssignment(sql.SQLTable): """Binding table assigning CMS roles to CMS users.""" name = 'cms_user_role_assignment' schemas = cms_schemas.value(globals()) fields = ( sql.PrimaryColumn('user_role_id', pytis.data.Serial()), sql.Column('uid', pytis.data.Integer(not_null=True), references=sql.gA(cms_users_table.value(globals()), ondelete='CASCADE')), sql.Column('role_id', pytis.data.Integer(not_null=True), references=sql.gA('cms_roles', ondelete='CASCADE')), ) with_oids = True unique = (( 'uid', 'role_id', ), ) depends_on = (CmsRoles, ) access_rights = cms_rights.value(globals())
class OnlyDigits(sql.SQLFunction): """Pomocná funkce pro CHECK constraint.""" name = 'only_digits' arguments = (sql.Column('', pytis.data.String()),) result_type = pytis.data.Boolean() multirow = False stability = 'VOLATILE' depends_on = () access_rights = () def body(self): return "select ($1 ~ '^[0-9]+$')"
class EPytisFormSettings(sql.SQLTable): """Storage of pytis profile independent form settings.""" name = 'e_pytis_form_settings' schemas = pytis_schemas.value(globals()) fields = ( sql.PrimaryColumn('id', pytis.data.Serial()), sql.Column('username', pytis.data.Name(not_null=True)), sql.Column('spec_name', pytis.data.String(not_null=True)), sql.Column('form_name', pytis.data.String(not_null=True)), sql.Column('pickle', pytis.data.String(not_null=True)), sql.Column('dump', pytis.data.String(not_null=False)), ) inherits = (XChanges, ) with_oids = True unique = (( 'username', 'spec_name', 'form_name', ), ) depends_on = () access_rights = default_access_rights.value(globals())
class XUpdates(sql.SQLTable): """Tabulka zaznamenávající změny v záznamech standardních tabulek.""" name = '_updates' fields = ( sql.PrimaryColumn('id', pytis.data.Serial(), doc="identifikace změnového řádku"), sql.Column('zmenil', pytis.data.Name(not_null=True), default=sqlalchemy.text('user')), sql.Column('zmeneno', pytis.data.DateTime(not_null=True), default=sqlalchemy.text('now()')), sql.Column('tabulka', pytis.data.String(not_null=False)), sql.Column('klic', pytis.data.String(not_null=False)), sql.Column('zmeny', pytis.data.String(not_null=False)), ) with_oids = True depends_on = () access_rights = default_access_rights.value(globals())
class EPytisHttpAttachmentStorageKeys(sql.SQLTable): """Store HttpAttachmentStorage access keys.""" name = 'e_pytis_http_attachment_storage_keys' schemas = pytis_schemas.value(globals()) fields = ( sql.PrimaryColumn('key_id', pytis.data.Serial()), sql.Column('username', pytis.data.String(not_null=True)), sql.Column('uri', pytis.data.String(not_null=True)), sql.Column('created', pytis.data.DateTime(not_null=True), default=sqlalchemy.text('now()')), sql.Column('readonly', pytis.data.Boolean(not_null=True), default=True), sql.Column('key', pytis.data.String(not_null=True)), ) unique = (( 'username', 'uri', ), ) depends_on = () access_rights = http_attachment_storage_rights.value(globals())
class Continents(sql.SQLTable): name = 'continents' fields = ( sql.PrimaryColumn('id', pytis.data.String(minlen=2, maxlen=2, not_null=False), "Code"), sql.Column('name', pytis.data.String(not_null=True), "Continent name", unique=True), sql.Column('smallest', pytis.data.String(), "Smallest country"), ) with_oids = True depends_on = () access_rights = (('all', 'pytis-demo'), ('select', 'www-data')) init_columns = ('id', 'name') init_values = ( ('AF', 'Africa'), ('AS', 'Asia'), ('EU', 'Europe'), ('NA', 'North America'), ('SA', 'South America'), ('OC', 'Oceania'), ('AN', 'Antarctica'), )
class EPytisAggregatedViews(sql.SQLTable): """Pytis aggregated views storage.""" name = 'e_pytis_aggregated_views' schemas = pytis_schemas.value(globals()) fields = ( sql.PrimaryColumn('id', pytis.data.Serial()), sql.Column('username', pytis.data.Name(not_null=True)), sql.Column('spec_name', pytis.data.String(not_null=True)), sql.Column('aggregated_view_id', pytis.data.String(not_null=True)), sql.Column('title', pytis.data.String(not_null=True)), sql.Column('pickle', pytis.data.String(not_null=True)), ) inherits = (XChanges, ) with_oids = True unique = (( 'username', 'spec_name', 'aggregated_view_id', ), ) depends_on = () access_rights = default_access_rights.value(globals())
class Products(sql.SQLTable): name = 'products' fields = ( sql.PrimaryColumn('product_id', pytis.data.Serial(), _("ID")), sql.Column('product', pytis.data.String(not_null=True), _("Product")), sql.Column('count', pytis.data.Integer(not_null=True), _("Count")), sql.Column('price', pytis.data.Float(precision=2, not_null=True), _("Price")), sql.Column('since', pytis.data.DateTime(not_null=True), _("Available since")), sql.Column('marked', pytis.data.Boolean(not_null=True), _("Marked"), default=False), sql.Column('notes', pytis.data.String(not_null=False), _("Notes")), ) with_oids = True depends_on = () access_rights = (('all', 'pytis-demo'), ('select', 'www-data')) init_columns = ('product', 'count', 'price', 'marked', 'since', 'notes') init_values = ( ('HP LaserJet 5L', 0, 399.99, False, '1994-08-18', None), ('HP LaserJet 3050', 32, 299.99, True, '2004-04-08 10:55:20', 'Free standard shipping'), ('HP Photosmart C7180', 8, 399.99, True, '2006-10-11 16:32:41', None), ('HP LaserJet 1020', 5, 179.99, False, '2005-12-01 08:52:22', 'Free standard shipping'), ('HP DeskJet 640s', 2, 188.00, True, '2007-10-11 10:21:00', None), ('HP DeskJet 347A', 6, 219.99, True, '2007-10-11 11:07:00', None), ('HP DeskJet 24D', 9, 249.99, True, '2007-10-11 11:07:00', None), )
class EPytisFormLog(sql.SQLTable): """ Statistics about using forms by users and form opening performance. form is fully qualified specification name. class is pytis class name of the form instance. login is login name of the user who has opened the form. info is optional extra information provided by the form (e.g. sorting used). t_start is the time when user invoked the form opening command. t_show is the time when the form got actually ready for operation after its start. """ name = 'e_pytis_form_log' schemas = pytis_schemas.value(globals()) fields = ( sql.PrimaryColumn('id', pytis.data.Serial()), sql.Column('form', pytis.data.String(not_null=True), index=True), sql.Column('class', pytis.data.String(not_null=True), index=True), sql.Column('info', pytis.data.String(not_null=False), index=True), sql.Column('login', pytis.data.Name(not_null=True), index=True), sql.Column('t_start', pytis.data.DateTime(not_null=True, without_timezone=True), index=True), sql.Column('t_show', pytis.data.DateTime(not_null=True, without_timezone=True)), ) inherits = (XChanges, ) with_oids = True depends_on = () access_rights = default_access_rights.value(globals())
class Bar(sql.SQLTable): """Bar table.""" name = 'bar' schemas = (( Private, 'public', ), ) fields = ( sql.PrimaryColumn('id', pytis.data.Serial()), sql.Column('foo_id', pytis.data.Integer(), references=sql.a(sql.r.Foo.id, onupdate='CASCADE')), sql.Column('description', pytis.data.String()), ) init_columns = ( 'foo_id', 'description', ) init_values = ((1, 'some text'), ) depends_on = (Foo2, ) def on_delete(self): return () def on_insert_also(self): Foo2 = sql.t.Foo2 n_column = sqlalchemy.literal_column('1').label('n') return ( Foo2.insert().values( n=sqlalchemy.literal_column('new.id'), foo=sqlalchemy.literal_column('new.description')), sql.InsertFromSelect(Foo2, sqlalchemy.select([n_column])), "select 42", ) owner = 'pytis' access_rights = (( 'ALL', True, ), )
class EPytisHelpSpecItems(Base_LogSQLTable): """Help texts for specification items, such as fields, bindings, actions.""" name = 'e_pytis_help_spec_items' fields = ( sql.PrimaryColumn('item_id', pytis.data.Serial()), sql.Column('spec_name', pytis.data.String(not_null=True), references=sql.a(sql.r.EPytisHelpSpec.spec_name, onupdate='CASCADE', ondelete='CASCADE')), sql.Column( 'kind', pytis.data.String(not_null=True), check="kind in ('field', 'profile', 'binding', 'action', 'proc')"), sql.Column('identifier', pytis.data.String(not_null=True)), sql.Column('content', pytis.data.String(not_null=False)), sql.Column('changed', pytis.data.Boolean(not_null=True), doc="True when the content was edited by hand.", default=False), sql.Column('removed', pytis.data.Boolean(not_null=True), doc="False when the item still exists in specification.", default=False), ) inherits = (XChanges, ) unique = (( 'spec_name', 'kind', 'identifier', ), ) depends_on = () access_rights = default_access_rights.value(globals())
class CmsModules(sql.SQLTable): """Codebook of extension modules available in the CMS.""" name = 'cms_modules' schemas = cms_schemas.value(globals()) fields = ( sql.PrimaryColumn('mod_id', pytis.data.Serial()), sql.Column('modname', pytis.data.String(maxlen=64, not_null=True), unique=True), ) with_oids = True depends_on = () access_rights = cms_rights.value(globals())
class CmsActions(sql.SQLTable): """Enumeration of valid actions. (Including both module independent actions and per module actions.) Module independent actions have NULL in the mod_id column. """ name = 'cms_actions' schemas = cms_schemas.value(globals()) fields = ( sql.PrimaryColumn('action_id', pytis.data.Serial()), sql.Column('mod_id', pytis.data.Integer(not_null=False), references=sql.gA('cms_modules', ondelete='CASCADE')), sql.Column('name', pytis.data.String(maxlen=16, not_null=True)), sql.Column('description', pytis.data.String(not_null=True)), ) with_oids = True unique = (( 'mod_id', 'name', ), ) depends_on = (CmsModules, ) access_rights = cms_rights.value(globals())
class CmsLanguages(sql.SQLTable): """Codebook of languages available in the CMS.""" name = 'cms_languages' schemas = cms_schemas.value(globals()) fields = ( sql.PrimaryColumn('lang_id', pytis.data.Serial()), sql.Column('lang', pytis.data.String(minlen=2, maxlen=2, not_null=True), unique=True), ) with_oids = True depends_on = () access_rights = cms_rights.value(globals())
class EPytisHelpMenu(Base_LogSQLTable): """Texts for help pages.""" name = 'e_pytis_help_menu' fields = ( sql.PrimaryColumn('fullname', pytis.data.String(not_null=False), references=sql.a(sql.r.CPytisMenuActions.fullname, onupdate='CASCADE', ondelete='CASCADE')), sql.Column('content', pytis.data.String(not_null=False)), sql.Column('changed', pytis.data.Boolean(not_null=True), doc="True when the content was edited by hand.", default=False), sql.Column('removed', pytis.data.Boolean(not_null=True), doc="False when the item still exists in menu.", default=False), ) inherits = (XChanges, ) depends_on = (EPytisMenu, ) access_rights = default_access_rights.value(globals())
class FDateMonth(sql.SQLFunction): """Pomocná funkce pro agregační matici pytisu.""" schemas = pytis_schemas.value(globals()) name = 'f_date_month' arguments = (sql.Column('', pytis.data.Date()),) result_type = pytis.data.Integer() multirow = False stability = 'VOLATILE' depends_on = () access_rights = () def body(self): return "select date_part('month', $1)::int"
class EPytisOutputTemplates(Base_LogSQLTable): """Storage of print output templates handled by a DatabaseResolver.""" name = 'e_pytis_output_templates' fields = ( sql.PrimaryColumn('id', pytis.data.Serial()), sql.Column('module', pytis.data.String(not_null=True)), sql.Column('specification', pytis.data.String(not_null=True)), sql.Column('template', pytis.data.String(not_null=False)), sql.Column('rowtemplate', pytis.data.String(not_null=False)), sql.Column('header', pytis.data.String(not_null=False)), sql.Column('first_page_header', pytis.data.String(not_null=False)), sql.Column('footer', pytis.data.String(not_null=False)), sql.Column('style', pytis.data.String(not_null=False)), sql.Column('username', pytis.data.String(not_null=False)), ) inherits = (XChanges, ) with_oids = True depends_on = () access_rights = default_access_rights.value(globals())
class CTypFormular(Base_LogSQLTable): """Slouží jako číselník typů formulářů""" name = 'c_typ_formular' fields = (sql.PrimaryColumn('id', pytis.data.String(maxlen=2, not_null=False)), sql.Column('popis', pytis.data.String(not_null=False)), ) inherits = (XChanges,) init_columns = ('id', 'popis') init_values = (('BF', 'Jednoduchý náhled',), ('DF', 'Duální náhled',), ) with_oids = True depends_on = () access_rights = default_access_rights.value(globals())
class CmsMenuStructure(sql.SQLTable): """Language independent menu structure.""" name = '_cms_menu_structure' schemas = cms_schemas.value(globals()) external = True fields = ( sql.PrimaryColumn('menu_item_id', pytis.data.Serial()), sql.Column( 'identifier', pytis.data.String(maxlen=32, not_null=True), ), sql.Column( 'parent', pytis.data.Integer(not_null=False), references=sql.a(sql.r.CmsMenuStructure.menu_item_id), ), sql.Column( 'mod_id', pytis.data.Integer(not_null=False), references=sql.a(sql.r.CmsModules.mod_id), ), sql.Column('ord', pytis.data.Integer(not_null=True)), sql.Column('tree_order', pytis.data.LTree(not_null=False)), ) index_columns = ( sql.Arguments('identifier', unique=True), sql.Arguments('ord', sqlalchemy.literal_column("coalesce(parent, 0)"), unique=True), ( 'parent', 'ord', ), ) depends_on = (CmsModules, ) access_rights = cms_rights.value(globals())
class PytisCryptoUnlockCurrentUserPasswords(sql.SQLPlFunction): name = 'pytis_crypto_unlock_current_user_passwords' schemas = pytis_schemas.value(globals()) arguments = (sql.Column('password_', pytis.data.String()), ) result_type = pytis.data.String() multirow = True access_rights = () depends_on = ( EPytisCryptoKeys, PytisCryptoDbKeys, PytisCryptoUnlockPasswords, ) def body(self): return """
class CPytisCryptoNames(Base_LogSQLTable): """Codebook of encryption areas defined in the application.""" name = 'c_pytis_crypto_names' schemas = pytis_schemas.value(globals()) fields = ( sql.PrimaryColumn('name', pytis.data.String(not_null=False), label=_("Šifrovací oblast")), sql.Column('description', pytis.data.String(not_null=False), label=_("Popis")), ) inherits = (XChanges, ) depends_on = () access_rights = default_access_rights.value(globals())
class GenMirrorSpec(Base_PyFunction): """Vygeneruje základní specifikace pro seznam tabulek""" name = 'gen_mirror_spec' arguments = (sql.Column('', pytis.data.String()), ) result_type = pytis.data.String() multirow = False stability = 'VOLATILE' depends_on = () access_rights = () @staticmethod def gen_mirror_spec(tables): """Vygeneruje základní specifikace pro seznam tabulek""" tables = [t.strip() for t in args[0].split(',')] specs = [] for table in tables: class_name = "%s%s" % (table[0:1].upper(), table[1:]) q = """select ' fields = (' as fields union all (SELECT ' Field(''' || a.attname || ''', _("' || a.attname || '"), ),' FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relname = '%s' AND c.oid = a.attrelid AND a.attnum > 0 AND NOT a.attisdropped AND a.attname not in ('vytvoril','vytvoreno','zmenil','zmeneno')) union all (select ' )') union all (SELECT ' columns = (' || array_to_string(array_agg('''' || a.attname || ''''), ', ') || ')' FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relname = '%s' AND c.oid = a.attrelid AND a.attnum > 0 AND NOT a.attisdropped AND a.attname not in ('vytvoril','vytvoreno','zmenil','zmeneno')) """ % (table, table) q = plpy.execute(q) fields = "\n".join([r["fields"] for r in q]) spec = ( 'class %s(Specification):\n public = True\n\n table = %s%s%s\n' ' title = _("%s")\n\n') % (class_name, "'", table, "'", class_name) specs.append(spec + fields) return "\n\n\n".join(specs)
class PytisCryptoDbKey(sql.SQLPlFunction): name = 'pytis_crypto_db_key' schemas = pytis_schemas.value(globals()) arguments = (sql.Column('key_name_', pytis.data.String()), ) result_type = pytis.data.String() multirow = False stability = 'STABLE' security_definer = True access_rights = () depends_on = ( EPytisCryptoKeys, PytisCryptoDbKeys, ) def body(self): return """
class PytisCryptoGenerateKey(Base_PyFunction): name = 'pytis_crypto_generate_key' arguments = (sql.Column('', pytis.data.Integer()), ) result_type = PytisCryptoTKeyPair multirow = False stability = 'VOLATILE' depends_on = (PytisCryptoTKeyPair, ) access_rights = () @staticmethod def pytis_crypto_generate_key(bits): bits = args[0] import Crypto.PublicKey.RSA rsa = Crypto.PublicKey.RSA.generate(bits) public = rsa.publickey().exportKey() private = rsa.exportKey() return [public, private]