Commit 4a6171b4 authored by Oleg Borisenko's avatar Oleg Borisenko
Browse files

files tab finished

parent b39fbb9d
......@@ -6,7 +6,7 @@
[app:main]
use = egg:tapebackup
pyramid.reload_templates = false
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
......@@ -38,7 +38,7 @@ file_template = %%(year)d%%(month).2d%%(day).2d_%%(rev)s
[server:main]
use = egg:waitress#main
listen = 0.0.0.0:6543
listen = 0.0.0.0:6544
###
# logging configuration
......
......@@ -202,4 +202,22 @@ body {
* {
box-sizing: border-box;
}
\ No newline at end of file
}
.pagination {
display: inline-block;
}
.pagination a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
}
.pagination a.active {
background-color: #4CAF50;
color: white;
}
.pagination a:hover:not(.active) {background-color: #ddd;}
......@@ -6,8 +6,32 @@
<form class="form" id="filter_files" action="/files" method="get">
<div class="form-group">
<label class="label">Вбейте лабномера через запятую или их подстроки для фильтрации</label>
<input placeholder="Лабномера" class="input" name="labnum"/>
<input label="labnum" placeholder="Лабномера" class="input" name="labnum" value="{{ request.GET.get('labnum') or ""}}"/>
</div>
<div>
<label class="label">Вбейте любой кусочек пути к файлам</label>
<input label="path_substring" placeholder="Пути" class="input" name="path_substring" value="{{ request.GET.get('path_substring') or "" }}">
</div>
<div class="form-group">
<label class="label">Вбейте уникальную метку кассеты для фильтрации</label>
<input placeholder="Кассета" class="input" name="tape_label" value="{{ request.GET.get('tape_label') or "" }}"/>
</div>
<div class="form-group">
<label class="label">Начиная с какого дня (создания файла)?</label>
<input class="input" name="file_mtime_after" type="date" value="{{ request.GET.get('file_mtime_after') }}" />
</div>
<div class="form-group">
<label class="label">До какого дня (создания файла)?</label>
<input class="input" name="file_mtime_before" type="date" value="{{ request.GET.get('file_mtime_before') }}"></input>
</div>
<div class="form-group">
<label class="label">Начиная с какого дня (фактического бэкапа)?</label>
<input class="input" name="copied_at_time_after" type="date" value="{{ request.GET.get('copied_at_time_after') }}"></input>
</div>
<div class="form-group">
<label class="label">До какого дня (фактического бэкапа)?</label>
<input class="input" name="copied_at_time_before" type="date" value="{{ request.GET.get('copied_at_time_before') }}"></input>
</div>`
<select class="select" name="backup_target">
<option value="">- Выберите изначальную цель бэкапа для восстановления -</option>
{% for target in backup_targets %}
......@@ -19,6 +43,25 @@
</div>
</form>
<div><p3>Отфильтровано {{ files_total }} файлов суммарным размером {{ files_total_size }} Гбайт</p3></div>
<div class="pagination">
{% if page != 0 %}
<a href="{{ request.current_route_path(_query=dict(request.params.dicts[0], page = 0)) }}">к началу</a>
<a>...</a>
{% endif %}
{% if page + pagination_pages_to_show < pages_total %}
<a class="active" href="{{ request.current_route_path(_query=dict(request.params.dicts[0])) }}">{{ page + 1 }}</a>
{% for i in range(page + 2, page + pagination_pages_to_show + 1) %}
<a href="{{ request.current_route_path(_query=dict(request.params.dicts[0], page = i-1)) }}">{{ i }}</a>
{% endfor %}
<a>...</a>
<a href="{{ request.current_route_path(_query=dict(request.params.dicts[0], page = pages_total-1)) }}">{{ pages_total }}</a>
{% else %}
<a class="active" href="{{ request.current_route_path(_query=dict(request.params.dicts[0])) }}">{{ page + 1 }}</a>
{% for i in range(page + 2, pages_total + 1) %}
<a href="{{ request.current_route_path(_query=dict(request.params.dicts[0], page = i-1)) }}">{{ i }}</a>
{% endfor %}
{% endif %}
</div>
<table class="files">
<thead>
<tr>
......@@ -75,9 +118,28 @@
<option value="{{ target['unique_label'] }}">"{{ target['unique_label'] }}"</option>
{% endfor %}
</select>
{% if request.GET.get('labnum') %}
<input type="hidden" name="labnum" value="{{ request.GET.get('labnum') }}"/>
{% endif %}
{% if request.GET.get('path_substring') %}
<input type="hidden" name="path_substring" value="{{ request.GET.get('path_substring') }}"/>
{% endif %}
{% if request.GET.get('tape_label') %}
<input type="hidden" name="tape_label" value="{{ request.GET.get('tape_label') }}"/>
{% endif %}
{% if request.GET.get('file_mtime_before') %}
<input type="hidden" name="file_mtime_before" value="{{ request.GET.get('file_mtime_before') }}"/>
{% endif %}
{% if request.GET.get('file_mtime_after') %}
<input type="hidden" name="file_mtime_after" value="{{ request.GET.get('file_mtime_after') }}"/>
{% endif %}
{% if request.GET.get('copied_at_time_before') %}
<input type="hidden" name="copied_at_time_before" value="{{ request.GET.get('copied_at_time_before') }}"/>
{% endif %}
{% if request.GET.get('copied_at_time_after') %}
<input type="hidden" name="copied_at_time_after" value="{{ request.GET.get('copied_at_time_after') }}"/>
{% endif %}
{% if request.GET.get('backup_target') %}
<input type="hidden" name="backup_target" value="{{ request.GET.get('backup_target') }}"/>
{% endif %}
......
import datetime
from math import ceil
from pyramid.view import view_config
from pyramid.response import Response
from pyramid.request import Request
......@@ -173,7 +176,23 @@ def files_route(request):
limit = int(limit)
page = request.GET.get('page') or 0
page = int(page)
pagination_pages_to_show = 10
files = request.dbsession.query(models.FileToBackup).filter(models.FileToBackup.is_file == True)
labnum_seq = request.GET.get('labnum')
if labnum_seq:
labnum_list = labnum_seq.split(',')
patterns = []
for labnum in labnum_list:
pattern = "%{}%".format(labnum.strip())
patterns.append(pattern)
files = files.filter(or_(*[models.FileToBackup.labnum.like(name) for name in patterns]))
path_substring = request.GET.get('path_substring')
if path_substring:
path_substring = "%{}%".format(path_substring)
files = files.filter(models.FileToBackup.relative_path.like(path_substring))
tape_label = request.GET.get('tape_label')
if tape_label:
files = files.filter(models.FileToBackup.tape_label == tape_label)
......@@ -183,32 +202,26 @@ def files_route(request):
kind = request.GET.get('kind')
if kind:
files = files.filter(models.FileToBackup.kind == kind)
file_mtime_before = request.GET.get('file_mtime_before')
file_mtime_before = request.GET.get('file_mtime_before') or "9999-01-01"
if file_mtime_before:
files = files.filter(models.FileToBackup.file_mtime <= file_mtime_before)
file_mtime_after = request.GET.get('file_mtime_after')
file_mtime_after = request.GET.get('file_mtime_after') or "1837-01-01"
if file_mtime_after:
files = files.filter(models.FileToBackup.file_mtime >= file_mtime_after)
copied_at_time_before = request.GET.get('copied_at_time_before')
copied_at_time_before = request.GET.get('copied_at_time_before') or "9999-01-01"
if copied_at_time_before:
files = files.filter(models.FileToBackup.copied_at_time <= copied_at_time_before)
copied_at_time_after = request.GET.get('copied_at_time_after')
copied_at_time_after = request.GET.get('copied_at_time_after') or "1837-01-01"
if copied_at_time_after:
files = files.filter(models.FileToBackup.copied_at_time >= copied_at_time_after)
labnum_seq = request.GET.get('labnum')
if labnum_seq:
labnum_list = labnum_seq.split(',')
patterns = []
for labnum in labnum_list:
pattern = "%{}%".format(labnum.strip())
patterns.append(pattern)
files = files.filter(or_(*[models.FileToBackup.labnum.like(name) for name in patterns]))
files_total = files.count()
if files.with_entities(func.sum(models.FileToBackup.fsize)).scalar():
files_total_size = round(files.with_entities(func.sum(models.FileToBackup.fsize)).scalar() / 1024**3, 2)
else:
files_total_size = 0
pages_total = ceil(files_total / limit)
files = files.order_by(models.FileToBackup.copied_at_time)
files = files.offset(page*limit)
files = files.limit(limit).all()
......@@ -220,8 +233,14 @@ def files_route(request):
return {"files": files,
"limit": limit,
"page": page,
"pages_total": pages_total,
"pagination_pages_to_show": pagination_pages_to_show,
"files_total": files_total,
"files_total_size": files_total_size,
"file_mtime_before": file_mtime_before,
"file_mtime_after": file_mtime_after,
"copied_at_time_before": copied_at_time_before,
"copied_at_time_after": copied_at_time_after,
"backup_targets": backup_targets,
"restore_targets": restore_targets}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment