diff --git a/histogram_file_manager/api/filters.py b/histogram_file_manager/api/filters.py index cd22ed4..a2ddba8 100644 --- a/histogram_file_manager/api/filters.py +++ b/histogram_file_manager/api/filters.py @@ -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): @@ -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"], +# } +# \ No newline at end of file diff --git a/histogram_file_manager/static/histogram_file_manager/js/components/file_table.js b/histogram_file_manager/static/histogram_file_manager/js/components/file_table.js index d542e40..92f115d 100644 --- a/histogram_file_manager/static/histogram_file_manager/js/components/file_table.js +++ b/histogram_file_manager/static/histogram_file_manager/js/components/file_table.js @@ -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; + } }, }; }, diff --git a/histogram_file_manager/tables.py b/histogram_file_manager/tables.py index 7da7b1d..9d8dfe7 100644 --- a/histogram_file_manager/tables.py +++ b/histogram_file_manager/tables.py @@ -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): @@ -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"} \ No newline at end of file diff --git a/histogram_file_manager/templates/histogram_file_manager/bootstrap.html b/histogram_file_manager/templates/histogram_file_manager/bootstrap.html new file mode 100644 index 0000000..a050a33 --- /dev/null +++ b/histogram_file_manager/templates/histogram_file_manager/bootstrap.html @@ -0,0 +1,112 @@ +{% load django_tables2 %} +{% load i18n %} +{% block table-wrapper %} +
+ {% block table %} + + {% block table.thead %} + {% if table.show_header %} + + + {% for column in table.columns %} + + {% endfor %} + + + {% endif %} + {% endblock table.thead %} + {% block table.tbody %} + + {% for row in table.paginated_rows %} + {% block table.tbody.row %} + + {% for column, cell in row.items %} + + {% endfor %} + + {% endblock table.tbody.row %} + {% empty %} + {% if table.empty_text %} + {% block table.tbody.empty_text %} + + {% endblock table.tbody.empty_text %} + {% endif %} + {% endfor %} + + {% endblock table.tbody %} + {% block table.tfoot %} + {% if table.has_footer %} + + + {% for column in table.columns %} + + {% endfor %} + + + {% endif %} + {% endblock table.tfoot %} +
+ {% if column.orderable %} + {{ column.header }} + {% else %} + {{ column.header }} + {% endif %} +
{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}
{{ table.empty_text }}
{{ column.footer }}
+ {% endblock table %} + + {% block pagination %} + {% if table.page and table.paginator.num_pages > 1 %} + + {% endif %} + {% endblock pagination %} +
+{% endblock table-wrapper %} diff --git a/histogram_file_manager/templates/histogram_file_manager/individual_file_viewer.html b/histogram_file_manager/templates/histogram_file_manager/individual_file_viewer.html new file mode 100644 index 0000000..9ef5902 --- /dev/null +++ b/histogram_file_manager/templates/histogram_file_manager/individual_file_viewer.html @@ -0,0 +1,38 @@ +{% extends 'base.html' %} +{% load static %} + +{% block extra_head %} + + +{% endblock %} + +{% block title %} +File ID {{file_id}} +{% endblock %} + +{% block content %} + +{% load render_table from django_tables2 %} +{% load bootstrap3 %} + +
+
+ Filter goes here. +
+
+ {% if errormsg %} +
+

{{errormsg}}

+ You are requesting file id {{file_id}}, but the file is not available on our database. +
+ Go back +
+ {% else %} +

{{filename}}

+
+ {% render_table hist_table 'histogram_file_manager/bootstrap.html' %} + {% endif %} +
+
+ +{% endblock %} \ No newline at end of file diff --git a/histogram_file_manager/urls.py b/histogram_file_manager/urls.py index 9c0abad..8545d17 100644 --- a/histogram_file_manager/urls.py +++ b/histogram_file_manager/urls.py @@ -5,4 +5,5 @@ urlpatterns = [ path("", views.histogram_file_manager, name="file_manager"), + path("", views.individual_file_viewer, name="file_viewer"), ] diff --git a/histogram_file_manager/views.py b/histogram_file_manager/views.py index e4dbc1b..5d285da 100644 --- a/histogram_file_manager/views.py +++ b/histogram_file_manager/views.py @@ -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__) @@ -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} + ) \ No newline at end of file