Commit d4f700f1 authored by BERJON Matthieu's avatar BERJON Matthieu
Browse files

Merge branch 'ui-fixes-queues' into 'django'

UI fixes for job queues

See merge request !129
parents 13aa574a fefe1344
Pipeline #40849 failed with stage
in 1 minute and 26 seconds
......@@ -59,6 +59,10 @@ class UserWebappForm(forms.ModelForm):
tags = TagField(label_suffix='')
memory_limit_mb = forms.IntegerField(label="Memory limit", label_suffix='',
min_value=0)
job_queue = forms.ModelChoiceField(
queryset=JobQueue.objects.all().distinct().order_by("timeout"),
label='Default job queue',
label_suffix='')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......@@ -79,7 +83,8 @@ class UserWebappForm(forms.ModelForm):
class Meta:
model = Webapp
fields = ('name', 'description', 'contact', 'notebook_gitrepo',
'private', 'owner', 'docker_os', 'tags', 'entrypoint')
'private', 'owner', 'docker_os', 'tags', 'entrypoint',
'job_queue')
class HomeSignupForm(SignupForm):
......@@ -100,7 +105,7 @@ class JobForm(forms.ModelForm):
queue_id = forms.ModelChoiceField(
queryset=JobQueue.objects.all().distinct(),
initial=1,
label='Queue type',
label='Queue',
label_suffix='',
)
param = forms.CharField(label='Parameters', label_suffix='', required=False)
......@@ -169,16 +174,14 @@ class WebappForm(forms.ModelForm):
# Advanced
docker_os = forms.ModelChoiceField(
queryset=DockerOs.objects.all().distinct(),
initial=1,
label='Operating sytem',
label_suffix='')
memory_limit_mb = forms.IntegerField(label="Memory limit", label_suffix='',
initial=config.env.ALLGO_WEBAPP_DEFAULT_MEMORY_LIMIT_MB,
min_value=0)
job_queue = forms.ModelChoiceField(
queryset=JobQueue.objects.all().distinct(),
initial=1,
label='Default queue type',
queryset=JobQueue.objects.all().distinct().order_by("timeout"),
label='Default job queue',
label_suffix='')
entrypoint = forms.CharField(label="Entrypoint", label_suffix="",
initial="/home/allgo/entrypoint")
......@@ -186,6 +189,9 @@ class WebappForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(WebappForm, self).__init__(*args, **kwargs)
self.instance.job_queue = JobQueue.objects.filter(
is_default=True).first()
for field in self.fields.values():
field.error_messages = {'required':'The field "{fieldname}" is required'.format(
fieldname=field.label)}
......
......@@ -460,7 +460,7 @@ class Quota(TimeStampModel):
class Job(TimeStampModel):
"""
Jobs ran with the specific data (user, webapp, queue type, ...)
Jobs ran with the specific data (user, webapp, queue, ...)
"""
#### Job States ####
......
from datetime import datetime
import json
import shlex
from django import template
from django.utils.safestring import mark_safe
from django.utils.timesince import timesince
from misaka import Markdown, HtmlRenderer, EXT_SUPERSCRIPT, EXT_FENCED_CODE, EXT_AUTOLINK
from main.models import Job
......@@ -37,6 +39,22 @@ def fancy_name(webapp_name):
""" Replace underscores by spaces """
return webapp_name.replace('_', ' ')
@register.filter(name='fancy_job_queue')
def fancy_job_queue(queue):
"""Display the queue name with its timeout (if any)"""
if queue.timeout is None:
return queue.name
if queue.timeout < 60:
return "%s (<%d seconds)" % (queue.name, queue.timeout)
else:
return "%s (<%s)" % (queue.name, timesince(
datetime.fromtimestamp(0),
datetime.fromtimestamp(queue.timeout)))
_JOB_STATUS_RENDER_VALUES = {
"NEW": ("New job", "fas fa-plus picto-green"),
......
{% extends "base.html" %}
{% load htmlattrs %}
{% load htmlattrs converters %}
{% block title %}Create a webapp{% endblock %}
......@@ -95,7 +95,9 @@
<select name="{{ form.job_queue.name }}" id="{{ form.job_queue.id_for_label }}" class="form-control">
{% for choice in form.job_queue.field.queryset %}
<option value="{{ choice.pk }}">{{ choice.name }}</option>
<option value="{{ choice.pk }}"
{% if choice.pk == form.instance.job_queue_id %} selected {% endif %}
>{{ choice | fancy_job_queue }}</option>
{% endfor %}
</select>
</div>
......
......@@ -117,7 +117,9 @@
<select name="{{ form.queue_id.name }}" id="{{ form.queue_id.id_for_label }}" class="form-control">
{% for choice in form.queue_id.field.queryset %}
<option value="{{ choice.pk }}">{{ choice.name }}</option>
<option value="{{ choice.pk }}"
{% if choice.pk == webapp.job_queue_id %} selected {% endif %}
>{{ choice | fancy_job_queue }}</option>
{% endfor %}
</select>
</div>
......
{% extends "base.html" %}
{% load i18n static htmlattrs %}
{% load i18n static htmlattrs converters %}
{% block title %}Update your webapp{% endblock %}
......@@ -67,6 +67,18 @@
{{ form.notebook_gitrepo.label_tag }}
{{ form.notebook_gitrepo | attr:"placeholder:https://example.tld/repo.git" | add_class:"form-control" }}
</div>
<div class="form-group">
{{ form.job_queue.label_tag }}
<select name="{{ form.job_queue.name }}" id="{{ form.job_queue.id_for_label }}" class="form-control">
{% for choice in form.job_queue.field.queryset %}
<option value="{{ choice.pk }}"
{% if choice.pk == form.instance.job_queue_id %} selected {% endif %}
>{{ choice | fancy_job_queue }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<div class="form-check">
......
Markdown is supported
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