| 1 | """Main Controller""" |
|---|
| 2 | from sipbmp3web.lib.base import BaseController |
|---|
| 3 | from tg import expose, flash, require, url, request, redirect, validate |
|---|
| 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 |
|---|
| 12 | from remctl import remctl |
|---|
| 13 | import tw.forms as twf |
|---|
| 14 | from sipbmp3web.widgets.slider import UISlider |
|---|
| 15 | |
|---|
| 16 | volume_form = twf.TableForm('volume_form', action='volume', children=[ |
|---|
| 17 | UISlider('volume', min=1, max=31, validator=twf.validators.NotEmpty()) |
|---|
| 18 | ]) |
|---|
| 19 | |
|---|
| 20 | server = "zygorthian-space-raiders.mit.edu" |
|---|
| 21 | |
|---|
| 22 | class RootController(BaseController): |
|---|
| 23 | admin = Catwalk(model, DBSession) |
|---|
| 24 | error = ErrorController() |
|---|
| 25 | |
|---|
| 26 | @expose('sipbmp3web.templates.index') |
|---|
| 27 | def index(self, **kw): |
|---|
| 28 | out = dict(page="index") |
|---|
| 29 | volume = int(remctl(server, command=["volume", "get"]).stdout.rstrip()) |
|---|
| 30 | if not "volume" in kw: kw["volume"] = volume |
|---|
| 31 | return dict( |
|---|
| 32 | page="index", |
|---|
| 33 | volume=volume, |
|---|
| 34 | volume_form=volume_form, |
|---|
| 35 | volume_data=kw, |
|---|
| 36 | ) |
|---|
| 37 | |
|---|
| 38 | @validate(form=volume_form, error_handler=index) |
|---|
| 39 | @expose() |
|---|
| 40 | def volume(self, **kw): |
|---|
| 41 | remctl(server, command=["volume", "set", kw["volume"]]) |
|---|
| 42 | redirect('index') |
|---|
| 43 | |
|---|
| 44 | @expose('sipbmp3web.templates.about') |
|---|
| 45 | def about(self): |
|---|
| 46 | return dict(page="about") |
|---|
| 47 | |
|---|