moviedemo / moviedemo / controllers /

"""Main Controller"""
from moviedemo.lib.base import BaseController
from tg import expose, flash, require, url, request, redirect
from pylons.i18n import ugettext as _
#from tg import redirect, validate
from moviedemo.model import DBSession, metadata
from moviedemo.controllers.error import ErrorController
from moviedemo import model
from catwalk.tg2 import Catwalk
from repoze.what import predicates
from import SecureController

# =====================================

from tgext.crud import CrudRestController
from moviedemo.model import DBSession, Movie
from sprox.tablebase import TableBase
from sprox.fillerbase import TableFiller

from sprox.formbase import AddRecordForm

class MovieAddForm(AddRecordForm):
    __model__ = Movie
    __omit_fields__ = ['genre_id', 'movie_id']
movie_add_form = MovieAddForm(DBSession)

from sprox.formbase import EditableForm

class MovieEditForm(EditableForm):
    __model__ = Movie
    __omit_fields__ = ['genre_id', 'movie_id']
movie_edit_form = MovieEditForm(DBSession)

from sprox.fillerbase import EditFormFiller

class MovieEditFiller(EditFormFiller):
    __model__ = Movie
movie_edit_filler = MovieEditFiller(DBSession)

#this is de-activated so that the controller uses the Sprox form.
from tw.core import WidgetsList
from tw.forms import TableForm, TextField, CalendarDatePicker, SingleSelectField, TextArea
from formencode.validators import Int, NotEmpty, DateConverter, DateValidator

class MovieForm(TableForm):
    class fields(WidgetsList):
        title = TextField(validator=NotEmpty)
        description = TextArea(attrs=dict(rows=7, cols=50))
        release_date = CalendarDatePicker(validator=DateConverter())
        genrechoices = ((None, '----------'),
        genre = SingleSelectField(options=genrechoices)
_movie_add_form = MovieForm("create_movie_form")
#end deactivation

def email_info():
    print 'emailing'

class MovieTable(TableBase):
    __model__ = Movie
    __omit_fields__ = ['genre_id', 'movie_id']
movie_table = MovieTable(DBSession)

class MovieTableFiller(TableFiller):
    __model__ = Movie
movie_table_filler = MovieTableFiller(DBSession)

from sprox.dojo.tablebase import DojoTableBase
class DojoMovieTable(DojoTableBase):
    __model__ = Movie
    __omit_fields__ = ['genre_id', 'movie_id']
dojo_movie_table = DojoMovieTable(DBSession)

from sprox.dojo.fillerbase import DojoTableFiller
class DojoMovieTableFiller(DojoTableFiller):
    __model__ = Movie
dojo_movie_table_filler = DojoMovieTableFiller(DBSession)

class MovieCrudRestController(CrudRestController):
    model = Movie

    table =  dojo_movie_table
    table_filler = dojo_movie_table_filler
    new_form = movie_add_form
    edit_form = movie_edit_form
    edit_filler = movie_edit_filler
    def post(self, **kw):
        return super(MovieController, self).post(**kw)
    def _post_delete(self, **kw):
        "not allowed"

from sprox.tablebase import TableBase
from sprox.formbase import EditableForm, AddRecordForm
from sprox.fillerbase import TableFiller, EditFormFiller

from tgext.admin import AdminController
class DeclarativeMovieController(CrudRestController):
    model = Movie
    class add_form_type(AddRecordForm):
        __model__ = Movie
        __omit_fields__ = ['genre_id', 'movie_id']

    class edit_form_type(EditableForm):
        __model__ = Movie
        __omit_fields__ = ['genre_id', 'movie_id']

    class edit_filler_type(EditFormFiller):
        __model__ = Movie

    class table_type(TableBase):
        __model__ = Movie
        __omit_fields__ = ['genre_id', 'movie_id']

    class table_filler_type(TableFiller):
        __model__ = Movie