Commit 0edc8ff2 by Kálmán Viktor

dashboard: pass the user to create empty/url disk

parent 70b50134
...@@ -734,6 +734,7 @@ class DiskAddForm(forms.Form): ...@@ -734,6 +734,7 @@ class DiskAddForm(forms.Form):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.is_template = kwargs.pop("is_template") self.is_template = kwargs.pop("is_template")
self.object_pk = kwargs.pop("object_pk") self.object_pk = kwargs.pop("object_pk")
self.user = kwargs.pop("user")
super(DiskAddForm, self).__init__(*args, **kwargs) super(DiskAddForm, self).__init__(*args, **kwargs)
self.initial['is_template'] = 1 if self.is_template is True else 0 self.initial['is_template'] = 1 if self.is_template is True else 0
self.initial['object_pk'] = self.object_pk self.initial['object_pk'] = self.object_pk
...@@ -771,7 +772,7 @@ class DiskAddForm(forms.Form): ...@@ -771,7 +772,7 @@ class DiskAddForm(forms.Form):
'size': data['size'], 'size': data['size'],
'dev_num': "a", 'dev_num': "a",
} }
d = Disk.create_empty(instance=inst, user=None, **kwargs) d = Disk.create_empty(instance=inst, user=self.user, **kwargs)
else: else:
kwargs = { kwargs = {
'name': data['name'], 'name': data['name'],
...@@ -779,7 +780,7 @@ class DiskAddForm(forms.Form): ...@@ -779,7 +780,7 @@ class DiskAddForm(forms.Form):
'dev_num': "a", 'dev_num': "a",
} }
Disk.create_from_url_async(data['url'], instance=inst, Disk.create_from_url_async(data['url'], instance=inst,
user=None, **kwargs) user=self.user, **kwargs)
d = None d = None
return d return d
......
...@@ -195,6 +195,7 @@ class VmDetailView(CheckedDetailView): ...@@ -195,6 +195,7 @@ class VmDetailView(CheckedDetailView):
context['acl'] = get_vm_acl_data(instance) context['acl'] = get_vm_acl_data(instance)
context['forms'] = { context['forms'] = {
'disk_add_form': DiskAddForm( 'disk_add_form': DiskAddForm(
user=self.request.user,
is_template=False, object_pk=self.get_object().pk, is_template=False, object_pk=self.get_object().pk,
prefix="disk"), prefix="disk"),
} }
...@@ -749,6 +750,7 @@ class TemplateDetail(LoginRequiredMixin, SuccessMessageMixin, UpdateView): ...@@ -749,6 +750,7 @@ class TemplateDetail(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
context['acl'] = get_vm_acl_data(obj) context['acl'] = get_vm_acl_data(obj)
context['disks'] = obj.disks.all() context['disks'] = obj.disks.all()
context['disk_add_form'] = DiskAddForm( context['disk_add_form'] = DiskAddForm(
user=self.request.user,
is_template=True, is_template=True,
object_pk=obj.pk, object_pk=obj.pk,
prefix="disk", prefix="disk",
...@@ -1756,6 +1758,7 @@ class DiskAddView(TemplateView): ...@@ -1756,6 +1758,7 @@ class DiskAddView(TemplateView):
form = DiskAddForm( form = DiskAddForm(
self.request.POST, self.request.POST,
user=self.request.user,
is_template=is_template, object_pk=object_pk, is_template=is_template, object_pk=object_pk,
prefix="disk" prefix="disk"
) )
......
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