[973dd91] | 1 | """Main Controller""" |
---|
| 2 | from sipbmp3web.lib.base import BaseController |
---|
[4b9d354] | 3 | from tg import expose, flash, require, url, request, redirect, validate |
---|
[973dd91] | 4 | from pylons.i18n import ugettext as _ |
---|
| 5 | #from tg import redirect, validate |
---|
| 6 | from sipbmp3web.model import DBSession, metadata |
---|
| 7 | from sipbmp3web.controllers.error import ErrorController |
---|
| 8 | from sipbmp3web import model |
---|
| 9 | from catwalk.tg2 import Catwalk |
---|
| 10 | from repoze.what import predicates |
---|
| 11 | from sipbmp3web.controllers.secure import SecureController |
---|
[84ed773] | 12 | from remctl import remctl |
---|
[4b9d354] | 13 | import tw.forms as twf |
---|
| 14 | |
---|
| 15 | volume_form = twf.TableForm('volume_form', action='volume', children=[ |
---|
| 16 | twf.TextField('volume', validator=twf.validators.Int(not_empty=True,min=1,max=31)) |
---|
| 17 | ]) |
---|
| 18 | |
---|
| 19 | server = "zygorthian-space-raiders.mit.edu" |
---|
[973dd91] | 20 | |
---|
| 21 | class RootController(BaseController): |
---|
| 22 | admin = Catwalk(model, DBSession) |
---|
| 23 | error = ErrorController() |
---|
| 24 | |
---|
| 25 | @expose('sipbmp3web.templates.index') |
---|
[4b9d354] | 26 | def index(self, **kw): |
---|
[1998d46] | 27 | out = dict(page="index") |
---|
[4b9d354] | 28 | volume = int(remctl(server, command=["volume", "get"]).stdout.rstrip()) |
---|
| 29 | if not "volume" in kw: kw["volume"] = volume |
---|
| 30 | return dict( |
---|
| 31 | page="index", |
---|
| 32 | volume=volume, |
---|
| 33 | volume_form=volume_form(kw), |
---|
| 34 | ) |
---|
| 35 | |
---|
| 36 | @validate(form=volume_form, error_handler=index) |
---|
| 37 | @expose() |
---|
| 38 | def volume(self, **kw): |
---|
| 39 | remctl(server, command=["volume", "set", kw["volume"]]) |
---|
| 40 | redirect('index') |
---|
[973dd91] | 41 | |
---|
| 42 | @expose('sipbmp3web.templates.about') |
---|
| 43 | def about(self): |
---|
[1998d46] | 44 | return dict(page="about") |
---|
[973dd91] | 45 | |
---|