aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/base/trait.py12
-rw-r--r--wqflask/utility/hmac.py2
-rw-r--r--wqflask/utility/redis_tools.py54
3 files changed, 59 insertions, 9 deletions
diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py
index e454c593..1b7cb23c 100644
--- a/wqflask/base/trait.py
+++ b/wqflask/base/trait.py
@@ -5,9 +5,6 @@ import resource
import codecs
import requests
-import redis
-Redis = redis.StrictRedis()
-
from base import webqtlConfig
from base.webqtlCaseData import webqtlCaseData
from base.data_set import create_dataset
@@ -15,6 +12,8 @@ from db import webqtlDatabaseFunction
from utility import webqtlUtil
from utility import hmac
from utility.tools import GN2_BASE_URL
+from utility.redis_tools import get_redis_conn
+Redis = get_redis_conn()
from wqflask import app
@@ -349,8 +348,13 @@ def jsonable_table_row(trait, dataset_name, index):
def retrieve_trait_info(trait, dataset, get_qtl_info=False):
assert dataset, "Dataset doesn't exist"
-
+
if dataset.type == 'Publish':
+ resource_id = hmac.data_hmac("{}:{}".format(dataset.id, trait.name))
+
+ the_url = "http://localhost:8080/run_action/?resource={}&user={}&branch=data&action=view".format(resource_id, g.user_session.user_id)
+ trait_data = json.loads(requests.get("http://localhost:8080/run_action/?resource={}&user={}&branch=data&action=view".format(resource_id, g.user_session.user_id)))
+
query = """
SELECT
PublishXRef.Id, InbredSet.InbredSetCode, Publication.PubMed_ID,
diff --git a/wqflask/utility/hmac.py b/wqflask/utility/hmac.py
index d8a0eace..b08be97e 100644
--- a/wqflask/utility/hmac.py
+++ b/wqflask/utility/hmac.py
@@ -3,6 +3,8 @@ from __future__ import print_function, division, absolute_import
import hmac
import hashlib
+from flask import url_for
+
from wqflask import app
def hmac_creation(stringy):
diff --git a/wqflask/utility/redis_tools.py b/wqflask/utility/redis_tools.py
index ca42f7b7..15841032 100644
--- a/wqflask/utility/redis_tools.py
+++ b/wqflask/utility/redis_tools.py
@@ -1,17 +1,25 @@
from __future__ import print_function, division, absolute_import
+import uuid
import simplejson as json
import redis # used for collections
-Redis = redis.StrictRedis()
import logging
from flask import (render_template, flash)
+from utility import hmac
+
from utility.logger import getLogger
logger = getLogger(__name__)
+def get_redis_conn():
+ Redis = redis.StrictRedis(port=6380)
+ return Redis
+
+Redis = get_redis_conn()
+
def is_redis_available():
try:
Redis.ping()
@@ -70,14 +78,15 @@ def check_verification_code(code):
email_address = None
user_details = None
email_address = Redis.hget("verification_codes", code)
- return email_address
if email_address:
user_details = get_user_by_unique_column('email_address', email_address)
- return user_details
+ if user_details:
+ return user_details
+ else:
+ return None
else:
return None
- flash("Invalid code: Password reset code does not exist or might have expired!", "error")
def get_user_groups(user_id):
#ZS: Get the groups where a user is an admin or a member and return lists corresponding to those two sets of groups
@@ -167,4 +176,39 @@ def change_group_name(user_id, group_id, new_name):
group_info["name"] = new_name
return group_info
else:
- return None \ No newline at end of file
+ return None
+
+def get_resources():
+ resource_list = Redis.hgetall("resources")
+ return resource_list
+
+def get_resource_id(dataset_type, dataset_id, trait_id = None, all_resources = None):
+ if not all_resources:
+ all_resources = get_resources()
+
+ resource_list = [[key, json.loads(value)] for key, value in all_resources.items()]
+
+ if not trait_id:
+ matched_resources = [resource[0] for resource in resource_list if resource[1]['data']['dataset'] == dataset_id]
+ else:
+ matched_resources = [resource[0] for resource in resource_list if resource[1]['data']['dataset'] == dataset_id and resource[1]['data']['trait'] == trait_id]
+
+ if len(matched_resources):
+ return matched_resources[0]
+ else:
+ return False
+
+def get_resource_info(resource_id):
+ resource_info = Redis.hget("resources", resource_id)
+ return json.loads(resource_info)
+
+def add_resource(resource_info):
+
+ if 'trait' in resource_info['data']:
+ resource_id = hmac.data_hmac('{}:{}'.format(str(resource_info['data']['dataset']), str(resource_info['data']['trait'])))
+ else:
+ resource_id = hmac.data_hmac('{}'.format(str(resource_info['data']['dataset'])))
+
+ Redis.hset("resources", resource_id, json.dumps(resource_info))
+
+ return resource_info