Commit 793af2e9 authored by BAIRE Anthony's avatar BAIRE Anthony

Squashed commit of the following:

commit 5311d3a7
Author: LETORT Sebastien <sebastien.letort@irisa.fr>
Date:   Tue Sep 17 09:29:45 2019 +0200

    WebappVersion.webapp related_name changed from 'webapp' to 'version'.

commit 0f68b0e0
Merge: 7aa839c4 8a251945
Author: LETORT Sebastien <sebastien.letort@irisa.fr>
Date:   Mon Sep 16 12:08:26 2019 +0200

    Merge branch 'django' into 266-allow-unpublished-webapp-version

commit 7aa839c4
Author: LETORT Sebastien <sebastien.letort@irisa.fr>
Date:   Mon Sep 16 12:07:00 2019 +0200

    Several fixes after code review.
    query_webapps_for_user doesn't have the only_published_version param anymore.
    comment explains the filtering with 'webapp__published'.
    debug log comment are removed.
    WebappVersion in error state are show to the user.
    WebappVersionList.get_queryset return query_set and not values.
    no more mention of atomic transaction.
    WebappVersionList.post: var name correction.

commit ab7107e3
Author: LETORT Sebastien <sebastien.letort@irisa.fr>
Date:   Mon Jul 22 12:19:55 2019 +0200

    sugar +/- PEP8 syntax correction.
    remove useless else in helpers.query_webapps_for_user

commit e32ec378
Author: LETORT Sebastien <sebastien.letort@irisa.fr>
Date:   Mon Jul 22 11:13:54 2019 +0200

    update of query_webapps_for_user, specially when used by views.WebappList.
    Now the user cannot view public app if no version is published.

commit 55061286
Merge: 5a2b0b7e 979954ef
Author: LETORT Sebastien <sebastien.letort@irisa.fr>
Date:   Mon Jul 1 14:12:17 2019 +0200

    Merge branch 'django' into 266-allow-unpublished-webapp-version

commit 5a2b0b7e
Merge: b7f1b67c ffa355b0
Author: sebastien letort <sletort@capri.irisa.fr>
Date:   Fri Apr 19 10:16:16 2019 +0200

    Merge branch 'django' into 266-allow-unpublished-webapp-version

commit b7f1b67c
Author: sebastien letort <sletort@capri.irisa.fr>
Date:   Fri Apr 19 10:15:27 2019 +0200

    Published status of version can now be updated.
    I used @transaction atomic to make all the update in one access to the DB (so speed up). But there is no constraint for that.

commit ddf2cf17
Author: sebastien letort <sletort@capri.irisa.fr>
Date:   Wed Apr 17 14:05:42 2019 +0200

    list all versions available for an app.
    The app owner will be able to update published status, not yet implemented.

commit d2d6176a
Author: sebastien letort <sletort@capri.irisa.fr>
Date:   Tue Apr 16 11:11:21 2019 +0200

    The owner of an app can run job on unpublished webapp (it appears in the list of available version).

commit 0c053a2d
Merge: a8c1d1d4 610f9c90
Author: sebastien letort <sletort@capri.irisa.fr>
Date:   Mon Apr 15 15:21:42 2019 +0200

    Merge branch 'django' into 266-allow-unpublished-webapp-version

commit a8c1d1d4
Author: sebastien letort <sletort@capri.irisa.fr>
Date:   Mon Apr 15 13:54:04 2019 +0200

    Webapp version can now be commited 'unpublished'.

commit 22799031
Author: sebastien letort <sletort@capri.irisa.fr>
Date:   Tue Apr 2 16:12:50 2019 +0200

    Only the published webapp versions are shown in the jobCreate view.
