123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- def upload_status(request, contentupload_id, frame=False):
- """If we're in an iframe, we can skip basically everything, and tell the
- template to redirect the parent window to the normal page.
- """
- if frame:
- return render_to_response(
- "rundb/ion_jailbreak.html",
- dictionary={
- "go": "/rundb/uploadstatus/%s/" % contentupload_id,
- "contentupload_id": contentupload_id,
- },
- context_instance=RequestContext(request),
- )
- upload = models.ContentUpload.objects.get(pk=contentupload_id)
- source = upload.source
- filemonitor = None
- try:
- filemonitor = models.FileMonitor.objects.get(url=source, status="Complete")
- except Exception as err:
- logger.error(err)
- logs = list(upload.logs.all())
- logs.sort(key=lambda x: x.timeStamp)
- file_log = ""
- try:
- with open(os.path.dirname(upload.file_path) + "/publisher.log", "r") as f:
- file_log = f.read()
- except Exception as err:
- # file_log = str(err)
- pass
- try:
- file_size_string = "(%s bytes)" % "{:,}".format(
- os.stat(upload.file_path).st_size
- )
- except Exception:
- file_size_string = ""
- processed_uploads = []
- for content in upload.contents.filter(type__in=["target", "hotspot"]):
- if "unmerged/detail" not in content.file:
- continue
- try:
- content_file_size_string = "(%s bytes)" % "{:,}".format(
- os.stat(content.file).st_size
- )
- except Exception:
- content_file_size_string = ""
- content_type = publisher_types.BED_TYPES.get(content.type) or content.type
- bonus_fields = []
- if content.type == "hotspot":
- if "reference" in content.meta:
- bonus_fields.append(
- {
- "label": labels.HotspotsContent.reference.verbose_name,
- "value": content.meta["reference"],
- }
- )
- if "num_loci" in content.meta:
- bonus_fields.append(
- {
- "label": labels.HotspotsContent.num_loci.verbose_name,
- "value": "{:,}".format(content.meta["num_loci"]),
- }
- )
- content_type_hash = "hotspots"
- else:
- if "reference" in content.meta:
- bonus_fields.append(
- {
- "label": labels.TargetRegionsContent.reference.verbose_name,
- "value": content.meta["reference"],
- }
- )
- if "num_targets" in content.meta:
- bonus_fields.append(
- {
- "label": labels.TargetRegionsContent.num_targets.verbose_name,
- "value": "{:,}".format(content.meta["num_targets"]),
- }
- )
- if "num_genes" in content.meta:
- bonus_fields.append(
- {
- "label": labels.TargetRegionsContent.num_genes.verbose_name,
- "value": "{:,}".format(content.meta["num_genes"]),
- }
- )
- if "num_bases" in content.meta:
- bonus_fields.append(
- {
- "label": labels.TargetRegionsContent.num_bases.verbose_name,
- "value": "{:,}".format(content.meta["num_bases"]),
- }
- )
- content_type_hash = "target-regions"
- enabled = content.meta.get("enabled", True)
- content_name = content.get_file_name()
- processed_uploads.append(
- {
- "file_name": content.file,
- "file_size_string": content_file_size_string,
- "file_name_label": labels.Content.file_name.verbose_name, # 'Processed File'
- "content_type_hash": content_type_hash,
- "description": content.description,
- "description_label": labels.Content.description.verbose_name, # 'Description'
- "notes": content.notes,
- "notes_label": labels.Content.notes.verbose_name, # 'Notes'
- "enabled": content.enabled,
- "enabled_label": labels.Content.enabled.verbose_name, # 'Enabled',
- "bonus_fields": bonus_fields,
- "content_id": content.id,
- "title": ugettext_lazy("Content.details.title").format(
- content_type=content_type, content_name=content_name
- ), # u'{content_type} Details - {content_name}'
- "action_back_label": ugettext_lazy("global.action.backto").format(
- name=content_type
- ),
- "action_back": "/configure/references/#{hash}".format(
- hash=content_type_hash
- ),
- }
- )
- return render_to_response(
- "rundb/ion_publisher_upload_status.html",
- {
- "contentupload": upload,
- "upload_name": upload.get_file_name(),
- "logs": logs,
- "file_log": file_log,
- "file_path_label": labels.ContentUpload.file_path.verbose_name,
- "upload_type": publisher_types.BED_TYPES.get(upload.upload_type)
- or upload.upload_type,
- "upload_type_label": labels.ContentUpload.upload_type.verbose_name,
- "upload_date": upload.upload_date,
- "upload_date_label": labels.ContentUpload.upload_date.verbose_name,
- "file_size_string": file_size_string,
- "status_line": upload.status,
- "status_line_label": labels.ContentUpload.status.verbose_name,
- "processed_uploads": processed_uploads,
- "filemonitor": filemonitor,
- },
- context_instance=RequestContext(request),
- )
|