Wednesday, January 16, 2013

wheezy web: Quick Start i18n Project

wheezy.web is a lightweight, high performance, high concurrency WSGI web framework with the key features to build modern, efficient web. Here we will use an i18n (multilingual internationalization) project quick start to build a new project.
  1. Download quickstart-i18n.zip and extract.
  2. Rename extracted directory `quickstart-i18n` to meet your project name, e.g. mysite and open terminal in that directory.
The i18n project quick start comes with Makefile with several handy targets. Setup development environment:
make env
Internationalization is built using gettext, thus you need extract gettext messages and compile `*.po` files that you can find in i18n directory.
make po
Let run test, look at coverage and finally benchmark tests:
$ make test nose-cover benchmark
....................................
..........
Name                 Stmts   Miss  Cover   Missing
--------------------------------------------------
public                   3      0   100%   
public.web               0      0   100%   
public.web.profile       5      0   100%   
public.web.urls         10      0   100%   
public.web.views        26      0   100%   
--------------------------------------------------
TOTAL                   44      0   100%   
-----------------------------------------------------
Ran 10 tests in 0.458s

OK
public: 5 x 1000
baseline throughput change target
  100.0%    5303rps  +0.0% test_root
   94.4%    5005rps  -5.6% test_home
   98.2%    5206rps  -1.8% test_error_400
   99.2%    5258rps  -0.8% test_error_403
   97.9%    5191rps  -2.1% test_error_404
static: 3 x 1000
baseline throughput change target
  100.0%    5172rps  +0.0% test_static_files
   47.4%    2453rps -52.6% test_static_file_not_found
   52.5%    2715rps -47.5% test_static_file_forbidden
-----------------------------------------------------
Ran 2 tests in 2.286s

OK
The tests are passed let run it in web browser:
$ make run
Visit http://localhost:8080/
Alternatively you can run it using uwsgi
env/bin/easy_install uwsgi
make uwsgi
Enjoy!

6 comments :

  1. I just completed the tutorial from docs (guestbook creation). Looks good to me.

    A few questions:
    - how to handle file uploads?
    - how to build modules/plugins (e.g. flask has blueprints)
    - does it work on appengine?

    ReplyDelete
    Replies
    1. 1. Look at http://packages.python.org/wheezy.http/userguide.html#http-request files attribute.
      2. All you need is a python package to structure your code. Look at here (there are two packages, one for public another one for membership): https://bitbucket.org/akorn/wheezy.web/src/tip/demos/template
      3. Since it WSGI application it is capable to run at any WSGI application server, including mentioned one.

      Delete
    2. For questions not related to this post please email me (see blogger profile).

      Delete
  2. and now a template question:
    why that is not possible?

    index.html
    @{
    a = range(10)
    }

    @for i in a:
    @str(i)
    @end

    1.py
    import os, sys
    current_folder = os.path.dirname(os.path.abspath(__file__))

    from wheezy.html.factory import widget
    from wheezy.template.engine import Engine
    from wheezy.template.loader import FileLoader
    from wheezy.template.ext.core import CoreExtension
    from wheezy.template.ext.code import CodeExtension

    engine = Engine(loader=FileLoader([os.path.join(current_folder, "templates")]), extensions=[CoreExtension(), CodeExtension()])

    print engine.get_template('index.html').render({})

    ReplyDelete
    Replies
    1. Most likely of misprint in your template (notice parentheses for code extension):
      @(
      a = range(10)
      )

      Delete