Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Open
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
34 changes: 33 additions & 1 deletion histogram_file_manager/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django_filters import rest_framework as filters
from histogram_file_manager.models import HistogramDataFile, HistogramDataFileContents

from histograms.models import LumisectionHistogramBase

class HistogramDataFileFilter(filters.FilterSet):

Expand Down Expand Up @@ -90,3 +90,35 @@ class Meta:
"granularity",
"processing_complete",
]

#class HistogramIndividualFileFilter(filters.FilterSet):
# lumisection__ls_number__in = InFilter(
# field_name="lumisection__ls_number", lookup_expr="in"
# )
# lumisection__run__run_number__in = InFilter(
# field_name="lumisection__run__run_number", lookup_expr="in"
# )
# source_data_file__filepath__contains = django_filters.CharFilter(
# field_name="source_data_file__filepath", lookup_expr="icontains"
# )
#
# class Meta:
# model = LumisectionHistogramBase
# fields = {
# "lumisection__run__run_number": [
# "exact",
# "gte",
# "lte",
# ],
# "lumisection__ls_number": [
# "exact",
# "gte",
# "lte",
# ],
# "entries": [
# "gte",
# "lte",
# ],
# "source_data_file": ["exact"],
# }
#
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ app.component('file-table', {
}
return ret;
},
id: function (value) {
var a = document.createElement('a');
var t = document.createTextNode(value);
a.href = `${value}`;
a.appendChild(t);
return a.outerHTML;
}
},
};
},
Expand Down
13 changes: 12 additions & 1 deletion histogram_file_manager/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from django.utils.html import format_html
from django.core.exceptions import ObjectDoesNotExist
from histogram_file_manager.models import HistogramDataFile
from histogram_file_manager.forms import HistogramDataFileForm
#from histogram_file_manager.forms import HistogramDataFileForm
from histograms.models import LumisectionHistogram2D, LumisectionHistogramBase


class HistogramDataFileTable(tables.Table):
Expand Down Expand Up @@ -90,3 +91,13 @@ class Meta:
#
model = HistogramDataFile
fields = []


class IndividualFileTable(tables.Table):
run = tables.Column()
lumisection = tables.Column()
dimension = tables.Column()
title = tables.Column(attrs={"td":{"style" : "min-width: 300px; word-break: break-all;" }})

class Meta:
attrs = {"class": "table table-hover table-striped"}
112 changes: 112 additions & 0 deletions histogram_file_manager/templates/histogram_file_manager/bootstrap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{% load django_tables2 %}
{% load i18n %}
{% block table-wrapper %}
<div class="table-container">
{% block table %}
<table {% render_attrs table.attrs class="table" %}>
{% block table.thead %}
{% if table.show_header %}
<thead {{ table.attrs.thead.as_html }}>
<tr>
{% for column in table.columns %}
<th {{ column.attrs.th.as_html }}>
{% if column.orderable %}
<a href="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}">{{ column.header }}</a>
{% else %}
{{ column.header }}
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
{% endif %}
{% endblock table.thead %}
{% block table.tbody %}
<tbody {{ table.attrs.tbody.as_html }}>
{% for row in table.paginated_rows %}
{% block table.tbody.row %}
<tr {{ row.attrs.as_html }}>
{% for column, cell in row.items %}
<td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
{% endfor %}
</tr>
{% endblock table.tbody.row %}
{% empty %}
{% if table.empty_text %}
{% block table.tbody.empty_text %}
<tr><td colspan="{{ table.columns|length }}">{{ table.empty_text }}</td></tr>
{% endblock table.tbody.empty_text %}
{% endif %}
{% endfor %}
</tbody>
{% endblock table.tbody %}
{% block table.tfoot %}
{% if table.has_footer %}
<tfoot {{ table.attrs.tfoot.as_html }}>
<tr>
{% for column in table.columns %}
<td {{ column.attrs.tf.as_html }}>{{ column.footer }}</td>
{% endfor %}
</tr>
</tfoot>
{% endif %}
{% endblock table.tfoot %}
</table>
{% endblock table %}

