# Create your views here.
+from datetime import datetime
+import os
+
#from django.template import Context, loader
#shortcut to the above modules
from django.contrib.auth.decorators import user_passes_test
+from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import EmailMessage, mail_managers
from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
-from django.template import Context
+from django.template import RequestContext
from django.template.loader import get_template
-from htsworkflow.frontend.experiments.models import *
+from htsworkflow.frontend.experiments.models import \
+ DataRun, \
+ DataFile, \
+ FlowCell, \
+ Lane, \
+ Sequencer
from htsworkflow.frontend.experiments.experiments import \
estimateFlowcellDuration, \
+ estimateFlowcellTimeRemaining, \
+ roundToDays, \
getUsersForFlowcell, \
makeEmailLaneMap
def index(request):
all_runs = DataRun.objects.order_by('-run_start_time')
- #t = loader.get_template('experiments/index.html')
- #c = Context({
- # 'data_run_list': all_runs,
- #})
- #return HttpResponse(t.render(c))
- # shortcut to the above module usage
- return render_to_response('experiments/index.html',{'data_run_list': all_runs})
-
+ return render_to_response('experiments/index.html',{'data_run_list': all_runs})
+
def detail(request, run_folder):
html_str = '<h2>Exp Track Details Page</h2>'
html_str += 'Run Folder: '+run_folder
email_lane = makeEmailLaneMap(fc)
flowcell_users = getUsersForFlowcell(fc)
- estimate_low, estimate_high = estimateFlowcellDuration(fc)
+ estimate = estimateFlowcellTimeRemaining(fc)
+ estimate_low, estimate_high = roundToDays(estimate)
email_verify = get_template('experiments/email_preview.html')
email_template = get_template('experiments/started_email.txt')
sender = settings.NOTIFICATION_SENDER
if user.email is None or len(user.email) == 0:
warnings.append((user.admin_url(), user.username))
user=None
-
+
for user_email in email_lane.keys():
sending = ""
# build body
- context = Context({u'flowcell': fc,
- u'lanes': email_lane[user_email],
- u'runfolder': 'blank',
- u'finish_low': estimate_low,
- u'finish_high': estimate_high,
- })
+ context = RequestContext(request,
+ {u'flowcell': fc,
+ u'lanes': email_lane[user_email],
+ u'runfolder': 'blank',
+ u'finish_low': estimate_low,
+ u'finish_high': estimate_high,
+ u'now': datetime.now(),
+ })
# build view
- subject = "Flowcell %s" % ( fc.flowcell_id )
+ subject = "Flowcell %s" % ( fc.flowcell_id )
body = email_template.render(context)
if send:
email = EmailMessage(subject, body, sender, to=[user_email])
+ notified = set()
if bcc_managers:
- email.bcc = settings.MANAGERS
+ for manager in settings.MANAGERS:
+ if len(manager) > 0:
+ notified.add(manager)
+ for user in settings.NOTIFICATION_BCC:
+ if len(user) > 0:
+ notified.add(user)
+ email.bcc = list(notified)
email.send()
emails.append((user_email, subject, body, sending))
- verify_context = Context({
- 'send': send,
- 'warnings': warnings,
- 'emails': emails,
- 'from': sender,
- 'site_managers': settings.MANAGERS,
+ verify_context = RequestContext(
+ request,
+ { 'emails': emails,
+ 'flowcell': fc,
+ 'from': sender,
+ 'send': send,
+ 'site_managers': settings.MANAGERS,
+ 'title': fc.flowcell_id,
+ 'warnings': warnings,
})
return HttpResponse(email_verify.render(verify_context))
-
+
def finishedEmail(request, pk):
"""
"""
return HttpResponse("I've got nothing.")
+
+
+def flowcell_detail(request, flowcell_id, lane_number=None):
+ fc = get_object_or_404(FlowCell, flowcell_id__startswith=flowcell_id)
+ fc.update_data_runs()
+
+
+ if lane_number is not None:
+ lanes = fc.lane_set.filter(lane_number=lane_number)
+ else:
+ lanes = fc.lane_set.all()
+
+ context = RequestContext(request,
+ {'flowcell': fc,
+ 'lanes': lanes})
+
+ return render_to_response('experiments/flowcell_detail.html',
+ context)
+
+def flowcell_lane_detail(request, lane_pk):
+ lane = get_object_or_404(Lane, id=lane_pk)
+ lane.flowcell.update_data_runs()
+
+ dataruns = []
+ lane.flowcell.update_data_runs()
+ for run in lane.flowcell.datarun_set.all():
+ files = run.lane_files().get(lane.lane_number, None)
+ dataruns.append((run,
+ lane.lane_number,
+ files))
+
+ context = RequestContext(request,
+ {'lib': lane.library,
+ 'lane': lane,
+ 'flowcell': lane.flowcell,
+ 'filtered_dataruns': dataruns})
+
+ return render_to_response('experiments/flowcell_lane_detail.html',
+ context)
+
+def read_result_file(self, key):
+ """Return the contents of filename if everything is approved
+ """
+ data_file = get_object_or_404(DataFile, random_key = key)
+
+ mimetype = 'application/octet-stream'
+ if data_file.file_type.mimetype is not None:
+ mimetype = data_file.file_type.mimetype
+
+ if os.path.exists(data_file.pathname):
+ return HttpResponse(open(data_file.pathname,'r'),
+ mimetype=mimetype)
+
+ raise Http404
+
+
+def sequencer(request, sequencer_id):
+ sequencer = get_object_or_404(Sequencer, id=sequencer_id)
+ context = RequestContext(request,
+ {'sequencer': sequencer})
+ return render_to_response('experiments/sequencer.html', context)