{ "info": { "author": "Joe Friedl", "author_email": "joe@joefriedl.net", "bugtrack_url": null, "classifiers": [], "description": "Django Tenant Templates\n=======================\n\nTenant-aware templating for Django.\n\nOverview\n--------\n\nA tenant is a set of application configurations and behaviors that runs\nalongside other tenants in the same server process.\n\nOne of the first challenges when building a multitenant Web app is loading\ndifferent templates for each tenant without making developers' lives harder.\nDjango Tenant Templates provies utilities for making templating in Django\ntenant-aware without getting in the way of normal Django development.\n\nInstallation and Usage\n----------------------\n\nInstall `django-tenant-templates` from PyPI::\n\n pip install django-tenant-templates\n\nAdd the tenant middleware class to your Django settings::\n\n MIDDLEWARE_CLASSES = (\n ...\n 'django_tenant_templates.middleware.TenantMiddleware',\n ...\n )\n\nAdd one or more of the tenant template loaders. They should be placed before\nthe standard Django loaders::\n\n TEMPLATE_LOADERS = (\n 'django_tenant_templates.loaders.TenantFileSystemLoader',\n ...\n )\n\nNow all you need to do is set `request.tenant_slug` somewhere before\n`TenantMiddleware` is called, and put your tenant-specific templates in\na subdirectory whose name is the value of `request.tenant_slug`.\n\nAfter that, all template names will get prefixed with `request.tenant_slug`\nand a forward slash. If `request.tenant_slug` is `'my_tenant'`,\n`'customers/customer_list.html'` becomes\n`'my_tenant/customers/customer_list.html'`.\n\nTo fall back to non-tenant template loading, make sure to include other\ntemplate loaders after the tenant loaders in `settings.TEMPLATE_LOADERS`.\n\nIf you want to explicitly load a non-tenant template, prefix the template name\nwith './'. This allows you to extend a non-tenant template with the same name\nas the tenant template, which can be useful for things like overriding only\npart of a base template rather than replacing the whole thing.\n\nMiddleware\n----------\n\n**TRIGGER WARNING: This section contains references to thread locals.**\n\nThe `django_tenant_templates.middleware.TenantMiddleware` class is what makes\nthe tenant template loaders work. It looks for `request.tenant_slug` and\nplaces it in thread local storage. The template loaders then use the\nthread local to figure out where they should look for templates.\n\nHow you get the value you assign to `request.tenant_slug` is up to you,\nbut it should be a valid directory name for whatever filesystem you're using.\nFor example::\n\n # Middleware that runs before TenantMiddleware\n class ExampleMiddleware(object):\n def process_request(self, request):\n # Get the tenant slug from an HTTP header.\n request.tenant_slug = request.META.get('HTTP_X_TENANT_ID', None)\n\nYou can change the `request` attribute `TenantMiddleware` looks for by using\na custom subclass::\n\n class CustomTenantMiddleware(TenantMiddleware):\n slug_attribute_name = 'fart'\n\nDjango Tenant Templates' template loaders would then use the value of\n`request.fart` as the tenant slug.\n\nLoaders\n-------\n\nDjango Tenant Templates provides a few template loaders that correspond to\nthe loaders provided by Django. They all live in the\n`django_tenant_templates.loaders` module.\n\nEach loader does essentially the same thing: a tenant slug is prefixed to the\ntemplate name, then the template is looked up normally. For example, if the\ntenant slug is `'my_tenant'`, the template name `customers/customer_list.html`\nwill be translated to `my_tenant/customers/customer_list.html`.\n\nTenantFileSystemLoader\n~~~~~~~~~~~~~~~~~~~~~~\n\nFinds templates using `settings.TEMPLATE_DIRS`. See\n`django.template.loaders.filesystem.Loader`.\n\nTenantAppLoader\n~~~~~~~~~~~~~~~\n\nFinds templates in each of your `INSTALLED_APPS`. See\n`django.template.loaders.app_directories.Loader`.\n\nTenantLoaderMixin\n~~~~~~~~~~~~~~~~~\n\nA mixin that adds tenant-awareness to template loading. Use this to create\ncustom template loaders.\n", "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/grampajoe/django-tenant-templates", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-tenant-templates", "package_url": "https://pypi.org/project/django-tenant-templates/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-tenant-templates/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/grampajoe/django-tenant-templates" }, "release_url": "https://pypi.org/project/django-tenant-templates/0.5/", "requires_dist": null, "requires_python": null, "summary": "Tenant-aware templating for Django.", "version": "0.5" }, "last_serial": 1028979, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "29b041efc933a2c51732bcff82318a8f", "sha256": "be1ec24c766684b3447673b10e6dcd33f5e01996823865297ab7c8728f64d008" }, "downloads": -1, "filename": "django-tenant-templates-0.1.tar.gz", "has_sig": false, "md5_digest": "29b041efc933a2c51732bcff82318a8f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1530, "upload_time": "2013-06-02T02:10:24", "url": "https://files.pythonhosted.org/packages/b5/c3/e1a1c02a24aac50f6d5711e08a44017174dba4fcd50a203b13499dd8f409/django-tenant-templates-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "3ea0ffef0e5cd958aa41b7850cb7e7d5", "sha256": "9220f5c6e16a2b103481ceba0f8bc07a946fb0cd33d808ef412f34db096992b4" }, "downloads": -1, "filename": "django-tenant-templates-0.2.tar.gz", "has_sig": false, "md5_digest": "3ea0ffef0e5cd958aa41b7850cb7e7d5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1537, "upload_time": "2013-06-02T19:40:18", "url": "https://files.pythonhosted.org/packages/7f/22/4973d319ffe8dc042c7376bf20fd2c431c11301b04c6919513c96861c300/django-tenant-templates-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "b5fe8005542a79aee94d786f63773201", "sha256": "118b891d0dc3906ad83d56e2b62a7105718ece8b73a38b163aed7a4ea89b6b99" }, "downloads": -1, "filename": "django-tenant-templates-0.3.tar.gz", "has_sig": false, "md5_digest": "b5fe8005542a79aee94d786f63773201", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1598, "upload_time": "2013-06-02T20:37:22", "url": "https://files.pythonhosted.org/packages/92/3d/6ef6cb0117674da170ad8e4a5e5716586c9f38913030fd056796d1efe836/django-tenant-templates-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "f97207d0b0f7c816e7c50ced14059a38", "sha256": "a9cda108215861acb4b198c5d51fbe697dc9219e5ca2a888ed4b98f3031517de" }, "downloads": -1, "filename": "django-tenant-templates-0.4.tar.gz", "has_sig": false, "md5_digest": "f97207d0b0f7c816e7c50ced14059a38", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1627, "upload_time": "2013-06-03T12:23:34", "url": "https://files.pythonhosted.org/packages/40/de/b5b470d1769290ca35bb053850688a381ee625622500bff01276d6084edb/django-tenant-templates-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "2a265f5d4d31a7cc7d5e9ec4692708f5", "sha256": "6a6626e8c3550579421b04b6a7c53fbc1c0e448bd5a816ae4f0e3e3f2e62e54d" }, "downloads": -1, "filename": "django-tenant-templates-0.5.tar.gz", "has_sig": false, "md5_digest": "2a265f5d4d31a7cc7d5e9ec4692708f5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3047, "upload_time": "2014-03-13T23:35:04", "url": "https://files.pythonhosted.org/packages/ea/0c/fb036aaa1dd7d20a14289604a3af6a439257b8c74b13039a3ae6c89ec9fc/django-tenant-templates-0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2a265f5d4d31a7cc7d5e9ec4692708f5", "sha256": "6a6626e8c3550579421b04b6a7c53fbc1c0e448bd5a816ae4f0e3e3f2e62e54d" }, "downloads": -1, "filename": "django-tenant-templates-0.5.tar.gz", "has_sig": false, "md5_digest": "2a265f5d4d31a7cc7d5e9ec4692708f5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3047, "upload_time": "2014-03-13T23:35:04", "url": "https://files.pythonhosted.org/packages/ea/0c/fb036aaa1dd7d20a14289604a3af6a439257b8c74b13039a3ae6c89ec9fc/django-tenant-templates-0.5.tar.gz" } ] }