{% block pagination %}
{% if table.page and table.paginator.num_pages > 1 %}
<nav aria-label="Table navigation">
<ul class="pb-3 pagination justify-content-center">
{% block pagination.previous %}
{% if table.page.has_previous %}
<li class="page-item previous">
<a class="page-link" href="{% querystring table.prefixed_page_field=table.page.previous_page_number %}">
Previous
</a>
</li>
{% else %}
<li class="page-item previous disabled">
<a class="page-link">
Previous
</a>
</li>
{% endif %}
{% endblock pagination.previous %}
{% if table.page.has_previous or table.page.has_next %}
{% block pagination.range %}
{% for p in table.page|table_page_range:table.paginator %}
<li {% if p == table.page.number %}class="page-item active"{% else %}class="page-item"{% endif %}>
{% if p == '...' %}
<a class="page-link" href="#">{{ p }}</a>
{% else %}
<a class="page-link" href="{% querystring table.prefixed_page_field=p %}">
{{ p }}
</a>
{% endif %}
</li>
{% endfor %}
{% endblock pagination.range %}
{% endif %}

{% block pagination.next %}
{% if table.page.has_next %}
<li class="page-item next">
<a class="page-link" href="{% querystring table.prefixed_page_field=table.page.next_page_number %}">
Next
</a>
</li>
{% else %}
<li class="page-item next disabled">
<a class="page-link">
Next
</a>
</li>
{% endif %}
{% endblock pagination.next %}
</ul>
</nav>
{% endif %}
{% endblock pagination %}
</div>
{% endblock table-wrapper %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends 'base.html' %}
{% load static %}

{% block extra_head %}
<!-- <script src="https://unpkg.com/vue@3"></script> -->
<!-- <script src="https://unpkg.com/axios/dist/axios.min.js"></script> -->
{% endblock %}

{% block title %}
File ID {{file_id}}
{% endblock %}

{% block content %}

{% load render_table from django_tables2 %}
{% load bootstrap3 %}

<div class="row">
<div class="col-lg-3 col-12">
Filter goes here.
</div>
<div class="col-lg-9 col-12">
{% if errormsg %}
<div class="alert alert-danger">
<h2>{{errormsg}}</h2>
You are requesting file id {{file_id}}, but the file is not available on our database.
<br>
<a class="btn btn-primary" href="{% url 'histogram_file_manager:file_manager' %}"><i class="bi bi-arrow-left"></i> Go back</a>
</div>
{% else %}
<h2><code>{{filename}}</code></h2>
<hr>
{% render_table hist_table 'histogram_file_manager/bootstrap.html' %}
{% endif %}
</div>
</div>

{% endblock %}
1 change: 1 addition & 0 deletions histogram_file_manager/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

urlpatterns = [
path("", views.histogram_file_manager, name="file_manager"),
path("<int:fileid>", views.individual_file_viewer, name="file_viewer"),
]
59 changes: 59 additions & 0 deletions histogram_file_manager/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django_tables2 import RequestConfig
from histogram_file_manager.models import HistogramDataFile
from histogram_file_manager.forms import HistogramDataFileStartParsingForm
from histogram_file_manager.api.filters import HistogramDataFileFilter
from histogram_file_manager.tables import IndividualFileTable
from histograms.models import LumisectionHistogram1D, LumisectionHistogram2D

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -31,3 +34,59 @@ def histogram_file_manager(request):
"histogram_file_manager/histogram_file_manager.html",
context={"field_choices": field_choices, "filter": hdf_filter},
)

@login_required
def individual_file_viewer(request, fileid):
try:
target_file = HistogramDataFile.objects.get(id=fileid)
hist1d = LumisectionHistogram1D.objects.filter(source_data_file=target_file)
hist2d = LumisectionHistogram2D.objects.filter(source_data_file=target_file)

histall = []
for hist in hist1d:
histall.append({
"run": hist.lumisection.run.run_number,
"lumisection": hist.lumisection.ls_number,
"dimension": "1D",
"title": hist.title
})
for hist in hist2d:
histall.append({
"run": hist.lumisection.run.run_number,
"lumisection": hist.lumisection.ls_number,
"dimension": "2D",
"title": hist.title
})

#histcollection = list(hist1d) + list(hist2d)
hist_table = IndividualFileTable(histall)

RequestConfig(request, paginate={"per_page": 25}).configure(hist_table)

context = {
"file_id": fileid,
"fileobj": target_file,
"filename": target_file.filepath,
"hist_table": hist_table
}

return render(
request,
"histogram_file_manager/individual_file_viewer.html",
context
)
except (HistogramDataFile.DoesNotExist):
return render(
request,
"histogram_file_manager/individual_file_viewer.html",
{
"file_id": fileid,
"errormsg": f"File {fileid} not found in database."
}
)

return render(
request,
"histogram_file_manager/individual_file_viewer.html",
context={"fileid": fileid}
)