django-helpdesk/helpdesk/management/commands/create_usersettings.py

34 lines
1.0 KiB
Python
Raw Normal View History

#!/usr/bin/python
"""
django-helpdesk - A Django powered ticket tracker for small enterprise.
See LICENSE for details.
2016-10-23 22:09:17 +02:00
create_usersettings.py - Easy way to create helpdesk-specific settings for
users who don't yet have them.
"""
from django.utils.translation import ugettext as _
from django.core.management.base import BaseCommand
2016-10-21 17:14:12 +02:00
from django.contrib.auth import get_user_model
from helpdesk.models import UserSettings
from helpdesk.settings import DEFAULT_USER_SETTINGS
2016-10-21 17:14:12 +02:00
User = get_user_model()
class Command(BaseCommand):
2016-10-21 17:14:12 +02:00
"""create_usersettings command"""
help = _('Check for user without django-helpdesk UserSettings '
'and create settings if required. Uses '
'settings.DEFAULT_USER_SETTINGS which can be overridden to '
'suit your situation.')
def handle(self, *args, **options):
2016-10-21 17:14:12 +02:00
"""handle command line"""
for u in User.objects.all():
2016-10-21 17:14:12 +02:00
UserSettings.objects.get_or_create(user=u,
defaults={'settings': DEFAULT_USER_SETTINGS})