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 #t = loader.get_template('experiments/index.html')
33 # 'data_run_list': all_runs,
35 #return HttpResponse(t.render(c))
36 # shortcut to the above module usage
37 return render_to_response('experiments/index.html',{'data_run_list': all_runs})
39 def detail(request, run_folder):
40 html_str = '<h2>Exp Track Details Page</h2>'
41 html_str += 'Run Folder: '+run_folder
42 r = get_object_or_404(DataRun,run_folder=run_folder)
43 return render_to_response('experiments/detail.html',{'run_f': r})
45 def makeFCSheet(request,fcid):
46 # get Flowcell by input fcid
50 rec = FlowCell.objects.get(flowcell_id=fcid)
51 except ObjectDoesNotExist:
53 lanes = ['1','2','3','4','5','6','7','8']
54 return render_to_response('experiments/flowcellSheet.html',{'fc': rec})
57 @user_passes_test(lambda u: u.is_staff)
58 def startedEmail(request, pk):
60 Create the we have started processing your samples email
62 fc = get_object_or_404(FlowCell, id=pk)
64 send = request.REQUEST.get('send',False)
65 if send in ('1', 'on', 'True', 'true', True):
70 bcc_managers = request.REQUEST.get('bcc', False)
71 if bcc_managers in ('on', '1', 'True', 'true'):
76 email_lane = makeEmailLaneMap(fc)
77 flowcell_users = getUsersForFlowcell(fc)
78 estimate = estimateFlowcellTimeRemaining(fc)
79 estimate_low, estimate_high = roundToDays(estimate)
80 email_verify = get_template('experiments/email_preview.html')
81 email_template = get_template('experiments/started_email.txt')
82 sender = settings.NOTIFICATION_SENDER
88 for user in flowcell_users:
90 if user.email is None or len(user.email) == 0:
91 warnings.append((user.admin_url(), user.username))
94 for user_email in email_lane.keys():
97 context = RequestContext(request,
99 u'lanes': email_lane[user_email],
100 u'runfolder': 'blank',
101 u'finish_low': estimate_low,
102 u'finish_high': estimate_high,
103 u'now': datetime.now(),
107 subject = "Flowcell %s" % ( fc.flowcell_id )
108 body = email_template.render(context)
111 email = EmailMessage(subject, body, sender, to=[user_email])
113 email.bcc = settings.MANAGERS
114 email.bcc = settings.NOTIFICATION_BCC
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)