Extend collective.easyform with a handler for Postgresql
Project description
This addon extends collective.easyform (https://pypi.org/project/collective.easyform/) providing means to store form data in a postgresql database
Features
New form action: “Postgres Data” and corresponding PostgresDataHandler. Action configuration fields: Database connection string, database table name, decimal separator Example for database connection string: dbname='postgres' user=='postgres',host='localhost' password = 'secret'
when decimal separator is selected, commas are treated as decimal separators as well (helpful with devices)
if the database table does not exist in the database it will be created:
create a postgres data form action
define your form fields
fill out all fields of your form with sample data once and submit the form
the database table will be generated in a way that the plone field ids serve as column names, the postgres data types are mapped accordingly to the python data types of the form fields. A primary key field (serial) with columname “_id_” will be generated automatically. This allows to view and edit the data using tools like pgadmin4 (https://www.pgadmin.org)
Postgres
You can connect to any postgres server (localhost or remote). This addon has been tested with Postgres V 10.
An other easy way to get postgres up and running is to use docker:
Install docker
docker pull postgres:[tag_you_want] tag e. g.110.5
Without .tag this will pull down the latest stable release Postgres image from the official Postgres docker hub repository.
Create a Directory to Serve as the Local Host Mount Point for Postgres Data Files If we want to persist data generated by the Postgres instance running inside a container beyond the container’s lifecycle, we need to map a local mount point as a data volume to an appropriate path inside the container. Typically I create a volumes folder (we can give the folder any name we like) in my homedirectory and then create subfolders for each of the applications I need to create data volume mount points for.
mkdir -p $HOME/docker/volumes/postgres
Run the Postgres Container
docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
Options:
rm: Automatically remove the container and it’s associated file system upon exit. In general, if we are running lots of short term containers, it is good practice to to pass rm flag to the docker run command for automatic cleanup and avoid disk space issues. We can always use the v option (described below) to persist data beyond the lifecycle of a container
name: An identifying name for the container. We can choose any name we want. Note that two existing (even if they are stopped) containers cannot have the same name. In order to re-use a name, you would either need pass the rm flag to the docker run command or explicitly remove the container by using the command docker rm [container name].
e: Expose environment variable of name POSTGRES_PASSWORD with value docker to the container. This environment variable sets the superuser password for PostgreSQL. We can set POSTGRES_PASSWORD to anything we like. I just choose it to be docker for demonstration. There are additional environment variables you can set. These include POSTGRES_USER and POSTGRES_DB. POSTGRES_USER sets the superuser name. If not provided, the superuser name defaults to postgres.POSTGRES_DB sets the name of the default database to setup. If not provided, it defaults to the value of POSTGRES_USER.
d: Launches the container in detached mode or in other words, in the background.
p: Bind port 5432 on localhost to port 5432 within the container. This option enables applications running out side of the container to be able to connect to the Postgres server running inside the container.
v: Mount $HOME/docker/volumes/postgres on the host machine to the container side volume path /var/lib/postgresql/data created inside the container. This ensures that postgres data persists even after the container is removed.
Connect to Postgres
Once the container is up an running, connecting to it from an application is no different than connecting to a Postgres instance running outside a docker container. For example, to connect using psql we can execute
psql -h localhost -U postgres -d postgres
Translations
No translations yet
Installation
Install collective.fgrcon.pgeasyform by adding it to your buildout:
[buildout] ... eggs = collective.fgrcon.pgeasyform
and then running bin/buildout
This addoon requires collective.easyform and psycopg2
Contribute
Support
If you are having issues, please let us know (use the issue tracker or mail to franz@fgrcon.net).
License
The project is licensed under the GPLv2.
Contributors
Franz Gerhard Reinisch, franz@fgrcon.net
Changelog
1.1 (2019-06-19)
Initial release. [fgrcon]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file collective.fgrcon.pgeasyform-1.1.tar.gz
.
File metadata
- Download URL: collective.fgrcon.pgeasyform-1.1.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86e82f6e80fc4bc57fc5101f949831990f42e273dcef967af17d23c9ca414ec9 |
|
MD5 | b9136e4933fec722c638adeb336b2eba |
|
BLAKE2b-256 | c14dc4b28ad6b4c4bdd76e05b3fe21c195f742fbae094e2976e6bccf6b0759bb |