##// END OF EJS Templates
Improve abs pattern views, templates and plots....
Improve abs pattern views, templates and plots. git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@203 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71

File last commit:

r172:a641bec15a9b
r180:d4783015f56a
Show More
views.py
322 lines | 9.9 KiB | text/x-python | PythonLexer
Fiorella Quino
Task #95: views...
r27 from django.shortcuts import redirect, render, get_object_or_404
Fiorella Quino
Task #94: edit, save, read function...
r31 from django.contrib import messages
Fiorella Quino
Task #95: Se agrego funcion "export" archivo .json para cgs. Se modifico modelo de cgs, de float a integer...
r43 from django.http import HttpResponse
Fiorella Quino
CGS model, form, view, url and html have been added....
r4
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 from apps.main.models import Experiment
Juan C. Espinoza
Updating base models and views ...
r6 from .models import CGSConfiguration
Fiorella Quino
Task #94: edit, save, read function...
r31
Fiorella Quino
Task #95: se agrego la funcion "import" para archivos .json ...
r42 from .forms import CGSConfigurationForm, UploadFileForm
Fiorella Quino
Task #94: edit, save, read function...
r31 from apps.main.views import sidebar
import requests
Fiorella Quino
Task #95...
r38 import json
Fiorella Quino
Task #95: Se modifico funcion "read"...
r39 #from __builtin__ import None
Juan C. Espinoza
Proyecto base en Django (refs #259) ...
r0 # Create your views here.
Fiorella Quino
CGS model, form, view, url and html have been added....
r4
Fiorella Quino
Task #95: views...
r27 def cgs_conf(request, id_conf):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 conf = get_object_or_404(CGSConfiguration, pk=id_conf)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #94: edit, save, read function...
r31 ip=conf.device.ip_address
port=conf.device.port_address
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 kwargs = {}
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 kwargs['status'] = conf.device.get_status_display()
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 #if request.method=='GET':
Fiorella Quino
Task #95: connect icon...
r36 #r: response = icon, status
Fiorella Quino
Task #95: Modulo CGS ...
r59 # try:
# route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548"
# r = requests.get(route)
# response = str(r.text)
# response = response.split(";")
# icon = response[0]
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 # status = response[-1]
Fiorella Quino
Task #95...
r38 #print r.text
#"icon" could be: "alert" or "okay"
# Si hay alerta pero esta conectado
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if "alert" in icon:
# if "Starting Up" in status: #No Esta conectado
# kwargs['connected'] = False
# else:
# kwargs['connected'] = True
# elif "okay" in icon:
# kwargs['connected'] = True
# else:
# kwargs['connected'] = False
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
# except:
Fiorella Quino
Task #95: Modulo CGS ...
r59 # kwargs['connected'] = False
# status = "The Device is not connected."
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 #if not kwargs['connected']:
# messages.error(request, message=status)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 kwargs['dev_conf'] = conf
Juan C. Espinoza
Improve Search view (filters and paginator added), add base_list template, delete unused templates...
r138 kwargs['dev_conf_keys'] = ['name',
Fiorella Quino
Task #95: views...
r27 'freq0', 'freq1',
'freq2', 'freq3']
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 kwargs['title'] = 'CGS Configuration'
kwargs['suptitle'] = 'Details'
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 kwargs['button'] = 'Edit Configuration'
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: Modulo CGS ...
r59 kwargs['no_play'] = True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 ###### SIDEBAR ######
Juan C. Espinoza
Update several views and models in main app...
r85 kwargs.update(sidebar(conf=conf))
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 return render(request, 'cgs_conf.html', kwargs)
Fiorella Quino
CGS model, form, view, url and html have been added....
r4
Fiorella Quino
Task #95: views...
r27 def cgs_conf_edit(request, id_conf):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 conf = get_object_or_404(CGSConfiguration, pk=id_conf)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 if request.method=='GET':
form = CGSConfigurationForm(instance=conf)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 if request.method=='POST':
form = CGSConfigurationForm(request.POST, instance=conf)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
SIR Task #95 Modelo CGS: ...
r8 if form.is_valid():
Fiorella Quino
Task #95: Se agrego funcion "export" archivo .json para cgs. Se modifico modelo de cgs, de float a integer...
r43 if conf.freq0 == None: conf.freq0 = 0
if conf.freq1 == None: conf.freq1 = 0
if conf.freq2 == None: conf.freq2 = 0
if conf.freq3 == None: conf.freq3 = 0
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #94: edit, save, read function...
r31 conf = form.save(commit=False)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #94: edit, save, read function...
r31 if conf.verify_frequencies():
conf.save()
return redirect('url_cgs_conf', id_conf=conf.id)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #94: edit, save, read function...
r31 ##ERRORS
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #95: views...
r27 kwargs = {}
Fiorella Quino
Task #94: edit, save, read function...
r31 kwargs['id_dev'] = conf.id
Fiorella Quino
Task #95: views...
r27 kwargs['form'] = form
kwargs['title'] = 'Device Configuration'
kwargs['suptitle'] = 'Edit'
Fiorella Quino
Task #94: edit, save, read function...
r31 kwargs['button'] = 'Save'
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Task #94: edit, save, read function...
r31 return render(request, 'cgs_conf_edit.html', kwargs)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # def cgs_conf_write(request, id_conf):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # conf = get_object_or_404(CGSConfiguration, pk=id_conf)
# ip=conf.device.ip_address
# port=conf.device.port_address
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # #Frequencies from form
# f0 = conf.freq0
# f1 = conf.freq1
# f2 = conf.freq2
# f3 = conf.freq3
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
# try:
Fiorella Quino
Task #95: Modulo CGS ...
r59 # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3}
# route = "http://" + str(ip) + ":" + str(port) + "/frequencies/"
# r = requests.post(route, post_data)
# text = r.text
# text = text.split(',')
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
# try:
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if len(text)>1:
# title = text[0]
# status = text[1]
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 # status_ok = r.status_code
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if title == "okay":
# messages.success(request, status)
# else:
# messages.error(request, status)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # else:
# title = text[0]
# messages.error(request, title)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # except:
# messages.error(request, "An hardware error was found.")
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # except:
# messages.error(request, "Could not write parameters.")
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
#
#
#
Fiorella Quino
Task #95: Modulo CGS ...
r59 # return redirect('url_cgs_conf', id_conf=conf.id)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # def cgs_conf_read(request, id_conf):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # conf = get_object_or_404(CGSConfiguration, pk=id_conf)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # ip=conf.device.ip_address
# port=conf.device.port_address
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if request.method=='POST':
# form = CGSConfigurationForm(request.POST, instance=conf)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if form.is_valid():
# cgs_model = form.save(commit=False)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if cgs_model.verify_frequencies():
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # cgs_model.save()
# return redirect('url_cgs_conf', id_conf=conf.id)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # messages.error(request, "Parameters could not be saved. Invalid parameters")
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # data = {}
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
#
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if request.method=='GET':
# #r: response = icon, status
# route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548"
# try:
# r = requests.get(route)
# response = str(r.text)
# response = response.split(";")
# icon = response[0]
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 # status = response[-1]
Fiorella Quino
Task #95: Modulo CGS ...
r59 # print r.text
# #"icon" could be: "alert" or "okay"
# if "okay" in icon:
# messages.success(request, status)
# else:
# messages.error(request, status)
# #Get Frequencies
# route = "http://" + str(ip) + ":" + str(port) + "/frequencies/"
# #frequencies = requests.get('http://10.10.10.175:8080/frequencies/')
# frequencies = requests.get(route)
# frequencies = frequencies.json()
# frequencies = frequencies.get("Frecuencias")
# f0 = frequencies.get("f0")
# f1 = frequencies.get("f1")
# f2 = frequencies.get("f2")
# f3 = frequencies.get("f3")
# print f0,f1,f2,f3
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
#
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if not response:
# messages.error(request, "Could not read parameters from Device")
# return redirect('url_cgs_conf', id_conf=conf.id)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # data = {'experiment' : conf.experiment.id,
# 'device' : conf.device.id,
# 'freq0' : f0,
# 'freq1' : f1,
# 'freq2' : f2,
# 'freq3' : f3,
# }
# except:
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 # messages.error(request, "Could not read parameters from Device")
Fiorella Quino
Task #95: Modulo CGS ...
r59 # data = {'experiment' : conf.experiment.id,
# 'device' : conf.device.id,
# 'freq0' : None,
# 'freq1' : None,
# 'freq2' : None,
# 'freq3' : None,
# }
# return redirect('url_cgs_conf', id_conf=conf.id)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # form = CGSConfigurationForm(initial = data)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # kwargs = {}
# kwargs['id_dev'] = conf.id
# kwargs['form'] = form
# kwargs['title'] = 'Device Configuration'
# kwargs['suptitle'] = 'Parameters read from device'
# kwargs['button'] = 'Save'
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # ###### SIDEBAR ######
# kwargs.update(sidebar(conf))
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # return render(request, 'cgs_conf_edit.html', kwargs)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # def cgs_conf_import(request, id_conf):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # conf = get_object_or_404(CGSConfiguration, pk=id_conf)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if request.method == 'POST':
# file_form = UploadFileForm(request.POST, request.FILES)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # if file_form.is_valid():
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # try:
# if conf.update_from_file(request.FILES['file']):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # try:
# conf.full_clean()
# except ValidationError as e:
# messages.error(request, e)
# else:
# conf.save()
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name)
# #messages.warning(request,"")
# return redirect('url_cgs_conf', id_conf=conf.id)
# except:
# messages.error(request, "No JSON object could be decoded.")
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # messages.error(request, "Could not import parameters from file")
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # else:
# file_form = UploadFileForm(initial={'title': '.json'})
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
#
Fiorella Quino
Task #95: Modulo CGS ...
r59 # kwargs = {}
# kwargs['id_dev'] = conf.id
# kwargs['title'] = 'Device Configuration'
# kwargs['form'] = file_form
# kwargs['suptitle'] = 'Importing file'
# kwargs['button'] = 'Import'
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # kwargs.update(sidebar(conf))
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # return render(request, 'cgs_conf_import.html', kwargs)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # def handle_uploaded_file(f):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # data = {'freq0' : 62500000,
# 'freq1' : 62500000,
# 'freq2' : 62500000,
# 'freq3' : 62500000,
# }
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # return data
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # def cgs_conf_export(request, id_conf):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # conf = get_object_or_404(CGSConfiguration, pk=id_conf)
# ip=conf.device.ip_address
# port=conf.device.port_address
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # #if request.method=='GET':
# # data = {"Frequencies": [
# # ["freq0", conf.freq0],
# # ["freq1", conf.freq1],
# # ["freq2", conf.freq2],
# # ["freq3", conf.freq3]
# # ]}
# # json_data = json.dumps(data)
# # conf.parameters = json_data
# # response = HttpResponse(conf.parameters, content_type="application/json")
# # response['Content-Disposition'] = 'attachment; filename="data.json"'
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # # return response
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # kwargs = {}
# kwargs['dev_conf'] = conf
# kwargs['dev_conf_keys'] = ['experiment', 'device',
# 'freq0', 'freq1',
# 'freq2', 'freq3']
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # kwargs['title'] = 'CGS Configuration'
# kwargs['suptitle'] = 'Details'
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # kwargs['button'] = 'Edit Configuration'
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 #
Fiorella Quino
Task #95: Modulo CGS ...
r59 # ###### SIDEBAR ######
# kwargs.update(sidebar(conf))
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172 # return render(request, 'cgs_conf.html', kwargs)