Commit f6571283 authored by Oleg Borisenko's avatar Oleg Borisenko
Browse files

files view basic filters

parent b8be2f29
......@@ -23,4 +23,5 @@ def includeme(config):
config.add_route('batches', '/batches')
config.add_route('batch_info', '/batch/{batch_id}')
config.add_route('file_location', '/file_location')
config.add_route('move_finalized_to_mailslot', '/move_finalized_to_mailslot')
\ No newline at end of file
config.add_route('move_finalized_to_mailslot', '/move_finalized_to_mailslot')
config.add_route('add_to_restore_queue', '/add_to_restore_queue')
\ No newline at end of file
......@@ -34,7 +34,7 @@
id="tapes">Обзор
кассет</a>
<a href="/files" class="navbar-menu-link" id="files">Обзор файлов</a>
<a href="/labnums" class="navbar-menu-link" id="labnums">Обзор лаб.номеров</a>
<!--<a href="/labnums" class="navbar-menu-link" id="labnums">Обзор лаб.номеров</a>-->
</nav>
</div>
</div>
......
......@@ -3,21 +3,22 @@
{% block content %}
<p>Вы можете выбрать параметры фильтрации для восстановления;
результирующий список будет пересечением указанных параметров</p>
<form class="form" id="filter_files" action="/filter_files" method="post">
<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 placeholder="Лабномера" class="input" name="labnum"/>
</div>
<select class="select" name="backup_target">
<option value="">- Выберите изначальную цель бэкапа для восстановления -</option>
{% for target in backup_targets %}
<option value="{{ target['unique_label'] }}">
<option value="{{ target['unique_label'] }}">"{{ target['unique_label'] }}"</option>
{% endfor %}
</select>
<div class="form-group">
<button type="submit" class="button">Отфильтровать</button>
</div>
</form>
<div><p3>Отфильтровано {{ files_total }} файлов суммарным размером {{ files_total_size }} Гбайт</p3></div>
<table class="files">
<thead>
<tr>
......@@ -45,6 +46,9 @@
<td>
Путь
</td>
<td>
Лаб.номер
</td>
</tr>
</thead>
<tbody>
......@@ -58,12 +62,25 @@
<td>{{ f.file_mtime }}</td>
<td>{{ f.copied_at_time }}</td>
<td>{{ f.relative_path }}</td>
<td>{{ f.labnum }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<form>
<form class="form" action="/add_to_restore_queue" method="get">
<div class="form-group">
<select class="select" name="restore_target">
<option value="">- Выберите цель восстановления -</option>
{% for target in restore_targets %}
<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('backup_target') %}
<input type="hidden" name="labnum" value="request.GET.get('backup_target')"/>
{% endif %}
<button type="submit" class="button">Восстановить попадающее под фильтр на выбранную цель восстановления</button>
</div>
</form>
......
......@@ -2,6 +2,7 @@ from pyramid.view import view_config
from pyramid.response import Response
from pyramid.request import Request
from pyramid.httpexceptions import HTTPException, HTTPFound
from sqlalchemy import func, BIGINT, or_
from .. import utils
from .. import models
......@@ -174,9 +175,9 @@ def files_route(request):
tape_label = request.GET.get('tape_label')
if tape_label:
files = files.filter(models.FileToBackup.tape_label == tape_label)
target_unique_label = request.GET.get('target_unique_label')
if target_unique_label:
files = files.filter(models.FileToBackup.target_unique_label == target_unique_label)
backup_target = request.GET.get('backup_target')
if backup_target:
files = files.filter(models.FileToBackup.target_unique_label == backup_target)
kind = request.GET.get('kind')
if kind:
files = files.filter(models.FileToBackup.kind == kind)
......@@ -192,12 +193,71 @@ def files_route(request):
copied_at_time_after = request.GET.get('copied_at_time_after')
if copied_at_time_after:
files = files.filter(models.FileToBackup.copied_at_time >= copied_at_time_after)
# labnum_pattern = request.GET.get('labnum_pattern')
# if labnum_pattern:
# pattern = "%{}%".format(labnum_pattern)
# files = files.filter(models.FileToBackup.labnum.like(pattern))
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
files = files.order_by(models.FileToBackup.copied_at_time)
files = files.offset(page*limit)
files = files.limit(limit).all()
return {"files": files, "limit": limit, "page": page}
\ No newline at end of file
subreq = Request.blank('/list_backup_targets')
backup_targets = request.invoke_subrequest(subreq, use_tweens=True).json
subreq = Request.blank('/list_restore_targets')
restore_targets = request.invoke_subrequest(subreq, use_tweens=True).json
return {"files": files,
"limit": limit,
"page": page,
"files_total": files_total,
"files_total_size": files_total_size,
"backup_targets": backup_targets,
"restore_targets": restore_targets}
@view_config(route_name="add_to_restore_queue")
def add_to_restore_queue(request):
try:
restore_target = request.GET.get('restore_target')
if not restore_target:
raise HTTPException("No restore target selected")
restore_target_object = request.dbsession.query(models.RestoreTarget).filter(models.RestoreTarget.unique_label == restore_target).one()
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]))
backup_target = request.GET.get('backup_target')
if backup_target:
files = files.filter(models.FileToBackup.target_unique_label == backup_target)
files = files.all()
for f in files:
restore_queue_object = models.RestoreHistory(
restore_target = restore_target_object,
file_to_restore = f,
status = False
)
request.dbsession.add(f)
next_url = request.route_url('files',
_query=(('result', 'Files added to restore queue'),
('color', 'green')))
return HTTPFound(location=next_url)
except HTTPException as e:
next_url = request.route_url('files',
_query=(('result', e.detail),
('color', 'red')))
return HTTPFound(location=next_url)
\ No newline at end of file
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