{ "info": { "author": "Mikko Hellsing", "author_email": "mikko@aino.se", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "django-primate\n==============\n\n- A modular django user.\n\nI am not going to discuss if this is a good idea or not. This Django\napplication monkey patches django in order to have a custom User model that\nplugs into the ``django.contrib.auth`` application.\n\n\nInstallation\n------------\nFirst of all install the module by checking out the latest code or use pip::\n\n pip install django-primate\n\nIn order to monkey patch we need to do this early. I have created a small\nmodified ``manage.py`` file that you can use for your development. This sets up\nyour environment and right before you run your management command (such as\n`runserver``) we apply the patch. Copy this into your project and overwrite the\ndefault ``manage.py``::\n\n #!/usr/bin/env python\n from django.core.management import setup_environ, ManagementUtility\n import imp\n try:\n imp.find_module('settings') # Assumed to be in the same directory.\n except ImportError:\n import sys\n sys.stderr.write(\n \"Error: Can't find the file 'settings.py' in the directory \"\n \"containing %r. It appears you've customized things.\\nYou'll have to \"\n \"run django-admin.py, passing it your settings module.\\n\" % __file__\n )\n sys.exit(1)\n\n import settings\n\n if __name__ == \"__main__\":\n setup_environ(settings)\n import primate\n primate.patch()\n ManagementUtility().execute()\n\nTo monkey patch your deployment you would apply the patch right after setting up\nthe ``DJANGO_SETTINGS_MODULE``.\n\n\nNow add ``django.contrib.auth`` to your ``INSTALLED_APPS``\n\n\nUsing\n-----\nAfter installing this patch you effectively have no User model at all. You have\nto create one on your own and define it in your settings. I will give you an\nexample on how to do this using the provided UserBase class.\n\n``project/users/models.py``::\n\n from primate.models import UserBase, UserMeta\n from django.db import models\n\n class CustomUser(UserBase):\n __metaclass__ = UserMeta\n name = models.CharField(max_length=500, default='Jon Deg')\n title = models.CharField(max_length=20, blank=True)\n\n\n``settings.py``::\n\n ``AUTH_USER_MODEL = 'users.models.CustomUser'``\n\n\nNow you can import this model by ``from django.contrib.auth.models import\nUser`` or ``from project.users.models import CustomUser``\n\n\nCustom fields and overriding default fields\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nIt's simple\n\n- To add a field just add a field to the model as you would normally.\n- To override a field just override the field name and it will be used instead\n of the one defined in ``UserBase``.\n\nThe overriding feature is something special not available in normal Django\nmodel abstract classes and is done in the custom metaclass. You can also remove\nfields defined in the ``UserBase`` class by altering the metaclass a little, you\ncan have a look in the code, its a really simple.\n\n\nAdmin\n^^^^^\nTo make the admin work I have made the monkey patch ``primate.patch`` patch the\n``admin.autodiscover`` so that it does not register the default admin class for\n``django.contrib.auth.User``. This means that you will need to register that\nyour self. The easiest way to do that is to first add ``users`` to your\n``INSTALLED_APPS`` and then add something like this to ``\u00f9sers/admin.py``::\n\n from primate.admin import UserAdminBase\n from django.contrib import admin\n from django.contrib.auth.models import User\n\n\n class UserAdmin(UserAdminBase):\n pass\n\n\n admin.site.register(User, UserAdmin)\n\n\nWhat's now in ``UserBase`` compared to ``django.contrib.auth.models.User``?\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nI have made some minor changes:\n\n1. Removed ``first_name`` and ``last_name``\n\n2. Added ``name``\n\n3. ``username`` is now max 50 chars\n\n4. Made ``email`` unique\n\n5. ``get_profile`` method just returns self\n\n\nAs stated earlier, you can now change all this, remove add and override fields\nin your user model.\n\n\nSouth\n^^^^^\nI was worried, this is a major feature, luckely Andrew already thought of this:\nqoute from the documentation under ``SOUTH_MIGRATION_MODULES``:\n\n\"Note that the keys in this dictionary are \u2018app labels\u2019, not the full paths to\napps; for example, were I to provide a migrations directory for\ndjango.contrib.auth, I\u2019d want to use auth as the key here.\"\n\nSo the time has come, just add this to your settings::\n\n SOUTH_MIGRATION_MODULES = {\n 'auth': 'users.migrations',\n }\n\n\nAlternative password hashing\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nSHA-1 is the default django hashing algorithm for passwords. Some may not agree\nthat this is the best choice. ``django-primate`` makes it simple for you to use\nalternative hashing as you can just override the ``check_password`` and\n``set_password`` methods in your custom user model. Since bcrypt is a good\nchoice there is a simple way for you to implement hashing using this::\n\n ``project/users/models.py``::\n\n from primate.models import UserBase, UserMeta, BcryptMixin\n from django.db import models\n\n class CustomUser(BcryptMixin, UserBase):\n __metaclass__ = UserMeta\n\n\nNote that this will update all passwords on authorization success to use bcrypt.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/aino/django-primate", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "django-primate", "package_url": "https://pypi.org/project/django-primate/", "platform": "any", "project_url": "https://pypi.org/project/django-primate/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/aino/django-primate" }, "release_url": "https://pypi.org/project/django-primate/0.1.1/", "requires_dist": null, "requires_python": null, "summary": "A modular django user", "version": "0.1.1" }, "last_serial": 4528464, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "907bc253f10a09b5ae239ea98b04c15b", "sha256": "fbbb2857096f9bbed2f712a6f9df51902498fa70c70323ca5d7591661145fd15" }, "downloads": -1, "filename": "django-primate-0.1.tar.gz", "has_sig": false, "md5_digest": "907bc253f10a09b5ae239ea98b04c15b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12337, "upload_time": "2011-03-09T03:31:59", "url": "https://files.pythonhosted.org/packages/63/f6/5cb0a7ad830552464f5850bc9bf65ccd8fd9f8038ef7189ef0397b5ff3c9/django-primate-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "b70f07a20296182290dc7fbc3f5555cb", "sha256": "4930fb9e4b5791c7c41a3887c9277c61f16b851b758ecb3b5ca09eea0491c65f" }, "downloads": -1, "filename": "django-primate-0.1.1.tar.gz", "has_sig": false, "md5_digest": "b70f07a20296182290dc7fbc3f5555cb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13200, "upload_time": "2011-03-17T23:10:12", "url": "https://files.pythonhosted.org/packages/6b/c8/eb3e5918432b58e485039c93228792ca80ccc7ad6eb00980be917150167c/django-primate-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b70f07a20296182290dc7fbc3f5555cb", "sha256": "4930fb9e4b5791c7c41a3887c9277c61f16b851b758ecb3b5ca09eea0491c65f" }, "downloads": -1, "filename": "django-primate-0.1.1.tar.gz", "has_sig": false, "md5_digest": "b70f07a20296182290dc7fbc3f5555cb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13200, "upload_time": "2011-03-17T23:10:12", "url": "https://files.pythonhosted.org/packages/6b/c8/eb3e5918432b58e485039c93228792ca80ccc7ad6eb00980be917150167c/django-primate-0.1.1.tar.gz" } ] }