Commit 55c953a1 authored by BAIRE Anthony's avatar BAIRE Anthony

handle webapp version selection in the job views

parent d33925c8
......@@ -8,7 +8,7 @@ RUN apt-getq update && apt-getq install \
python3-django python3-django-allauth python3-misaka \
nginx-light zip gcc python3-dev python3-pip python3-wheel python3-mysqldb \
python-mysqldb python3-crypto gunicorn3 python3-redis python-mysqldb \
python3-crypto supervisor
python3-crypto python3-natsort supervisor
COPY requirements.txt /tmp/
RUN cd /tmp && pip3 install -r requirements.txt && rm requirements.txt
......
......@@ -75,6 +75,9 @@ class HomeSignupForm(SignupForm):
class JobForm(forms.ModelForm):
version = forms.CharField(
label = 'Version',
label_suffix='')
files = forms.FileField(
widget=forms.FileInput(attrs={'multiple': True}),
required=False,
......
......@@ -7,6 +7,7 @@ import os
import zipfile
import config.env
import natsort
import redis
from django.conf import settings
from django.contrib import messages
......@@ -469,6 +470,7 @@ class JobCreate(SuccessMessageMixin, LoginRequiredMixin, CreateView):
obj.result = 0
obj.user_id = self.request.user.id
obj.webapp_id = webapp.id
obj.version = form.cleaned_data.get('version')
obj.save()
if self.request.FILES:
......@@ -477,8 +479,25 @@ class JobCreate(SuccessMessageMixin, LoginRequiredMixin, CreateView):
return super(JobCreate, self).form_valid(form)
def get_context_data(self, **kwargs):
queryset = Webapp.objects.get(docker_name=self.kwargs['docker_name'])
kwargs['webapp_name'] = queryset.name
webapp = Webapp.objects.get(docker_name=self.kwargs['docker_name'])
kwargs['webapp_name'] = webapp.name
# select the list of versions to be displayed
versions = natsort.versorted(set(v for v, in WebappVersion.objects
.filter(webapp=webapp, state__in=( WebappVersion.SANDBOX,
WebappVersion.COMMITTED,
WebappVersion.READY))
.values_list("number")))
# also list 'sandbox' if the sandbox is running and if the current user
# is allowed to use the sandbox
if webapp.sandbox_state == Webapp.RUNNING and (
webapp.is_pushable_by(self.request.user)):
versions.append("sandbox")
versions.reverse()
kwargs['versions'] = versions
return super(JobCreate, self).get_context_data(**kwargs)
......
......@@ -24,6 +24,16 @@
<div class="tab-content">
<div class="tab-pane active" id="basic">
<div class="form-group">
{{ form.version.label_tag }}
<select name="version" id="id_version" class="form-control">
{% for choice in versions %}
<option value="{{ choice }}">{{ choice }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
{{ form.files.label_tag }}
<input type="file" class="form-control-file filestyle" id="inputGroupFile01" data-buttonBefore="true" data-badge="true" multiple>
......
......@@ -39,7 +39,7 @@
</tr>
<tr>
<td class="text-muted">Version</td>
<td>TODO</td>
<td>{{ job.version }}</td>
</tr>
<tr>
<td class="text-muted">Parameters</td>
......
......@@ -18,6 +18,7 @@
<th scope="col">#</th>
<th scope="col">Date</th>
<th scope="col">App</th>
<th scope="col">Version</th>
<th scope="col">Parameters</th>
<th scope="col">Queue</th>
<th scope="col" class="text-center">Status</th>
......@@ -30,6 +31,7 @@
<th scope="row"><a href="{% url 'main:job_detail' job.id %}">{{ job.id }}</a></th>
<td>{{ job.created_at | naturalday }}</td>
<td><a href="{% url 'main:webapp_detail' job.webapp.docker_name %}">{{ job.webapp.name | fancy_webapp_name }}</a></td>
<td>{{ job.version }}</td>
<td>{{ job.param }}</td>
<td>{{ job.queue.name }}</td>
<td class="text-center">
......
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