publishers_15.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. def upload_status(request, contentupload_id, frame=False):
  2. """If we're in an iframe, we can skip basically everything, and tell the
  3. template to redirect the parent window to the normal page.
  4. """
  5. if frame:
  6. return render_to_response(
  7. "rundb/ion_jailbreak.html",
  8. dictionary={
  9. "go": "/rundb/uploadstatus/%s/" % contentupload_id,
  10. "contentupload_id": contentupload_id,
  11. },
  12. context_instance=RequestContext(request),
  13. )
  14. upload = models.ContentUpload.objects.get(pk=contentupload_id)
  15. source = upload.source
  16. filemonitor = None
  17. try:
  18. filemonitor = models.FileMonitor.objects.get(url=source, status="Complete")
  19. except Exception as err:
  20. logger.error(err)
  21. logs = list(upload.logs.all())
  22. logs.sort(key=lambda x: x.timeStamp)
  23. file_log = ""
  24. try:
  25. with open(os.path.dirname(upload.file_path) + "/publisher.log", "r") as f:
  26. file_log = f.read()
  27. except Exception as err:
  28. # file_log = str(err)
  29. pass
  30. try:
  31. file_size_string = "(%s bytes)" % "{:,}".format(
  32. os.stat(upload.file_path).st_size
  33. )
  34. except Exception:
  35. file_size_string = ""
  36. processed_uploads = []
  37. for content in upload.contents.filter(type__in=["target", "hotspot"]):
  38. if "unmerged/detail" not in content.file:
  39. continue
  40. try:
  41. content_file_size_string = "(%s bytes)" % "{:,}".format(
  42. os.stat(content.file).st_size
  43. )
  44. except Exception:
  45. content_file_size_string = ""
  46. content_type = publisher_types.BED_TYPES.get(content.type) or content.type
  47. bonus_fields = []
  48. if content.type == "hotspot":
  49. if "reference" in content.meta:
  50. bonus_fields.append(
  51. {
  52. "label": labels.HotspotsContent.reference.verbose_name,
  53. "value": content.meta["reference"],
  54. }
  55. )
  56. if "num_loci" in content.meta:
  57. bonus_fields.append(
  58. {
  59. "label": labels.HotspotsContent.num_loci.verbose_name,
  60. "value": "{:,}".format(content.meta["num_loci"]),
  61. }
  62. )
  63. content_type_hash = "hotspots"
  64. else:
  65. if "reference" in content.meta:
  66. bonus_fields.append(
  67. {
  68. "label": labels.TargetRegionsContent.reference.verbose_name,
  69. "value": content.meta["reference"],
  70. }
  71. )
  72. if "num_targets" in content.meta:
  73. bonus_fields.append(
  74. {
  75. "label": labels.TargetRegionsContent.num_targets.verbose_name,
  76. "value": "{:,}".format(content.meta["num_targets"]),
  77. }
  78. )
  79. if "num_genes" in content.meta:
  80. bonus_fields.append(
  81. {
  82. "label": labels.TargetRegionsContent.num_genes.verbose_name,
  83. "value": "{:,}".format(content.meta["num_genes"]),
  84. }
  85. )
  86. if "num_bases" in content.meta:
  87. bonus_fields.append(
  88. {
  89. "label": labels.TargetRegionsContent.num_bases.verbose_name,
  90. "value": "{:,}".format(content.meta["num_bases"]),
  91. }
  92. )
  93. content_type_hash = "target-regions"
  94. enabled = content.meta.get("enabled", True)
  95. content_name = content.get_file_name()
  96. processed_uploads.append(
  97. {
  98. "file_name": content.file,
  99. "file_size_string": content_file_size_string,
  100. "file_name_label": labels.Content.file_name.verbose_name, # 'Processed File'
  101. "content_type_hash": content_type_hash,
  102. "description": content.description,
  103. "description_label": labels.Content.description.verbose_name, # 'Description'
  104. "notes": content.notes,
  105. "notes_label": labels.Content.notes.verbose_name, # 'Notes'
  106. "enabled": content.enabled,
  107. "enabled_label": labels.Content.enabled.verbose_name, # 'Enabled',
  108. "bonus_fields": bonus_fields,
  109. "content_id": content.id,
  110. "title": ugettext_lazy("Content.details.title").format(
  111. content_type=content_type, content_name=content_name
  112. ), # u'{content_type} Details - {content_name}'
  113. "action_back_label": ugettext_lazy("global.action.backto").format(
  114. name=content_type
  115. ),
  116. "action_back": "/configure/references/#{hash}".format(
  117. hash=content_type_hash
  118. ),
  119. }
  120. )
  121. return render_to_response(
  122. "rundb/ion_publisher_upload_status.html",
  123. {
  124. "contentupload": upload,
  125. "upload_name": upload.get_file_name(),
  126. "logs": logs,
  127. "file_log": file_log,
  128. "file_path_label": labels.ContentUpload.file_path.verbose_name,
  129. "upload_type": publisher_types.BED_TYPES.get(upload.upload_type)
  130. or upload.upload_type,
  131. "upload_type_label": labels.ContentUpload.upload_type.verbose_name,
  132. "upload_date": upload.upload_date,
  133. "upload_date_label": labels.ContentUpload.upload_date.verbose_name,
  134. "file_size_string": file_size_string,
  135. "status_line": upload.status,
  136. "status_line_label": labels.ContentUpload.status.verbose_name,
  137. "processed_uploads": processed_uploads,
  138. "filemonitor": filemonitor,
  139. },
  140. context_instance=RequestContext(request),
  141. )