Attention une mise à jour du serveur va être effectuée le vendredi 16 avril entre 12h et 12h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 32fd3aca authored by Ryan Herbert's avatar Ryan Herbert

refactor id strings and id extraction

For adding files to sample_sets. Alters the existing id strings by
removing dates.
I wanted to clean things up a little and alter the way id_strings are
created/decoded before making them a little more flexible in order to
produce more aesthetically pleasing id_strings.
parent a5b87796
......@@ -15,19 +15,14 @@ if request.env.http_origin:
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
def extract_id(target, error):
def extract_set_type(target):
mapping = {
'p': 'patient',
'r': 'run',
's': 'generic'
}
try:
t_split = target.strip().split(' ')
tid = int(' '.join(t_split[1:]).split('(')[-1][:-1])
ttype = mapping[t_split[0].split(':')[1]]
return ttype, tid
except:
raise ValueError('invalid input %s' % target)
return mapping[target.split(':')[1][0]]
def manage_filename(filename):
filepath = ""
......@@ -170,6 +165,9 @@ def submit():
datetime.datetime.strptime(""+request.vars['sampling_date'], '%Y-%m-%d')
except ValueError:
error += "date (wrong format), "
mf = ModelFactory()
helpers = {}
set_ids = request.vars['set_ids'].split(',')
set_ids = [x.strip() for x in set_ids]
......@@ -178,9 +176,11 @@ def submit():
for sid in set_ids:
if sid != '':
try:
set_type, set_id = extract_id(sid, error)
set_type = extract_set_type(sid)
if set_type not in id_dict:
helpers[set_type] = mf.get_instance(set_type)
id_dict[set_type] = []
set_id = helpers[set_type].parse_id_string(sid)
id_dict[set_type].append(set_id)
if not auth.can_modify(set_type, set_id) :
error += " missing permission for %s %d" % (set_type, set_id)
......
......@@ -12,6 +12,7 @@ if request.env.http_origin:
def anon_names(data):
for row in data:
# TODO use helper ?
row.name = vidjil_utils.anon_ids(row.id)
return data
......
......@@ -128,6 +128,13 @@ class SampleSet(object):
def get_id_string(self, data):
pass
def parse_id_string(self, string):
try:
value = string[string.find("(")+1:string.find(")")]
return int(value)
except:
raise ValueError('invalid input %s' % string)
def get_sample_name(sample_set_id):
'''
Return the name associated with a sample set (eg. a run or a
......
......@@ -26,4 +26,4 @@ class Generic(SampleSet):
def get_id_string(self, data):
name = data.name if data.name is not None else "Unnamed Sample Set"
return ":s %s (%d)" % (name, data.id)
return ":s %s (%d)" % (name, data.id)
......@@ -45,6 +45,5 @@ class Patient(SampleSet):
def get_id_string(self, data):
name = self.get_name(data)
birth = "[%s]" % str(data.birth)
id = "(%d)" % data.id
return ":p %s %s %s" % (birth, name, id)
ident = "(%d)" % data.id
return ":p %s %s" % (name, ident)
......@@ -41,6 +41,5 @@ class Run(SampleSet):
def get_id_string(self, data):
name = data.name
run_date = "[%s]" % str(data.run_date)
id = "(%d)" % data.id
return ":r %s %s %s" % (run_date, name, id)
ident = "(%d)" % data.id
return ":r %s %s" % (name, ident)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment