Skip to content

Commit

Permalink
T209948: Fix UI and connection error (#12)
Browse files Browse the repository at this point in the history
* Add a new case for connection errors

* Fix UI checkboxes

* Incorporate suggestions from #9

* Remove class from checkbox as suggested in #9

* Fix CSS classes of checkboxes
  • Loading branch information
jan-jockusch authored Mar 12, 2021
1 parent c2deab9 commit a0ae436
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
1 change: 1 addition & 0 deletions Products/ZPsycopgDA/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def is_connection_error(error):
'OperationalError',
'InterfaceError'
) and (
'SSL SYSCALL error' in value or
'server closed the connection' in value or
'terminating connection due to administrator command' in value or
'connection already closed' in value
Expand Down
43 changes: 20 additions & 23 deletions Products/ZPsycopgDA/dtml/add.dtml
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
<dtml-var manage_page_header>

<dtml-var "manage_form_title(this(), _,
form_title='Add Z Psycopg 2 Database Connection',
help_product='ZPsycopgDA',
help_topic='ZPsycopgDA-Method-Add.stx'
)">
form_title='Add Z Psycopg 2 Database Connection')">

<main class="container-fluid">

<p class="form-help">
A Zope Psycopg 2 Database Connection is used to connect and execute
queries on a PostgreSQL database. In the form below <em>Connection String</em>
(also called the Data Source Name or DSN for short) is a string containing
the connection parameters, for example:
queries on a PostgreSQL database. In the form below <em>Connection String</em>
(also called the Data Source Name or DSN for short) is a string containing
the connection parameters, for example:
<samp>“dbname=test user=postgres password=secret”</samp>
</p>

<form action="manage_addZPsycopgConnection" method="POST">
<div class="form-group row">
<label for="id" class="form-label col-sm-4 col-md-3">Id</label>
<div class="col-sm-8 col-md-9">
<input id="id" class="form-control" type="text" name="id"
<input id="id" class="form-control" type="text" name="id"
placeholder="Psycopg2_database_connection"
value="Psycopg2_database_connection" />
</div>
Expand All @@ -29,7 +26,7 @@
<div class="form-group row">
<label for="title" class="form-label col-sm-4 col-md-3">Title</label>
<div class="col-sm-8 col-md-9">
<input id="title" class="form-control" type="text" name="title"
<input id="title" class="form-control" type="text" name="title"
placeholder="Z Psycopg 2 Database Connection"
value="Z Psycopg 2 Database Connection" />
</div>
Expand All @@ -38,8 +35,8 @@
<div class="form-group row">
<label for="connection_string" class="form-label col-sm-4 col-md-3">Connection string</label>
<div class="col-sm-8 col-md-9">
<input id="connection_string" class="form-control" type="text" name="connection_string"
placeholder="dbname=test user=postgres password=secret"
<input id="connection_string" class="form-control" type="text" name="connection_string"
placeholder="dbname=test user=postgres password=secret"
value="" />
<small>
The basic connection parameters are:
Expand All @@ -62,14 +59,14 @@
<div class="form-group row">
<label for="check" class="form-label col-sm-4 col-md-3">Connect immediately</label>
<div class="col-sm-5 col-md-1">
<input class="btn btn-primary" type="checkbox" id="check" name="check" value="YES" checked="YES" class="form-control"/>
<input class="form-check-input" type="checkbox" id="check" name="check" value="YES" checked="checked" />
</div>
</div>

<div class="form-group row">
<label for="zdatetime" class="form-label col-sm-4 col-md-3">Use Zope's internal DateTime</label>
<div class="col-sm-5 col-md-1">
<input class="btn btn-primary" type="checkbox" id="zdatetime" name="zdatetime" value="YES" checked="YES" class="form-control"/>
<input class="form-check-input" type="checkbox" id="zdatetime" name="zdatetime" value="YES" checked="checked" />
</div>
</div>

