From 0c636403a78218b7b1f3ad8fa3ffadb3be567d25 Mon Sep 17 00:00:00 2001 From: yomguy Date: Wed, 7 Mar 2012 18:17:07 +0100 Subject: [PATCH] try to go to full json interface.. --- telecaster/htdocs/js/application.js | 78 +++++++++++++ telecaster/models.py | 49 +++++---- telecaster/templates/telecaster/index.html | 121 +++++++++++++++++++++ telecaster/urls.py | 3 +- telecaster/views.py | 69 +++++------- 5 files changed, 256 insertions(+), 64 deletions(-) create mode 100644 telecaster/templates/telecaster/index.html diff --git a/telecaster/htdocs/js/application.js b/telecaster/htdocs/js/application.js index 14b4d10..cf04c20 100644 --- a/telecaster/htdocs/js/application.js +++ b/telecaster/htdocs/js/application.js @@ -171,3 +171,81 @@ function server_status_callback(){ refresh(); setInterval(refresh,d); }; + +function station_status(){ + var j = json; //global variable + var data = j({},"telecaster.station_status", + function(data){ + var res = data.result; + return res; + }, + function(){ + return false; + } + ); +}; + + + +var playlistUtils = { + playlists : [], + + /** + * Returns an uniqid by creating the current local time in millisecond + a random number. Used for markers and some json calls + * Copied from Timeside.utils.uniqid (Timeside might NOT ALWAYS be loaded, see home.html when user is authenitcated) + **/ + + uniqid : function() { + var d = new Date(); + return new String(d.getTime() + '' + Math.floor(Math.random() * 1000000)).substr(0, 18); + }, + + start : function(dictionary){ + + if(dictionary.public_id===undefined){ + dictionary.public_id = this.uniqid(); //defined in application.js + } + json([dictionary],'telemeta.start',function(){ + station_status(); + }); + }, + + showForm: function(anchorElement, id){ + + var o = 'organization'; + var d = 'department'; + var d = 'department'; + + var dd = {}; + var playlist = this; + + var playlists = this.playlists; + for (var i=0; i< playlists.length; i++){ + if (playlists[i].id == id){ + dd[t] = playlists[i].title; + dd[d] = playlists[i].description; + } + } + + new PopupDiv({ + 'content':dd, + invoker:anchorElement, + showOk:true, + onOk:function(data){ + if(!data[t] && !data[d]){ + return; + } + //convert language + playlist.update({ + 'public_id': id, + 'title': data[t], + 'description': data[d], + }); + } + }).show(); + }, + +} + + + diff --git a/telecaster/models.py b/telecaster/models.py index 6dd369a..012d39e 100644 --- a/telecaster/models.py +++ b/telecaster/models.py @@ -132,22 +132,18 @@ add_introspection_rules([], ["^telecaster\.models\.ShortTextField"]) class Station(Model): - organization = ForeignKey(Organization, related_name='stations', verbose_name='organization', - null=True, on_delete=models.SET_NULL) - department = ForeignKey(Department, related_name='stations', verbose_name='department', - null=True, on_delete=models.SET_NULL) - conference = ForeignKey(Conference, related_name='stations', verbose_name='conference', - null=True, on_delete=models.SET_NULL) - session = ForeignKey(Session, related_name='stations', verbose_name='session', - null=True, blank=True, on_delete=models.SET_NULL) - professor = ForeignKey(Professor, related_name='stations', verbose_name='professor', - null=True, blank=True, on_delete=models.SET_NULL) - professor_free = CharField(_('professor'), max_length=255, blank=True) + public_id = CharField(_('public_id'), max_length=255, required=True) + organization = CharField(_('organization'), max_length=255, blank=True) + department = CharField(_('department'), max_length=255, blank=True) + conference = CharField(_('conference'), max_length=255, blank=True) + session = CharField(_('session'), max_length=255, blank=True) + professor = CharField(_('professor'), max_length=255, blank=True) comment = ShortTextField(_('comments'), blank=True) started = BooleanField(_('started')) datetime_start = DateTimeField(_('time_start'), blank=True, null=True) datetime_stop = DateTimeField(_('time_stop'), blank=True, null=True) + class Meta: db_table = app_label + '_' + 'station' @@ -155,11 +151,12 @@ class Station(Model): return ' - '.join(self.description) + ' - ' + str(self.datetime_start) + ' > ' + str(self.datetime_stop) def to_dict(self): - dict = [ {'id':'organization','value': self.organization.name, 'class':'', 'label':'Organization'}, - {'id': 'department', 'value': self.department.name , 'class':'', 'label':'Departement'}, - {'id' : 'conference', 'value': self.conference.title, 'class':'' , 'label': 'Conference'}, - {'id': 'professor', 'value': self.professor.name, 'class':'' , 'label': 'Professor'}, - {'id': 'session', 'value': self.session.name, 'class':'' , 'label': 'Session'}, + dict = [{'id':'public_id','value': self.public_id, 'class':'', 'label':'public_id'}, + {'id':'organization','value': self.organization, 'class':'', 'label':'Organization'}, + {'id': 'department', 'value': self.department , 'class':'', 'label':'Departement'}, + {'id' : 'conference', 'value': self.conference, 'class':'' , 'label': 'Conference'}, + {'id': 'professor', 'value': self.professor, 'class':'' , 'label': 'Professor'}, + {'id': 'session', 'value': self.session, 'class':'' , 'label': 'Session'}, {'id': 'comment', 'value': self.comment, 'class':'' , 'label': 'Comment'}, {'id': 'started', 'value': str(self.started), 'class':'' , 'label': 'Started'}, ] @@ -167,11 +164,11 @@ class Station(Model): @property def description(self): - description = [self.organization.name, self.conference.department.name, self.conference.title] + description = [self.organization, self.conference.department, self.conference] if self.session: - description.append(self.session.name) + description.append(self.session) if self.professor: - description.append(self.professor.name) + description.append(self.professor) description.append(self.comment) return description @@ -194,12 +191,12 @@ class Station(Model): self.ogg_quality = self.conf['media']['ogg_quality'] self.format = self.conf['media']['format'] self.channels = int(self.conf['media']['channels']) - self.server_name = [self.organization.name, self.conference.department.name, self.conference.title] + self.server_name = [self.organization, self.department, self.conference] self.ServerDescription = clean_string('-'.join(self.description)) self.ServerName = clean_string('_-_'.join(self.server_name)) self.mount_point = self.ServerName + '.' + self.format self.filename = clean_string('_-_'.join(self.description[1:])) + '-' + self.time_txt + '.' + self.format - self.output_dir = self.rec_dir + os.sep + self.date + os.sep + self.conference.department.name + self.output_dir = self.rec_dir + os.sep + self.date + os.sep + self.department self.file_dir = self.output_dir + os.sep + self.ServerName self.uid = os.getuid() self.deefuzzer_pid = get_pid('/usr/bin/deefuzzer '+self.deefuzzer_user_file, self.uid) @@ -314,6 +311,7 @@ class Station(Model): # self.deefuzzer_setup() # self.deefuzzer_write_conf() # self.deefuzzer_start() + self.save() def stop(self): self.started = False @@ -321,6 +319,15 @@ class Station(Model): # self.rec_stop() # time.sleep(2) # self.deefuzzer_stop() + self.save() + + def configure(self, dict): + self.organization = dict['organization'] + self.department = dict['department'] + self.session = dict['session'] + self.professor = dict['professor'] + self.comment = dict['comment'] + self.save() class Record(Model): diff --git a/telecaster/templates/telecaster/index.html b/telecaster/templates/telecaster/index.html new file mode 100644 index 0000000..6980f93 --- /dev/null +++ b/telecaster/templates/telecaster/index.html @@ -0,0 +1,121 @@ + +{% load telecaster_utils %} +{% load i18n %} + + + +TeleCaster - {{ self.title }} + + + + +{% block javascript %} + + + +{% endblock javascript %} + + + + + +
+ +
+logo_telecaster +
 TeleCaster
+
+ +{% block hardware %} +
+
Status
+ +{% block video %} +
+ +
+{% endblock video %} + +
+
+ +
+
+{% endblock hardware %} + +{% block message %} +{% if messages %} + +{% endif %} +{% endblock message %} + +{% block content %} +
+ +
{% csrf_token %} + + + {% for field in station %} + + {% if field.errors %}{% endif %} + {% if not field.html_name in hidden_fields %} + + {% else %} + + {% endif %} + + {% endfor %} +
{% for error in form.non_field_errors %}
  • {{ error }}
  • {% endfor %}
    {{ field.errors }}
    {% trans field.label_tag %}:{{ field }}{{ field.label_tag.as_hidden }}{{ field.as_hidden }}
    +
    + +
    +{% endblock content %} + +{% block buttons %} +
    + Record + Play Live + Archives + Trash +
    +{% endblock buttons %} + +
    TeleCaster 0.6 © 2011 Parisson SARL. {% trans "All rights reserved" %}
    + + + + + + diff --git a/telecaster/urls.py b/telecaster/urls.py index d0fcdc4..e88990d 100644 --- a/telecaster/urls.py +++ b/telecaster/urls.py @@ -43,12 +43,11 @@ import os.path # initialization -web_view = WebView(settings.TELECASTER_CONF) +web_view = WebView() htdocs = os.path.dirname(__file__) + '/htdocs' urlpatterns = patterns('', url(r'^$', web_view.index, name="telecaster-index"), - url(r'^record/$', web_view.record, name="telecaster-record"), url(r'^items/(?P.*)$', web_view.index, name="telecaster-item"), # CSS+Images (FIXME: for developement only) diff --git a/telecaster/views.py b/telecaster/views.py index 6de23a9..504e8fd 100644 --- a/telecaster/views.py +++ b/telecaster/views.py @@ -37,7 +37,7 @@ def render(request, template, data = None, mimetype = None): class WebView(object): - hidden_fields = ['started', 'datetime_start', 'datetime_stop'] + hidden_fields = ['started', 'datetime_start', 'datetime_stop', 'public_id'] def __init__(self, conf_file): self.uid = os.getuid() @@ -45,7 +45,7 @@ class WebView(object): self.user_dir = '/home' + os.sep + self.user + os.sep + '.telecaster' if not os.path.exists(self.user_dir): os.makedirs(self.user_dir) - self.conf_file = conf_file + self.conf_file = settings.TELECASTER_CONF conf_dict = xml2dict(self.conf_file) self.conf = conf_dict['telecaster'] self.title = self.conf['infos']['name'] @@ -54,44 +54,15 @@ class WebView(object): self.url = self.conf['infos']['url'] self.status = Status() - def index(self, request, id=None): + def index(self, request): + template = 'telecaster/index.html' stations = Station.objects.filter(started=True) if stations: - # FIXME: manage multiple stations - template = 'telecaster/stop.html' - if id: - station = Station.objects.get(id=id) - else: - station = stations[0] - if request.method == 'POST': - station.stop() -# time.sleep(2) - station.save() - self.logger.write_info('stop') - return HttpResponseRedirect('/telecaster/record') - else: - return render(request, template, {'station': station, 'hidden_fields': self.hidden_fields, 'host': self.get_host(request) }) - else: - return HttpResponseRedirect('/telecaster/record') - - - def record(self, request): - template = 'telecaster/start.html' - if request.method == 'POST': - station = Station() - form = StationForm(data=request.POST, instance=station) - if form.is_valid(): - station.set_conf(self.conf) - station.setup() - station.start() - station.save() - self.logger.write_info('start') -# time.sleep(2) - return HttpResponseRedirect('/telecaster/') - else: - form = StationForm() + messages.warning(request, 'A station is already started !') + form = StationForm() + return render(request, template, {'station': form, 'hidden_fields': self.hidden_fields, + 'host': self.get_host(request) }) - return render(request, template, {'station': form, 'hidden_fields': self.hidden_fields, 'host': self.get_host(request) }) def get_host(self, request): host = request.META['HTTP_HOST'] @@ -105,10 +76,6 @@ class WebView(object): status.update() return status.to_dict() - def get_server_status(self): - self.status.update() - return self.status - @jsonrpc_method('telecaster.get_station_status') def get_station_status(request): stations = Station.objects.filter(started=True) @@ -117,3 +84,23 @@ class WebView(object): else: station = {} return station + + @jsonrpc_method('telecaster.start') + def start(request, station_dict): + if isinstance(station_dict, dict): + station = Station(public_id=dict['public_id']) + station.configure(station_dict) + conf = xml2dict(settings.TELECASTER_CONF) + conf = conf['telecaster'] + station.set_conf(conf) + station.setup() + station.start() + else: + messages.error(request, 'Bad station dictionary') + + @jsonrpc_method('telecaster.stop') + def stop(request): + stations = Station.objects.filter(started=True) + for station in stations: + station.stop() + -- 2.39.5