[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 _ |
---|
[6ab0b45] | 5 | from pylons import config |
---|
[973dd91] | 6 | #from tg import redirect, validate |
---|
| 7 | from sipbmp3web.model import DBSession, metadata |
---|
| 8 | from sipbmp3web.controllers.error import ErrorController |
---|
| 9 | from sipbmp3web import model |
---|
| 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 | |
---|
[973dd91] | 20 | class RootController(BaseController): |
---|
| 21 | error = ErrorController() |
---|
| 22 | |
---|
| 23 | @expose('sipbmp3web.templates.index') |
---|
[4b9d354] | 24 | def index(self, **kw): |
---|
[6ab0b45] | 25 | server = config['sipbmp3.server'] |
---|
[1998d46] | 26 | out = dict(page="index") |
---|
[4b9d354] | 27 | volume = int(remctl(server, command=["volume", "get"]).stdout.rstrip()) |
---|
[c283cb9] | 28 | playing = remctl(server, command=["status", "get"]).stdout |
---|
| 29 | # Todo: add better parsing |
---|
| 30 | if not playing: playing = "Nothing playing" |
---|
[4b9d354] | 31 | if not "volume" in kw: kw["volume"] = volume |
---|
| 32 | return dict( |
---|
| 33 | page="index", |
---|
[c283cb9] | 34 | playing=playing, |
---|
[4b9d354] | 35 | volume=volume, |
---|
[0b8c868] | 36 | volume_form=volume_form, |
---|
| 37 | volume_data=kw, |
---|
[4b9d354] | 38 | ) |
---|
| 39 | |
---|
| 40 | @validate(form=volume_form, error_handler=index) |
---|
| 41 | @expose() |
---|
| 42 | def volume(self, **kw): |
---|
[64ee2c9] | 43 | server = config['sipbmp3.server'] |
---|
[4b9d354] | 44 | remctl(server, command=["volume", "set", kw["volume"]]) |
---|
| 45 | redirect('index') |
---|
[973dd91] | 46 | |
---|
| 47 | @expose('sipbmp3web.templates.about') |
---|
| 48 | def about(self): |
---|
[1998d46] | 49 | return dict(page="about") |
---|
[973dd91] | 50 | |
---|
[0603e20] | 51 | @expose('sipbmp3web.templates.todo') |
---|
| 52 | def todo(self): |
---|
| 53 | return dict(page="todo") |
---|
| 54 | |
---|