source: gutenbach-web/root.py @ 64ee2c9

debianmacno-cupsweb
Last change on this file since 64ee2c9 was 64ee2c9, checked in by Edward Z. Yang <edwardzyang@…>, 15 years ago

Fix bug in volume control involving undefined server variable.
Signed-off-by: Edward Z. Yang <edwardzyang@…>

  • Property mode set to 100644
File size: 1.8 KB
Line 
1"""Main Controller"""
2from sipbmp3web.lib.base import BaseController
3from tg import expose, flash, require, url, request, redirect, validate
4from pylons.i18n import ugettext as _
5from pylons import config
6#from tg import redirect, validate
7from sipbmp3web.model import DBSession, metadata
8from sipbmp3web.controllers.error import ErrorController
9from sipbmp3web import model
10from repoze.what import predicates
11from sipbmp3web.controllers.secure import SecureController
12from remctl import remctl
13import tw.forms as twf
14from sipbmp3web.widgets.slider import UISlider
15
16volume_form = twf.TableForm('volume_form', action='volume', children=[
17    UISlider('volume', min=1, max=31, validator=twf.validators.NotEmpty())
18])
19
20class RootController(BaseController):
21    error = ErrorController()
22
23    @expose('sipbmp3web.templates.index')
24    def index(self, **kw):
25        server = config['sipbmp3.server']
26        out = dict(page="index")
27        volume = int(remctl(server, command=["volume", "get"]).stdout.rstrip())
28        playing = remctl(server, command=["status", "get"]).stdout
29        # Todo: add better parsing
30        if not playing: playing = "Nothing playing"
31        if not "volume" in kw: kw["volume"] = volume
32        return dict(
33                    page="index",
34                    playing=playing,
35                    volume=volume,
36                    volume_form=volume_form,
37                    volume_data=kw,
38                )
39
40    @validate(form=volume_form, error_handler=index)
41    @expose()
42    def volume(self, **kw):
43        server = config['sipbmp3.server']
44        remctl(server, command=["volume", "set", kw["volume"]])
45        redirect('index')
46
47    @expose('sipbmp3web.templates.about')
48    def about(self):
49        return dict(page="about")
50
51    @expose('sipbmp3web.templates.todo')
52    def todo(self):
53        return dict(page="todo")
54
Note: See TracBrowser for help on using the repository browser.