From: yomguy Date: Thu, 30 Jun 2011 13:02:50 +0000 (+0200) Subject: fix station json method X-Git-Tag: 1.0~74 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=a065c4fb72c76f7c31dfd3e1c4e8c035b6c5efaa;p=telecaster-server.git fix station json method --- diff --git a/telecaster/models.py b/telecaster/models.py index 190a09d..3445ba6 100644 --- a/telecaster/models.py +++ b/telecaster/models.py @@ -135,6 +135,17 @@ class Station(Model): def __str__(self): return ' - '.join(self.description) + ' - ' + str(self.datetime_start) + ' > ' + str(self.datetime_stop) + def to_dict(self): + dict = {'organization': self.organization.name, + 'department': self.department.name, + 'conference': self.conference.title, + 'professor': self.professor.name, + 'session': self.session.name, + 'comment': self.comment, + 'started': str(self.started), + } + return dict + @property def description(self): return [self.organization.name, self.conference.department.name, self.conference.title, self.session.name, self.professor.name, self.comment] diff --git a/telecaster/views.py b/telecaster/views.py index f59eabf..0aab941 100644 --- a/telecaster/views.py +++ b/telecaster/views.py @@ -56,9 +56,8 @@ class WebView(object): self.status = Status() def index(self, request): - status = self.get_status() stations = Station.objects.filter(started=True) - status = self.get_status() + status = self.get_server_status() if stations or (status['writing'] or status['casting']): template = 'telecaster/stop.html' @@ -90,21 +89,29 @@ class WebView(object): return render(request, template, {'station': station, 'status': status, - 'hidden_fields': self.hidden_fields}) + 'hidden_fields': self.hidden_fields, }) - @jsonrpc_method('telecaster.get_status') - def get_status_json(request): + @jsonrpc_method('telecaster.get_server_status') + def get_server_status_json(request): status = Status() status.update() return status.to_dict() - def get_status(self): + def get_server_status(self): status = Status() status.update() return status.to_dict() - + @jsonrpc_method('telecaster.get_station_status') + def get_station_status_json(request): + stations = Station.objects.filter(started=True) + if stations: + station = stations[0].to_dict() + else: + station = {} + return station + class Status(object): interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2','eth3']