mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 03:54:15 +00:00
Cleaned up UserAttributes model
This commit is contained in:
parent
20d4aaac30
commit
2951d0b035
2 changed files with 15 additions and 23 deletions
|
@ -55,28 +55,6 @@ class UserAttributes(models.Model):
|
||||||
validators=[MinValueValidator(-1)],
|
validators=[MinValueValidator(-1)],
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def create_missing_userattributes(user):
|
|
||||||
try:
|
|
||||||
userattributes = user.userattributes
|
|
||||||
except UserAttributes.DoesNotExist:
|
|
||||||
userattributes = UserAttributes(user=user)
|
|
||||||
userattributes.save()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def add_default_instances(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()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def configure_user(user):
|
|
||||||
UserAttributes.create_missing_userattributes(user)
|
|
||||||
UserAttributes.add_default_instances(user)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.user.username
|
return self.user.username
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import Group, User
|
from django.contrib.auth.models import Group, User
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from accounts.models import UserAttributes
|
from accounts.models import UserAttributes, UserInstance, Instance
|
||||||
from appsettings.models import AppSettings
|
from appsettings.models import AppSettings
|
||||||
from logs.models import Logs
|
from logs.models import Logs
|
||||||
|
|
||||||
|
@ -97,6 +98,7 @@ def user_create(request):
|
||||||
attributes = attributes_form.save(commit=False)
|
attributes = attributes_form.save(commit=False)
|
||||||
attributes.user = user
|
attributes.user = user
|
||||||
attributes.save()
|
attributes.save()
|
||||||
|
add_default_instances(user)
|
||||||
return redirect('admin:user_list')
|
return redirect('admin:user_list')
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
|
@ -169,3 +171,15 @@ def logs(request):
|
||||||
page = request.GET.get('page', 1)
|
page = request.GET.get('page', 1)
|
||||||
logs = paginator.page(page)
|
logs = paginator.page(page)
|
||||||
return render(request, 'admin/logs.html', {'logs': logs})
|
return render(request, 'admin/logs.html', {'logs': logs})
|
||||||
|
|
||||||
|
|
||||||
|
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…
Reference in a new issue