Beispiel #1
0
def make_main_window(request,json_param=None):
    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.make_main_window')}))
    else:
        #if request.GET:
           #return render(request, 'testplot_form.html', { })
        #else:
            #if not json_param:
            #    print "testing through form (no link from ESGF yet)"
            n="-90"
            s="90"
            e="0"
            w="180"

            try:
                #myfile=request.POST['file']
                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, 'testplot_form.html', {
                    'error_message': "Please fill all required fields",
                })
        
            selection_dict = {
                'latitude':(-90,90),
                'longitude':(0,180),
                'time':slice(0,1)
            }
            myfile = "http://pcmdi9.llnl.gov/thredds/dodsC/cmip5.output1.INM.inmcm4.1pctCO2.mon.atmos.Amon.r1i1p1.cl.20130207.aggregation.1"
            # tell curl what certificate to use
            #TODO: sanitize request.user.name!
            active_cert = settings.PROXY_CERT_DIR + request.user.username + '.pem'
            varlist=get_var(myfile)
            if not varlist:
                return render_to_response("accessDenied.html",None,context_instance=RequestContext(request))

            """
            if json_param:
                plot_filename = box_fill(myfile, varlist, selection_dict, proxy_cert = active_cert)
            else:
                plot_filename=None
            """
            #plot_filename=settings.MEDIA_URL + "plot-boxfill_httppcmdi9llnlgovthreddsdodsccmip5output1inminmcm41pctco2monatmosamonr1i1p1ccb20130207aggregation1_ccb_latitude_-90_90_longitude_-180_180_time_slice1_6_none_none_none.png"
            """
            mycontent={"curOpt":{"total":total_plot,"type":plot_type,"n":n,"s":s,"e":e,"w":w,"active_plot":active_plot},
                    "dataset":[{"file":myfile,"var":varlist,"id":"2"}],"user":request.user.username,
                    }
            """
            mycontent={"dataset":[{"file":myfile,"var":varlist,"id":"2"}],"user":request.user.username}
            return render(request, 'plot.html',mycontent)
Beispiel #2
0
def run_main_window(request):
    if not request.user.is_authenticated():
        print "NOT 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.run_main_window')}))
    else:
        if request.GET:
            return render(request, 'test_datasetId_form.html', { })
        else:
            datasetIds=request.POST['datasetIds']
            n="-90"
            s="90"
            e="0"
            w="180"
            counter = 1 
            mylist_dict=[]
            try:
                datasetIds_token=datasetIds.split(',')
                for datasetId in datasetIds_token:
                    print datasetId
                    htmllist=datasetId2htmllist(datasetId)
                    myhtmllist=htmllist.split(',')
                    for html in myhtmllist:
                        myfile=html
                        print html
                        active_cert = settings.PROXY_CERT_DIR + request.user.username + '.pem'
                        varlist=get_var(myfile)
                        if not varlist:
                            return render_to_response("accessDenied.html",None,context_instance=RequestContext(request))
                        mydict={"file":myfile,"var":varlist,"id":counter}
                        mylist_dict.append(mydict)
                        counter=counter+1
                print mylist_dict
            except Exception, err:
                print err
                return render(request, 'test_datasetId_form.html', {
                    'error_message': "Please fill all required fields",
                    })
        
            selection_dict = {
                'latitude':(-90,90),
                'longitude':(0,180),
                'time':slice(0,1)
            }
               
            mycontent={"dataset":mylist_dict,"user":request.user.username}
            return render(request, 'plot.html',mycontent)
Beispiel #3
0
def get_variable(request):
    myfile=request.GET['file']
    varlist=get_var(myfile)
    obj={"variable":varlist}
    json_res=simplejson.dumps(obj) 
    return HttpResponse(json_res, content_type="application/json")