# HG changeset patch # User Peter Sanchez # Date 1463440440 25200 # Mon May 16 16:14:00 2016 -0700 # Node ID d8d8457afbe3a28f63557f2d8c14fd2e0fd43ed5 # Parent 11606cabab0d3b49ff9b89432dc7d0d5822290f4 Updated for new version. diff --git a/README.txt b/README.rst rename from README.txt rename to README.rst --- a/README.txt +++ b/README.rst @@ -1,11 +1,14 @@ -django-easyconfig ------------------- +============================== +django-easyconfig |nlshield| +============================== + This app will make it easy to customize external Django apps that use it. -It takes an approach very similar to the django.contrib.comments -framework. It makes it easy to use custom forms, values, etc. +It takes an approach very similar to the old django.contrib.comments +(now django-comments) framework. It makes it easy to use custom +forms, values, etc. Quick example... @@ -42,25 +45,26 @@ Here is a basic example. -### yourapp/__init__.py +### yourapp/config.py +:: -from django.contrib.auth.forms import AuthenticationForm -from yourapp.forms import PasswordChangeForm -from easyconfig import EasyConfig + from easyconfig import EasyConfig + from django.contrib.auth.forms import AuthenticationForm + from yourapp.forms import PasswordChangeForm -class Config(object): - ''' Base config class to easily pass forms, etc. to - yourapp views. - ''' - # Use the dotted Python path to this class - config = EasyConfig('yourapp.Config', 'YOURAPP_CONFIG') + class Config(object): + ''' Base config class to easily pass forms, etc. to + yourapp views. + ''' + # Use the dotted Python path to this class + config = EasyConfig('yourapp.config.Config', 'YOURAPP_CONFIG') - def get_login_form(self): - return self.config.get_object('get_login_form', AuthenticationForm) + def get_login_form(self): + return self.config.get_object('get_login_form', AuthenticationForm) - def get_password_change_form(self): - return self.config.get_object('get_password_change_form', PasswordChangeForm) + def get_password_change_form(self): + return self.config.get_object('get_password_change_form', PasswordChangeForm) Now, you just need to use your yourapp.Config class any time you need @@ -69,25 +73,27 @@ Here's how it could be used in a urls.py file ### urls.py +:: -from yourapp import Config -from django.conf.urls.defaults import * + from django.conf.urls import url + from yourapp import views + from yourapp.config import Config -config = Config() + config = Config() -urlpatterns = patterns('yourapp.views', - url(r'^login/$', - 'login', { - 'template_name': 'yourapp/login.html', - 'authentication_form': config.get_login_form(), - }, name='yourapp-login'), - url(r'^passwd_change/$', - 'passwd_change', { - 'template_name': 'yourapp/passwd_change.html', - 'passwd_change_form': config.get_password_change_form(), - }, name='yourapp-passwd-change'), -) + urlpatterns = [ + url(r'^login/$', + views.login, { + 'template_name': 'yourapp/login.html', + 'authentication_form': config.get_login_form(), + }, name='yourapp-login'), + url(r'^passwd_change/$', + views.passwd_change, { + 'template_name': 'yourapp/passwd_change.html', + 'passwd_change_form': config.get_password_change_form(), + }, name='yourapp-passwd-change'), + ] Now, anybody using your app in their own project can easily change the login and password change forms to whatever form they want. Here is how @@ -95,24 +101,25 @@ ### settings.py +:: -# Dotted python path to their own CustomConfig class -YOURAPP_CONFIG = 'myproject.myapp.CustomConfig' + # Dotted python path to their own CustomConfig class + YOURAPP_CONFIG = 'myproject.myapp.config.CustomConfig' + +### myproject/myapp/config.py +:: + + from myproject.myapp.forms import AuthForm, ChangeForm -### myproject/myapp/__init__.py - -from myproject.myapp.forms import AuthForm, ChangeForm - - -class CustomConfig(object): - ''' Customize the forms! - ''' - def get_login_form(self): - return AuthForm + class CustomConfig(object): + ''' Customize the forms! + ''' + def get_login_form(self): + return AuthForm - def get_password_change_form(self): - return ChangeForm + def get_password_change_form(self): + return ChangeForm That's it. Easy right? :) @@ -124,3 +131,16 @@ Copyright 2010 Peter Sanchez . The library and sample code are made available to you under the terms of the BSD license which is contained in the included file, BSD-LICENSE. + +================== +Commercial Support +================== +This software, and lots of other software like it, has been built in +support of many of Netlandish's own projects, and the projects of our +clients. We would love to help you on your next project so get in +touch by dropping us a note at hello@netlandish.com. + + +.. |nlshield| image:: https://img.shields.io/badge/100%-Netlandish-blue.svg?style=square-flat + :target: http://www.netlandish.com + diff --git a/easyconfig/__init__.py b/easyconfig/__init__.py --- a/easyconfig/__init__.py +++ b/easyconfig/__init__.py @@ -1,9 +1,10 @@ +from importlib import import_module + from django.conf import settings from django.core.exceptions import ImproperlyConfigured -from django.utils.importlib import import_module -__version__ = '0.1' +__version__ = '0.2' class EasyConfig(object): def __init__(self, default_module, setting_name): @@ -27,20 +28,20 @@ 'The %s setting refers to a non-existing package.' % \ self.setting_name ) - + if callable(package): package = package() return package def _get_config_name(self): - ''' Returns the name of the support config (either the setting value, + ''' Returns the name of the support config (either the setting value, if it exists, or the default). ''' return getattr(settings, self.setting_name, self.default_module) def get_object(self, method, default_obj, *args, **kwargs): - ''' Check that the support config is custom, and if so, that the + ''' Check that the support config is custom, and if so, that the right methods exist. If not, return the default_obj ''' if self._get_config_name() != self.default_module: diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -2,9 +2,9 @@ from distutils.core import setup -version = '0.1' +version = '0.2' project_name = 'easyconfig' -long_description = open('README.txt').read() +long_description = open('README.rst').read() # Idea from django-registration setup.py packages, data_files = [], []