Skip to content

Commit 23e94bc

Browse files
committed
Fix #246
1 parent 0359750 commit 23e94bc

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

labman/db/plate.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ def list_plates(plate_types=None, only_quantified=False,
232232
sql_studies = (', labman.get_plate_studies(p.plate_id) '
233233
'AS studies')
234234

235-
sql = """SELECT p.plate_id, p.external_id {}
236-
FROM (SELECT DISTINCT plate_id, external_id
235+
sql = """SELECT p.plate_id, p.external_id, p.creation_timestamp {}
236+
FROM (SELECT DISTINCT plate_id, external_id,
237+
creation_timestamp
237238
FROM labman.plate
238239
JOIN labman.well USING (plate_id)
239240
JOIN labman.composition USING (container_id)
@@ -290,6 +291,10 @@ def create(cls, external_id, plate_configuration):
290291
TRN.add(sql, [external_id, plate_configuration.id])
291292
return cls(TRN.execute_fetchlast())
292293

294+
@property
295+
def creation_timestamp(self):
296+
return self._get_attr('creation_timestamp')
297+
293298
@property
294299
def external_id(self):
295300
"""The plate external identifier"""

labman/db/support_files/db_patch.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ CREATE TABLE labman.plate (
118118
plate_configuration_id integer NOT NULL,
119119
discarded bool DEFAULT 'False' NOT NULL,
120120
notes varchar(600) ,
121+
creation_timestamp timestamp default now() NOT NULL,
121122
CONSTRAINT pk_plate PRIMARY KEY ( plate_id ),
122123
CONSTRAINT idx_plate UNIQUE ( external_id )
123124
);

labman/db/testing.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ def reset_test_db():
5454

5555

5656
class LabmanTestCase(TestCase):
57+
_perform_reset = True
58+
59+
def do_not_reset_at_teardown(self):
60+
self.__class__._perform_reset = False
61+
5762
@classmethod
5863
def tearDownClass(cls):
59-
reset_test_db()
64+
if cls._perform_reset:
65+
reset_test_db()
66+
else:
67+
cls._perform_reset = True

labman/db/tests/test_plate.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from unittest import main
1010
from types import GeneratorType
11+
import datetime
1112

1213
from labman.db.testing import LabmanTestCase
1314
from labman.db.plate import PlateConfiguration, Plate
@@ -184,6 +185,23 @@ def test_list_plates(self):
184185
'studies': ['Identification of the Microbiomes '
185186
'for Cannabis Soils']}])
186187

188+
def test_plate_list_include_timestamp(self):
189+
# ...limit pathological failures by testing within an hour of creation
190+
exp = datetime.datetime.now()
191+
exp = datetime.datetime(exp.year,
192+
exp.month,
193+
exp.day,
194+
exp.hour)
195+
196+
for i in Plate.list_plates():
197+
obs = i['creation_timestamp']
198+
obs = datetime.datetime(obs.year,
199+
obs.month,
200+
obs.day,
201+
obs.hour)
202+
203+
self.assertEqual(obs, exp)
204+
187205
def test_plate_list_discarded_functionality(self):
188206
# test case based on the test_list_plates
189207
obs = Plate.list_plates()
@@ -268,6 +286,15 @@ def test_create(self):
268286
def test_properties(self):
269287
# Plate 21 - Defined in the test DB
270288
tester = Plate(21)
289+
290+
obs = tester.creation_timestamp
291+
obs = datetime.datetime(obs.year,
292+
obs.month,
293+
obs.day,
294+
obs.hour)
295+
exp = datetime.datetime.now()
296+
exp = datetime.datetime(exp.year, exp.month, exp.day, exp.hour)
297+
self.assertEqual(obs, exp)
271298
self.assertEqual(tester.external_id, 'Test plate 1')
272299
self.assertEqual(tester.plate_configuration, PlateConfiguration(1))
273300
self.assertFalse(tester.discarded)

labman/gui/handlers/plate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def get(self):
8181
if plate_type is not None else None)
8282
only_quantified = True if only_quantified == 'true' else False
8383

84-
rows_list = [[p['plate_id'], p['external_id'],
84+
rows_list = [[p['plate_id'],
85+
p['external_id'],
86+
str(p['creation_timestamp']),
8587
p['studies'] if p['studies'] is not None else []]
8688
for p in Plate.list_plates(
8789
plate_type, only_quantified=only_quantified,

labman/gui/templates/plate_list.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@
105105
var deleteButton = '<button onclick="discardPlate(' + row[0] + ', this)" class="btn btn-danger">Discard Plate ' +
106106
'<span class="glyphicon glyphicon-remove" data-toggle="tooltip" title="Discard plate"></span>' +
107107
'</button> ';
108-
// row[0] = plate id, row[1] = external id, row[2] = list of names of
109-
// studies associated with any sample on plate (may be empty list)
110-
newData.push([chBox, row[0], row[1], row[2].join('<br />'), deleteButton]);
108+
// row[0] = plate id, row[1] = external id, row[2] = creation
109+
// timestamprow[3] = list of names of studies associated with any
110+
// sample on plate (may be empty list)
111+
newData.push([chBox, row[0], row[1], row[2], row[3].join('<br />'), deleteButton]);
111112
}
112113
datatable.clear();
113114
datatable.rows.add(newData);
@@ -159,6 +160,7 @@
159160
<th></th>
160161
<th>Plate id</th>
161162
<th>Plate name</th>
163+
<th>Creation timestamp</th>
162164
<th>Studies</th>
163165
<th></th>
164166
</tr>

0 commit comments

Comments
 (0)