mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 11:46:49 +00:00
fix(admin): a default VM that is not exactly one VM is refused on the form
NEW_USER_DEFAULT_INSTANCES names VMs, and a name may repeat across hosts. A name with no VM, or with one on two hosts, made creating any user a 500. The create form now looks the names up and says which one is not exactly one VM; the user and its default VMs are saved together.
This commit is contained in:
parent
2e5ef34473
commit
addff12652
4 changed files with 47 additions and 21 deletions
|
|
@ -127,7 +127,8 @@ def user_create(request):
|
|||
attributes = attributes_form.save(commit=False)
|
||||
attributes.user = user
|
||||
attributes.save()
|
||||
add_default_instances(user)
|
||||
UserInstance.objects.bulk_create(UserInstance(user=user, instance=instance)
|
||||
for instance in user_form.default_instances)
|
||||
return redirect("admin:user_list")
|
||||
|
||||
return render(
|
||||
|
|
@ -346,14 +347,3 @@ def tombstone_delete(request, pk):
|
|||
"consequence": _("Its owners no longer get the VM back if its UUID shows up again.")},
|
||||
)
|
||||
|
||||
|
||||
def add_default_instances(user):
|
||||
"""
|
||||
Adds instances listed in NEW_USER_DEFAULT_INSTANCES to user
|
||||
"""
|
||||
existing_instances = UserInstance.objects.filter(user=user)
|
||||
if not existing_instances:
|
||||
for instance_name in settings.NEW_USER_DEFAULT_INSTANCES:
|
||||
instance = Instance.objects.get(name=instance_name)
|
||||
user_instance = UserInstance(user=user, instance=instance)
|
||||
user_instance.save()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue