##// END OF EJS Templates
Check the readme.md for the bokeh version notes and requeriments.
Check the readme.md for the bokeh version notes and requeriments.

File last commit:

r316:0d39f71bbf42
r344:ada396c7b35b
Show More
views.py
194 lines | 6.6 KiB | text/x-python | PythonLexer
Juan C. Espinoza
Updating base models and views ...
r6 from django.shortcuts import render_to_response
from django.template import RequestContext
Fiorella Quino
Task #99: Modulo web del JARS...
r118 from django.shortcuts import redirect, render, get_object_or_404
Fiorella Quino
Task #99: View & Edit Jars Filters...
r135 from django.contrib import messages
Fiorella Quino
Task #1127: Get Log function has been implemented...
r274 from django.http import HttpResponse
Juan C. Espinoza
Updating base models and views ...
r6
from apps.main.models import Device
Miguel Urco
Buttons "Import", "Export, "Read" and "Write" added to Configuration View...
r30 from apps.main.views import sidebar
Juan C. Espinoza
Update Views y several improvements
r316 from .models import JARSConfiguration, JARSFilter
from .forms import JARSConfigurationForm, JARSFilterForm, JARSImportForm
Fiorella Quino
Filter template name combo box and change_filter views...
r269
import json
Juan C. Espinoza
Updating base models and views ...
r6 # Create your views here.
Fiorella Quino
Task #99: Modulo web del JARS...
r118 def jars_conf(request, id_conf):
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: Modulo web del JARS...
r118 conf = get_object_or_404(JARSConfiguration, pk=id_conf)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
Update Views y several improvements
r316 filter_parms = json.loads(conf.filter_parms)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: Modulo web del JARS...
r118 kwargs = {}
Fiorella Quino
Filter template name combo box and change_filter views...
r269 kwargs['filter'] = filter_parms
Juan C. Espinoza
Update Views y several improvements
r316 kwargs['filter_obj'] = JARSFilter.objects.get(pk=1)
kwargs['filter_keys'] = ['clock', 'multiplier', 'frequency', 'f_decimal',
'cic_2', 'scale_cic_2', 'cic_5', 'scale_cic_5', 'fir',
'scale_fir', 'number_taps', 'taps']
Fiorella Quino
jars ...
r293
Juan C. Espinoza
Update Views y several improvements
r316 filter_resolution = conf.filter_resolution()
Fiorella Quino
Task #1119: save and cancel button...
r270 kwargs['resolution'] = '{} (MHz)'.format(filter_resolution)
if filter_resolution < 1:
kwargs['resolution'] = '{} (kHz)'.format(filter_resolution*1000)
Fiorella Quino
jars ...
r293
Fiorella Quino
Task #99: Modulo web del JARS...
r118 kwargs['status'] = conf.device.get_status_display()
kwargs['dev_conf'] = conf
Juan C. Espinoza
Update Views y several improvements
r316 kwargs['dev_conf_keys'] = ['cards_number', 'channels_number', 'channels',
Fiorella Quino
jars ...
r293 'ftp_interval', 'data_type','acq_profiles',
Fiorella Quino
Task #1068: Import function has been implemented...
r275 'profiles_block', 'raw_data_blocks', 'ftp_interval',
'cohe_integr_str', 'cohe_integr', 'decode_data', 'post_coh_int',
'incohe_integr', 'fftpoints', 'spectral_number',
Fiorella Quino
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@157 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r136 'spectral', 'create_directory', 'include_expname',
Juan C. Espinoza
sync repo...
r157 'save_ch_dc', 'save_data']
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #1068: Import function has been implemented...
r275 if conf.exp_type == 0:
for field in ['incohe_integr','fftpoints','spectral_number', 'spectral', 'save_ch_dc']:
kwargs['dev_conf_keys'].remove(field)
if conf.decode_data == 0:
kwargs['dev_conf_keys'].remove('decode_data')
kwargs['dev_conf_keys'].remove('post_coh_int')
Fiorella Quino
Task #99: Modulo web del JARS...
r118 kwargs['title'] = 'JARS Configuration'
kwargs['suptitle'] = 'Details'
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: Modulo web del JARS...
r118 ###### SIDEBAR ######
kwargs.update(sidebar(conf=conf))
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: Modulo web del JARS...
r118 return render(request, 'jars_conf.html', kwargs)
Juan C. Espinoza
Updating base models and views ...
r6
Fiorella Quino
Task #99: Modulo web del JARS...
r118 def jars_conf_edit(request, id_conf):
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: Modulo web del JARS...
r118 conf = get_object_or_404(JARSConfiguration, pk=id_conf)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
Update Views y several improvements
r316 filter_parms = json.loads(conf.filter_parms)
Fiorella Quino
Task #99: Modulo web del JARS...
r118 if request.method=='GET':
form = JARSConfigurationForm(instance=conf)
Juan C. Espinoza
Update Views y several improvements
r316 filter_form = JARSFilterForm(initial=filter_parms)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: Modulo web del JARS...
r118 if request.method=='POST':
form = JARSConfigurationForm(request.POST, instance=conf)
Juan C. Espinoza
Update Views y several improvements
r316 filter_form = JARSFilterForm(request.POST)
Fiorella Quino
Filter template name combo box and change_filter views...
r269
if filter_form.is_valid():
Juan C. Espinoza
Update Views y several improvements
r316 jars_filter = filter_form.cleaned_data
jars_filter['id'] = request.POST['filter_template']
else:
messages.error(request, filter_form.errors)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: Modulo web del JARS...
r118 if form.is_valid():
conf = form.save(commit=False)
Fiorella Quino
Filter template name combo box and change_filter views...
r269 conf.filter_parms = json.dumps(jars_filter)
Fiorella Quino
Task #99: Modulo web del JARS...
r123 conf.save()
Fiorella Quino
Task #99: Modulo web del JARS...
r118 return redirect('url_jars_conf', id_conf=conf.id)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: Modulo web del JARS...
r118 kwargs = {}
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: Modulo web del JARS...
r118 kwargs['id_dev'] = conf.id
kwargs['form'] = form
Fiorella Quino
Filter template name combo box and change_filter views...
r269 kwargs['filter_form'] = filter_form
Juan C. Espinoza
Update Views y several improvements
r316 kwargs['filter_name'] = JARSFilter.objects.get(pk=filter_parms['id']).name
Fiorella Quino
Task #99: Modulo web del JARS...
r118 kwargs['title'] = 'Device Configuration'
kwargs['suptitle'] = 'Edit'
kwargs['button'] = 'Save'
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Fiorella Quino
Task #99: View & Edit Jars Filters...
r135 return render(request, 'jars_conf_edit.html', kwargs)
Juan C. Espinoza
sync repo...
r157 def import_file(request, conf_id):
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 conf = get_object_or_404(JARSConfiguration, pk=conf_id)
if request.method=='POST':
form = JARSImportForm(request.POST, request.FILES)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209 if form.is_valid():
Fiorella Quino
Task #1068: Import function has been implemented...
r275 try:
Fiorella Quino
Jars files have been update...
r263 data = conf.import_from_file(request.FILES['file_name'])
conf.dict_to_parms(data)
messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name'])
return redirect(conf.get_absolute_url_edit())
Fiorella Quino
jars ...
r293
Fiorella Quino
Task #1068: Import function has been implemented...
r275 except Exception as e:
messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], repr(e)))
Juan C. Espinoza
sync repo...
r157 else:
messages.warning(request, 'Your current configuration will be replaced')
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209 form = JARSImportForm()
Juan C. Espinoza
sync repo...
r157 kwargs = {}
kwargs['form'] = form
kwargs['title'] = 'JARS Configuration'
kwargs['suptitle'] = 'Import file'
kwargs['button'] = 'Upload'
kwargs['previous'] = conf.get_absolute_url()
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 return render(request, 'jars_import.html', kwargs)
def read_conf(request, conf_id):
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 conf = get_object_or_404(JARSConfiguration, pk=conf_id)
#filter = get_object_or_404(JARSfilter, pk=filter_id)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 if request.method=='GET':
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 parms = conf.read_device()
conf.status_device()
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 if not parms:
messages.error(request, conf.message)
return redirect(conf.get_absolute_url())
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 form = JARSConfigurationForm(initial=parms, instance=conf)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 if request.method=='POST':
form = JARSConfigurationForm(request.POST, instance=conf)
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 if form.is_valid():
form.save()
return redirect(conf.get_absolute_url())
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 messages.error(request, "Parameters could not be saved")
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 kwargs = {}
kwargs['id_dev'] = conf.id
kwargs['filter_id'] = conf.filter.id
kwargs['form'] = form
kwargs['title'] = 'Device Configuration'
kwargs['suptitle'] = 'Parameters read from device'
kwargs['button'] = 'Save'
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 ###### SIDEBAR ######
kwargs.update(sidebar(conf=conf))
Fiorella Quino
Standardize jars functions: start, stop, write, read, status...
r209
Juan C. Espinoza
sync repo...
r157 return render(request, 'jars_conf_edit.html', kwargs)
Juan C. Espinoza
Update Views y several improvements
r316 def change_filter(request, conf_id, filter_id):
Fiorella Quino
Filter template name combo box and change_filter views...
r269
conf = get_object_or_404(JARSConfiguration, pk=conf_id)
Juan C. Espinoza
Update Views y several improvements
r316 filter = get_object_or_404(JARSFilter, pk=filter_id)
conf.filter_parms = json.dumps(filter.jsonify())
conf.save()
Fiorella Quino
jars ...
r293
Juan C. Espinoza
Update Views y several improvements
r316 return redirect('url_edit_jars_conf', id_conf=conf.id)
Fiorella Quino
Task #1127: Get Log function has been implemented...
r274
def get_log(request, conf_id):
conf = get_object_or_404(JARSConfiguration, pk=conf_id)
response = conf.get_log()
if not response:
message = conf.message
messages.error(request, message)
return redirect('url_jars_conf', id_conf=conf.id)
Fiorella Quino
jars ...
r293
Fiorella Quino
Task #1127: Get Log function has been implemented...
r274 try:
message = response.json()['message']
messages.error(request, message)
return redirect('url_jars_conf', id_conf=conf.id)
except Exception as e:
message = 'Restarting Report.txt has been downloaded successfully.'
Fiorella Quino
jars ...
r293
Fiorella Quino
Task #1127: Get Log function has been implemented...
r274 content = response
filename = 'Log_%s_%s.txt' %(conf.experiment.name, conf.experiment.id)
response = HttpResponse(content,content_type='text/plain')
response['Content-Disposition'] = 'attachment; filename="%s"' %filename
Fiorella Quino
jars ...
r293 return response