From b6f8a46681dd07cd49a4138a05df07e6cc04193b Mon Sep 17 00:00:00 2001
From: drfho
Date: Sun, 13 Dec 2020 17:04:01 +0100
Subject: [PATCH] ZMI: Improved GUI-compatibility to Zope4+
---
CHANGES.txt | 6 +
Products/ZPsycopgDA/DA.py | 2 +
Products/ZPsycopgDA/__init__.py | 2 +-
Products/ZPsycopgDA/dtml/add.dtml | 258 +++++++++++++----------------
Products/ZPsycopgDA/dtml/edit.dtml | 232 +++++++++++---------------
psycopg2da/adapter.py | 24 +--
6 files changed, 236 insertions(+), 288 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 1cc538b..b715011 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,12 @@
Changelog
=========
+2.4.8
+--------------------
+
+Restuctered ZMI according to Zope4+
+
+
2.4.7.dev1+perfact.4
--------------------
diff --git a/Products/ZPsycopgDA/DA.py b/Products/ZPsycopgDA/DA.py
index f51ddd4..71b7d19 100644
--- a/Products/ZPsycopgDA/DA.py
+++ b/Products/ZPsycopgDA/DA.py
@@ -81,6 +81,8 @@ class Connection(Shared.DC.ZRDB.Connection.Connection):
database_type = 'Psycopg2'
meta_type = title = 'Z Psycopg 2 Database Connection'
icon = 'misc_/conn'
+ zmi_icon = 'fas fa-database text-info'
+ zmi_show_add_dialog = True
def __init__(self, id, title, connection_string,
zdatetime, check=None, tilevel=DEFAULT_TILEVEL,
diff --git a/Products/ZPsycopgDA/__init__.py b/Products/ZPsycopgDA/__init__.py
index aa9cda8..0fe8336 100644
--- a/Products/ZPsycopgDA/__init__.py
+++ b/Products/ZPsycopgDA/__init__.py
@@ -16,7 +16,7 @@
# their work without bothering about the module dependencies.
__doc__ = "ZPsycopg Database Adapter Registration."
-__version__ = '2.4.7.dev1+perfact.4'
+__version__ = '2.4.8'
# Python2 backward compatibility
try:
diff --git a/Products/ZPsycopgDA/dtml/add.dtml b/Products/ZPsycopgDA/dtml/add.dtml
index cbd91e6..0555d74 100644
--- a/Products/ZPsycopgDA/dtml/add.dtml
+++ b/Products/ZPsycopgDA/dtml/add.dtml
@@ -6,159 +6,131 @@
help_topic='ZPsycopgDA-Method-Add.stx'
)">
-
-A Zope Psycopg 2 Database Connection is used to connect and execute
-queries on a PostgreSQL database.
-
-
-
-In the form below Connection String (also called the Data Source Name
-or DSN for short) is a string containing the connection parameters, for
-example: “dbname=test user=postgres password=secret”
-
-
-
-The basic connection parameters are:
-
- - dbname: the database name (only in dsn string)
- - database: the database name (only as keyword argument)
- - user: user name used to authenticate
- - password: password used to authenticate
- - host: database host address (defaults to UNIX socket if not provided)
- - port: connection port number (defaults to 5432 if not provided)
-
-
-
-
-Note on transaction levels: Unless your server is capable of retries
-(Setting "max-conflict-retries" in zope.conf), you should not use
-"repeatable read" or "serializable", because both can produce random errors
-on contradicting transactions.
-
-
-
-Note on two-phase commit: This feature uses "PREPARE TRANSACTION", which
-has some limitations (no NOTIFY or LISTEN is possible), and needs special
-provisions to clean up orphaned prepared transactions. Use with care.
-
-
-
+
+
+
diff --git a/Products/ZPsycopgDA/dtml/edit.dtml b/Products/ZPsycopgDA/dtml/edit.dtml
index 29a4835..d15be9c 100644
--- a/Products/ZPsycopgDA/dtml/edit.dtml
+++ b/Products/ZPsycopgDA/dtml/edit.dtml
@@ -1,148 +1,116 @@
-
-In the form below Connection String (also called the Data Source Name
-or DSN for short) is a string containing the connection parameters, for
-example: “dbname=test user=postgres password=secret”
-
+
-
-The basic connection parameters are:
-
- - dbname: the database name (only in dsn string)
- - database: the database name (only as keyword argument)
- - user: user name used to authenticate
- - password: password used to authenticate
- - host: database host address (defaults to UNIX socket if not provided)
- - port: connection port number (defaults to 5432 if not provided)
-
-
+
+ A Zope Psycopg 2 Database Connection is used to connect and execute
+ queries on a PostgreSQL database. In the form below Connection String
+ (also called the Data Source Name or DSN for short) is a string containing
+ the connection parameters, for example:
+ “dbname=test user=postgres password=secret”
+
-
-Note on transaction levels: Unless your server is capable of retries
-(Setting "max-conflict-retries" in zope.conf), you should not use
-"repeatable read" or "serializable", because both can produce random errors
-on contradicting transactions.
-
-
-
-Note on two-phase commit: This feature uses "PREPARE TRANSACTION", which
-has some limitations (no NOTIFY or LISTEN is possible), and needs special
-provisions to clean up orphaned prepared transactions. Use with care.
-
-
-
+
+
+
diff --git a/psycopg2da/adapter.py b/psycopg2da/adapter.py
index 2ddc0a2..0e9b101 100644
--- a/psycopg2da/adapter.py
+++ b/psycopg2da/adapter.py
@@ -62,7 +62,7 @@ def parse_date(s):
"""
m = _dateFmt.match(s)
if m is None:
- raise ValueError, 'invalid date string: %s' % s
+ raise ValueError('invalid date string: %s' % s)
year, month, day = m.groups()
return int(year), int(month), int(day)
@@ -83,7 +83,7 @@ def parse_time(s):
"""
m = _timeFmt.match(s)
if m is None:
- raise ValueError, 'invalid time string: %s' % s
+ raise ValueError('invalid time string: %s' % s)
hr, mn, sc, msc = m.groups(0)
if msc != 0:
sc = float("%s.%s" % (sc, msc))
@@ -108,7 +108,7 @@ def parse_tz(s):
return 0
m = _tzFmt.match(s)
if m is None:
- raise ValueError, 'invalid time zone: %s' % s
+ raise ValueError('invalid time zone: %s' % s)
d, hoff, moff = m.groups(0)
if d == "-":
return - int(hoff) * 60 - int(moff)
@@ -145,7 +145,7 @@ def _split_datetime(s):
"""
m = _datetimeFmt.search(s)
if m is None:
- raise ValueError, 'time part of datetime missing: %s' % s
+ raise ValueError('time part of datetime missing: %s' % s)
pos = m.start()
return s[:pos], s[pos + 1:]
@@ -224,7 +224,7 @@ def parse_interval(s):
elif unit == 'years':
years += int(count)
else:
- raise ValueError, 'unknown time interval %s %s' % (count, unit)
+ raise ValueError('unknown time interval %s %s' % (count, unit))
if len(elements) % 2 == 1:
hours, minutes, seconds = parse_time(elements[-1])
return (years, months, days, hours, minutes, seconds)
@@ -332,8 +332,8 @@ def connect(self):
self._v_connection = Psycopg2Connection(
self._connection_factory(), self
)
- except psycopg2.Error, error:
- raise DatabaseException, str(error)
+ except psycopg2.Error as error:
+ raise DatabaseException(str(error))
def registerTypes(self):
registerTypes(self.getEncoding())
@@ -343,7 +343,7 @@ def _connection_factory(self):
self.registerTypes()
conn_info = parseDSN(self.dsn)
conn_list = []
- for dsnname, optname in dsn2option_mapping.iteritems():
+ for dsnname, optname in dsn2option_mapping.items():
if conn_info[dsnname]:
conn_list.append('%s=%s' % (optname, conn_info[dsnname]))
conn_str = ' '.join(conn_list)
@@ -386,7 +386,7 @@ def cursor(self):
def commit(self):
try:
ZopeConnection.commit(self)
- except psycopg2.Error, error:
+ except psycopg2.Error as error:
_handle_psycopg_exception(error)
@@ -396,13 +396,13 @@ def execute(self, operation, parameters=None):
"""See IZopeCursor"""
try:
return ZopeCursor.execute(self, operation, parameters)
- except psycopg2.Error, error:
+ except psycopg2.Error as error:
_handle_psycopg_exception(error)
def executemany(operation, seq_of_parameters=None):
"""See IZopeCursor"""
- raise RuntimeError, 'Oos'
+ raise RuntimeError('Oos')
try:
return ZopeCursor.execute(self, operation, seq_of_parameters)
- except psycopg2.Error, error:
+ except psycopg2.Error as error:
_handle_psycopg_exception(error)