Commit 6608d8a8 by Szabolcs Gelencser

Fix lease creation page

parent 7f6dd7de
......@@ -577,6 +577,7 @@ class LeaseForm(forms.ModelForm):
(role.name, role.name) for role in roles
)
if self.instance.id:
related_roles = self.instance.roles_permitted.all()
self.fields['roles'].initial = [
role.role_name for role in related_roles
......@@ -649,6 +650,10 @@ class LeaseForm(forms.ModelForm):
self.instance.delete_interval = delete_seconds
self.instance.suspend_interval = suspend_seconds
instance = super(LeaseForm, self).save(commit=False)
if commit:
instance.save()
self.instance.roles_permitted.clear()
for role_name in data['roles']:
try:
......@@ -656,9 +661,9 @@ class LeaseForm(forms.ModelForm):
except Role.DoesNotExist:
self.instance.roles_permitted.create(role_name=role_name)
instance = super(LeaseForm, self).save(commit=False)
if commit:
instance.save()
return instance
class Meta:
......
......@@ -17,7 +17,44 @@
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
<form method="post">
{% csrf_token %}
<div class="row container-fluid">
<div class="col-md-7">
{{ form.name|as_crispy_field }}
<label>Suspend in</label>
<div class="input-group interval-input">
{{ form.suspend_hours }}
<div class="input-group-addon">hours</div>
{{ form.suspend_days }}
<div class="input-group-addon">days</div>
{{ form.suspend_weeks }}
<div class="input-group-addon">weeks</div>
{{ form.suspend_months }}
<div class="input-group-addon">months</div>
</div>
<label>Delete in</label>
<div class="input-group interval-input">
{{ form.delete_hours }}
<div class="input-group-addon">hours</div>
{{ form.delete_days }}
<div class="input-group-addon">days</div>
{{ form.delete_weeks }}
<div class="input-group-addon">weeks</div>
{{ form.delete_months }}
<div class="input-group-addon">months</div>
</div>
</div>
<div class="col-md-5">
{{ form.roles }}
</div>
<div class="form-group">
<div class="controls ">
<input type="submit" name="submit" value="Create lease" class="btn btn-primary" id="submit-id-submit">
</div>
</div>
</div>
</form>
</div>
</div>
</div>
......
......@@ -56,22 +56,4 @@
</form>
</div>
</div>
{# <div class="col-md-5">#}
{# <div class="panel panel-default">#}
{# <div class="panel-heading">#}
{# <h4 class="no-margin"><i class="icon-group"></i> {% trans "Manage access" %}</h4>#}
{# </div>#}
{# <div class="panel-body">#}
{# <form action="{% url "dashboard.views.lease-acl" pk=object.pk %}" method="post">#}
{# {% csrf_token %}#}
{##}
{# <div class="pull-right" style="margin-top: 1em">#}
{# <button type="submit" class="btn btn-success">{% trans "Save" %}</button>#}
{# </div>#}
{# </form>#}
{# </div>#}
{# </div>#}
{# </div>#}
{% endblock %}
......@@ -416,6 +416,12 @@ class LeaseCreate(LoginRequiredMixin, PolicyMixin,
def get_success_url(self):
return reverse_lazy("dashboard.views.template-list")
def get_form_kwargs(self):
from openstack_api import keystone
kwargs = super(LeaseCreate, self).get_form_kwargs()
kwargs['roles'] = keystone.role_list(self.request)
return kwargs
class LeaseDetail(LoginRequiredMixin, PolicyMixin,
SuccessMessageMixin, UpdateView):
......
......@@ -713,7 +713,7 @@ def role_delete(request, role_id):
def role_list(request, filters=None):
"""Returns a global list of available roles."""
manager = keystoneclient(request).roles
manager = keystoneclient(request).roles #TODO: was admin API call
roles = []
kwargs = {}
if filters is not None:
......@@ -733,7 +733,7 @@ def role_list(request, filters=None):
def roles_for_user(request, user, project=None, domain=None):
"""Returns a list of user roles scoped to a project or domain."""
manager = keystoneclient(request).roles
manager = keystoneclient(request).roles #TODO: was admin API call
if VERSIONS.active < 3:
return manager.roles_for_user(user, project)
else:
......
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 sign in to comment