Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/apps/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,31 @@ def get_context_data(self, *args, **kwargs):
context['submissions'] = qs[:250]

for submission in context['submissions']:
# Get filesize from each submissions's data
submission.file_size = self.format_file_size(submission.data.file_size)
# Get queue from each submission's competition
queue_name = "*" if submission.phase.competition.queue is None else submission.phase.competition.queue.name
submission.competition_queue = queue_name

return context

def format_file_size(self, file_size):
"""
A custom function to convert file size to KB, MB, GB and return with the unit
"""
try:
n = float(file_size)
except ValueError:
return ""

units = ['KB', 'MB', 'GB']
i = 0
while n >= 1000 and i < len(units) - 1:
n /= 1000
i += 1

return f"{n:.1f} {units[i]}"


def page_not_found_view(request, exception):
print(request)
Expand Down
2 changes: 2 additions & 0 deletions src/templates/pages/server_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1>Recent submissions (up to 250 or 2 days old)</h1>
<thead>
<th>Competition</th>
<th>Submission PK</th>
<th>Size</th>
<th>Submitter</th>
<th>Queue</th>
<th>Hostname</th>
Expand All @@ -27,6 +28,7 @@ <h1>Recent submissions (up to 250 or 2 days old)</h1>
<tr>
<td><a class="link-no-deco" target="_blank" href="./competitions/{{ submission.phase.competition.id }}">{{ submission.phase.competition.title }}</a></td>
<td>{{ submission.pk }}</td>
<td>{{ submission.file_size }}</td>
<td><a target="_blank" href="/profiles/user/{{ submission.owner.username }}">{{ submission.owner.username }}</a></td>
<td>{{ submission.competition_queue }}</td>
<td>{{ submission.worker_hostname }}</td>
Expand Down