|
|
# -*- coding: utf-8 -*-
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
import os
|
|
|
from datetime import datetime
|
|
|
|
|
|
from django import forms
|
|
|
from django.contrib import messages
|
|
|
from django.utils.safestring import mark_safe
|
|
|
from django.shortcuts import render
|
|
|
|
|
|
from bootstrap3_datetime.widgets import DateTimePicker
|
|
|
|
|
|
from pymongo import MongoClient
|
|
|
|
|
|
host = os.environ.get('HOST_MONGO', 'localhost')
|
|
|
|
|
|
CLIENT = MongoClient('{}:27017'.format(host))
|
|
|
DB = CLIENT['dbplots']
|
|
|
|
|
|
# Forms
|
|
|
class SearchForm(forms.Form):
|
|
|
|
|
|
experiment = forms.ChoiceField()
|
|
|
plot = forms.ChoiceField(
|
|
|
choices = [(0, 'Select Plot'), ('rti', 'RTI'),('spc', 'Spectra'),('noise', 'Noise')]
|
|
|
)
|
|
|
date = forms.DateField(
|
|
|
widget=DateTimePicker(options={"format": "DD/MM/YYYY"})
|
|
|
)
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
|
exp_choices = kwargs.pop('exp_choices', [])
|
|
|
super(SearchForm, self).__init__(*args, **kwargs)
|
|
|
self.fields['experiment'].choices = [(0, 'Select Experiment')] + exp_choices
|
|
|
|
|
|
# Create your views here.
|
|
|
def main(request, code=None, plot=None):
|
|
|
|
|
|
initial = {}
|
|
|
date = request.GET.get('date', datetime.now().strftime('%d/%m/%Y'))
|
|
|
initial['date'] = date
|
|
|
|
|
|
if code is not None:
|
|
|
initial['experiment'] = code
|
|
|
if plot is not None:
|
|
|
initial['plot'] = plot
|
|
|
|
|
|
print 'hola'
|
|
|
codes = DB.experiment.find().distinct('code')
|
|
|
print codes
|
|
|
exps = [DB.experiment.find_one({'code': c}, ['name']) for c in codes]
|
|
|
print exps
|
|
|
names = [q['name'] for q in exps]
|
|
|
print names
|
|
|
form = SearchForm(
|
|
|
initial = initial,
|
|
|
exp_choices = [(e[0], e[1]) for e in zip(codes, names)]
|
|
|
)
|
|
|
|
|
|
kwargs = {
|
|
|
'code': code,
|
|
|
'plot': plot,
|
|
|
'date': date,
|
|
|
'form': form,
|
|
|
}
|
|
|
|
|
|
if code and codes:
|
|
|
kwargs['title'] = [t[1] for t in zip(codes, names) if t[0]==int(code)][0]
|
|
|
else:
|
|
|
kwargs['title'] = 'JRO'
|
|
|
|
|
|
if plot == 'rti':
|
|
|
return render(request, 'rti.html', kwargs)
|
|
|
elif plot == 'spc':
|
|
|
return render(request, 'spectra.html', kwargs)
|
|
|
elif plot == 'noise':
|
|
|
return render(request, 'scatter.html', kwargs)
|
|
|
else:
|
|
|
return render(request, 'base.html', kwargs)
|