Plone Add-on Gallery

collective.fgrcon.pgeasyform

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

Changelog

1.1 (2019-06-19)

  • Initial release. [fgrcon]