Permalink
Browse files

Preparing for release

  • Loading branch information...
1 parent 99806f5 commit 1c676b0cb4f18bc2e04a8c1ece128104d2ae0bb7 @robmadole robmadole committed Apr 28, 2010
Showing with 125 additions and 42 deletions.
  1. +4 −0 .hgignore
  2. +4 −12 NEWS.txt
  3. +100 −17 README.rst
  4. +4 −0 setup.cfg
  5. +10 −7 setup.py
  6. +0 −4 src/immutablefield/__init__.py
  7. +3 −2 src/immutablefield/models.py
View
@@ -13,3 +13,7 @@ eggs
tmp
build
dist
+py-*
+Django-*
+coverage-*
+nose-*
View
@@ -3,21 +3,13 @@
.. The content of this file, along with README.rst, will appear in your
.. project's PyPI page.
-News
-====
-
-0.2a1
------
-
-*Release date: UNRELEASED*
-
-* Example news entry for the in-development version
-
+Release notes
+=============
0.1
---
-*Release date: 15-Mar-2010*
+*Release date: 28-Apr-2010*
-* Example news entry for a released version
+* Initial release
View
@@ -1,23 +1,106 @@
-This file requires editing
-==========================
+django-immutablefield
+=====================
-Note to the author: Please add something informative to this README *before*
-releasing your software, as `a little documentation goes a long way`_. Both
-README.rst (this file) and NEWS.txt (release notes) will be included in your
-package metadata which gets displayed in the PyPI page for your project.
+Inspired by a Google search that didn't turn up reusable solution for making
+fields immutable inside of a Django model.
-You can take a look at the README.txt of other projects, such as repoze.bfg
-(http://bfg.repoze.org/trac/browser/trunk/README.txt) for some ideas.
+Installing
+----------
-.. _`a little documentation goes a long way`: http://www.martinaspeli.net/articles/a-little-documentation-goes-a-long-way
+One of the following:
-Credits
--------
+Via the ole' standby::
-- `Distribute`_
-- `Buildout`_
-- `modern-package-template`_
+ easy_install django-immutablefield
-.. _Buildout: http://www.buildout.org/
-.. _Distribute: http://pypi.python.org/pypi/distribute
-.. _`modern-package-template`: http://pypi.python.org/pypi/modern-package-template
+Pip::
+
+ pip install django-immutablefield
+
+To install directly from Bitbucket::
+
+ pip install -e hg+http://bitbucket.org/robmadole/django-immutablefield#egg=django-immutablefield
+
+**Do you need this in Django's ``INSTALLED_APPS``?**
+
+ No, it's not necessary. You just have to be able to
+ ``from immutablefield.models import ImmutableModel``.
+
+What does it do
+---------------
+
+Allows you to define certain fields as immutable inside of Django models.
+
+It works as a drop-in replacement for Django's own ``Model``. This means you
+can ``ImmutableModel`` even if you don't specify meta information specific to
+it.
+
+Here's an example::
+
+ from django.db import models
+
+ from immutablefield.models import ImmutableModel
+
+ CruiseShip(ImmutableModel):
+ name = models.CharField(max_length=50)
+
+ class ImmutableMeta:
+ # After ya name a ship, you can't change it matey
+ immutable = ['name']
+
+ def __unicode__(self):
+ return u'%s' % self.name
+
+Now you can try with all your might, but the field won't change (within reason,
+sure this is Python we can do almost anything if we try hard enough)::
+
+ >>> queen_anne = CruiseShip.objects.create(name='Queen Anne')
+ <CruiseShip 'Queen Anne'>
+ >>> queen_anne.name = 'King George'
+ >>> queen_anne.name
+ 'Queen Anne'
+
+You can make it complain
+------------------------
+
+Change the meta section to include ``quiet = False`` and it will raise a
+``ValueError`` if an attempt is made to change this value::
+
+ class ImmutableMeta:
+ # After ya name a ship, you can't change it matey
+ immutable = ['name']
+ quiet = False
+
+Example::
+
+ >>> queen_anne = CruiseShip.objects.create(name='Queen Anne')
+ <CruiseShip 'Queen Anne'>
+ >>> queen_anne.name = 'King George'
+ ValueError: name is immutable and cannot be changed
+
+Reference
+---------
+
+**``ImmutableMeta``**
+
+ Specify options that control how immutable fields are handled when
+ subclassing the ``ImmutableModel` class
+
+ ``immutable``
+
+ Tell ``ImmutableModel`` which fields should not be allowed to change.
+ This value must be a tuple or a list and contain the names of the fields
+ as strings.
+
+ Example ::
+
+ class ImmutableMeta:
+ immutable = ['my_special_id']
+
+ ``quiet``
+
+ If an attempt is made to change an immutable field, should we quietly
+ prevent it.
+
+ Set this value to ``False`` to raise a ``ValueError`` when an immutable
+ field is changed.
View
@@ -0,0 +1,4 @@
+[nosetests]
+detailed-errors=1
+with-coverage=1
+cover-package=immutablefield
View
@@ -5,22 +5,24 @@
README = open(os.path.join(here, 'README.rst')).read()
NEWS = open(os.path.join(here, 'NEWS.txt')).read()
-
version = '0.1'
-install_requires = [
- # List your project dependencies here.
- # For more details, see:
- # http://packages.python.org/distribute/setuptools.html#declaring-dependencies
-]
+install_requires = []
+
+setup_requires = ['nose>=0.11.3', 'django>=1.1.1', 'py>=1.2.1', 'coverage>=3.3.1']
setup(name='django-immutablefield',
version=version,
description="A base class for Django to allow immutable fields on Models",
long_description=README + '\n\n' + NEWS,
classifiers=[
- # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ 'Development Status :: 3 - Alpha',
+ 'Framework :: Django',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: BSD License',
+ 'Programming Language :: Python',
+ 'Topic :: Database'
],
keywords='django model fields immutable frozen',
author='Rob Madole',
@@ -31,5 +33,6 @@
package_dir = {'': 'src'},include_package_data=True,
zip_safe=False,
install_requires=install_requires,
+ setup_requires=setup_requires,
entry_points={}
)
@@ -1,4 +0,0 @@
-# Example package with a console entry point
-
-def main():
- print "Hello World"
@@ -1,12 +1,13 @@
from django.db import models
from django.db.models.base import ModelBase
+
class ImmutableModelOptions(object):
immutable = []
quiet = True
-
+
def __init__(self, opts):
- if opts:
+ if opts:
for key, value in opts.__dict__.iteritems():
setattr(self, key, value)

0 comments on commit 1c676b0

Please sign in to comment.