1 from __future__ import absolute_import, print_function, unicode_literals
3 # Create your views here.
4 from datetime import datetime
7 #from django.template import Context, loader
8 #shortcut to the above modules
9 from django.contrib.auth.decorators import user_passes_test
10 from django.conf import settings
11 from django.core.exceptions import ObjectDoesNotExist
12 from django.core.mail import EmailMessage, mail_managers
13 from django.http import HttpResponse
14 from django.shortcuts import render_to_response, get_object_or_404
15 from django.template import RequestContext
16 from django.template.loader import get_template
18 from .models import DataRun, DataFile, FlowCell, Lane, Sequencer
19 from .experiments import estimateFlowcellDuration, estimateFlowcellTimeRemaining, roundToDays, \
20 getUsersForFlowcell, \
24 all_runs = DataRun.objects.order_by('-run_start_time')
25 return render_to_response('experiments/index.html',{'data_run_list': all_runs})
27 def detail(request, run_folder):
28 html_str = '<h2>Exp Track Details Page</h2>'
29 html_str += 'Run Folder: '+run_folder
30 r = get_object_or_404(DataRun,run_folder=run_folder)
31 return render_to_response('experiments/detail.html',{'run_f': r})
33 def makeFCSheet(request,fcid):
34 # get Flowcell by input fcid
38 rec = FlowCell.objects.get(flowcell_id=fcid)
39 except ObjectDoesNotExist:
41 lanes = ['1','2','3','4','5','6','7','8']
42 return render_to_response('experiments/flowcellSheet.html',{'fc': rec})
45 @user_passes_test(lambda u: u.is_staff)
46 def startedEmail(request, pk):
48 Create the we have started processing your samples email
50 fc = get_object_or_404(FlowCell, id=pk)
52 send = request.REQUEST.get('send',False)
53 if send in ('1', 'on', 'True', 'true', True):
58 bcc_managers = request.REQUEST.get('bcc', False)
59 if bcc_managers in ('on', '1', 'True', 'true'):
64 email_lane = makeEmailLaneMap(fc)
65 flowcell_users = getUsersForFlowcell(fc)
66 estimate = estimateFlowcellTimeRemaining(fc)
67 estimate_low, estimate_high = roundToDays(estimate)
68 email_verify = get_template('experiments/email_preview.html')
69 email_template = get_template('experiments/started_email.txt')
70 sender = settings.NOTIFICATION_SENDER
76 for user in flowcell_users:
78 if user.email is None or len(user.email) == 0:
79 warnings.append((user.admin_url(), user.username))
82 for user_email in email_lane.keys():
85 context = RequestContext(request,
87 u'lanes': email_lane[user_email],
88 u'runfolder': 'blank',
89 u'finish_low': estimate_low,
90 u'finish_high': estimate_high,
91 u'now': datetime.now(),
95 subject = "Flowcell %s" % ( fc.flowcell_id )
96 body = email_template.render(context)
99 email = EmailMessage(subject, body, sender, to=[user_email])
102 for manager in settings.MANAGERS:
104 notified.add(manager)
105 for user in settings.NOTIFICATION_BCC:
108 email.bcc = list(notified)
111 emails.append((user_email, subject, body, sending))
113 verify_context = RequestContext(
119 'site_managers': settings.MANAGERS,
120 'title': fc.flowcell_id,
121 'warnings': warnings,
123 return HttpResponse(email_verify.render(verify_context))
125 def finishedEmail(request, pk):
128 return HttpResponse("I've got nothing.")
131 def flowcell_detail(request, flowcell_id, lane_number=None):
132 fc = get_object_or_404(FlowCell, flowcell_id__startswith=flowcell_id)
133 fc.update_data_runs()
136 if lane_number is not None:
137 lanes = fc.lane_set.filter(lane_number=lane_number)
139 lanes = fc.lane_set.all()
141 context = RequestContext(request,
145 return render_to_response('experiments/flowcell_detail.html',
148 def flowcell_lane_detail(request, lane_pk):
149 lane = get_object_or_404(Lane, id=lane_pk)
150 lane.flowcell.update_data_runs()
153 lane.flowcell.update_data_runs()
154 for run in lane.flowcell.datarun_set.all():
155 files = run.lane_files().get(lane.lane_number, None)
156 dataruns.append((run,
160 context = RequestContext(request,
161 {'lib': lane.library,
163 'flowcell': lane.flowcell,
164 'filtered_dataruns': dataruns})
166 return render_to_response('experiments/flowcell_lane_detail.html',
169 def read_result_file(self, key):
170 """Return the contents of filename if everything is approved
172 data_file = get_object_or_404(DataFile, random_key = key)
174 content_type = 'application/octet-stream'
175 if data_file.file_type.mimetype is not None:
176 content_type = data_file.file_type.mimetype
178 if os.path.exists(data_file.pathname):
179 return HttpResponse(open(data_file.pathname,'rb'),
180 content_type=content_type)
185 def sequencer(request, sequencer_id):
186 sequencer = get_object_or_404(Sequencer, id=sequencer_id)
187 context = RequestContext(request,
188 {'sequencer': sequencer})
189 return render_to_response('experiments/sequencer.html', context)