clearwing

changeset 232:307ebe3e1bfe

Fixing Region form to use Firethorn
author Stelios <stv@roe.ac.uk>
date Tue Sep 04 00:33:16 2018 +0300 (2018-09-04)
parents 6090e1d3f173
children 2f3122efdcb9
files src/freeform_sql/misc.py src/helper_functions/helper_urls.py
line diff
     1.1 --- a/src/freeform_sql/misc.py	Sat Sep 01 18:31:51 2018 +0300
     1.2 +++ b/src/freeform_sql/misc.py	Tue Sep 04 00:33:16 2018 +0300
     1.3 @@ -767,7 +767,17 @@
     1.4      json_list = ""
     1.5      content = ""
     1.6  
     1.7 -    if votable == "MAX_ERROR" or votable == "ERROR" or (getattr(votable, "columns", None)==None and (votable!='' and votable!= None)):
     1.8 +    if votable!='' and votable!= None and not (((type(votable) is str) or (type(votable) is unicode)) and votable.startswith("Query")):
     1.9 +        json_data = json.loads(votable)
    1.10 +    
    1.11 +        if len(json_data)<2:
    1.12 +            votable = "ERROR"
    1.13 +        else :
    1.14 +            cols = json_data[0]
    1.15 +            row_length = len(json_data[1])
    1.16 +    
    1.17 +    if votable == "MAX_ERROR" or votable == "ERROR" or ( ((type(votable) is str) or (type(votable) is unicode)) and votable.startswith("Query")):
    1.18 +
    1.19  	data_results = ["ERROR"]	
    1.20  	if votable == "MAX_ERROR":
    1.21  	    data_results.append("Query exceeded maximum return size limit")
    1.22 @@ -780,17 +790,16 @@
    1.23  	else :
    1.24  	    query_id_content = ""
    1.25  	data_results.append(query_id_content)
    1.26 -	
    1.27          return json.dumps(data_results)
    1.28 +
    1.29 +
    1.30      elif votable!='' and votable!= None:
    1.31          if len(votable)>0:
    1.32 -            cols = list(votable.columns)
    1.33 -            row_list = votable.data.tolist() 
    1.34              if tap_endpoint!="" and query!="":
    1.35                  content = '<form class="launch_viewer" style="float:left;z-index:100;position: relative;" action="' + survey_prefix + '/viewer" method="post" target="_blank"><input type="hidden" name="query" value="'+ string_functions.encode(query) +'"/><input type="hidden" name="cols" value="'+ html_functions.escape(json.dumps(cols)) +'"/><input type="hidden" name="filepath" id="temp_file" value="'+ pathname +'"/><input type="hidden" name="tap_endpoint" value="'+ tap_endpoint +'"/>'
    1.36                  content += '<input type="hidden" name="adql_table" id="adql_table" value="'+ adql_table +'"/>'
    1.37                  if table_mode == 'interactive':
    1.38 -                    data_results = html_functions.escape_list(row_list)
    1.39 +                    data_results = ""#html_functions.escape_list(row_list)
    1.40                      json_list = html_functions.escape(json.dumps(data_results))
    1.41                      content += '<input type="hidden" id="hidden_json_results" name="results" value="' + json_list  + '" />'
    1.42                  content += '<div style="margin-bottom:5px;text-align:left;margin-left:20px;font-size:13px;color:#C2BEAD">Launch in Plotter<input class="plotter_button" type="submit" value="" /></form></div><br /><br />'
    1.43 @@ -802,13 +811,13 @@
    1.44              content += '<div style="text-align:left;margin-left:15px;float:left;z-index:100;position: relative;clear:both"><img id ="samp_connection" src="' + survey_prefix + '/static/images/red-button.png" height="17" width="17" /><button id="register">Connect to SAMP</button><button id="unregister" style="display: none;">Disconnect from SAMP</button><button id="loadvotable" style="display: none;">Broadcast results table</button></div>'
    1.45  
    1.46              data_results = [cols]
    1.47 -            data_results.append([len(row_list)])
    1.48 +            data_results.append([row_length])
    1.49              data_results.append([content])
    1.50              return json.dumps(data_results)
    1.51          else:
    1.52              return json.dumps([])
    1.53 +
    1.54      else:
    1.55 -
    1.56             
    1.57  	data_results = ["ERROR"]
    1.58  	if votable == "MAX_ERROR":
    1.59 @@ -953,32 +962,41 @@
    1.60      votable = ''
    1.61      jobId= 'None'
    1.62      file_path=''
    1.63 +
    1.64 +    def read_json(url):
    1.65 +        request2 = urllib2.Request(url,headers={"Accept" : "application/json", "firethorn.auth.identity" : session.get("email","unknown user"), "firethorn.auth.community" : config.firethorn_admin_community, "firethorn.auth.username" : config.firethorn_admin_username, "firethorn.auth.password" : config.firethorn_admin_password})
    1.66 +        f_read = urllib2.urlopen(request2)
    1.67 +        query_json = json.loads(f_read.read())
    1.68 +        f_read.close()
    1.69 +        return query_json   
    1.70 +
    1.71      try:
    1.72 -        
    1.73 -        #Submit job and get job id 
    1.74 -        req = urllib2.Request(full_url, params)
    1.75 -        opener = urllib2.build_opener()
    1.76 -  
    1.77 -        f = opener.open(req)
    1.78 -        jobId = f.url
    1.79 -        logging.exception("Jobid:" + jobId)
    1.80 -        #Execute job and start loop requests for results
    1.81 -        req2 = urllib2.Request(jobId+'/phase',urllib.urlencode({'PHASE' : 'RUN'}))
    1.82 -        f2 = opener.open(req2) #@UnusedVariable
    1.83 +        url="http://gillian:8080/firethorn/adql/schema/579/"
    1.84  
    1.85          # Return results as a votable object
    1.86 -        votable = start_async_loop(jobId)
    1.87 -        
    1.88 +        votable, adql_table, query_loop_results = run_query(q,"",query_space=url)   
    1.89 +        jobId=adql_table
    1.90 +         
    1.91          if votable!='' and votable !="MAX_ERROR" and not (((type(votable) is str) or (type(votable) is unicode)) and votable.startswith("Query")):
    1.92              multiframeID_index = -1
    1.93              framesetID_index = -1
    1.94              dec_index = -1  
    1.95              ra_index = -1
    1.96              clear_temp_folder()
    1.97 -            cols = list(votable.columns)
    1.98 +            if votable!='' and votable!= None and not (((type(votable) is str) or (type(votable) is unicode)) and votable.startswith("Query")):
    1.99 +                json_data = json.loads(votable)
   1.100 +                if len(json_data)<2:
   1.101 +                    votable = "ERROR"
   1.102 +                else :
   1.103 +                    cols = json_data[0]
   1.104 +                    row_length = len(json_data[1])
   1.105 +            else:
   1.106 +                cols = list(votable.columns)
   1.107 +
   1.108              cols.insert(0,"getFSLink")
   1.109 -            col_data_to_list =  list(votable.columns)
   1.110 -            
   1.111 +            #col_data_to_list =  list(votable.columns)
   1.112 +            col_data_to_list = cols
   1.113 +
   1.114              if 'ra' in col_data_to_list:
   1.115                  ra_index = col_data_to_list.index('ra')
   1.116              else :
   1.117 @@ -998,48 +1016,36 @@
   1.118                  else:
   1.119                      multiframeID_index = -1
   1.120  
   1.121 -            #if getattr(session, "community_input","").lower()=="vphas":
   1.122 -            #    db = PRIVATE_SURVEY_DB_VPHAS
   1.123 -            #else:
   1.124 -            #    db = SURVEY_DB
   1.125 -            #db=db
   1.126 +                    multiframeID_index = -1
   1.127 +
   1.128              temp_row=[]
   1.129 -            for i in votable.data.tolist():
   1.130 +            votable_json = json.loads(votable)[1]
   1.131 +            newdatatable = []
   1.132 +            for i in votable_json:
   1.133                  if framesetID_index == -1 and multiframeID_index == -1:
   1.134                      getFSLink = ''
   1.135                  elif framesetID_index == -1 and ra_index!=-1 and dec_index!=-1:
   1.136 -                    getFSLink = '<a target="getI" href="' + getImageURL +'?mode=show&ra=' + str(i[ra_index])  + '&dec=' + str(i[dec_index]) + '&mfid=' + str(i[ multiframeID_index]) + '&database=' + db + '&archive=' + archive_input +'">view</a>'
   1.137 -                    
   1.138 +                    getFSLink = '<a target="getI" href="' + getImageURL +'?mode=show&ra=' + str(i["ra"])  + '&dec=' + str(i["dec"]) + '&mfid=' + str(i["multiframeID"]) + '&database=' + db + '&archive=' + archive_input +'">view</a>'
   1.139                  elif multiframeID_index == -1 and ra_index!=-1 and dec_index!=-1:
   1.140 -                    getFSLink = '<a target="getI" href="' + getImageURL +'?mode=show&ra=' + str(i[ra_index])  + '&dec=' + str(i[dec_index]) + '&fsid=' + str(i[framesetID_index]) + '&database=' + db + '&archive=' + archive_input +'">view</a>'   
   1.141 +                    getFSLink = '<a target="getI" href="' + getImageURL +'?mode=show&ra=' + str(i["ra"])  + '&dec=' + str(i["dec"]) + '&fsid=' + str(i["frameSetID"]) + '&database=' + db + '&archive=' + archive_input +'">view</a>'   
   1.142                  else :
   1.143 -                    getFSLink = '<a target="getI" href="' + getImageURL +'?mode=show&ra=' + str(i[ra_index])  + '&dec=' + str(i[dec_index]) + '&fsid=' + str(i[framesetID_index]) + '&database=' + db + '&archive=' + archive_input +'">view</a>'
   1.144 -                temp_row.append(getFSLink)
   1.145 -           
   1.146 -            votable.add_column(name="getFSLink",data=temp_row,position=0)
   1.147 -            
   1.148 -            
   1.149 -            lst = []
   1.150 -            for x in votable.data.tolist():
   1.151 -                second_counter = 0
   1.152 -                obj_list = {}
   1.153 -                for y in x:
   1.154 -                    obj_list[cols[second_counter]] = y 
   1.155 -                    second_counter = second_counter + 1
   1.156 -                lst.append(obj_list)
   1.157 -            
   1.158 -            #html_functions.escape_list(votable.data.tolist())
   1.159 -            lst = [cols,lst] 
   1.160 +                    getFSLink = '<a target="getI" href="' + getImageURL +'?mode=show&ra=' + str(i["ra"])  + '&dec=' + str(i["dec"]) + '&fsid=' + str(i["frameSetID"]) + '&database=' + db + '&archive=' + archive_input +'">view</a>'
   1.161 +                i["getFSLink"] = getFSLink
   1.162 +                newdatatable.append(i)
   1.163 +
   1.164 +            votable=json.dumps([cols,newdatatable])
   1.165 +
   1.166              file_handle = File_handler()
   1.167              file_handle.create_temp_file()
   1.168 -            file_handle.write_to_temp_file(json.dumps(lst))
   1.169 +            file_handle.write_to_temp_file(votable)
   1.170              file_handle.close_handle()    
   1.171              file_path = file_handle.pathname
   1.172 -            
   1.173 +                        
   1.174      except Exception as e:
   1.175          logging.exception('Exception caught:')
   1.176  
   1.177 -    return (votable,jobId,file_path,"",jobId)
   1.178 +    return (votable,jobId,file_path,adql_table, query_loop_results)
   1.179 +    #return (votable,jobId,file_path,"",jobId)
   1.180  
   1.181  
   1.182  
   1.183 @@ -1276,4 +1282,4 @@
   1.184      response = urllib2.urlopen(req)
   1.185      info = json.loads(response.read())
   1.186      response.close()
   1.187 -    return info
   1.188 +    return info
   1.189 \ No newline at end of file
     2.1 --- a/src/helper_functions/helper_urls.py	Sat Sep 01 18:31:51 2018 +0300
     2.2 +++ b/src/helper_functions/helper_urls.py	Tue Sep 04 00:33:16 2018 +0300
     2.3 @@ -75,7 +75,7 @@
     2.4          """
     2.5          from helper_functions import MultipartPostHandler
     2.6          web.header('Content-Type', 'text/html')
     2.7 -        data = web.input(href="", params="", action="", uploadFile="", file1="")
     2.8 +        data = web.input(href="", params="", action="", uploadFile="", file1="", programmeID="170")
     2.9          return_str = ''
    2.10          f = ''
    2.11          temp_URL = ''