Skip to content
Snippets Groups Projects
Commit 35698719 authored by Stefano Alberto Russo's avatar Stefano Alberto Russo
Browse files

Added support for searching in the container name and filtering on container...

Added support for searching in the container name and filtering on container type from the container page.
parent 40687ec3
No related branches found
No related tags found
No related merge requests found
...@@ -13,9 +13,45 @@ ...@@ -13,9 +13,45 @@
<h1><a href="/containers">Containers</a> <span style="font-size:18px"> / {{ data.container.name }}</span></h1> <h1><a href="/containers">Containers</a> <span style="font-size:18px"> / {{ data.container.name }}</span></h1>
{% else %} {% else %}
<h1>Containers</h1> <h1>Containers</h1>
{% endif %}
<hr/> <hr/>
<div class="form-filter" style="margin-bottom:20px">
<form action="" method="POST">
<input type="text" class="form-control" id="search_text" name="search_text" placeholder="Search..." style="width:200px; margin:0; display:inline" value="{{data.search_text}}" autofocus>
<select class="form-control" id="search_type" name="search_type" style="width:120px; margin:0; display:inline">
{% if data.search_type == 'All' %}
<option selected>All</option>
{% else %}
<option>All</option>
{% endif %}
{% if data.search_type == 'Docker' %}
<option selected>Docker</option>
{% else %}
<option>Docker</option>
{% endif %}
{% if data.search_type == 'Singularity' %}
<option selected>Singularity</option>
{% else %}
<option>Singularity</option>
{% endif %}
</select>
{% csrf_token %}
<button type="submit" class="btn btn-secondary">Go</button>
</form>
</div>
{% endif %}
<div class="row" style="padding:5px"> <div class="row" style="padding:5px">
{% if data.container %} {% if data.container %}
{% include "components/container.html" with container=data.container details=True %} {% include "components/container.html" with container=data.container details=True %}
......
...@@ -306,10 +306,7 @@ def tasks(request): ...@@ -306,10 +306,7 @@ def tasks(request):
# Attach user config to computing # Attach user config to computing
task.computing.attach_user_conf_data(task.user) task.computing.attach_user_conf_data(task.user)
#----------------
# Task actions # Task actions
#----------------
if action=='delete': if action=='delete':
if task.status not in [TaskStatuses.stopped, TaskStatuses.exited]: if task.status not in [TaskStatuses.stopped, TaskStatuses.exited]:
try: try:
...@@ -363,11 +360,7 @@ def tasks(request): ...@@ -363,11 +360,7 @@ def tasks(request):
# Do we have to list all the tasks? # Do we have to list all the tasks?
if not uuid or (uuid and not details): if not uuid or (uuid and not details):
#---------------- # Get all tasks for list
# Task list
#----------------
# Get all tasks
try: try:
tasks = Task.objects.filter(user=request.user).order_by('created') tasks = Task.objects.filter(user=request.user).order_by('created')
except Exception as e: except Exception as e:
...@@ -600,6 +593,15 @@ def containers(request): ...@@ -600,6 +593,15 @@ def containers(request):
uuid = request.GET.get('uuid', None) uuid = request.GET.get('uuid', None)
action = request.GET.get('action', None) action = request.GET.get('action', None)
# Get filter/search if any
search_text = request.POST.get('search_text', '')
search_type = request.POST.get('search_type', 'All')
# Set bak to page data
data['search_type'] = search_type
data['search_text'] = search_text
# Do we have to operate on a specific container? # Do we have to operate on a specific container?
if uuid: if uuid:
...@@ -614,10 +616,7 @@ def containers(request): ...@@ -614,10 +616,7 @@ def containers(request):
raise ErrorMessage('Container does not exists or no access rights') raise ErrorMessage('Container does not exists or no access rights')
data['container'] = container data['container'] = container
#-------------------
# Container actions # Container actions
#-------------------
if action and action=='delete': if action and action=='delete':
# Delete # Delete
...@@ -628,12 +627,26 @@ def containers(request): ...@@ -628,12 +627,26 @@ def containers(request):
logger.error('Error in getting the container with uuid="{}" or performing the required action: "{}"'.format(uuid, e)) logger.error('Error in getting the container with uuid="{}" or performing the required action: "{}"'.format(uuid, e))
return render(request, 'error.html', {'data': data}) return render(request, 'error.html', {'data': data})
#----------------
# Container list
#----------------
# Get containers # Get containers for list
data['containers'] = list(Container.objects.filter(user=None)) + list(Container.objects.filter(user=request.user)) if search_type and search_type != 'All':
if search_text:
user_containers = Container.objects.filter(user=None, type=search_type.lower(), name__icontains=search_text)
platform_containers = Container.objects.filter(user=request.user, type=search_type.lower(), name__icontains=search_text)
else:
user_containers = Container.objects.filter(user=None, type=search_type.lower())
platform_containers = Container.objects.filter(user=request.user, type=search_type.lower())
else:
if search_text:
user_containers = Container.objects.filter(user=None, name__icontains=search_text)
platform_containers = Container.objects.filter(user=request.user, name__icontains=search_text)
else:
user_containers = Container.objects.filter(user=None)
platform_containers = Container.objects.filter(user=request.user)
data['containers'] = list(user_containers) + list(platform_containers)
return render(request, 'containers.html', {'data': data}) return render(request, 'containers.html', {'data': data})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment