cubicweb-preview


Namecubicweb-preview JSON
Version 3.0.0 PyPI version JSON
download
home_pagehttps://www.cubicweb.org/project/cubicweb-preview
SummaryEnables adding a preview button in your forms
upload_time2023-08-10 15:00:56
maintainer
docs_urlNone
authorLOGILAB S.A. (Paris, FRANCE)
requires_python
licenseLGPL
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            General description
===================

Preview cube adds the ability to preview the effect of a form submission.

The main idea is:

* submit the form data to a special controller, that will
  insert / update data in the database transaction, as normal

* generate the preview

* rollback the database changes to leave the database unchanged

The only exceptions to this rules are downloadable entities, like images : when
an html page (as a preview example view) that contains newly created / updated
images is rendered, the actual image content is queried by users' browser a
while after the above-mentionned database rollback was performed. The solution
adopted in this cube is to save such contents on the disk, and keep it for some
time (that can be set using the preview-time option) so that it can be previewed
and clean it up afterwards.

Usage
=====

Simplest usage concerns automatic entity forms, where you generally want to
preview the just created or updated entity : in this case, import
PreviewFormMixin from cubicweb_preview.utils and make your form inherit it :
you're done. For example, to apply it to all AutomaticEntityForm forms, use::

 from cubicweb.selectors import yes
 from cubicweb_web.views.autoform import AutomaticEntityForm
 from cubicweb_preview.views.forms import PreviewFormMixin

 class PreviewAutomaticEntityForm(PreviewFormMixin, AutomaticEntityForm):
     __select__ = AutomaticEntityForm.__select__ & yes()

You can of course customize the preview, using PreviewFormMixin preview_vid
and preview_rql attributes, that will be used by the controller to create a
result set (using preview_rql, if not None) and apply a view (which name is
preview_vid value, default to "index") to it.

Below is an example for a CubicWeb instance using the file and preview cubes,
that can be used to preview the list of all images when you add or edit one :
we request all images through the preview_rql setting and display them using
the primary view ::

  from cubicweb.selectors import is_instance
  from cubicweb_web.views.autoform import AutomaticEntityForm
  from cubicweb_preview.views.forms import PreviewFormMixin

  class ImageForm(PreviewFormMixin, AutomaticEntityForm):
     __select__ = AutomaticEntityForm.__select__ & is_instance('Image')
     preview_vid = 'primary'
     preview_rql = 'Any X WHERE X is Image'
     preview_mode = 'inline'

Note that the previously created images are stored in the database while the
previewed one is temporarily stored on disk. By default, the previewed image
will be kept for one hour on disk, which can be set using the preview-store-time
option.

The `preview_mode` attribute accepts `newtab` (the default, opening
the preview in a new browser windows/tab within a custom template), or
`inline` (will show the preview below the form).



Authors
=======

This cube has been written by SecondWeb S.A.S. and is now maintained
and developped by Logilab S.A.

License
=======

This cube is distributed under the LGPL-2 license.

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.cubicweb.org/project/cubicweb-preview",
    "name": "cubicweb-preview",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "LOGILAB S.A. (Paris, FRANCE)",
    "author_email": "contact@logilab.fr",
    "download_url": "https://files.pythonhosted.org/packages/3f/57/99059b96a8d6085a99955baf3509c21306fb02fa5c56d598dedcfbece9fd/cubicweb-preview-3.0.0.tar.gz",
    "platform": null,
    "description": "General description\n===================\n\nPreview cube adds the ability to preview the effect of a form submission.\n\nThe main idea is:\n\n* submit the form data to a special controller, that will\n  insert / update data in the database transaction, as normal\n\n* generate the preview\n\n* rollback the database changes to leave the database unchanged\n\nThe only exceptions to this rules are downloadable entities, like images : when\nan html page (as a preview example view) that contains newly created / updated\nimages is rendered, the actual image content is queried by users' browser a\nwhile after the above-mentionned database rollback was performed. The solution\nadopted in this cube is to save such contents on the disk, and keep it for some\ntime (that can be set using the preview-time option) so that it can be previewed\nand clean it up afterwards.\n\nUsage\n=====\n\nSimplest usage concerns automatic entity forms, where you generally want to\npreview the just created or updated entity : in this case, import\nPreviewFormMixin from cubicweb_preview.utils and make your form inherit it :\nyou're done. For example, to apply it to all AutomaticEntityForm forms, use::\n\n from cubicweb.selectors import yes\n from cubicweb_web.views.autoform import AutomaticEntityForm\n from cubicweb_preview.views.forms import PreviewFormMixin\n\n class PreviewAutomaticEntityForm(PreviewFormMixin, AutomaticEntityForm):\n     __select__ = AutomaticEntityForm.__select__ & yes()\n\nYou can of course customize the preview, using PreviewFormMixin preview_vid\nand preview_rql attributes, that will be used by the controller to create a\nresult set (using preview_rql, if not None) and apply a view (which name is\npreview_vid value, default to \"index\") to it.\n\nBelow is an example for a CubicWeb instance using the file and preview cubes,\nthat can be used to preview the list of all images when you add or edit one :\nwe request all images through the preview_rql setting and display them using\nthe primary view ::\n\n  from cubicweb.selectors import is_instance\n  from cubicweb_web.views.autoform import AutomaticEntityForm\n  from cubicweb_preview.views.forms import PreviewFormMixin\n\n  class ImageForm(PreviewFormMixin, AutomaticEntityForm):\n     __select__ = AutomaticEntityForm.__select__ & is_instance('Image')\n     preview_vid = 'primary'\n     preview_rql = 'Any X WHERE X is Image'\n     preview_mode = 'inline'\n\nNote that the previously created images are stored in the database while the\npreviewed one is temporarily stored on disk. By default, the previewed image\nwill be kept for one hour on disk, which can be set using the preview-store-time\noption.\n\nThe `preview_mode` attribute accepts `newtab` (the default, opening\nthe preview in a new browser windows/tab within a custom template), or\n`inline` (will show the preview below the form).\n\n\n\nAuthors\n=======\n\nThis cube has been written by SecondWeb S.A.S. and is now maintained\nand developped by Logilab S.A.\n\nLicense\n=======\n\nThis cube is distributed under the LGPL-2 license.\n",
    "bugtrack_url": null,
    "license": "LGPL",
    "summary": "Enables adding a preview button in your forms",
    "version": "3.0.0",
    "project_urls": {
        "Homepage": "https://www.cubicweb.org/project/cubicweb-preview"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b4f1e6d0cbb66c570afd60ccca425eb7be4f7b4399b6522f5c8713d5564855e",
                "md5": "ea331744338372d05aecfb035adcfa0d",
                "sha256": "aa780ebb976e16501869dbbf5a769a131cef9445333b57dc07da816dd9405c37"
            },
            "downloads": -1,
            "filename": "cubicweb_preview-3.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ea331744338372d05aecfb035adcfa0d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 19676,
            "upload_time": "2023-08-10T15:00:54",
            "upload_time_iso_8601": "2023-08-10T15:00:54.950051Z",
            "url": "https://files.pythonhosted.org/packages/8b/4f/1e6d0cbb66c570afd60ccca425eb7be4f7b4399b6522f5c8713d5564855e/cubicweb_preview-3.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3f5799059b96a8d6085a99955baf3509c21306fb02fa5c56d598dedcfbece9fd",
                "md5": "e60dcf839aafed5ba6d0081c8cdc6e6c",
                "sha256": "e59457f7da38d6eb3d6eddbf7ee1d4d484e4c4bf24d577c7f08d4f7506799990"
            },
            "downloads": -1,
            "filename": "cubicweb-preview-3.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e60dcf839aafed5ba6d0081c8cdc6e6c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 23017,
            "upload_time": "2023-08-10T15:00:56",
            "upload_time_iso_8601": "2023-08-10T15:00:56.671357Z",
            "url": "https://files.pythonhosted.org/packages/3f/57/99059b96a8d6085a99955baf3509c21306fb02fa5c56d598dedcfbece9fd/cubicweb-preview-3.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-10 15:00:56",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "cubicweb-preview"
}
        
Elapsed time: 0.11985s