Differences between revisions 2 and 3
Revision 2 as of 2013-07-17 07:00:15
Size: 1107
Editor: IanRees
Comment:
Revision 3 as of 2013-07-17 07:00:51
Size: 1089
Editor: IanRees
Comment:
Deletions are marked like this. Additions are marked like this.
Line 31: Line 31:
        value_square = int(value) ** 2         value = int(value)
Line 33: Line 33:
        self.ctxt['value_square'] = name_square         self.ctxt['value_square'] = value ** 2
Line 47: Line 47:
<p>The value argument squared is ${value_square}, or ${int(value)**2}</p> <p>The value argument squared is ${value_square}, or ${value**2}</p>

**Note**: More to come...

The EMEN2 web interface can be extended fairly easily.

First, create a directory with the following structure:

<ext>/
     /__init__.py
     /views/
     /views/__init__.py
     /views/example.py
     /templates/
     /templates/example/
     /templates/example/example.mako

In example.py:

from emen2.web.view import View

@View.register
class ExampleView(View):
    @View.add_matcher(r'^/example/square/(?P<value>[^/]*)/$')
    def example_test(self, value):
        self.title = 'Example extension'
        self.template = '/example/example'
        value = int(value)
        self.ctxt['value'] = value
        self.ctxt['value_square'] = value ** 2

In example.mako:

<%inherit file="/page" />

<h1>Example</h1>

<p>This is an example of how to create a view and template.</p>

<p>The value argument was: ${value}</p>

<p>The value argument squared is ${value_square}, or ${value**2}</p>

And finally, in <ext>/views/init.py:

import example

EMEN2/Extensions (last edited 2013-07-17 07:00:51 by IanRees)