Commit 464250cd authored by BERJON Matthieu's avatar BERJON Matthieu

Add of job list view

I added the job list for every registered user.
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <matthieu.berjon@inria.fr>
parent f3d8842a
......@@ -186,12 +186,12 @@ class Job(TimeStampModel):
result = models.IntegerField()
# Relationships
dj_queue = models.ForeignKey(JobQueue, related_name="jobqueue")
dj_webapp = models.ForeignKey(Webapp, related_name="jobwebapp")
dj_user = models.ForeignKey(AllgoUser, related_name="jobuser")
queue = models.ForeignKey(JobQueue, related_name="queue")
webapp = models.ForeignKey(Webapp, related_name="webapp")
user = models.ForeignKey(User, related_name="user")
# Not in use because I don't have any related table yet
dj_container_id = models.IntegerField(blank=True, null=True)
container_id = models.IntegerField(blank=True, null=True)
class Meta:
db_table = 'dj_jobs'
......
......@@ -4,8 +4,8 @@ from . import views
urlpatterns = [
url(r'^$', views.index, name="poc_home"),
url(r'^webapps/$', views.list_webapps, name='list_webapps'),
url(r'^apps/$', views.WebappList.as_view(), name='webapp_list'),
url(r'^jobs/$', views.JobList.as_view(), name='job_list'),
url('^auth/', include('django.contrib.auth.urls')),
# Registration
......
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import CreateView, ListView
from .models import Webapp
from .models import Webapp, Job
def index(request):
......@@ -22,6 +23,19 @@ class WebappList(ListView):
template_name = 'webapp_list.html'
class JobList(LoginRequiredMixin, ListView):
model = Job
pattern_name = 'job_list'
template_name = 'job_list.html'
paginate_by = 10
login_url = '/auth/login'
redirect_field_name = 'redirect_to'
def get_queryset(self):
queryset = Job.objects.filter(user_id=self.request.user.id)
return queryset
class SignUp(CreateView):
form_class = UserCreationForm
success_url = reverse_lazy('login')
......
{% extends "base.html" %}
{% block title %}Your job list{% endblock %}
{% block content %}
<h2>Your job list</h2>
{% if job_list %}
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">App</th>
<th scope="col">Parameters</th>
<th scope="col">Queue</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
{% for job in job_list %}
<tr>
<th scope="row">{{ job.id }}</th>
<td>{{ job.webapp.name }}</td>
<td>{{ job.param }}</td>
<td>{{ job.queue.name }}</td>
<td>{{ job.result }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No current job history available.</p>
{% endif %}
{% if is_paginated %}
<nav aria-label="Webapp page navigation">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">Previous</a>
</li>
{% endif %}
{% for page in page_obj.paginator.page_range %}
{% if page == page_obj.number %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">{{ page }}</a>
</li>
{% else %}
<li class="page_item"><a class="page-link" href="?page={{ page }}">{{ page }}</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}">Next</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">Next</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
{% endblock %}
......@@ -21,6 +21,9 @@
<a class="nav-link" href="{% url 'signup' %}"><i class="fas fa-user-plus"></i> Sign up</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'job_list' %}"><i class="fas fa-database"></i> My jobs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}"><i class="fas fa-sign-out-alt"></i> Sign out</a>
</li>
......
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