from django.core.mail import send_mail, mail_admins
from django.http import HttpResponse, Http404
-from htsworkflow.frontend import settings
-from htsworkflow.frontend.experiments.models import FlowCell, DataRun
-from htsworkflow.frontend.samples.models import Library
from htsworkflow.frontend.auth import require_api_key
+from htsworkflow.frontend import settings
+from htsworkflow.frontend.experiments.models import FlowCell, DataRun, Lane
+from htsworkflow.frontend.samples.models import Library, HTSUser
def flowcell_information(flowcell_id):
"""
fc_json = json.dumps(fc_dict)
return HttpResponse(fc_json, mimetype = 'application/json')
+
+def lanes_for(username=None):
+ """
+ Given a user id try to return recent lanes as a list of dictionaries
+ """
+ query = {}
+ if username is not None:
+ user = HTSUser.objects.get(username=username)
+ query.update({'library__affiliations__users__id': user.id})
+
+ lanes = Lane.objects.filter(**query).order_by('-flowcell__run_date')
+
+ result = []
+ for l in lanes:
+ result.append({ 'flowcell': l.flowcell.flowcell_id,
+ 'run_date': l.flowcell.run_date.isoformat(),
+ 'lane_number': l.lane_number,
+ 'library': l.library.id,
+ 'comment': l.comment})
+ return result
+
+def lanes_for_json(request, username):
+ """
+ Format lanes for a user
+ """
+ require_api_key(request)
+
+ try:
+ result = lanes_for(username)
+ except ObjectDoesNotExist, e:
+ raise Http404
+
+ #convert query set to python structure
+ result_json = json.dumps(result)
+ return HttpResponse(result_json, mimetype='application/json')
+
def updStatus(request):
output=''
user = 'none'
[
- {"pk": 1, "model": "samples.affiliation",
- "fields": {
- "users": [],
- "contact": "group 1",
- "name": "affiliation 1",
- "email": "pk1@example.com"
- }
- },
- {"pk": 2, "model": "samples.affiliation",
- "fields": {
- "users": [],
- "contact": "group 2",
- "name": "affiliation 2",
- "email": "pk2@example.com"
- }
- },
- {"pk": 3, "model": "samples.affiliation",
- "fields": {
- "users": [],
- "contact": "group 3",
- "name": "affiliation 3",
- "email": "pk3@example.com"
- }
- },
- {"pk": 4, "model": "samples.affiliation",
- "fields": {
- "users": [],
- "contact": "group 4",
- "name": "affiliation 4",
- "email": "pk1@example.com"
- }
- },
- {"pk": 5, "model": "samples.affiliation",
- "fields": {
- "users": [],
- "contact": "group 5",
- "name": "affiliation 5",
- "email": "pk5@example.com"
- }
- },
{"pk": 5, "model": "auth.user",
"fields": {
"username": "test",
"date_joined": "2009-01-01 00:01:01"
}
},
- {"pk": 6, "model": "auth.user",
+ {"pk": 5, "model": "samples.htsuser",
+ "fields" : {}
+ },
+ {"pk": 6, "model": "auth.user",
"fields": {
"username": "admintest",
"first_name": "",
"date_joined": "2009-01-01 00:01:01"
}
},
- {"pk": 7, "model": "auth.user",
+ {"pk": 6, "model": "samples.htsuser",
+ "fields" : {}
+ },
+ {"pk": 7, "model": "auth.user",
"fields": {
"username": "supertest",
"first_name": "",
"date_joined": "2009-01-01 00:01:01"
}
},
+ {"pk": 7, "model": "samples.htsuser",
+ "fields" : {}
+ },
+ {"pk": 1, "model": "samples.affiliation",
+ "fields": {
+ "users": [5],
+ "contact": "group 1",
+ "name": "affiliation 1",
+ "email": "pk1@example.com"
+ }
+ },
+ {"pk": 2, "model": "samples.affiliation",
+ "fields": {
+ "users": [6],
+ "contact": "group 2",
+ "name": "affiliation 2",
+ "email": "pk2@example.com"
+ }
+ },
+ {"pk": 3, "model": "samples.affiliation",
+ "fields": {
+ "users": [],
+ "contact": "group 3",
+ "name": "affiliation 3",
+ "email": "pk3@example.com"
+ }
+ },
+ {"pk": 4, "model": "samples.affiliation",
+ "fields": {
+ "users": [],
+ "contact": "group 4",
+ "name": "affiliation 4",
+ "email": "pk1@example.com"
+ }
+ },
+ {"pk": 5, "model": "samples.affiliation",
+ "fields": {
+ "users": [],
+ "contact": "group 5",
+ "name": "affiliation 5",
+ "email": "pk5@example.com"
+ }
+ },
{"pk": 1, "model": "experiments.clusterstation", "fields": {"name": "old"}},
{"pk": 2, "model": "experiments.clusterstation", "fields": {"name": "loaner"}},
{"pk": 3, "model": "experiments.clusterstation", "fields": {"name": "new"}},
import sys
from django.core import mail
+from django.core.exceptions import ObjectDoesNotExist
from django.test import TestCase
from htsworkflow.frontend.experiments import models
from htsworkflow.frontend.experiments import experiments
self.failUnlessEqual(library_id, expected_ids[i])
self.failUnlessEqual(input_field['value'], library_id)
+ def test_lanes_for(self):
+ """
+ Check the code that packs the django objects into simple types.
+ """
+ user = 'test'
+ lanes = experiments.lanes_for(user)
+ self.failUnlessEqual(len(lanes), 5)
+
+ response = self.client.get('/experiments/lanes_for/%s/json' % (user,), apidata)
+ lanes_json = json.loads(response.content)
+ self.failUnlessEqual(len(lanes), len(lanes_json))
+ for i in range(len(lanes)):
+ self.failUnlessEqual(lanes[i]['comment'], lanes_json[i]['comment'])
+ self.failUnlessEqual(lanes[i]['lane_number'], lanes_json[i]['lane_number'])
+ self.failUnlessEqual(lanes[i]['flowcell'], lanes_json[i]['flowcell'])
+ self.failUnlessEqual(lanes[i]['run_date'], lanes_json[i]['run_date'])
+
+ def test_lanes_for_no_lanes(self):
+ """
+ Do we get something meaningful back when the user isn't attached to anything?
+ """
+ user = 'supertest'
+ lanes = experiments.lanes_for(user)
+ self.failUnlessEqual(len(lanes), 0)
+
+ response = self.client.get('/experiments/lanes_for/%s/json' % (user,), apidata)
+ lanes_json = json.loads(response.content)
+
+ def test_lanes_for_no_user(self):
+ """
+ Do we get something meaningful back when its the wrong user
+ """
+ user = 'not a real user'
+ self.failUnlessRaises(ObjectDoesNotExist, experiments.lanes_for, user)
+
+ response = self.client.get('/experiments/lanes_for/%s/json' % (user,), apidata)
+ self.failUnlessEqual(response.status_code, 404)
+
+
class TestEmailNotify(TestCase):
fixtures = ['test_flowcells.json']
#(r'^liblist$', 'htsworkflow.frontend.experiments.views.test_Libs'),
#(r'^(?P<run_folder>.+)/$', 'gaworkflow.frontend.experiments.views.detail'),
(r'^config/(?P<fc_id>.+)/json$', 'htsworkflow.frontend.experiments.experiments.flowcell_json'),
+ (r'^lanes_for/(?P<username>.+)/json$', 'htsworkflow.frontend.experiments.experiments.lanes_for_json'),
(r'^fcsheet/(?P<fcid>.+)/$', 'htsworkflow.frontend.experiments.views.makeFCSheet'),
(r'^updStatus$', 'htsworkflow.frontend.experiments.experiments.updStatus'),
(r'^getConfile$', 'htsworkflow.frontend.experiments.experiments.getConfile'),