Expand All @@ -79,12 +76,12 @@
<select class="form-control" id="tilevel" name="tilevel:int">
<option value="4">Read uncommitted</option>
<option value="1">Read committed</option>
<option value="2" selected="YES">Repeatable read</option>
<option value="2" selected="selected">Repeatable read</option>
<option value="3">Serializable</option>
</select>
<small>
Note: Unless your server is capable of retries (Setting <samp>max-conflict-retries</samp>
in zope.conf), you should not use <samp>repeatable read</samp> or <samp>serializable</samp>,
Note: Unless your server is capable of retries (Setting <samp>max-conflict-retries</samp>
in zope.conf), you should not use <samp>repeatable read</samp> or <samp>serializable</samp>,
because both can produce random errors on contradicting transactions.
</small>
</div>
Expand All @@ -93,25 +90,25 @@
<div class="form-group row">
<label for="autocommit" class="form-label col-sm-4 col-md-3">Auto-commit each query</label>
<div class="col-sm-5 col-md-1">
<input class="btn btn-primary" type="checkbox" id="autocommit" name="autocommit" value="YES" checked="YES" class="form-control"/>
<input class="form-check-input" type="checkbox" id="autocommit" name="autocommit" value="YES" checked="checked" />
</div>
</div>

<div class="form-group row">
<label for="readonlymode" class="form-label col-sm-4 col-md-3">Read-only mode</label>
<div class="col-sm-5 col-md-1">
<input class="btn btn-primary" type="checkbox" id="readonlymode" name="readonlymode" value="YES" checked="YES" class="form-control"/>
<input class="form-check-input" type="checkbox" id="readonlymode" name="readonlymode" value="YES" checked="checked" />
</div>
</div>

<div class="form-group row">
<label for="use_tpc" class="form-label col-sm-4 col-md-3">Use Two-Phase Commit</label>
<div class="col-sm-8 col-md-9">
<input class="btn btn-primary" type="checkbox" id="use_tpc" name="use_tpc" value="YES" checked="YES" class="form-control"/>
<input class="form-check-input" type="checkbox" id="use_tpc" name="use_tpc" value="YES" checked="checked" />
<small class="d-block">
Note: "Two-Phase Commit" uses <samp>PREPARE TRANSACTION</samp>, which
has some limitations (no <samp>NOTIFY</samp> or <samp>LISTEN</samp> is possible),
and needs special provisions to clean up orphaned prepared transactions.
Note: "Two-Phase Commit" uses <samp>PREPARE TRANSACTION</samp>, which
has some limitations (no <samp>NOTIFY</samp> or <samp>LISTEN</samp> is possible),
and needs special provisions to clean up orphaned prepared transactions.
Use with care.
</small>
</div>
Expand All @@ -121,7 +118,7 @@
<label for="encoding" class="form-label col-sm-4 col-md-3">Encoding</label>
<div class="col-sm-8 col-md-9">
<input id="encoding" class="form-control" type="text" name="encoding"
placeholder="UTF-8"
placeholder="UTF-8"
value="" />
</div>
</div>
Expand Down
38 changes: 19 additions & 19 deletions Products/ZPsycopgDA/dtml/edit.dtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

<p class="form-help">
A Zope Psycopg 2 Database Connection is used to connect and execute
queries on a PostgreSQL database. In the form below <em>Connection String</em>
(also called the Data Source Name or DSN for short) is a string containing
the connection parameters, for example:
queries on a PostgreSQL database. In the form below <em>Connection String</em>
(also called the Data Source Name or DSN for short) is a string containing
the connection parameters, for example:
<samp>“dbname=test user=postgres password=secret”</samp>
</p>

<form action="manage_edit" method="POST">
<div class="form-group row">
<label for="title" class="form-label col-sm-4 col-md-3">Title</label>
<div class="col-sm-8 col-md-9">
<input id="title" class="form-control" type="text" name="title"
<input id="title" class="form-control" type="text" name="title"
placeholder="&dtml-title;"
value="&dtml-title;" />
</div>
Expand All @@ -24,7 +24,7 @@
<div class="form-group row">
<label for="connection_string" class="form-label col-sm-4 col-md-3">Connection string</label>
<div class="col-sm-8 col-md-9">
<input id="connection_string" class="form-control" type="text" name="connection_string"
<input id="connection_string" class="form-control" type="text" name="connection_string"
placeholder="dbname=test user=postgres password=secret"
value="&dtml-connection_string;"/>
<small>
Expand All @@ -48,22 +48,22 @@
<div class="form-group row">
<label for="zdatetime" class="form-label col-sm-4 col-md-3">Use Zope's internal DateTime</label>
<div class="col-sm-5 col-md-1">
<input class="btn btn-primary" type="checkbox" id="zdatetime" name="zdatetime" value="YES" checked="YES" class="form-control" <dtml-if expr="zdatetime">checked="YES"</dtml-if>/>
<input class="form-check-input" type="checkbox" id="zdatetime" name="zdatetime" value="YES" <dtml-if expr="zdatetime">checked="checked"</dtml-if>/>
</div>
</div>

