mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +00:00
adding new instance to user checks existing instances assigned to user
This commit is contained in:
parent
d036d582fd
commit
8deb844c35
1 changed files with 11 additions and 12 deletions
|
@ -136,11 +136,6 @@ def account(request, user_id):
|
||||||
user_insts = UserInstance.objects.filter(user_id=user_id)
|
user_insts = UserInstance.objects.filter(user_id=user_id)
|
||||||
instances = Instance.objects.all()
|
instances = Instance.objects.all()
|
||||||
|
|
||||||
def add_user_inst(request, inst_id, user_id):
|
|
||||||
add_user_inst = UserInstance(instance_id=int(inst_id), user_id=user_id)
|
|
||||||
add_user_inst.save()
|
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
|
||||||
|
|
||||||
if user.username == request.user.username:
|
if user.username == request.user.username:
|
||||||
return HttpResponseRedirect(reverse('profile'))
|
return HttpResponseRedirect(reverse('profile'))
|
||||||
|
|
||||||
|
@ -161,14 +156,18 @@ def account(request, user_id):
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
if 'add' in request.POST:
|
if 'add' in request.POST:
|
||||||
inst_id = request.POST.get('inst_id', '')
|
inst_id = request.POST.get('inst_id', '')
|
||||||
|
|
||||||
if settings.ALLOW_INSTANCE_MULTIPLE_OWNER:
|
if settings.ALLOW_INSTANCE_MULTIPLE_OWNER:
|
||||||
return add_user_inst(request, inst_id, user_id)
|
check_inst = UserInstance.objects.filter(instance_id=int(inst_id), user_id=int(user_id))
|
||||||
else:
|
else:
|
||||||
try:
|
check_inst = UserInstance.objects.filter(instance_id=int(inst_id))
|
||||||
check_inst = UserInstance.objects.get(instance_id=int(inst_id))
|
|
||||||
msg = _("Instance already added")
|
if check_inst:
|
||||||
error_messages.append(msg)
|
msg = _("Instance already added")
|
||||||
except UserInstance.DoesNotExist:
|
error_messages.append(msg)
|
||||||
return add_user_inst(request, inst_id, user_id)
|
else:
|
||||||
|
add_user_inst = UserInstance(instance_id=int(inst_id), user_id=int(user_id))
|
||||||
|
add_user_inst.save()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
|
||||||
return render(request, 'account.html', locals())
|
return render(request, 'account.html', locals())
|
||||||
|
|
Loading…
Reference in a new issue