From: G. Pellerin Date: Sat, 28 May 2011 22:45:38 +0000 (+0200) Subject: add forms, fix urls X-Git-Tag: 0.9~136 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=d3f9dcea47d155df8f631eb35b0cee0374fe117d;p=telecaster-client.git add forms, fix urls --- diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..3d75000 --- /dev/null +++ b/forms.py @@ -0,0 +1,17 @@ + +from models import * + + +class StationForm(ModelForm): + class Meta: + model = Station + + def __init__(self, *args, **kwds): + super(StationForm, self).__init__(*args, **kwds) + self.fields['organization'].queryset = Organization.objects.order_by('name') + self.fields['department'].queryset = Department.objects.order_by('name') + self.fields['conference'].queryset = Conference.objects.order_by('title') + self.fields['session'].queryset = Session.objects.order_by('name') + self.fields['professor'].queryset = Professor.objects.order_by('name') + + diff --git a/models.py b/models.py index 5e8a592..77d4903 100644 --- a/models.py +++ b/models.py @@ -48,14 +48,15 @@ from mutagen.id3 import ID3, TIT2, TP1, TAL, TDA, TDAT, TDRC, TCO, COM from django.db.models import * from django.forms import ModelForm +from django.utils.translation import ugettext_lazy as _ app_label = 'telecaster' class Organization(Model): - name = CharField(_('name')) - description = CharField(_('description')) + name = CharField(_('name'), max_length=255) + description = CharField(_('description'), max_length=255) def __str__(self): return self.name @@ -65,8 +66,8 @@ class Organization(Model): class Department(Model): - name = CharField(_('name')) - description = CharField(_('description')) + name = CharField(_('name'), max_length=255) + description = CharField(_('description'), max_length=255) def __str__(self): return self.name @@ -77,9 +78,9 @@ class Department(Model): class Conference(Model): - title = CharField(_('title')) - description = CharField(_('description')) - department = Foreignkey('Department', related_name='conferences', verbose_name='department') + title = CharField(_('title'), max_length=255) + description = CharField(_('description'), max_length=255) + department = ForeignKey('Department', related_name='conferences', verbose_name='department') def __str__(self): return self.title @@ -90,8 +91,8 @@ class Conference(Model): class Session(Model): - name = CharField(_('name')) - description = CharField(_('description')) + name = CharField(_('name'), max_length=255) + description = CharField(_('description'), max_length=255) number = IntegerField(_('number')) def __str__(self): @@ -103,11 +104,11 @@ class Session(Model): class Professor(Model): - name = CharField(_('name')) - institution = CharField(_('institution')) - address = CharField(_('address')) - telephone = CharField(_('telephone')) - email = CharField(_('email')) + name = CharField(_('name'), max_length=255) + institution = CharField(_('institution'), max_length=255) + address = CharField(_('address'), max_length=255) + telephone = CharField(_('telephone'), max_length=255) + email = CharField(_('email'), max_length=255) def __str__(self): return self.name @@ -118,10 +119,10 @@ class Professor(Model): class Station(Model): - organization = Foreignkey('Organization', related_name='stations', verbose_name='organization') - conference = Foreignkey('Conference', related_name='stations', verbose_name='conference') - session = Foreignkey('Session', related_name='stations', verbose_name='session') - professor = Foreignkey('Professor', related_name='stations', verbose_name='professor') + organization = ForeignKey('Organization', related_name='stations', verbose_name='organization') + conference = ForeignKey('Conference', related_name='stations', verbose_name='conference') + session = ForeignKey('Session', related_name='stations', verbose_name='session') + professor = ForeignKey('Professor', related_name='stations', verbose_name='professor') comment = TextField(_('comment')) started = BooleanField(_('started')) datetime_start = DateTimeField(_('datetime_start'), auto_now_add=True) diff --git a/telecaster.py b/telecaster.py deleted file mode 100755 index 5cefb0a..0000000 --- a/telecaster.py +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# *-* coding: utf-8 *-* -""" - telecaster - - Copyright (c) 2006-2010 Guillaume Pellerin - -# This software is governed by the CeCILL license under French law and -# abiding by the rules of distribution of free software. You can use, -# modify and/ or redistribute the software under the terms of the CeCILL -# license as circulated by CEA, CNRS and INRIA at the following URL -# "http://www.cecill.info". - -# As a counterpart to the access to the source code and rights to copy, -# modify and redistribute granted by the license, users are provided only -# with a limited warranty and the software's author, the holder of the -# economic rights, and the successive licensors have only limited -# liability. - -# In this respect, the user's attention is drawn to the risks associated -# with loading, using, modifying and/or developing or reproducing the -# software by the user in light of its specific status of free software, -# that may mean that it is complicated to manipulate, and that also -# therefore means that it is reserved for developers and experienced -# professionals having in-depth computer knowledge. Users are therefore -# encouraged to load and test the software's suitability as regards their -# requirements in conditions enabling the security of their systems and/or -# data to be ensured and, more generally, to use and operate it in the -# same conditions as regards security. - -# The fact that you are presently reading this means that you have had -# knowledge of the CeCILL license and that you accept its terms. - -# Author: Guillaume Pellerin -""" - -version = '0.5.2' - - -import os -import sys -import pwd -import cgi -import cgitb -import time -from tools import * -from webview import * -from station import * -cgitb.enable() - - -class TeleCaster: - """Manage the calls of Station and Webview to get the network and - disk streams""" - - def __init__(self, conf_file): - """Main function""" - self.conf_file = conf_file - conf_dict = xml2dict(self.conf_file) - self.conf = conf_dict['telecaster'] - self.title = self.conf['infos']['name'] - self.log_file = self.conf['log'] - self.logger = Logger(self.log_file) - self.uid = os.getuid() - self.url = self.conf['infos']['url'] - self.user = pwd.getpwuid(os.getuid())[0] - 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.lock_file = self.user_dir + os.sep + 'telecaster.lock' - - def transition_head(self): - html_file = open('telecaster_starting_head.html', 'r') - html = html_file.read() - html_file.close() - return html - - def transition_foot(self): - html_file = open('telecaster_starting_foot.html', 'r') - html = html_file.read() - html_file.close() - return html - - def main(self): - edcast_pid = get_pid('edcast_jack', self.uid) - deefuzzer_pid = get_pid('/usr/bin/deefuzzer '+self.user_dir+os.sep+'deefuzzer.xml', self.uid) - writing = edcast_pid != [] - casting = deefuzzer_pid != [] - form = WebView(self.conf, version) - - if deefuzzer_pid == [] and form.has_key("action") and \ - form.has_key("department") and form.has_key("conference") and \ - form.has_key("session") and form["action"].value == "start": - - self.conference_dict = {'title': '', - 'department': '', - 'conference': '', - 'session': '', - 'professor': '', - 'comment': ''} - - for data in self.conference_dict: - if not form.has_key(data): - self.conference_dict[data] = 'Inconnu' - else: - value = form.getfirst(data) - if '....' in value: - self.conference_dict[data] = 'Inconnu' - else: - self.conference_dict[data] = value - - self.conference_dict['title'] = self.title - s = Station(self.conf_file, self.conference_dict, self.lock_file) - s.start() - time.sleep(2) - self.logger.write_info('starting') - self.main() - - elif deefuzzer_pid != [] and os.path.exists(self.lock_file) and not form.has_key("action"): - self.conference_dict = get_conference_from_lock(self.lock_file) - form.stop_form(self.conference_dict, writing, casting) - self.logger.write_info('started') - - elif deefuzzer_pid and form.has_key("action") and form["action"].value == "stop": - self.logger.write_info('stopping') - if os.path.exists(self.lock_file): - self.conference_dict = get_conference_from_lock(self.lock_file) - s = Station(self.conf_file, self.conference_dict, self.lock_file) - s.stop() - time.sleep(2) - self.main() - - elif deefuzzer_pid == []: - form.start_form(writing, casting) - self.logger.write_info('stopped') - - elif deefuzzer_pid != []: - os.system('kill -9 '+deefuzzer_pid[0]) - self.main() - - -conf_file = '/etc/telecaster/telecaster.xml' - -if __name__ == '__main__': - sys.stderr = sys.stdout - t = TeleCaster(conf_file) - t.main() - - diff --git a/telecaster_old.py b/telecaster_old.py new file mode 100755 index 0000000..392a8e3 --- /dev/null +++ b/telecaster_old.py @@ -0,0 +1,150 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# *-* coding: utf-8 *-* +""" + telecaster + + Copyright (c) 2006-2010 Guillaume Pellerin + +# This software is governed by the CeCILL license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL +# license as circulated by CEA, CNRS and INRIA at the following URL +# "http://www.cecill.info". + +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. + +# In this respect, the user's attention is drawn to the risks associated +# with loading, using, modifying and/or developing or reproducing the +# software by the user in light of its specific status of free software, +# that may mean that it is complicated to manipulate, and that also +# therefore means that it is reserved for developers and experienced +# professionals having in-depth computer knowledge. Users are therefore +# encouraged to load and test the software's suitability as regards their +# requirements in conditions enabling the security of their systems and/or +# data to be ensured and, more generally, to use and operate it in the +# same conditions as regards security. + +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL license and that you accept its terms. + +# Author: Guillaume Pellerin +""" + +version = '0.5.2' + + +import os +import sys +import pwd +import cgi +import cgitb +import time +from tools import * +from webview import * +from station import * +cgitb.enable() + + +class TeleCaster: + """Manage the calls of Station and Webview to get the network and + disk streams""" + + def __init__(self, conf_file): + """Main function""" + self.conf_file = conf_file + conf_dict = xml2dict(self.conf_file) + self.conf = conf_dict['telecaster'] + self.title = self.conf['infos']['name'] + self.log_file = self.conf['log'] + self.logger = Logger(self.log_file) + self.uid = os.getuid() + self.url = self.conf['infos']['url'] + self.user = pwd.getpwuid(os.getuid())[0] + 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.lock_file = self.user_dir + os.sep + 'telecaster.lock' + + def transition_head(self): + html_file = open('telecaster_starting_head.html', 'r') + html = html_file.read() + html_file.close() + return html + + def transition_foot(self): + html_file = open('telecaster_starting_foot.html', 'r') + html = html_file.read() + html_file.close() + return html + + def main(self): + edcast_pid = get_pid('edcast_jack', self.uid) + deefuzzer_pid = get_pid('/usr/bin/deefuzzer '+self.user_dir+os.sep+'deefuzzer.xml', self.uid) + writing = edcast_pid != [] + casting = deefuzzer_pid != [] + form = WebView(self.conf, version) + + if deefuzzer_pid == [] and form.has_key("action") and \ + form.has_key("department") and form.has_key("conference") and \ + form.has_key("session") and form["action"].value == "start": + + self.conference_dict = {'title': '', + 'department': '', + 'conference': '', + 'session': '', + 'professor': '', + 'comment': ''} + + for data in self.conference_dict: + if not form.has_key(data): + self.conference_dict[data] = 'Inconnu' + else: + value = form.getfirst(data) + if '....' in value: + self.conference_dict[data] = 'Inconnu' + else: + self.conference_dict[data] = value + + self.conference_dict['title'] = self.title + s = Station(self.conf_file, self.conference_dict, self.lock_file) + s.start() + time.sleep(2) + self.logger.write_info('starting') + self.main() + + elif deefuzzer_pid != [] and os.path.exists(self.lock_file) and not form.has_key("action"): + self.conference_dict = get_conference_from_lock(self.lock_file) + form.stop_form(self.conference_dict, writing, casting) + self.logger.write_info('started') + + elif deefuzzer_pid and form.has_key("action") and form["action"].value == "stop": + self.logger.write_info('stopping') + if os.path.exists(self.lock_file): + self.conference_dict = get_conference_from_lock(self.lock_file) + s = Station(self.conf_file, self.conference_dict, self.lock_file) + s.stop() + time.sleep(2) + self.main() + + elif deefuzzer_pid == []: + form.start_form(writing, casting) + self.logger.write_info('stopped') + + elif deefuzzer_pid != []: + os.system('kill -9 '+deefuzzer_pid[0]) + self.main() + + +conf_file = '/etc/telecaster/telecaster.xml' + +if __name__ == '__main__': + sys.stderr = sys.stdout + t = TeleCaster(conf_file) + t.main() + + diff --git a/tools/tools.py b/tools/tools.py index 776bf97..e4f4d14 100644 --- a/tools/tools.py +++ b/tools/tools.py @@ -76,18 +76,18 @@ def get_ip_address(ifname): )[20:24]) def get_lines(file): - """Get lines from a file""" - fic = open(file,'r') - lines = fic.readlines() - fic.close() - return lines + """Get lines from a file""" + fic = open(file,'r') + lines = fic.readlines() + fic.close() + return lines def clean_string(string): - """removes blank spaces and accents""" - string = string.replace(' ','_') - #string = string.replace('é','e') - #string = string.replace('è','e') - return string + """removes blank spaces and accents""" + string = string.replace(' ','_') + #string = string.replace('é','e') + #string = string.replace('è','e') + return string def xml2dict(conf_file): confile = open(conf_file,'r') diff --git a/urls.py b/urls.py index 0c22d81..d9f4d1f 100644 --- a/urls.py +++ b/urls.py @@ -35,35 +35,20 @@ """ from django.conf.urls.defaults import * -from telemeta.models import * -from telemeta.views import WebView +from django.conf import settings +from telecaster.models import * +from telecaster.views import WebView from jsonrpc import jsonrpc_site import os.path -#import telecaster.config -#telecaster.config.check() # initialization -web_view = WebView() - - +web_view = WebView(settings.TELECASTER_CONF) htdocs = os.path.dirname(__file__) + '/htdocs' urlpatterns = patterns('', - url(r'^$', web_view.index, name="telemeta-home"), - - # items - url(r'^items/$', 'django.views.generic.list_detail.object_list', - dict(all_items, paginate_by=20, template_name="telemeta/mediaitem_list.html"), - name="telemeta-items"), - url(r'^items/(?P[A-Za-z0-9._-]+)/$', web_view.item_detail, - name="telemeta-item-detail"), - url(r'^items/(?P[A-Za-z0-9._-]+)/dc/$', web_view.item_detail, - {'template': 'telemeta/mediaitem_detail_dc.html'}, - name="telemeta-item-dublincore"), - url(r'^items/(?P[A-Za-z0-9._-]+)/dc/xml/$', web_view.item_detail, - {'format': 'dublin_core_xml'}, - + url(r'^', web_view.index, name="telecaster-index"), + # CSS+Images (FIXME: for developement only) url(r'^css/(?P.*)$', 'django.views.static.serve', {'document_root': htdocs+'/css'}, @@ -74,3 +59,10 @@ urlpatterns = patterns('', url(r'^js/(?P.*)$', 'django.views.static.serve', {'document_root': htdocs+'/js'}, name="telemeta-js"), + + # JSON RPC + url(r'^json/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'), + # for the graphical browser/web console only, omissible + url(r'^json/browse/', 'jsonrpc.views.browse', name="jsonrpc_browser"), + +)