From b2828d1e1c159e4565d227dccad38262e60b94ac Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 27 Sep 2012 01:49:27 -0400 Subject: [PATCH] Move setting from settings file to registry and add default values to literals file --- apps/common/literals.py | 2 ++ apps/common/registry.py | 37 ++++++++++++++++++++++- apps/common/settings.py | 65 ----------------------------------------- 3 files changed, 38 insertions(+), 66 deletions(-) delete mode 100644 apps/common/settings.py diff --git a/apps/common/literals.py b/apps/common/literals.py index 61f42db086..353d88cd83 100644 --- a/apps/common/literals.py +++ b/apps/common/literals.py @@ -41,3 +41,5 @@ PAGE_ORIENTATION_CHOICES = ( DEFAULT_PAGE_SIZE = PAGE_SIZE_LETTER DEFAULT_PAGE_ORIENTATION = PAGE_ORIENTATION_PORTRAIT +DEFAULT_LOGIN_METHOD = 'username' +DEFAULT_TEMPORARY_DIRECTORY = '/tmp' diff --git a/apps/common/registry.py b/apps/common/registry.py index 0e0632bd61..5d32dc19d8 100644 --- a/apps/common/registry.py +++ b/apps/common/registry.py @@ -2,12 +2,47 @@ from __future__ import absolute_import from django.utils.translation import ugettext_lazy as _ +from smart_settings import ClusterScope, LocalScope + from .icons import icon_tick from .links import link_admin_site +from .literals import (DEFAULT_TEMPORARY_DIRECTORY, DEFAULT_PAGE_SIZE, + DEFAULT_PAGE_ORIENTATION, DEFAULT_LOGIN_METHOD) -name = 'common' label = _(u'Common') description = _(u'Contains many commonly used models, views and utilities.') dependencies = ['app_registry'] icon = icon_tick setup_links = [link_admin_site] +settings=[ + { + 'name': 'TEMPORARY_DIRECTORY', + 'default': DEFAULT_TEMPORARY_DIRECTORY, + 'description': _(u'Temporary directory used site wide to store thumbnails, previews and temporary files. If none is specified, one will be created using tempfile.mkdtemp().'), + 'exists': True, + 'scopes': [LocalScope()] + }, + { + 'name': 'DEFAULT_PAPER_SIZE', + 'default': DEFAULT_PAGE_SIZE, + 'scopes': [ClusterScope()] + }, + { + 'name': 'DEFAULT_PAGE_ORIENTATION', + 'default': DEFAULT_PAGE_ORIENTATION, + 'description': _(u'Password of the superuser admin that will be created.'), + 'scopes': [ClusterScope()] + }, + { + 'name': 'LOGIN_METHOD', + 'default': DEFAULT_LOGIN_METHOD, + 'description': _(u'Controls the mechanism used to authenticated user. Options are: username, email.'), + 'scopes': [ClusterScope()] + }, + { + 'name': 'ALLOW_ANONYMOUS_ACCESS', + 'default': False, + 'description': _(u'Allow non authenticated users, access to all views.'), + 'scopes': [ClusterScope()] + } +] diff --git a/apps/common/settings.py b/apps/common/settings.py deleted file mode 100644 index da07502dd1..0000000000 --- a/apps/common/settings.py +++ /dev/null @@ -1,65 +0,0 @@ -""" -Configuration options for the common app -""" -from __future__ import absolute_import - -from django.utils.translation import ugettext_lazy as _ -from django.contrib.auth.models import User - -from smart_settings import SettingsNamespace, LocalScope - -from .literals import DEFAULT_PAGE_SIZE, DEFAULT_PAGE_ORIENTATION - -namespace = SettingsNamespace(name='common', label=_(u'common'), module='common.settings') - -namespace.add_setting( - name='TEMPORARY_DIRECTORY', - default=u'/tmp', - description=_(u'Temporary directory used site wide to store thumbnails, previews and temporary files. If none is specified, one will be created using tempfile.mkdtemp().'), - exists=True, - scopes=[LocalScope()] -) - -namespace.add_setting( - name=u'DEFAULT_PAPER_SIZE', - default=DEFAULT_PAGE_SIZE, - scopes=[LocalScope()] -) - -namespace.add_setting( - name=u'DEFAULT_PAGE_ORIENTATION', - default=DEFAULT_PAGE_ORIENTATION, - scopes=[LocalScope()] -) - -namespace.add_setting( - name=u'AUTO_CREATE_ADMIN', - default=True, - scopes=[LocalScope()] -) - -namespace.add_setting( - name=u'AUTO_ADMIN_USERNAME', - default=u'admin', - scopes=[LocalScope()] -) - -namespace.add_setting( - name=u'AUTO_ADMIN_PASSWORD', - default=User.objects.make_random_password(), - scopes=[LocalScope()] -) - -namespace.add_setting( - name=u'LOGIN_METHOD', - default=u'username', - description=_(u'Controls the mechanism used to authenticated user. Options are: username, email'), - scopes=[LocalScope()] -) - -namespace.add_setting( - name=u'ALLOW_ANONYMOUS_ACCESS', - default=False, - description=_(u'Allow non authenticated users, access to all views'), - scopes=[LocalScope()] -)