Commit 8675b32a authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

some factorisation

parent db9c8fcc
......@@ -224,6 +224,11 @@ class WebappUpdate(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
queryset = get_object_or_404(Webapp, docker_name=data, user_id=self.request.user.id)
return queryset
def get_context_data(self, **kwargs):
ctx=super().get_context_data(**kwargs)
ctx["action"] = "Update"
return ctx
def get_form(self):
form = super().get_form()
if not self.request.user.is_superuser:
......@@ -279,6 +284,11 @@ class WebappCreate(SuccessMessageMixin, LoginRequiredMixin, IsProviderMixin, Cre
form.fields['memory_limit_mb'].widget.attrs['readonly'] = True
return form
def get_context_data(self, **kwargs):
ctx=super().get_context_data(**kwargs)
ctx["action"] = "Create"
return ctx
def form_valid(self, form):
"""Save data coming from the form in the database """
obj = form.save(commit=False)
......
......@@ -2,22 +2,12 @@
{% load htmlattrs converters %}
{% block title %}
{% url 'main:webapp_creation' as webapp_url %}
{% if request.get_full_path == webapp_url %}
Create a webapp
{% else %}
Update webapp
{% endif %}
{{action}} a webapp
{% endblock %}
{% block breadcrumb %}
<li class="breadcrumb-item"><a href="{% url 'main:webapp_list' %}">Applications</a></li>
{% url 'main:webapp_creation' as webapp_url %}
{% if request.get_full_path == webapp_url %}
<li class="breadcrumb-item active" aria-current="page">Create</li>
{% else %}
<li class="breadcrumb-item active" aria-current="page">Update</li>
{% endif %}
<li class="breadcrumb-item active" aria-current="page">{{action}}</li>
{% endblock %}
{% block content %}
......@@ -132,8 +122,7 @@
</div>
<small class="form-text text-muted">{{ form.entrypoint.help_text }}</small>
{% url 'main:webapp_creation' as webapp_url %}
{% if request.get_full_path != webapp_url %}
{% if action != "Create" %}
<div class="form-group">
{{ form.owner.label_tag }}
{{ form.owner | attr:"placeholder:Enter the new owner username" | add_class:"form-control" }}
......@@ -147,12 +136,7 @@
</div>
</div>
{% url 'main:webapp_creation' as webapp_url %}
{% if request.get_full_path == webapp_url %}
<input class="btn btn-primary float-right mt-4" type="submit" value="Create webapp">
{% else %}
<input class="btn btn-primary float-right mt-4" type="submit" value="Update webapp">
{% endif %}
<input class="btn btn-primary float-right mt-4" type="submit" value="{{action}} webapp">
</form>
</div>
......
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