Commit a5b87796 authored by Ryan Herbert's avatar Ryan Herbert
Browse files

split add utils display_names

this is a refactor of anon_names. We want to use anon_names elsewhere
but without the id when the user is admin. display_names replaces
anon_names and behaves as anon_names did before.
parent 5766203a
......@@ -589,7 +589,8 @@ def custom():
row.checked = True
if row.patient.id is not None:
row.names = vidjil_utils.anon_names(row.patient.id, row.patient.first_name, row.patient.last_name)
#TODO use helper.
row.names = vidjil_utils.display_names(row.patient.id, row.patient.first_name, row.patient.last_name)
info = row.patient.info
elif row.run.id is not None:
row.names = row.run.name
......
......@@ -20,6 +20,9 @@ class SampleSet(object):
def get_name(self, data):
return data.name
def get_display_name(self, data):
return self.get_name(data)
def get_info(self, data):
return data.info
......@@ -43,7 +46,7 @@ class SampleSet(object):
def get_config_urls(self, data):
configs = []
for conf in data.conf_list:
filename = "(%s %s)" % (self.get_name(data), conf['name'])
filename = "(%s %s)" % (self.get_display_name(data), conf['name'])
if conf['fused_file'] is not None :
configs.append(
str(A(conf['name'],
......@@ -67,7 +70,7 @@ class SampleSet(object):
def get_fields(self):
fields = []
fields.append({'name': 'name', 'sort': 'name', 'call': self.get_name, 'width': 200, 'public': True})
fields.append({'name': 'name', 'sort': 'name', 'call': self.get_display_name, 'width': 200, 'public': True})
fields.append({'name': 'info', 'sort': 'info', 'call': self.get_tagged_info, 'width': None, 'public': True})
fields.append({'name': 'results', 'sort': 'confs', 'call': self.get_config_urls, 'width': None, 'public': True})
if auth.is_admin() or len(get_group_list(auth)) > 1:
......
......@@ -12,7 +12,7 @@ class Generic(SampleSet):
return filter(lambda row : vidjil_utils.advanced_filter(row['string'], filter_str), data)
def get_info_dict(self, data):
return dict(name = "set : %s" % self.get_name(data),
return dict(name = "set : %s" % self.get_display_name(data),
filename = "sample_set_%d" % data.id,
label = "",
info = ""
......
......@@ -18,6 +18,9 @@ class Patient(SampleSet):
def get_name(self, data, anon=None):
return vidjil_utils.anon_names(data.id, data.first_name, data.last_name, anon)
def get_display_name(self, data, anon=None):
return vidjil_utils.display_names(data.id, data.first_name, data.last_name, anon)
def get_birth(self, data):
return "%s" % str(data.birth) if data.birth is not None else ''
......@@ -27,7 +30,7 @@ class Patient(SampleSet):
return filter(lambda row : vidjil_utils.advanced_filter(row['string'], filter_str), data)
def get_info_dict(self, data):
name = self.get_name(data)
name = self.get_display_name(data)
return dict(name = name,
filename = name,
label = data.id_label + " (" + str(data.birth) + ")",
......
......@@ -94,7 +94,7 @@ def anon_ids(patient_id):
last_name = db.patient[patient_id].last_name
first_name = db.patient[patient_id].first_name
return anon_names(patient_id, first_name, last_name)
return display_names(patient_id, first_name, last_name)
def anon_names(patient_id, first_name, last_name, can_view=None):
'''
......@@ -113,6 +113,20 @@ def anon_names(patient_id, first_name, last_name, can_view=None):
ln = safe_encoding(last_name)
name = ln[:3]
return name
def display_names(patient_id, first_name, last_name, can_view=None):
'''
Return the name as displayed to a user or admin of a patient
whose ID is patient_id.
It makes use of anon_names which will return an anonymised version
of the patient name if the user doesn't have permission to see the real name.
Admins will also see the patient id.
'''
auth = current.auth
name = anon_names(patient_id, first_name, last_name, can_view)
# Admins also see the patient id
if auth.is_admin():
name += ' (%s)' % patient_id
......
......@@ -4,10 +4,10 @@
{{if 'message' in globals():}}
<div>
<h3>{{=message}}: {{helper.get_name(data)}}
<h3>{{=message}}: {{helper.get_display_name(data)}}
</h3>
Are you sure you want to delete the {{=helper.get_type()}} {{=helper.get_name(data)}} ?</br>
Are you sure you want to delete the {{=helper.get_type()}} {{=helper.get_display_name(data)}} ?</br>
This will delete {{=helper.get_sequence_count(data)}} sequence file(s) and {{=helper.get_data_count(data)}} result files.</br>
This action cannot be undone.
......
{{extend 'db_layout.html'}}
<h3>
Access to {{=helper.get_type_display()}} {{=helper.get_name(data)}}
Access to {{=helper.get_type_display()}} {{=helper.get_display_name(data)}}
</h3>
<div id="db_table_container">
......
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