[c203b8]: examples / web_framework / README  Maximize  Restore  History

Download this file

80 lines (57 with data), 3.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
This example automatically generates programs to render HTMLTemplates
(http://py-templates.sourceforge.net/htmltemplate/index.html).

It uses the sqlgen example on the back-end to generate and run SQL statements.
You'll need to first set up the sqlgen example database before using this
example.  Check there for the movie_db schema.  You'll also need the directory
containing the "examples" directory to be on your PYTHONPATH (e.g., if you
downloaded the pyke_examples separately).

This is also an example of using multiple rule bases (its own rule base, and
the sqlgen/database.krb rule base).

This example also caches the plans returned from pyke so it should be extremely
fast!

To run this example:

    >>> import simple_server
    >>> simple_server.run()

Then point your browser at:

    http://localhost:8080/movie/1/movie.html

The "movie/1" says that you're starting with a unique row (id of 1) in the
"movie" table.  The "movie.html" is the name of the HTMLTemplate file you want
to use.  You may specify multiple unique starting tables by pairing the table
name with the id value: "/movie/1/genre/2/movie.html", though this doesn't
make much sense with the example templates...

web.krb
    This uses backward-chaining to build a program to fill an HTMLTemplate.

    The top-level goal is:

        process($starting_tables, $template_name)
        taking (db_cursor, starting_keys)

    The plan returned from this goal returns a three tuple:

        http_status, header_list, html_document

wsgi_app.py
    The WSGI front-end that drives pyke and executes the resulting plans.
    This parses the path from the WSGI environ and creates a plan for the
    combination of starting_tables and template_file, if one hasn't already
    been created by an earlier request, or if the template_file has been
    modified since the last plan for it was created.

    To create the plan, it establishes some of the interesting values in its
    environ as facts, then does the "process" goal above.
    
    The plan returned is run with the specific key to produce the WSGI output.

simple_server.py
    This is just a simple driver to run the wsgi_app as a local http server
    (default port 8080).

test.py
    This is a test driver to let you type goals in and run them to debug the
    rules.

    Test functions:

        init()
            Creates a pyke engine and calls load_mysql_schema.load_schema.
        run()
            Loops on "goal: " prompt.  Type a goal, or trace/untrace rule_name.
            Empty string terminates the loop.  When the plan is returned,
            it enters a loop prompting for a python expression to run the plan
            (the plan itself is in a variable called "plan", and "Db_cursor"
            is a variable containing a database cursor).  For example:
            "plan(Db_cursor, {'movie': 1})".  An empty line terminates the plan
            loop.

movie.html
movie2.html
    Two very simple html templates that you can play with.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks