Differences between revisions 1 and 2
Revision 1 as of 2013-07-17 06:58:49
Size: 1093
Editor: IanRees
Comment:
Revision 2 as of 2013-07-17 07:00:15
Size: 1107
Editor: IanRees
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
# EMEN2 Extensions # EMEN2 Extensions #
Line 27: Line 27:
    @View.add_matcher(r'^/example/square/(?P<name>[^/]*)/$')
    def example_test(self, name):
    @View.add_matcher(r'^/example/square/(?P<value>[^/]*)/$')
    def example_test(self, value):
Line 31: Line 31:
        name_square = int(name) ** 2
        self.ctxt['name'] = name
        self.ctxt['name_square'] = name_square
        value_square = int(value) ** 2
        self.ctxt['value'] = value
        self.ctxt['value_square'] = name_square
Line 45: Line 45:
<p>The name argument was: ${name}</p> <p>The value argument was: ${value}</p>
Line 47: Line 47:
<p>The name argument squared is ${name_square}, or ${int(name)**2}</p> <p>The value argument squared is ${value_square}, or ${int(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_square = int(value) ** 2
        self.ctxt['value'] = value
        self.ctxt['value_square'] = name_square

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 ${int(value)**2}</p>

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

import example

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