source: gutenbach-web/root.py @ 6388b71

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

Make it work with TG2rc1.
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 _
5#from tg import redirect, validate
6from sipbmp3web.model import DBSession, metadata
7from sipbmp3web.controllers.error import ErrorController
8from sipbmp3web import model
9from repoze.what import predicates
10from sipbmp3web.controllers.secure import SecureController
11from remctl import remctl
12import tw.forms as twf
13from sipbmp3web.widgets.slider import UISlider
14
15volume_form = twf.TableForm('volume_form', action='volume', children=[
16    UISlider('volume', min=1, max=31, validator=twf.validators.NotEmpty())
17])
18
19server = "zygorthian-space-raiders.mit.edu"
20
21class RootController(BaseController):
22    error = ErrorController()
23
24    @expose('sipbmp3web.templates.index')
25    def index(self, **kw):
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        remctl(server, command=["volume", "set", kw["volume"]])
44        redirect('index')
45
46    @expose('sipbmp3web.templates.about')
47    def about(self):
48        return dict(page="about")
49
50    @expose('sipbmp3web.templates.todo')
51    def todo(self):
52        return dict(page="todo")
53
Note: See TracBrowser for help on using the repository browser.