source: gutenbach-web/root.py @ e0a78b1

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

Add quick-and-dirty now playing information.
Signed-off-by: Edward Z. Yang <edwardzyang@…>

  • Property mode set to 100644
File size: 1.7 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 _
5#from tg import redirect, validate
6from sipbmp3web.model import DBSession, metadata
7from sipbmp3web.controllers.error import ErrorController
8from sipbmp3web import model
9from catwalk.tg2 import Catwalk
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
20server = "zygorthian-space-raiders.mit.edu"
21
22class 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        playing = remctl(server, command=["status", "get"]).stdout
31        # Todo: add better parsing
32        if not playing: playing = "Nothing playing"
33        if not "volume" in kw: kw["volume"] = volume
34        return dict(
35                    page="index",
36                    playing=playing,
37                    volume=volume,
38                    volume_form=volume_form,
39                    volume_data=kw,
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')
47
48    @expose('sipbmp3web.templates.about')
49    def about(self):
50        return dict(page="about")
51
Note: See TracBrowser for help on using the repository browser.