From b3c53f1bc85d8b45e95f9cb1909823c4890eab56 Mon Sep 17 00:00:00 2001 From: Ross Poulton Date: Wed, 2 Feb 2011 08:15:49 +0000 Subject: [PATCH] Addresses issue 20: when creating a new user, the signal that creates a UserSettings entry now creates some default settings. These are driven by settings.py so can be overridden per-install. --- helpdesk/models.py | 5 +++-- helpdesk/settings.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/helpdesk/models.py b/helpdesk/models.py index e79e8301..3b40091f 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -933,9 +933,10 @@ def create_usersettings(sender, created_models=[], instance=None, created=False, If we end up with users with no UserSettings, then we get horrible 'DoesNotExist: UserSettings matching query does not exist.' errors. """ + from helpdesk.settings import DEFAULT_USER_SETTINGS if sender == User and created: # This is a new user, so lets create their settings entry. - s, created = UserSettings.objects.get_or_create(user=instance) + s, created = UserSettings.objects.get_or_create(user=instance, defaults={'settings': DEFAULT_USER_SETTINGS}) s.save() elif UserSettings in created_models: # We just created the UserSettings model, lets create a UserSettings @@ -946,7 +947,7 @@ def create_usersettings(sender, created_models=[], instance=None, created=False, try: s = UserSettings.objects.get(user=u) except UserSettings.DoesNotExist: - s = UserSettings(user=u) + s = UserSettings(user=u, settings=DEFAULT_USER_SETTINGS) s.save() models.signals.post_syncdb.connect(create_usersettings) diff --git a/helpdesk/settings.py b/helpdesk/settings.py index 53c25b3f..661dc042 100644 --- a/helpdesk/settings.py +++ b/helpdesk/settings.py @@ -12,3 +12,18 @@ try: import tagging except ImportError: HAS_TAG_SUPPORT = False + +try: + DEFAULT_USER_SETTINGS = settings.HELPDESK_DEFAULT_SETTINGS +except: + DEFAULT_USER_SETTINGS = None + +if type(DEFAULT_USER_SETTINGS) != type(dict()): + DEFAULT_USER_SETTINGS = { + 'use_email_as_submitter': True, + 'email_on_ticket_assign': True, + 'email_on_ticket_change': True, + 'login_view_ticketlist': True, + 'email_on_ticket_apichange': True, + 'tickets_per_page': 25 + }