Esempio n. 1
0
def boxfill(request):
    if not request.user.is_authenticated():
        # send them to the login page, with a ?redir= on the end pointing back to this page
        return HttpResponseRedirect(reverse('login:login') + "?" + urlencode({'redir':reverse('home.views.boxfill')}))
    else:
        if request.GET:
            return render(request, 'boxfill_form.html', { })
        else:
            
            try:
                myfile=request.POST['file']
                myvar=request.POST['var']
                latitude_from=int(request.POST['latitude_from'])
                latitude_to=int(request.POST['latitude_to'])
                longitude_from=int(request.POST['longitude_from'])
                longitude_to=int(request.POST['longitude_to'])
                time_slice_from=int(request.POST['time_slice_from'])
                time_slice_to=int(request.POST['time_slice_to'])
                lev1=None
                lev2=None
                if 'lev1' in request.POST:
                    lev1=request.POST['lev1']
                if 'lev2' in request.POST:
                    lev2=request.POST['lev2']
            except:
                return render(request, 'boxfill_form.html', {
                    'error_message': "Please fill all required fields",
                })
        
            selection_dict = {
                'latitude':(latitude_from,latitude_to),
                'longitude':(longitude_from,longitude_to),
                'time':slice(time_slice_from,time_slice_to)
            }
               
            # tell curl what certificate to use
            #TODO: sanitize request.user.name!
            active_cert = settings.PROXY_CERT_DIR + request.user.username + '.pem'
            plot_filename = box_fill(myfile, myvar, selection_dict, proxy_cert = active_cert)
            
            if not plot_filename:
                return render_to_response("accessDenied.html",None,context_instance=RequestContext(request))
            
            return render(request, 'boxfill.html', {
                'png': plot_filename,
            })
Esempio n. 2
0
def make_boxfill(request):
    if not request.user.is_authenticated():
        # send them to the login page, with a ?redir= on the end pointing back to this page
        return HttpResponseRedirect(reverse('login:login') + "?" + urlencode({'redir':reverse('home.views.main_main_window')}))
    else:
        active_cert = settings.PROXY_CERT_DIR + request.user.username + '.pem'
        myfile=request.GET['fnm']
        myvar=request.GET['var']
        n=request.GET['n']
        s=request.GET['s']
        e=request.GET['e']
        w=request.GET['w']
        selection_dict = {'latitude':(int(n),int(s)),'longitude':(int(e),int(w)),'time':slice(0,1)}
        try:
            plot_filename = box_fill(myfile, myvar, selection_dict, proxy_cert = active_cert)
            obj={"png":plot_filename}
            json_res=simplejson.dumps(obj) 
        except Exception, err:
            obj={"png":""}
            json_res=simplejson.dumps(obj) 
        return HttpResponse(json_res, content_type="application/json")