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 email_lane.keys():
91 context = RequestContext(request,
93 u'lanes': email_lane[user_email],
94 u'runfolder': 'blank',
95 u'finish_low': estimate_low,
96 u'finish_high': estimate_high,
97 u'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])
107 email.bcc = settings.MANAGERS
108 email.bcc = settings.NOTIFICATION_BCC
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 mimetype = 'application/octet-stream'
175 if data_file.file_type.mimetype is not None:
176 mimetype = data_file.file_type.mimetype
178 if os.path.exists(data_file.pathname):
179 return HttpResponse(open(data_file.pathname,'r'),
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)