Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install player

How to install player

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install player
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
0.3
0.6.1Never BuiltWhy not?
0.3 Available View build log
Linux (32-bit)
0.3
0.6.1Never BuiltWhy not?
0.3 Available View build log
0.3
0.6.1Never BuiltWhy not?
0.3 Available View build log
Linux (64-bit)
0.6.1 Available View build log
0.3 Available View build log
0.3
0.6.1Never BuiltWhy not?
0.3 Available View build log
0.6.1 Available View build log
 
Author
License
BSD
Depended by
Imports
Lastest release
version 0.6.1 on Sep 20th, 2013

player

https://travis-ci.org/fafhrd91/player.png

player allows to address templates with two parameters, category and name. Also it is possible to use set of directories for each layer, in that case player searches templates in each directory. It allows to override templates without changing code. For example form library can define layer field:

>> ls ./fields/
.. bool.pt
.. file.pt
...
.. textarea.pt

In your application you can override any of this template by defining new layer for field category:

>> ls ./myproject/fields/
.. bool.pt

Usually top level directory is a category and file in directory is template. For example 'form:view.lt':

`form` - layer category
`view` - template name
`.lt`  - custom pyramid renderer factory

Layer can to be defined with add_layer config directive:

System Message: ERROR/3 (<string>, line 34)

Unknown directive type "code-block".

.. code-block:: python

    >> config = Configurator()
    .. config.include('player')
    ..
    .. config.add_layer('form', path='./path_to_form_dirctory/form/')

form directory can contain any template:

System Message: ERROR/3 (<string>, line 43)

Unknown directive type "code-block".

.. code-block:: python

    >> ./form/
    ..   view.pt
    ..   actions.jinja2

It is possible to use any of this templates as pyramid renderer path:

System Message: ERROR/3 (<string>, line 51)

Unknown directive type "code-block".

.. code-block:: python

    >> config.add_view(
    ..     name='view.html',
    ..     renderer='form:view.lt')

or :

System Message: ERROR/3 (<string>, line 59)

Unknown directive type "code-block".

.. code-block:: python

    >> config.add_view(
    ..     name='actions.html',
    ..     renderer='form:actions.lt')


It is possible to run python code before rendering template. There are add_tmpl_filter directive and player.tmpl_filter decorator:

System Message: ERROR/3 (<string>, line 70)

Unknown directive type "code-block".

.. code-block:: python

    >> def form_actions(context, request):
    ..     return {'url': ...}

    >> config.add_tmpl_filter('form:actions', form_action, name='custom')

or:

System Message: ERROR/3 (<string>, line 79)

Unknown directive type "code-block".

.. code-block:: python

    >> import player

    >> @player.tmpl_filter('form:actions', name='custom')
    .. def form_actions(context, request):
    ..     return {'url': ...}

form_actions function gets call just before rendering template. Layer has to be defined with add_layer directve before registering template filter function.

Customization

Any number of layer categories can be registered and any number of layers can be registered in each category. It doesnt require to override all templates from category. For example it is possible to override just view.pt template:

>> config.add_layer('form', 'custom', path='path_to_form_directory_2/form')

and content of this new directory:

>> ./another_path/form/
..   view.jinja2

Now view view.html uses view.jinja2 template. But actions.html stil uses original template.

Another example, if you want customize bool field from ptah.form package all you need is to create some folder, add it as 'fields' layer, and put bool.pt template to this folder, something like that:

>> config.add_layer('fields', 'custom', 'mypackage:fields')

and

>> .mypackage/fields/
..    bool.pt
Request method

player also provides request method render_tmpl. It acccepts path:

..  ${structure: request.render_tmpl('form:actions')

.lt extension is optional in this case.

player

...

License

player is offered under the BSD license.

CHANGES

0.6.1 (01-22-2013)
  • Added python 2.6
0.6 (12-10-2012)
  • Allow to use standard renderers in render function
0.5 (11-30-2012)
  • Use jinja2 for templates
  • Added layout_data request property
  • Allow to pass several messages to error message
0.4 (11-12-2012)
  • Added player.layout renderer
  • Added -c argument to player console script, it allows to customize templates
  • set_layout_data accepts keyword arguments
  • Removed player.wrap_layout()
  • Removed python2.6 support
0.3 (11-07-2012)
  • Added set_layout_data request method, allow to set global layout options
  • Added status messages
  • Added formatters
0.2 (11-01-2012)
  • Added layout subsystem
0.1 (10-30-2012)
  • Initial release

Subscribe to package updates

Last updated Sep 20th, 2013

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.