Package Camelot :: Package camelot :: Package admin :: Package form_action :: Class PrintHtmlFormAction |
[frames] | no frames]

# Class PrintHtmlFormAction

source code

    Create an action for a form that pops up a print preview for generated html.
    Overwrite the html function to customize the html that should be shown::

      class PrintMovieAction(PrintHtmlFormAction):

        def html(self, movie):
          html = '<h1>' + movie.title + '</h1>'
          html += movie.description
        return html

      class Movie(Entity):
        title = Field(Unicode(60), required=True)
        description = Field(camelot.types.RichText)

        class Admin(EntityAdmin):
          list_display = ['title', 'description']
          form_actions = [PrintMovieAction('summary')]

    will put a print button on the form :

    .. image:: ../_static/formaction/print_html_form_action.png

    .. attribute:: HtmlDocument the class used to render the html, by default this is
    a QTextDocument, but a QtWebKit.QWebView can be used as well.

Nested Classes
| HtmlDocument QTextDocument(QObject parent=None) QTextDocument(QString, QObject parent=None)

Instance Methods
__init__(self, name, icon=Icon('tango/16x16/actions/document-print.png')) x.__init__(...) initializes x; see x.__class__.__doc__ for signature | source code
html(self, o) Overwrite this function to generate custom html to be printed :arg o: the object that is displayed in the form | source code
run(*args, **kwargs) Overwrite this method to create an action that does something | source code
Inherited from `FormActionFromModelFunction`: `enabled` Inherited from `FormAction`: `get_icon`, `get_name`, `render` Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, name, icon=Icon('tango/16x16/actions/document-print.png')) (Constructor) | source code
x.__init__(...) initializes x; see x.__class__.__doc__ for signature Parameters: `name` - the name of the action `model_function` - a function that has 1 arguments : the object on which to apply the action `icon` - an Icon `flush` - flush the object to the db and refresh it in the views `enabled` - a function that has 1 argument : the object on which the action would be applied Overrides: object.__init__ (inherited documentation)

### run(*args, **kwargs) | source code
Overwrite this method to create an action that does something Decorators: `@gui_function` Overrides: FormAction.run (inherited documentation)