parent ccf8ad31
......@@ -218,6 +218,18 @@ def query_webapps_for_user(user):
if user.is_superuser:
return Webapp.objects.all()
else:
# select webapps that are either public or owned by the user
return Webapp.objects.filter(Q(private=False) | Q(user_id=user.id))
# select webapps that are either public (and have at least one published version) or owned by
# the current user
#
# if only_published_version is True, then only published version of non user app
# are returned.
# version__ refers to WebappVersion_set, with 'related_name'
# cf https://docs.djangoproject.com/en/2.2/topics/db/queries/#following-relationships-backward
q_filter = Q(private=False) & Q(version__published=True)
qs = Webapp.objects \
.filter(Q(user_id=user.id) | q_filter) \
.distinct()
return qs
......@@ -414,7 +414,7 @@ class WebappVersion(TimeStampModel):
# flag indicating if this version was imported from rails
imported = models.BooleanField(default=False)
webapp = models.ForeignKey('Webapp', on_delete=models.CASCADE, related_name="webapp")
webapp = models.ForeignKey('Webapp', on_delete=models.CASCADE, related_name="version")
class Meta:
db_table = 'dj_webapp_versions'
......
......@@ -64,6 +64,8 @@ urlpatterns = [
name="webapp_update"),
url(r'^apps/(?P<docker_name>[\w-]+)/sandbox$', views.WebappSandboxPanel.as_view(),
name="webapp_sandbox_panel"),
url(r'^apps/(?P<docker_name>[\w-]+)/versions$', views.WebappVersionList.as_view(),
name="webapp_version_list"),
url(r'^apps/(?P<docker_name>[\w-]+)/json$', views.WebappJson.as_view(), name='webapp_json'),
url(r'^apps/(?P<docker_name>[\w-]+)$', views.JobCreate.as_view(), name='webapp_detail'),
......
......@@ -588,6 +588,53 @@ class WebappVersionImport(UserAccessMixin, DetailView):
return HttpResponseRedirect(request.path_info)
class WebappVersionList(UserAccessMixin, ListView):
"""Display the list of versions for a given app and identified user
Attributes:
model: model used in the view.
# ~ context_object_name: the name used in the template to display each
# ~ variable.
# ~ paginate_by: the number of occurences per page
template_name: name of the template loaded with this view.
"""
model = WebappVersion
context_object_name = 'version_list'
template_name = 'webapp_version_list.html'
# ~ paginate_by = 10
def get_queryset(self):
"""get all versions of this webapp"""
name = self.kwargs['docker_name']
queryset = WebappVersion.objects \
.filter(webapp__docker_name=name) \
.exclude(state__in=(WebappVersion.REPLACED))
return queryset
def get_context_data(self, **kwargs):
"""Pass on the docker name to the template"""
webapp = Webapp.objects.get(docker_name=self.kwargs['docker_name'])
kwargs['webapp'] = webapp
return super().get_context_data(**kwargs)
def post(self, request, *args, **kwargs):
log.info("WebappVersionList.post {} - {}".format(request.POST, kwargs))
for version_id, value in request.POST.items():
if 'csrfmiddlewaretoken' == version_id:
continue
o_version = WebappVersion.objects.get(id=version_id)
o_version.published = value
o_version.save()
messages.success(request, "Published status have been updated.\n")
return redirect('main:webapp_version_list', kwargs['docker_name'])
class WebappJson(UserAccessMixin, DetailView):
"""json variant of the application details
......@@ -719,7 +766,7 @@ class WebappSandboxPanel(UserAccessMixin, TemplateView):
webapp=webapp,
number=number,
state=WebappVersion.SANDBOX,
published=True,
published=request.POST["published"],
description=request.POST["description"],
**extra)
version.save()
......@@ -1281,6 +1328,7 @@ class JobCreate(AllAccessMixin, SuccessMessageMixin, CreateView):
.filter(webapp=webapp, state__in=( WebappVersion.SANDBOX,
WebappVersion.COMMITTED,
WebappVersion.READY))
.filter(Q(published=True) | Q(webapp__user=self.request.user))
.values_list("number")))
# also list 'sandbox' if the sandbox is running and if the current user
......
......@@ -55,6 +55,16 @@
</a>
{% endif %}
{% endif %}
<a class="fa-layers fa-2x"
href="{% url 'main:webapp_version_list' webapp.docker_name %}"
data-toggle="tooltip"
data-placement="top"
title="List versions">
<i class="fas fa-square"></i>
<i class="fa-inverse fas fa-tasks" data-fa-transform="shrink-7 down-.25 left-.25"></i>
<span class="text-hide">List versions</span>
</a>
</div>
</div>
......
......@@ -142,6 +142,17 @@
</div>
</div>
</div>
<div class="form-row">
<div class="form-group">
<p>Do you want to publish it ?</p>
<input type="radio" name="published" value="True" id="yes_publish" checked>
<label for="yes_publish">yes</label>
<input type="radio" name="published" value="False" id="no_publish">
<label for="no_publish">no</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">
<i class="fas fa-download"></i> Commit</button>
......
{% extends "base.html" %}
{% load static converters humanize %}
{% block title %}{{ webapp.name | fancy_webapp_name | title }} versions{% endblock %}
{% block breadcrumb %}
<li class="breadcrumb-item"><a href="{% url 'main:webapp_list' %}">Applications</a></li>
<li class="breadcrumb-item active" aria-current="page">
<a href="{% url 'main:webapp_detail' webapp.name %}">{{ webapp.name | fancy_webapp_name | title }}</a>
</li>
<li class="breadcrumb-item active" aria-current="page">versions</li>
{% endblock %}
{% block messages %}
{{ block.super }}
{% endblock %}
{% block content %}
<div class="container">
<div class="allgo-page">
<h5>Versions available for the app.</h5>
{% if version_list %}
<form action="{% url 'main:webapp_version_list' webapp.name %}" method="post">
{% csrf_token %}
<table class="table table-striped">
<thead>
<tr>
<th scope="col">name</th>
<th scope="col">description</th>
{% if webapp.user == user %}
<th scope="col">published</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for version in version_list %}
<tr id="version-{{version.id}}">
<td>{{ version.number }}</td>
<td>{{ version.description }}</td>
{% if webapp.user == user %}
<td>
{% if version.published %}
<input type="radio" name="{{version.id}}" id="{{version.id}}_yes" value="True" checked>
<label for="{{version.id}}_yes">yes</label>
<input type="radio" name="{{version.id}}" id="{{version.id}}_no" value="False" >
<label for="{{version.id}}_no">no</label>
{% else %}
<input type="radio" name="{{version.id}}" id="{{version.id}}_yes" value="True" >
<label for="{{version.id}}_yes">yes</label>
<input type="radio" name="{{version.id}}" id="{{version.id}}_no" value="False" checked>
<label for="{{version.id}}_no">no</label>
{% endif %}
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
<input type="submit" value="Update all">
</form>
{% else %}
<p>No version available.
{% if webapp.user == user %}
create a
<a href="{% url 'main:webapp_sandbox_panel' webapp.docker_name %}"
title="Create a new version">
new version.
</a>.
{% endif %}
</p>
{% endif %}
</div>
</div>
{% endblock %}
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