Skip to main content

This package contains Django's CBVs adapted to use with Tornado framework.

Project description

Django’s CBVs adapted to be used with Tornado along with SQLAlchemy and WTForms. It’s highly recomended to read the docs here first: https://github.com/BeardyBear/tornado-generic-handlers

Changelog

0.2: new handler - DeleteHandler
0.2.5: fixed missing context in ProcessFormHandler

Configuration

The only requirement is SQLAlchemy’s session stored in application’s db attribute.

from sqlalchemy.orm import scoped_session, sessionmaker

class Application(tornado.web.Application):
    def __init__(self):
        self.db = scoped_session(sessionmaker(bind=engine))

Basic usage

from torgen.base import TemplateHandler
from torgen.list import ListHandler
from torgen.detail import DetailHandler
from torgen.edit import FormHandler, DeleteHandler
from my_alchemy_models import Post
from my_wtforms import LoginForm

class HomeHandler(TemplateHandler):
    template_name = 'home.html'

class BlogHandler(ListHandler):
    template_name = 'blog.html'
    paginate_by = 10
    context_object_name = 'post_list'
    model = Post

class PostHandler(DetailHandler):
    template_name = 'post.html'
    model = Post
    context_object_name = 'post'

class LoginHandler(FormHandler):
    template_name = 'login.html'
    form_class = LoginForm
    success_url = '/'

    def form_valid(self, form):
        self.set_secure_cookie('user', form.data['username'])
        return super(LoginHandler, self).form_valid(form)

class DeletePostHandler(DeleteHandler):
    template_name = 'confirm_delete.html'
    model = Post
    success_url = '/blog/'

Installation

Using pip:

$ pip install torgen

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for torgen, version 0.2.5
Filename, size & hash File type Python version Upload date
torgen-0.2.5.tar.gz (5.9 kB) View hashes Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page