1 # Create your views here.
2 from datetime import datetime
5 #from django.template import Context, loader
6 #shortcut to the above modules
7 from django.contrib.auth.decorators import user_passes_test
8 from django.conf import settings
9 from django.core.exceptions import ObjectDoesNotExist
10 from django.core.mail import EmailMessage, mail_managers
11 from django.http import HttpResponse
12 from django.shortcuts import render_to_response, get_object_or_404
13 from django.template import RequestContext
14 from django.template.loader import get_template
16 from htsworkflow.frontend.experiments.models import \
22 from htsworkflow.frontend.experiments.experiments import \
23 estimateFlowcellDuration, \
24 estimateFlowcellTimeRemaining, \
26 getUsersForFlowcell, \
30 all_runs = DataRun.objects.order_by('-run_start_time')
31 return render_to_response('experiments/index.html',{'data_run_list': all_runs})
33 def detail(request, run_folder):
34 html_str = '<h2>Exp Track Details Page</h2>'
35 html_str += 'Run Folder: '+run_folder
36 r = get_object_or_404(DataRun,run_folder=run_folder)
37 return render_to_response('experiments/detail.html',{'run_f': r})
39 def makeFCSheet(request,fcid):
40 # get Flowcell by input fcid
44 rec = FlowCell.objects.get(flowcell_id=fcid)
45 except ObjectDoesNotExist:
47 lanes = ['1','2','3','4','5','6','7','8']
48 return render_to_response('experiments/flowcellSheet.html',{'fc': rec})
51 @user_passes_test(lambda u: u.is_staff)
52 def startedEmail(request, pk):
54 Create the we have started processing your samples email
56 fc = get_object_or_404(FlowCell, id=pk)
58 send = request.REQUEST.get('send',False)
59 if send in ('1', 'on', 'True', 'true', True):
64 bcc_managers = request.REQUEST.get('bcc', False)
65 if bcc_managers in ('on', '1', 'True', 'true'):
70 email_lane = makeEmailLaneMap(fc)
71 flowcell_users = getUsersForFlowcell(fc)
72 estimate = estimateFlowcellTimeRemaining(fc)
73 estimate_low, estimate_high = roundToDays(estimate)
74 email_verify = get_template('experiments/email_preview.html')
75 email_template = get_template('experiments/started_email.txt')
76 sender = settings.NOTIFICATION_SENDER
82 for user in flowcell_users:
84 if user.email is None or len(user.email) == 0:
85 warnings.append((user.admin_url(), user.username))
88 for user_email in list(email_lane.keys()):
91 context = RequestContext(request,
93 'lanes': email_lane[user_email],
95 'finish_low': estimate_low,
96 'finish_high': estimate_high,
97 'now': datetime.now(),
101 subject = "Flowcell %s" % ( fc.flowcell_id )
102 body = email_template.render(context)
105 email = EmailMessage(subject, body, sender, to=[user_email])
108 for manager in settings.MANAGERS:
110 notified.add(manager)
111 for user in settings.NOTIFICATION_BCC:
114 email.bcc = list(notified)
117 emails.append((user_email, subject, body, sending))
119 verify_context = RequestContext(
125 'site_managers': settings.MANAGERS,
126 'title': fc.flowcell_id,
127 'warnings': warnings,
129 return HttpResponse(email_verify.render(verify_context))
131 def finishedEmail(request, pk):
134 return HttpResponse("I've got nothing.")
137 def flowcell_detail(request, flowcell_id, lane_number=None):
138 fc = get_object_or_404(FlowCell, flowcell_id__startswith=flowcell_id)
139 fc.update_data_runs()
142 if lane_number is not None:
143 lanes = fc.lane_set.filter(lane_number=lane_number)
145 lanes = fc.lane_set.all()
147 context = RequestContext(request,
151 return render_to_response('experiments/flowcell_detail.html',
154 def flowcell_lane_detail(request, lane_pk):
155 lane = get_object_or_404(Lane, id=lane_pk)
156 lane.flowcell.update_data_runs()
159 lane.flowcell.update_data_runs()
160 for run in lane.flowcell.datarun_set.all():
161 files = run.lane_files().get(lane.lane_number, None)
162 dataruns.append((run,
166 context = RequestContext(request,
167 {'lib': lane.library,
169 'flowcell': lane.flowcell,
170 'filtered_dataruns': dataruns})
172 return render_to_response('experiments/flowcell_lane_detail.html',
175 def read_result_file(self, key):
176 """Return the contents of filename if everything is approved
178 data_file = get_object_or_404(DataFile, random_key = key)
180 mimetype = 'application/octet-stream'
181 if data_file.file_type.mimetype is not None:
182 mimetype = data_file.file_type.mimetype
184 if os.path.exists(data_file.pathname):
185 return HttpResponse(open(data_file.pathname,'r'),
191 def sequencer(request, sequencer_id):
192 sequencer = get_object_or_404(Sequencer, id=sequencer_id)
193 context = RequestContext(request,
194 {'sequencer': sequencer})
195 return render_to_response('experiments/sequencer.html', context)