Commit 73228b24 authored by BERJON Matthieu's avatar BERJON Matthieu
Browse files

Updating the webapp form and views

I merged the `UserWebappForm` into the `WebappForm`. I updated the views
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <>
parent f9ce65d5
......@@ -52,44 +52,6 @@ class SSHForm(forms.ModelForm):
fields = ('sshkey',)
class UserWebappForm(forms.ModelForm):
name = forms.CharField(label_suffix='')
private = forms.BooleanField(required=False, label='Private', label_suffix='')
description = forms.CharField(widget=forms.Textarea, label_suffix='')
contact = forms.EmailField(required=False, label="Contact", label_suffix='')
notebook_gitrepo = forms.URLField(required=False, label="Notebook repository", label_suffix="")
owner = forms.CharField(required=False, label="Owner", label_suffix='', help_text="Username of the new owner of the application. You will immediately loose access to the application.")
tags = TagField(label_suffix='')
memory_limit_mb = forms.IntegerField(label="Memory limit", label_suffix='',
job_queue = forms.ModelChoiceField(
label='Default job queue',
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
webapp = Webapp.objects.get(docker_name=self.instance.docker_name)
self.fields['owner'].initial = self.instance.user
self.fields['memory_limit_mb'].initial = (
self.instance.memory_limit // 1024**2
def get_memory_limit(self, request):
# only allgo admins are allowed to change the memory limit
if request.user.is_superuser:
# value is converted into bytes
return self.cleaned_data["memory_limit_mb"] * 1024**2
return self.instance.memory_limit
class Meta:
model = Webapp
fields = ('name', 'description', 'contact', 'notebook_gitrepo',
'private', 'owner', 'docker_os', 'tags', 'entrypoint',
class HomeSignupForm(SignupForm):
......@@ -195,10 +157,15 @@ class WebappForm(forms.ModelForm):
entrypoint = forms.CharField(label="Entrypoint", label_suffix="",
help_text=mark_safe('This is the <a href="">command executed when allgo runs a job</a> for this app.'),
owner = forms.CharField(required=False, label="Owner", label_suffix='', help_text="Username of the new owner of the application. You will immediately loose access to the application.")
tags = TagField(label_suffix='', help_text="Tags are separated by a comma.")
def __init__(self, *args, **kwargs):
super(WebappForm, self).__init__(*args, **kwargs)
if self.instance is None:
self.fields['owner'].initial = self.instance.user
self.instance.job_queue = JobQueue.objects.filter(
......@@ -216,7 +183,7 @@ class WebappForm(forms.ModelForm):
class Meta:
model = Webapp
fields = ('name', 'description', 'logo_file_name', 'contact', 'entrypoint', 'job_queue', 'private', 'docker_os', 'entrypoint')
fields = ('name', 'description', 'contact', 'entrypoint', 'job_queue', 'private', 'docker_os', 'entrypoint', 'owner', 'tags')
class WebappSandboxForm(forms.ModelForm):
......@@ -58,7 +58,6 @@ from allauth.account.models import EmailAddress
from .forms import (
......@@ -210,14 +209,14 @@ class WebappUpdate(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
success_message: message when the form is properly submitted.
form_class = UserWebappForm
template_name = 'webapp_update.html'
form_class = WebappForm
template_name = 'webapp_add_update.html'
success_message = 'Your app has been successfully updated.'
error_message = 'The email doesn\'t belong to any registered user. Please enter a valid owner email address.'
def get_success_url(self):
"""If successful redirect to the same page"""
return reverse('main:webapp_update', args=(self.object.docker_name,))
return reverse('main:webapp_add_update', args=(self.object.docker_name,))
def get_object(self):
"""Returns the object according to its docker name or a 404 error"""
......@@ -266,7 +265,7 @@ class WebappCreate(SuccessMessageMixin, LoginRequiredMixin, IsProviderMixin, Cre
model = Webapp
form_class = WebappForm
success_message = 'Webapp created successfully.'
template_name = 'webapp_add.html'
template_name = 'webapp_add_update.html'
# group_required = ['inria', ]
def get_success_url(self):
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