From c906a5dcee596fd5a908c979bdfb410ab4276a94 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 7 Sep 2012 02:04:14 -0400 Subject: [PATCH] Common app updates --- apps/common/__init__.py | 34 ++++++----- apps/common/icons.py | 15 +++++ apps/common/links.py | 15 ++--- apps/common/literals.py | 3 + .../middleware/login_required_middleware.py | 3 +- apps/common/registry.py | 11 ++++ apps/common/settings.py | 57 +++++++++---------- apps/common/views.py | 2 +- 8 files changed, 82 insertions(+), 58 deletions(-) create mode 100644 apps/common/icons.py create mode 100644 apps/common/registry.py diff --git a/apps/common/__init__.py b/apps/common/__init__.py index 2739cee8ad..a462a8c144 100644 --- a/apps/common/__init__.py +++ b/apps/common/__init__.py @@ -10,28 +10,27 @@ from django.contrib.auth.models import User from django.dispatch import receiver from django.conf import settings from django.db.models.signals import post_save +from django.contrib.auth.models import User from navigation.api import bind_links, register_top_menu, Link from project_setup.api import register_setup -from project_tools.api import register_tool +#from project_tools.api import register_tool -from .conf.settings import (AUTO_CREATE_ADMIN, AUTO_ADMIN_USERNAME, +from .settings import (AUTO_CREATE_ADMIN, AUTO_ADMIN_USERNAME, AUTO_ADMIN_PASSWORD, TEMPORARY_DIRECTORY) -from .conf import settings as common_settings from .utils import validate_path -from .links import (password_change_view, current_user_details, - current_user_edit, about_view, license_view, admin_site, sentry) +from .links import (link_password_change, link_current_user_details, + link_current_user_edit, link_about, link_license, link_admin_site) from .models import AutoAdminSingleton from .debug import insert_pdb_exception_hook - +from .literals import PAGE_SIZE_LETTER, PAGE_ORIENTATION_PORTRAIT if getattr(settings, 'DEBUG_ON_EXCEPTION', False): insert_pdb_exception_hook() -bind_links(['about_view', 'license_view'], [about_view, license_view], menu_name='secondary_menu') -bind_links(['current_user_details', 'current_user_edit', 'password_change_view'], [current_user_details, current_user_edit, password_change_view], menu_name='secondary_menu') - -register_top_menu('about', link=Link(text=_(u'about'), view='about_view', sprite='information'), position=-1) +bind_links(['about_view', 'license_view'], [link_about, link_license], menu_name='secondary_menu') +bind_links(['current_user_details', 'current_user_edit', 'password_change_view'], [link_current_user_details, link_current_user_edit, link_password_change], menu_name='secondary_menu') +register_top_menu('about', link=link_about, position=-1) @receiver(post_migrate, dispatch_uid='create_superuser') def create_superuser(sender, **kwargs): @@ -63,7 +62,7 @@ def create_superuser(sender, **kwargs): auto_admin_properties.save() else: print 'Super admin user already exists. -- login: %s' % AUTO_ADMIN_USERNAME - + @receiver(post_save, dispatch_uid='auto_admin_account_passwd_change', sender=User) def auto_admin_account_passwd_change(sender, instance, **kwargs): @@ -72,12 +71,11 @@ def auto_admin_account_passwd_change(sender, instance, **kwargs): # Only delete the auto admin properties when the password has been changed auto_admin_properties.delete(force=True) +# TODO: Fix +#if (validate_path(TEMPORARY_DIRECTORY) == False) or (not TEMPORARY_DIRECTORY): +# setattr(common_settings, 'TEMPORARY_DIRECTORY', tempfile.mkdtemp()) -if (validate_path(TEMPORARY_DIRECTORY) == False) or (not TEMPORARY_DIRECTORY): - setattr(common_settings, 'TEMPORARY_DIRECTORY', tempfile.mkdtemp()) +#if 'django.contrib.admin' in settings.INSTALLED_APPS: +# register_setup(admin_site) -if 'django.contrib.admin' in settings.INSTALLED_APPS: - register_setup(admin_site) - -if 'sentry' in settings.INSTALLED_APPS: - register_tool(sentry) +#app.set_backup([ModelBackup()]) diff --git a/apps/common/icons.py b/apps/common/icons.py new file mode 100644 index 0000000000..39cdbaaf27 --- /dev/null +++ b/apps/common/icons.py @@ -0,0 +1,15 @@ +from __future__ import absolute_import + +from icons.literals import (CROSS, TICK, COMPUTER_KEY, VCARD, VCARD_EDIT, + INFORMATION, SCRIPT, KEYBOARD) +from icons import Icon + +icon_cross = Icon(CROSS) +icon_tick = Icon(TICK) + +icon_password_change = Icon(COMPUTER_KEY) +icon_current_user_details = Icon(VCARD) +icon_current_user_edit = Icon(VCARD_EDIT) +icon_about = Icon(INFORMATION) +icon_license = Icon(SCRIPT) +icon_admin_site = Icon(KEYBOARD) diff --git a/apps/common/links.py b/apps/common/links.py index 3180001f1c..1801485186 100644 --- a/apps/common/links.py +++ b/apps/common/links.py @@ -2,6 +2,8 @@ from django.utils.translation import ugettext_lazy as _ from navigation.api import Link +from .icons import (icon_password_change, icon_current_user_details, icon_current_user_edit, + icon_about, icon_license, icon_admin_site) def has_usable_password(context): return context['request'].user.has_usable_password @@ -11,10 +13,9 @@ def is_superuser(context): return context['request'].user.is_staff or context['request'].user.is_superuser -password_change_view = Link(text=_(u'change password'), view='password_change_view', sprite='computer_key', condition=has_usable_password) -current_user_details = Link(text=_(u'user details'), view='current_user_details', sprite='vcard') -current_user_edit = Link(text=_(u'edit details'), view='current_user_edit', sprite='vcard_edit') -about_view = Link(text=_('about'), view='about_view', sprite='information') -license_view = Link(text=_('license'), view='license_view', sprite='script') -sentry = Link(text=_(u'sentry'), view='sentry', sprite='bug', icon='bug.png', condition=is_superuser) -admin_site = Link(text=_(u'admin site'), view='admin:index', sprite='keyboard', icon='keyboard.png', condition=is_superuser) +link_password_change = Link(text=_(u'change password'), view='password_change_view', icon=icon_password_change, condition=has_usable_password) +link_current_user_details = Link(text=_(u'user details'), view='current_user_details', icon=icon_current_user_details) +link_current_user_edit = Link(text=_(u'edit details'), view='current_user_edit', icon=icon_current_user_edit) +link_about = Link(text=_('about'), view='about_view', icon=icon_about) +link_license = Link(text=_('license'), view='license_view', icon=icon_license) +link_admin_site = Link(text=_(u'admin site'), view='admin:index', icon=icon_admin_site, condition=is_superuser) diff --git a/apps/common/literals.py b/apps/common/literals.py index 96a7737ceb..61f42db086 100644 --- a/apps/common/literals.py +++ b/apps/common/literals.py @@ -38,3 +38,6 @@ PAGE_ORIENTATION_CHOICES = ( (PAGE_ORIENTATION_PORTRAIT, _(u'Portrait')), (PAGE_ORIENTATION_LANDSCAPE, _(u'Landscape')), ) + +DEFAULT_PAGE_SIZE = PAGE_SIZE_LETTER +DEFAULT_PAGE_ORIENTATION = PAGE_ORIENTATION_PORTRAIT diff --git a/apps/common/middleware/login_required_middleware.py b/apps/common/middleware/login_required_middleware.py index 94331d32aa..105e6b119f 100644 --- a/apps/common/middleware/login_required_middleware.py +++ b/apps/common/middleware/login_required_middleware.py @@ -5,7 +5,8 @@ import re from django.http import HttpResponseRedirect from django.conf import settings -from ..conf.settings import ALLOW_ANONYMOUS_ACCESS +#from ..conf.settings import ALLOW_ANONYMOUS_ACCESS +from .. import ALLOW_ANONYMOUS_ACCESS EXEMPT_URLS = [re.compile(settings.LOGIN_URL.lstrip('/'))] if hasattr(settings, 'LOGIN_EXEMPT_URLS'): diff --git a/apps/common/registry.py b/apps/common/registry.py new file mode 100644 index 0000000000..bdfd490567 --- /dev/null +++ b/apps/common/registry.py @@ -0,0 +1,11 @@ +from __future__ import absolute_import + +from django.utils.translation import ugettext_lazy as _ + +from .icons import icon_tick + +name = 'common' +label = _(u'Common') +description = _(u'Contains many commonly used models, views and utilities.') +dependencies = ['app_registry'] +icon = icon_tick diff --git a/apps/common/settings.py b/apps/common/settings.py index 00b8a8f6ee..da07502dd1 100644 --- a/apps/common/settings.py +++ b/apps/common/settings.py @@ -1,70 +1,65 @@ -"""Configuration options for the common app""" +""" +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.api import Setting, SettingNamespace +from smart_settings import SettingsNamespace, LocalScope -from common.literals import PAGE_SIZE_LETTER, PAGE_ORIENTATION_PORTRAIT +from .literals import DEFAULT_PAGE_SIZE, DEFAULT_PAGE_ORIENTATION -namespace = SettingNamespace('common', _(u'Common'), module=u'common.conf.settings') +namespace = SettingsNamespace(name='common', label=_(u'common'), module='common.settings') -Setting( - namespace=namespace, +namespace.add_setting( name='TEMPORARY_DIRECTORY', - global_name='COMMON_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 + exists=True, + scopes=[LocalScope()] ) -Setting( - namespace=namespace, +namespace.add_setting( name=u'DEFAULT_PAPER_SIZE', - global_name=u'COMMON_DEFAULT_PAPER_SIZE', - default=PAGE_SIZE_LETTER, + default=DEFAULT_PAGE_SIZE, + scopes=[LocalScope()] ) -Setting( - namespace=namespace, +namespace.add_setting( name=u'DEFAULT_PAGE_ORIENTATION', - global_name=u'COMMON_DEFAULT_PAGE_ORIENTATION', - default=PAGE_ORIENTATION_PORTRAIT, + default=DEFAULT_PAGE_ORIENTATION, + scopes=[LocalScope()] ) -Setting( - namespace=namespace, +namespace.add_setting( name=u'AUTO_CREATE_ADMIN', - global_name=u'COMMON_AUTO_CREATE_ADMIN', default=True, + scopes=[LocalScope()] ) -Setting( - namespace=namespace, +namespace.add_setting( name=u'AUTO_ADMIN_USERNAME', - global_name=u'COMMON_AUTO_ADMIN_USERNAME', default=u'admin', + scopes=[LocalScope()] ) -Setting( - namespace=namespace, +namespace.add_setting( name=u'AUTO_ADMIN_PASSWORD', - global_name=u'COMMON_AUTO_ADMIN_PASSWORD', default=User.objects.make_random_password(), + scopes=[LocalScope()] ) -Setting( - namespace=namespace, +namespace.add_setting( name=u'LOGIN_METHOD', - global_name=u'COMMON_LOGIN_METHOD', default=u'username', description=_(u'Controls the mechanism used to authenticated user. Options are: username, email'), + scopes=[LocalScope()] ) -Setting( - namespace=namespace, +namespace.add_setting( name=u'ALLOW_ANONYMOUS_ACCESS', - global_name=u'COMMON_ALLOW_ANONYMOUS_ACCESS', default=False, description=_(u'Allow non authenticated users, access to all views'), + scopes=[LocalScope()] ) diff --git a/apps/common/views.py b/apps/common/views.py index 1624dc6fe6..ba664c10ca 100644 --- a/apps/common/views.py +++ b/apps/common/views.py @@ -17,7 +17,7 @@ from django.conf import settings from .forms import (ChoiceForm, UserForm, UserForm_view, LicenseForm, EmailAuthenticationForm) -from .conf.settings import LOGIN_METHOD +from .settings import LOGIN_METHOD def multi_object_action_view(request):