django-threaded-multihost-1.3-2/0000755000076500001200000000000011240614505015525 5ustar bruceadmindjango-threaded-multihost-1.3-2/.hgignore0000644000076500001200000000012211112424457017326 0ustar bruceadminsyntax: glob build *.orig *.rej *~ *.o *.pyo *.pyc _private dist build *.egg-info django-threaded-multihost-1.3-2/LICENSE.rst0000644000076500001200000000323511112340643017341 0ustar bruceadminBanjo Blog Application License ============================== :Authors: - Bruce Kroeze New BSD License =============== Copyright (c) 2008, Bruce Kroeze http://solidsitesolutions.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of SolidSiteSolutions LLC, Zefamily LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. django-threaded-multihost-1.3-2/PKG-INFO0000644000076500001200000000131711240614505016624 0ustar bruceadminMetadata-Version: 1.0 Name: django-threaded-multihost Version: 1.3-2 Summary: Django Threaded Multihost Home-page: http://getbanjo.com/threaded-multihost/ Author: Bruce Kroeze Author-email: brucek@solidsitesolutions.com License: New BSD License Description: django-threaded multihost provides support utilities to enable easy multi-site awareness in Django apps. Platform: any Classifier: Development Status :: 4 - Beta Classifier: Environment :: Web Environment Classifier: Framework :: Django Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Topic :: Utilities django-threaded-multihost-1.3-2/django_threaded_multihost.egg-info/0000755000076500001200000000000011240614505024431 5ustar bruceadmindjango-threaded-multihost-1.3-2/django_threaded_multihost.egg-info/PKG-INFO0000644000076500001200000000131711240614504025527 0ustar bruceadminMetadata-Version: 1.0 Name: django-threaded-multihost Version: 1.3-2 Summary: Django Threaded Multihost Home-page: http://getbanjo.com/threaded-multihost/ Author: Bruce Kroeze Author-email: brucek@solidsitesolutions.com License: New BSD License Description: django-threaded multihost provides support utilities to enable easy multi-site awareness in Django apps. Platform: any Classifier: Development Status :: 4 - Beta Classifier: Environment :: Web Environment Classifier: Framework :: Django Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Topic :: Utilities django-threaded-multihost-1.3-2/django_threaded_multihost.egg-info/SOURCES.txt0000644000076500001200000000125411240614505026317 0ustar bruceadmin.hgignore LICENSE.rst ez_setup.py setup.py django_threaded_multihost.egg-info/PKG-INFO django_threaded_multihost.egg-info/SOURCES.txt django_threaded_multihost.egg-info/dependency_links.txt django_threaded_multihost.egg-info/top_level.txt docs/AUTHORS.rst docs/CONTRIBUTING.rst docs/INSTALL.rst docs/TESTING.rst tests/__init__.py tests/manage.py tests/settings.py tests/urls.py tests/model_tests/__init__.py tests/model_tests/models.py tests/model_tests/tests.py threaded_multihost/__init__.py threaded_multihost/fields.py threaded_multihost/middleware.py threaded_multihost/multihost_patch.py threaded_multihost/sites.py threaded_multihost/threadlocals.py threaded_multihost/utils.pydjango-threaded-multihost-1.3-2/django_threaded_multihost.egg-info/dependency_links.txt0000644000076500001200000000000111240614504030476 0ustar bruceadmin django-threaded-multihost-1.3-2/django_threaded_multihost.egg-info/top_level.txt0000644000076500001200000000002311240614504027155 0ustar bruceadminthreaded_multihost django-threaded-multihost-1.3-2/docs/0000755000076500001200000000000011240614505016455 5ustar bruceadmindjango-threaded-multihost-1.3-2/docs/AUTHORS.rst0000644000076500001200000000070011240065651020333 0ustar bruceadminThreaded Multihost Authors and Contributors =========================================== Core developers --------------- - [Bruce Kroeze brucek@solidsitesolutions.com] Contributors ------------ - Herbert Poul http://sct.sphene.net, for inspiration, ideas, and the original Threadlocals we have heavily modified. - Dirk Datzert for contributing the initial test suite and the UserField/CreatorField/EditorField in fields.py django-threaded-multihost-1.3-2/docs/CONTRIBUTING.rst0000644000076500001200000000500011112340643021106 0ustar bruceadminContributing to django-threaded-multihost ----------------------------------------- We are pleased to accept contributions and bugfixes for django-threaded-multihost. To make a contribution: 1. First branch the project from launchpad. See `django-threaded-multihost on Launchpad`_ for a list of the current branches. If you simply want to branch the trunk, then all you need do is "bzr branch lp:banjo" to make your own local branch 2. Build and test your addon or update. You **must** provide tests for us to accept your contribution, and these tests *should* be unit tests rather than doctests. However, doctests in models are acceptible. If you are fixing a bug, it is a good rule of thumb to provide a test which provides a regression-test against that bug. 3. If this is a simple patch, go to `django-threaded-multihost on Launchpad`_ and enter a bug with the "bundled" patch generated like this: - Go to the root of your working copy. - Issue the "bzr update" command. This updates your working copy with changes from the repository. Check for conflicts and resolve them. - Issue the "bzr status" command. This shows the status of files. Ensure that all conflicts are resolved. - Commit your changes locally with: bzr commit -m "your narrative here" - Create your bundle with: bzr bundle > diffname.txt 4. If this is a larger patch or a new feature, make a branch and propose its merger: - Make a branch on Launchpad for your addition: - Go to launchpad, login, go to your homepage, click on "code" and click on "register branch" - Enter "django-threaded-multihost" for the project, and "hosted" for the branch type. - When you submit the form, it will give you a command to update the branch, copy it. - Push your branch to launchpad using this command. For example:: "bzr push lp:~bkroeze/django-threaded-multihost/1.0-release" - Note: For some reason, you may need to force bzr to use the empty-and-waiting directory by adding the "use existing dir" switch, like so:: "bzr push --use-existing-dir lp:~bkroeze/django-threaded-multihost/1.0-release" - Go to the page for your branch and click on "Propose for Merger." See `Merge Proposals`_ documentation for more information about this.: - Select the target branch: most likely the trunk. - enter any notes in the whiteboard - click "register" .. _`django-threaded-multihost on Launchpad`: http://code.launchpad.net/django-threaded-multihost .. _`Merge Proposals`: https://help.launchpad.net/BranchMergeProposals django-threaded-multihost-1.3-2/docs/INSTALL.rst0000644000076500001200000000004611112340643020312 0ustar bruceadminInstalling Banjo ================ TBDdjango-threaded-multihost-1.3-2/docs/TESTING.rst0000644000076500001200000000013611240065722020325 0ustar bruceadminTesting ======= Test suite can be done by running ./manage.py test in the "tests" directory. django-threaded-multihost-1.3-2/ez_setup.py0000644000076500001200000002276411240064226017747 0ustar bruceadmin#!python """Bootstrap setuptools installation If you want to use setuptools in your package's setup.py, just include this file in the same directory with it, and add this to the top of your setup.py:: from ez_setup import use_setuptools use_setuptools() If you want to require a specific version of setuptools, set a download mirror, or use an alternate download directory, you can do so by supplying the appropriate options to ``use_setuptools()``. This file can also be run as a script to install or upgrade setuptools. """ import sys DEFAULT_VERSION = "0.6c9" DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3] md5_data = { 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', 'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20', 'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab', 'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53', 'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2', 'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e', 'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372', 'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902', 'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de', 'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b', 'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03', 'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a', 'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6', 'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a', } import sys, os try: from hashlib import md5 except ImportError: from md5 import md5 def _validate_md5(egg_name, data): if egg_name in md5_data: digest = md5(data).hexdigest() if digest != md5_data[egg_name]: print >>sys.stderr, ( "md5 validation of %s failed! (Possible download problem?)" % egg_name ) sys.exit(2) return data def use_setuptools( version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15 ): """Automatically find/download setuptools and make it available on sys.path `version` should be a valid setuptools version number that is available as an egg for download under the `download_base` URL (which should end with a '/'). `to_dir` is the directory where setuptools will be downloaded, if it is not already available. If `download_delay` is specified, it should be the number of seconds that will be paused before initiating a download, should one be required. If an older version of setuptools is installed, this routine will print a message to ``sys.stderr`` and raise SystemExit in an attempt to abort the calling script. """ was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules def do_download(): egg = download_setuptools(version, download_base, to_dir, download_delay) sys.path.insert(0, egg) import setuptools; setuptools.bootstrap_install_from = egg try: import pkg_resources except ImportError: return do_download() try: pkg_resources.require("setuptools>="+version); return except pkg_resources.VersionConflict, e: if was_imported: print >>sys.stderr, ( "The required version of setuptools (>=%s) is not available, and\n" "can't be installed while this script is running. Please install\n" " a more recent version first, using 'easy_install -U setuptools'." "\n\n(Currently using %r)" ) % (version, e.args[0]) sys.exit(2) else: del pkg_resources, sys.modules['pkg_resources'] # reload ok return do_download() except pkg_resources.DistributionNotFound: return do_download() def download_setuptools( version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, delay = 15 ): """Download setuptools from a specified location and return its filename `version` should be a valid setuptools version number that is available as an egg for download under the `download_base` URL (which should end with a '/'). `to_dir` is the directory where the egg will be downloaded. `delay` is the number of seconds to pause before an actual download attempt. """ import urllib2, shutil egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) url = download_base + egg_name saveto = os.path.join(to_dir, egg_name) src = dst = None if not os.path.exists(saveto): # Avoid repeated downloads try: from distutils import log if delay: log.warn(""" --------------------------------------------------------------------------- This script requires setuptools version %s to run (even to display help). I will attempt to download it for you (from %s), but you may need to enable firewall access for this script first. I will start the download in %d seconds. (Note: if this machine does not have network access, please obtain the file %s and place it in this directory before rerunning this script.) ---------------------------------------------------------------------------""", version, download_base, delay, url ); from time import sleep; sleep(delay) log.warn("Downloading %s", url) src = urllib2.urlopen(url) # Read/write all in one block, so we don't create a corrupt file # if the download is interrupted. data = _validate_md5(egg_name, src.read()) dst = open(saveto,"wb"); dst.write(data) finally: if src: src.close() if dst: dst.close() return os.path.realpath(saveto) def main(argv, version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" try: import setuptools except ImportError: egg = None try: egg = download_setuptools(version, delay=0) sys.path.insert(0,egg) from setuptools.command.easy_install import main return main(list(argv)+[egg]) # we're done here finally: if egg and os.path.exists(egg): os.unlink(egg) else: if setuptools.__version__ == '0.0.1': print >>sys.stderr, ( "You have an obsolete version of setuptools installed. Please\n" "remove it from your system entirely before rerunning this script." ) sys.exit(2) req = "setuptools>="+version import pkg_resources try: pkg_resources.require(req) except pkg_resources.VersionConflict: try: from setuptools.command.easy_install import main except ImportError: from easy_install import main main(list(argv)+[download_setuptools(delay=0)]) sys.exit(0) # try to force an exit else: if argv: from setuptools.command.easy_install import main main(argv) else: print "Setuptools version",version,"or greater has been installed." print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' def update_md5(filenames): """Update our built-in md5 registry""" import re for name in filenames: base = os.path.basename(name) f = open(name,'rb') md5_data[base] = md5(f.read()).hexdigest() f.close() data = [" %r: %r,\n" % it for it in md5_data.items()] data.sort() repl = "".join(data) import inspect srcfile = inspect.getsourcefile(sys.modules[__name__]) f = open(srcfile, 'rb'); src = f.read(); f.close() match = re.search("\nmd5_data = {\n([^}]+)}", src) if not match: print >>sys.stderr, "Internal error!" sys.exit(2) src = src[:match.start(1)] + repl + src[match.end(1):] f = open(srcfile,'w') f.write(src) f.close() if __name__=='__main__': if len(sys.argv)>2 and sys.argv[1]=='--md5update': update_md5(sys.argv[2:]) else: main(sys.argv[1:]) django-threaded-multihost-1.3-2/setup.cfg0000644000076500001200000000007311240614505017346 0ustar bruceadmin[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 django-threaded-multihost-1.3-2/setup.py0000644000076500000240000000222311240614024017250 0ustar brucestaffimport ez_setup ez_setup.use_setuptools() from setuptools import setup, find_packages version = __import__('threaded_multihost').__version__ setup( name = 'django-threaded-multihost', version = version, description = "Django Threaded Multihost", long_description = """django-threaded multihost provides support utilities to enable easy multi-site awareness in Django apps.""", author = 'Bruce Kroeze', author_email = 'brucek@solidsitesolutions.com', url = 'http://getbanjo.com/threaded-multihost/', license = 'New BSD License', platforms = ['any'], classifiers = ['Development Status :: 4 - Beta', 'Environment :: Web Environment', 'Framework :: Django', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Utilities'], packages = ['threaded_multihost'], #package_dir = {'':'threaded_multihost'}, include_package_data = False, setup_requires = ["setuptools_hg"], ) django-threaded-multihost-1.3-2/tests/0000755000076500001200000000000011240614505016667 5ustar bruceadmindjango-threaded-multihost-1.3-2/tests/__init__.py0000644000076500001200000000000011240066016020764 0ustar bruceadmindjango-threaded-multihost-1.3-2/tests/manage.py0000755000076500000240000000104311240064670020512 0ustar brucestaff#!/usr/bin/env python from django.core.management import execute_manager try: import settings # Assumed to be in the same directory. except ImportError: import sys sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) sys.exit(1) if __name__ == "__main__": execute_manager(settings) django-threaded-multihost-1.3-2/tests/model_tests/0000755000076500001200000000000011240614505021211 5ustar bruceadmindjango-threaded-multihost-1.3-2/tests/model_tests/__init__.py0000644000076500001200000000000011240066040023303 0ustar bruceadmindjango-threaded-multihost-1.3-2/tests/model_tests/models.py0000644000076500000240000000106011240064670023063 0ustar brucestafffrom django.db import models from threaded_multihost import fields class Article(models.Model): user = fields.UserField(related_name='articles') text = models.TextField() def __unicode__(self): return self.text class ArticleCreator(models.Model): user = fields.CreatorField(related_name='created_articles') text = models.TextField() def __unicode__(self): return self.text class ArticleEditor(models.Model): user = fields.EditorField(related_name='edited_articles') text = models.TextField() def __unicode__(self): return self.text django-threaded-multihost-1.3-2/tests/model_tests/tests.py0000644000076500000240000000214011240064670022742 0ustar brucestafffrom models import Article, ArticleCreator, ArticleEditor from django.contrib.auth.models import User from threaded_multihost.threadlocals import get_current_user, set_current_user __test__ = {'API_TESTS': """ >>> a = Article(text="Look at me any user") >>> a.save() >>> a.user is None True >>> u = User(username='user') >>> u.save() >>> a.user = u >>> a.save() >>> a.user is None False >>> a.user.pk == u.pk True >>> a.user >>> u = User(username='creator') >>> u.save() >>> set_current_user(u) >>> b = ArticleCreator(text="Look at me creator") >>> b.save() >>> b.user.pk == u.pk True >>> b.user >>> b = ArticleCreator.objects.get(pk=b.pk) >>> b.user.pk == u.pk True >>> b.user >>> c = ArticleEditor(text="Look at me editor") >>> c.save() >>> c.user.pk == u.pk True >>> c.user >>> u = User(username='editor') >>> u.save() >>> set_current_user(u) >>> c.text = "Changed from editor" >>> c.save() >>> c.user.pk == u.pk True >>> c.user >>> c = ArticleEditor.objects.get(pk=c.pk) >>> c.user.pk == u.pk True >>> c.user """} django-threaded-multihost-1.3-2/tests/settings.py0000644000076500000240000000576411240064670021135 0ustar brucestaff# Django settings for mytest project. from os.path import normpath, join, dirname #ROOT : the django project root ROOT = lambda *base : normpath(join(dirname(__file__), *base)).replace('\\','/') DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', 'your_email@domain.com'), ) MANAGERS = ADMINS DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_NAME = 'threaded.db' # Or path to database file if using sqlite3. DATABASE_USER = '' # Not used with sqlite3. DATABASE_PASSWORD = '' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. # If running in a Windows environment this must be set to the same as your # system time zone. TIME_ZONE = 'America/Chicago' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en-us' SITE_ID = 1 # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = True # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" MEDIA_ROOT = '' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). # Examples: "http://media.lawrence.com", "http://example.com/media/" MEDIA_URL = '' # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. # Examples: "http://foo.com/media/", "/media/". ADMIN_MEDIA_PREFIX = '/media/' # Make this unique, and don't share it with anybody. SECRET_KEY = '$%b)@1zxin5gh19vsj(@nn=hm-!31ejy4gyc*391@-(odwsf+u' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', # 'django.template.loaders.eggs.load_template_source', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'threaded_multihost.middleware.ThreadLocalMiddleware', ) ROOT_URLCONF = 'urls' TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. # ROOT('templates') ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.admin', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'tests.model_tests', ) django-threaded-multihost-1.3-2/tests/urls.py0000644000076500000240000000103611240064670020246 0ustar brucestafffrom django.conf.urls.defaults import * # Uncomment the next two lines to enable the admin: # from django.contrib import admin # admin.autodiscover() urlpatterns = patterns('', # Example: # (r'^mytest/', include('mytest.foo.urls')), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: # (r'^admin/', include(admin.site.urls)), ) django-threaded-multihost-1.3-2/threaded_multihost/0000755000076500001200000000000011240614505021415 5ustar bruceadmindjango-threaded-multihost-1.3-2/threaded_multihost/__init__.py0000644000076500000240000000036211240614116023543 0ustar brucestaffVERSION = (1, 3, 2) # Dynamically calculate the version based on VERSION tuple if len(VERSION)>2 and VERSION[2] is not None: str_version = "%d.%d_%s" % VERSION[:3] else: str_version = "%d.%d" % VERSION[:2] __version__ = str_version django-threaded-multihost-1.3-2/threaded_multihost/fields.py0000644000076500000240000000240111240064702023246 0ustar brucestafffrom django.db.models import ForeignKey from django.contrib.auth.models import User import threadlocals class UserField(ForeignKey): """ UserField By defaults, foreign key to User; null=True, blank=True """ def __init__(self, **kwargs): kwargs.setdefault('null', True) kwargs.setdefault('blank', True) ForeignKey.__init__(self, User, **kwargs) class CreatorField(UserField): """ CreatorField By default, sets editable=False, default=threadlocals.get_current_user """ def __init__(self, **kwargs): kwargs.setdefault('editable', False) kwargs.setdefault('default', threadlocals.get_current_user) UserField.__init__(self, **kwargs) class EditorField(CreatorField): """ EditorField By default, sets editable=False, default=threadlocals.get_current_user Sets value to get_current_user() on each save of the model. """ def __init__(self, **kwargs): super(CreatorField, self).__init__(**kwargs) def pre_save(self, model_instance, add): value = threadlocals.get_current_user() setattr(model_instance, self.name, value) if value: value = value.pk setattr(model_instance, self.attname, value) return value django-threaded-multihost-1.3-2/threaded_multihost/middleware.py0000644000076500001200000000132711112340643024104 0ustar bruceadmin# -*- coding: utf-8 -*- """ threadlocals Middleware, provides a better, faster way to get at request and user. :Authors: - Herbert Poul http://sct.sphene.net - Bruce Kroeze Branched from [http://code.djangoproject.com/wiki/CookBookthreadlocalsAndUser CookBookThreadLocalsAndUser] as modified by [http://sct.sphene.net Sphene Community tools]. """ from threaded_multihost.threadlocals import set_thread_variable, set_current_user class ThreadLocalMiddleware(object): """Middleware that gets various objects from the request object and saves them in thread local storage.""" def process_request(self, request): set_thread_variable('request', request) set_current_user(request.user) django-threaded-multihost-1.3-2/threaded_multihost/multihost_patch.py0000644000076500001200000000044711112340643025200 0ustar bruceadminfrom django.contrib.sites.models import SiteManager, Site from threaded_multihost import sites def site_get_current(self): """Overridden version of get_current, which is multihost aware.""" return sites.by_host() SiteManager.get_current = site_get_current SiteManager.MULTIHOST = True django-threaded-multihost-1.3-2/threaded_multihost/sites.py0000644000076500001200000001300011162734725023122 0ustar bruceadmin# -*- coding: utf-8 -*- """Provides utilities to help multi-site aware applications. :Authors: - Bruce Kroeze """ """ New BSD License =============== Copyright (c) 2008, Bruce Kroeze http://coderseye.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of SolidSiteSolutions LLC, Zefamily LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ __docformat__="restructuredtext" from threaded_multihost import threadlocals from django.conf import settings from django.contrib.sites.models import Site from django.db.models.loading import app_cache_ready import keyedcache import logging log = logging.getLogger('threaded_multihost.sites') _WARNED = {} class MultihostNotReady(Exception): pass def by_host(host=None, id_only=False): """Get the current site by looking at the request stored in the thread. Returns the best match found in the `django.contrib.sites` app. If not found, then returns the default set as given in `settings.SITE_ID` Params: - `host`: optional, host to look up - `id_only`: if true, then do not retrieve the full site, just the id. """ global _WARNED if id_only: site = -1 else: site = None if not host: request = threadlocals.get_current_request() if request and 'HTTP_HOST' in request.META: host = request.META['HTTP_HOST'] else: log.debug('No request') site = by_settings(id_only=id_only) if host: if app_cache_ready(): try: site = keyedcache.cache_get('SITE', host=host, id_only=id_only) except keyedcache.NotCachedError, nce: try: log.debug('looking up site by host: %s', host) site = Site.objects.get(domain=host) except Site.DoesNotExist: if host.find(":") > -1: try: # strip the port host = host.split(":")[0] site = Site.objects.get(domain=host) except Site.DoesNotExist: pass if site: keyedcache.cache_set(nce.key, value=site) if id_only: site = site.id else: if not host in _WARNED: log.warn("Site for '%s' is not configured on this site - add to sites in admin", host) _WARNED[host] = True site = by_settings(id_only=id_only) else: log.debug('app cache not ready') site = by_settings(id_only=id_only) else: pass #log.debug('no host') # if site is None or site == -1: # raise MultihostNotReady() #log.debug("current site: %s", site) return site def by_request(request=None, id_only=False): """Look up a site given an explicit request rather than using the request currently in the `threadlocals`. Params: - `request`: optional, the request to use, defaults to the request found in the threadlocals - `id_only`: if true, then only the id is returned. """ host = None if request and 'HTTP_HOST' in request.META: host = request.META['HTTP_HOST'] return by_host(host=host, id_only=id_only) def by_settings(id_only=False): """Get the site according to the SITE_ID in settings. Params: - `id_only`: if true, then only the id is returned. """ #log.debug('from_settings') global _WARNED if id_only: return settings.SITE_ID try: return Site.objects.get(pk=settings.SITE_ID) except Exception, e: message = e.args[0] if message.find("django_site") > 0: site = None if not 'django_site' in _WARNED: log.warn("Error, couldn't find django_site in database, ok if you are in syncdb") _WARNED['django_site'] = True else: raise return site django-threaded-multihost-1.3-2/threaded_multihost/threadlocals.py0000644000076500001200000000602511112340643024434 0ustar bruceadmin# -*- coding: utf-8 -*- """__init__ module for the threadlocals package :Authors: - Herbert Poul http://sct.sphene.net - Bruce Kroeze http://gosatchmo.com """ """ New BSD License =============== Copyright (c) 2008, Bruce Kroeze http://solidsitesolutions.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of SolidSiteSolutions LLC, Zefamily LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ __docformat__="restructuredtext" import logging log = logging.getLogger('ThreadLocalMiddleware') try: from threading import local except ImportError: log.warn('getting threadlocal support from django') from django.utils._threading_local import local from django.contrib.sites.models import Site _threadlocals = local() def get_current_host(request = None): if not request: request = get_current_request() if request: try: host = request.META["HTTP_HOST"] return host except KeyError: pass #log.warn('No request found - returning default site') site = Site.objects.get_current() return site.domain def get_current_request(): return get_thread_variable('request', None) def get_current_session(): req = get_current_request() if req == None: return None return req.session def get_current_user(): user = get_thread_variable('user', None) if user != None: return user req = get_current_request() if req == None: return None return req.user def set_current_user(user): set_thread_variable('user', user) def set_thread_variable(key, var): setattr(_threadlocals, key, var) def get_thread_variable(key, default=None): return getattr(_threadlocals, key, default)django-threaded-multihost-1.3-2/threaded_multihost/utils.py0000644000076500001200000000456211162734725023150 0ustar bruceadmin# -*- coding: utf-8 -*- """utilities using the threaded multihost system. :Authors: - Herbert Poul http://sct.sphene.net - Bruce Kroeze http://gosatchmo.com """ """ New BSD License =============== Copyright (c) 2008, Bruce Kroeze http://solidsitesolutions.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of SolidSiteSolutions LLC, Zefamily LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ __docformat__="restructuredtext" from django.conf import settings import threadlocals import logging log = logging.getLogger('threaded_multihost.utils') def is_secure(): req = threadlocals.get_current_request() if not req: log.warning("No request found while doing media_tags. Are you missing the ThreadLocalMiddleware?") return False return req.is_secure() def current_media_url(): if not is_secure(): return settings.MEDIA_URL else: try: return settings.MEDIA_SECURE_URL except AttributeError: return settings.MEDIA_URL.replace('http://','https://')