Module to make it easy to configure external Django apps.
Project description
django-easyconfig
------------------
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.
Quick example...
Say you have an open source Django app that lets you upload a
Photo and some metadata to that photo. To be able to customize
that form, the project owners would have to hack the app's
source to fit their needs (class names, etc.) or you have to
make your app customizable. That's where django-easyconfig
comes in...
Install
-------
Basic Install:
$ python setup.py build
$ sudo python setup.py install
Alternative Install (Manually):
Place webutils directory in your Python path. Either in your Python
installs site-packages directory or set your $PYTHONPATH environment
variable to include a directory where the webutils directory lives.
Use
---
* XXX * These are not great docs. I'll work on updating this soon!
You must create a "Config" object in your app and use that to fetch
any object or value you want to be able to have customized.
Here is a basic example.
### yourapp/__init__.py
from django.contrib.auth.forms import AuthenticationForm
from yourapp.forms import PasswordChangeForm
from easyconfig import EasyConfig
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')
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)
Now, you just need to use your yourapp.Config class any time you need
to fetch one of these objects for use.
Here's how it could be used in a urls.py file
### urls.py
from yourapp import Config
from django.conf.urls.defaults import *
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'),
)
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
they would do so in their own project.
### settings.py
# Dotted python path to their own CustomConfig class
YOURAPP_CONFIG = 'myproject.myapp.CustomConfig'
### myproject/myapp/__init__.py
from myproject.myapp.forms import AuthForm, ChangeForm
class CustomConfig(object):
''' Customize the forms!
'''
def get_login_form(self):
return AuthForm
def get_password_change_form(self):
return ChangeForm
That's it. Easy right? :)
Copyright & Warranty
--------------------
All documentation, libraries, and sample code are
Copyright 2010 Peter Sanchez <petersanchez@gmail.com>. 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.
------------------
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.
Quick example...
Say you have an open source Django app that lets you upload a
Photo and some metadata to that photo. To be able to customize
that form, the project owners would have to hack the app's
source to fit their needs (class names, etc.) or you have to
make your app customizable. That's where django-easyconfig
comes in...
Install
-------
Basic Install:
$ python setup.py build
$ sudo python setup.py install
Alternative Install (Manually):
Place webutils directory in your Python path. Either in your Python
installs site-packages directory or set your $PYTHONPATH environment
variable to include a directory where the webutils directory lives.
Use
---
* XXX * These are not great docs. I'll work on updating this soon!
You must create a "Config" object in your app and use that to fetch
any object or value you want to be able to have customized.
Here is a basic example.
### yourapp/__init__.py
from django.contrib.auth.forms import AuthenticationForm
from yourapp.forms import PasswordChangeForm
from easyconfig import EasyConfig
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')
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)
Now, you just need to use your yourapp.Config class any time you need
to fetch one of these objects for use.
Here's how it could be used in a urls.py file
### urls.py
from yourapp import Config
from django.conf.urls.defaults import *
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'),
)
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
they would do so in their own project.
### settings.py
# Dotted python path to their own CustomConfig class
YOURAPP_CONFIG = 'myproject.myapp.CustomConfig'
### myproject/myapp/__init__.py
from myproject.myapp.forms import AuthForm, ChangeForm
class CustomConfig(object):
''' Customize the forms!
'''
def get_login_form(self):
return AuthForm
def get_password_change_form(self):
return ChangeForm
That's it. Easy right? :)
Copyright & Warranty
--------------------
All documentation, libraries, and sample code are
Copyright 2010 Peter Sanchez <petersanchez@gmail.com>. 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-easyconfig-0.1.tar.gz
(3.5 kB
view details)
File details
Details for the file django-easyconfig-0.1.tar.gz
.
File metadata
- Download URL: django-easyconfig-0.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9db95dbc32b84af78b7c8ece2348a3e1a4e574a56c35e2e11d5460df8da116cf |
|
MD5 | a4be411dae8935e2cc6af3cc0eadadc1 |
|
BLAKE2b-256 | 073ef55287606c02abfb19c2796243ed49e70c5ac172bb59782c0924b223f6ff |