Common app updates

This commit is contained in:
Roberto Rosario
2012-09-07 02:04:14 -04:00
parent 9e4a7025de
commit c906a5dcee
8 changed files with 82 additions and 58 deletions

View File

@@ -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()])

15
apps/common/icons.py Normal file
View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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'):

11
apps/common/registry.py Normal file
View File

@@ -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

View File

@@ -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()]
)

View File

@@ -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):