[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 |
---|
[0b8c868] | 14 | from sipbmp3web.widgets.slider import UISlider |
---|
[4b9d354] | 15 | |
---|
| 16 | volume_form = twf.TableForm('volume_form', action='volume', children=[ |
---|
[0b8c868] | 17 | UISlider('volume', min=1, max=31, validator=twf.validators.NotEmpty()) |
---|
[4b9d354] | 18 | ]) |
---|
| 19 | |
---|
| 20 | server = "zygorthian-space-raiders.mit.edu" |
---|
[973dd91] | 21 | |
---|
| 22 | class RootController(BaseController): |
---|
| 23 | admin = Catwalk(model, DBSession) |
---|
| 24 | error = ErrorController() |
---|
| 25 | |
---|
| 26 | @expose('sipbmp3web.templates.index') |
---|
[4b9d354] | 27 | def index(self, **kw): |
---|
[1998d46] | 28 | out = dict(page="index") |
---|
[4b9d354] | 29 | volume = int(remctl(server, command=["volume", "get"]).stdout.rstrip()) |
---|
[c283cb9] | 30 | playing = remctl(server, command=["status", "get"]).stdout |
---|
| 31 | # Todo: add better parsing |
---|
| 32 | if not playing: playing = "Nothing playing" |
---|
[4b9d354] | 33 | if not "volume" in kw: kw["volume"] = volume |
---|
| 34 | return dict( |
---|
| 35 | page="index", |
---|
[c283cb9] | 36 | playing=playing, |
---|
[4b9d354] | 37 | volume=volume, |
---|
[0b8c868] | 38 | volume_form=volume_form, |
---|
| 39 | volume_data=kw, |
---|
[4b9d354] | 40 | ) |
---|
| 41 | |
---|
| 42 | @validate(form=volume_form, error_handler=index) |
---|
| 43 | @expose() |
---|
| 44 | def volume(self, **kw): |
---|
| 45 | remctl(server, command=["volume", "set", kw["volume"]]) |
---|
| 46 | redirect('index') |
---|
[973dd91] | 47 | |
---|
| 48 | @expose('sipbmp3web.templates.about') |
---|
| 49 | def about(self): |
---|
[1998d46] | 50 | return dict(page="about") |
---|
[973dd91] | 51 | |
---|