<div class="form-group row">
<label for="tilevel" class="form-label col-sm-4 col-md-3">Transaction isolation level</label>
<div class="col-sm-8 col-md-9">
<select id="tilevel" class="form-control" name="tilevel:int">
<option value="4" <dtml-if expr="tilevel==4">selected="YES"</dtml-if>>Read uncommitted</option>
<option value="1" <dtml-if expr="tilevel==1">selected="YES"</dtml-if>>Read committed</option>
<option value="2" <dtml-if expr="tilevel==2">selected="YES"</dtml-if>>Repeatable read</option>
<option value="3" <dtml-if expr="tilevel==3">selected="YES"</dtml-if>>Serializable</option>
<option value="4" <dtml-if expr="tilevel==4">selected="selected"</dtml-if>>Read uncommitted</option>
<option value="1" <dtml-if expr="tilevel==1">selected="selected"</dtml-if>>Read committed</option>
<option value="2" <dtml-if expr="tilevel==2">selected="selected"</dtml-if>>Repeatable read</option>
<option value="3" <dtml-if expr="tilevel==3">selected="selected"</dtml-if>>Serializable</option>
</select>
<small>
Note: Unless your server is capable of retries (Setting <samp>max-conflict-retries</samp>
in zope.conf), you should not use <samp>repeatable read</samp> or <samp>serializable</samp>,
Note: Unless your server is capable of retries (Setting <samp>max-conflict-retries</samp>
in zope.conf), you should not use <samp>repeatable read</samp> or <samp>serializable</samp>,
because both can produce random errors on contradicting transactions.
</small>
</div>
Expand All @@ -73,25 +73,25 @@
<div class="form-group row">
<label for="autocommit" class="form-label col-sm-4 col-md-3">Auto-commit each query</label>
<div class="col-sm-5 col-md-1">
<input class="btn btn-primary" type="checkbox" id="autocommit" name="autocommit" value="YES" checked="YES" class="form-control"/>
<input class="form-check-input" type="checkbox" id="autocommit" name="autocommit" value="YES" <dtml-if expr="autocommit">checked="checked"</dtml-if> />
</div>
</div>

<div class="form-group row">
<label for="readonlymode" class="form-label col-sm-4 col-md-3">Read-only mode</label>
<div class="col-sm-5 col-md-1">
<input class="btn btn-primary" type="checkbox" id="readonlymode" name="readonlymode" value="YES" checked="YES" class="form-control"/>
<input class="form-check-input" type="checkbox" id="readonlymode" name="readonlymode" value="YES" <dtml-if expr="readonlymode">checked="checked"</dtml-if> />
</div>
</div>

<div class="form-group row">
<label for="use_tpc" class="form-label col-sm-4 col-md-3">Use Two-Phase Commit</label>
<div class="col-sm-8 col-md-9">
<input class="btn btn-primary" type="checkbox" id="use_tpc" name="use_tpc" value="YES" checked="YES" class="form-control"/>
<input class="form-check-input" type="checkbox" id="use_tpc" name="use_tpc" value="YES" <dtml-if expr="use_tpc">checked="checked"</dtml-if> />
<small class="d-block">
Note: "Two-Phase Commit" uses <samp>PREPARE TRANSACTION</samp>, which
has some limitations (no <samp>NOTIFY</samp> or <samp>LISTEN</samp> is possible),
and needs special provisions to clean up orphaned prepared transactions.
Note: "Two-Phase Commit" uses <samp>PREPARE TRANSACTION</samp>, which
has some limitations (no <samp>NOTIFY</samp> or <samp>LISTEN</samp> is possible),
and needs special provisions to clean up orphaned prepared transactions.
Use with care.
</small>
</div>
Expand All @@ -100,7 +100,7 @@
<div class="form-group row">
<label for="encoding" class="form-label col-sm-4 col-md-3">Encoding</label>
<div class="col-sm-8 col-md-9">
<input id="encoding" class="form-control" type="text" name="encoding"
<input id="encoding" class="form-control" type="text" name="encoding"
placeholder="UTF-8"
value="&dtml-encoding;" />
</div>
Expand Down

0 comments on commit a0ae436

Please sign in to comment.