aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruditgulati2020-08-16 17:11:03 -0500
committeruditgulati2020-11-01 06:47:00 -0600
commitf52499653858512320ae17a2ff48671d82fc31fb (patch)
treef39c46d3d1fa22c2215cb89066a96d41ec055427
parent876b95a8e1ad5944105b8d23ae362415011239b5 (diff)
downloadgenenetwork2-f52499653858512320ae17a2ff48671d82fc31fb.tar.gz
move SnpPage to a generic class ServerSide
-rw-r--r--wqflask/wqflask/server_side.py74
-rw-r--r--wqflask/wqflask/snp_browser/snp_browser.py71
-rw-r--r--wqflask/wqflask/views.py17
3 files changed, 89 insertions, 73 deletions
diff --git a/wqflask/wqflask/server_side.py b/wqflask/wqflask/server_side.py
new file mode 100644
index 00000000..090720ec
--- /dev/null
+++ b/wqflask/wqflask/server_side.py
@@ -0,0 +1,74 @@
+# handles server side table processing
+
+
+
+class ServerSide(object):
+
+ def __init__(self, table_data, request_values):
+ self.request_values = request_values
+ self.sEcho = self.request_values['sEcho']
+
+ self.table_data = table_data
+ self.rows_count = self.table_data.rows_count
+ self.table_rows = self.table_data.table_rows
+ self.header_data_names = self.table_data.header_data_names
+
+ self.sort_rows()
+ self.paginate_rows()
+
+ def sort_rows(self):
+ '''
+ Sorts the rows taking in to account the column (or columns) that the
+ user has selected.
+ '''
+ def is_reverse(str_direction):
+ ''' Maps the 'desc' and 'asc' words to True or False. '''
+ return True if str_direction == 'desc' else False
+
+ if (self.request_values['iSortCol_0'] != "") and (int(self.request_values['iSortingCols']) > 0):
+ for i in range(0, int(self.request_values['iSortingCols'])):
+ column_number = int(self.request_values['iSortCol_' + str(i)])
+ column_name = self.header_data_names[column_number - 1]
+ sort_direction = self.request_values['sSortDir_' + str(i)]
+ self.table_rows = sorted(self.table_rows,
+ key=lambda x: x[column_name],
+ reverse=is_reverse(sort_direction))
+
+ def paginate_rows(self):
+ '''
+ Selects a subset of the filtered and sorted data based on if the table
+ has pagination, the current page and the size of each page.
+ '''
+ def requires_pagination():
+ ''' Check if the table is going to be paginated '''
+ if self.request_values['iDisplayStart'] != "":
+ if int(self.request_values['iDisplayLength']) != -1:
+ return True
+ return False
+
+ if not requires_pagination():
+ return
+
+ start = int(self.request_values['iDisplayStart'])
+ length = int(self.request_values['iDisplayLength'])
+
+ # if search returns only one page
+ if len(self.table_rows) <= length:
+ # display only one page
+ self.table_rows = self.table_rows[start:]
+ else:
+ limit = -len(self.table_rows) + start + length
+ if limit < 0:
+ # display pagination
+ self.table_rows = self.table_rows[start:limit]
+ else:
+ # display last page of pagination
+ self.table_rows = self.table_rows[start:]
+
+ def get_page(self):
+ output = {}
+ output['sEcho'] = str(self.sEcho)
+ output['iTotalRecords'] = str(float('Nan'))
+ output['iTotalDisplayRecords'] = str(self.rows_count)
+ output['data'] = self.table_rows
+ return output
diff --git a/wqflask/wqflask/snp_browser/snp_browser.py b/wqflask/wqflask/snp_browser/snp_browser.py
index 58c90f11..a52399a2 100644
--- a/wqflask/wqflask/snp_browser/snp_browser.py
+++ b/wqflask/wqflask/snp_browser/snp_browser.py
@@ -641,77 +641,6 @@ class SnpBrowser(object):
#for i in range(n_click):
# href = url_for('snp_browser', first_run="false", chosen_strains_mouse=self.chosen_strains_mouse, chosen_strains_rat=self.chosen_strains_rat, variant=self.variant_type, species=self.species_name, gene_name=self.gene_name, chr=self.chr, start_mb=self.start_mb, end_mb=self.end_mb, limit_strains=self.limit_strains, domain=self.domain, function=self.function, criteria=self.criteria, score=self.score, diff_alleles=self.diff_alleles)
-class SnpPage(object):
-
- def __init__(self, request):
- self.request_values = request
- self.sEcho = self.request_values['sEcho']
-
- self.snp_browser = SnpBrowser(request)
- self.rows_count = self.snp_browser.rows_count
- self.table_rows = self.snp_browser.table_rows
- self.header_data_names = self.snp_browser.header_data_names
-
- self.sort_rows()
- self.paginate_rows()
-
- def sort_rows(self):
- '''
- Sorts the rows taking in to account the column (or columns) that the
- user has selected.
- '''
- def is_reverse(str_direction):
- ''' Maps the 'desc' and 'asc' words to True or False. '''
- return True if str_direction == 'desc' else False
-
- if (self.request_values['iSortCol_0'] != "") and (int(self.request_values['iSortingCols']) > 0):
- for i in range(0, int(self.request_values['iSortingCols'])):
- column_number = int(self.request_values['iSortCol_' + str(i)])
- column_name = self.header_data_names[column_number - 1]
- sort_direction = self.request_values['sSortDir_' + str(i)]
- self.table_rows = sorted(self.table_rows,
- key=lambda x: x[column_name],
- reverse=is_reverse(sort_direction))
-
- def paginate_rows(self):
- '''
- Selects a subset of the filtered and sorted data based on if the table
- has pagination, the current page and the size of each page.
- '''
- def requires_pagination():
- ''' Check if the table is going to be paginated '''
- if self.request_values['iDisplayStart'] != "":
- if int(self.request_values['iDisplayLength']) != -1:
- return True
- return False
-
- if not requires_pagination():
- return
-
- start = int(self.request_values['iDisplayStart'])
- length = int(self.request_values['iDisplayLength'])
-
- # if search returns only one page
- if len(self.table_rows) <= length:
- # display only one page
- self.table_rows = self.table_rows[start:]
- else:
- limit = -len(self.table_rows) + start + length
- if limit < 0:
- # display pagination
- self.table_rows = self.table_rows[start:limit]
- else:
- # display last page of pagination
- self.table_rows = self.table_rows[start:]
-
- def get_page(self):
- output = {}
- output['sEcho'] = str(self.sEcho)
- output['iTotalRecords'] = str(float('Nan'))
- output['iTotalDisplayRecords'] = str(self.rows_count)
- output['data'] = self.table_rows
- return output
-
def get_browser_sample_lists(species_id=1):
strain_lists = {}
mouse_strain_list = []
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 12ebf595..185517d3 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -27,7 +27,19 @@ import array
import sqlalchemy
from wqflask import app
from flask import g, Response, request, make_response, render_template, send_from_directory, jsonify, redirect, url_for, send_file
-
+<<<<<<< HEAD
+
+=======
+from wqflask import group_manager
+from wqflask import resource_manager
+from wqflask import search_results
+from wqflask import export_traits
+from wqflask import gsearch
+from wqflask import update_search_results
+from wqflask import docs
+from wqflask import news
+from wqflask import server_side
+>>>>>>> ed2afa4a (move SnpPage to a generic class ServerSide)
from wqflask.submit_bnw import get_bnw_input
from base.data_set import create_dataset, DataSet # Used by YAML in marker_regression
from wqflask.show_trait import show_trait
@@ -909,7 +921,8 @@ def db_info_page():
@app.route("/snp_browser_table", methods=('GET',))
def snp_browser_table():
logger.info(request.url)
- current_page = snp_browser.SnpPage(request.args).get_page()
+ snp_table_data = snp_browser.SnpBrowser(request.args)
+ current_page = server_side.ServerSide(snp_table_data, request.args).get_page()
return flask.jsonify(current_page)