From e59bb89f6c6724b4654fed193ca3a8773122b17d Mon Sep 17 00:00:00 2001 From: leidel Date: Fri, 20 Jul 2007 14:52:00 +0000 Subject: [PATCH] again: refactoring as a standalone application git-svn-id: https://django-dbtemplates.googlecode.com/svn/trunk@13 cfb8ba98-e953-0410-9cff-959ffddf5974 committer: leidel --HG-- extra : convert_revision : 7974964ff8ace563a81a23cd6308934a2461e5fb --- INSTALL | 15 +++++++++++++++ MANIFEST.in | 4 ++++ README | 16 ++++++++-------- dbtemplates/loader.py | 3 ++- dbtemplates/management.py | 9 +++------ dbtemplates/models.py | 2 +- dbtemplates/sync_templates.py | 12 +++++------- setup.py | 18 ++++++++++++++++++ 8 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 INSTALL create mode 100644 MANIFEST.in create mode 100644 setup.py diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..ecf0b30 --- /dev/null +++ b/INSTALL @@ -0,0 +1,15 @@ +To install it, run the following command inside this directory: + + python setup.py install + +Or if you'd prefer you can simply place the included ``dbtemplates`` +directory somewhere on your Python path, or symlink to it from +somewhere on your Python path; this is useful if you're working from a +Subversion checkout. + +Note that this application requires Python 2.3 or later, and a recent +Subversion checkout of Django. You can obtain Python from +http://www.python.org/ and Django from http://www.djangoproject.com/. + +This install notice was bluntly stolen from James Bennett's registration +package, http://code.google.com/p/django-registration/ \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..7f4ead8 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include INSTALL +include LICENSE +include MANIFEST.in +include README \ No newline at end of file diff --git a/README b/README index 72af47f..ec5aec5 100644 --- a/README +++ b/README @@ -1,3 +1,4 @@ +=================================== Database template loader for Django =================================== @@ -8,11 +9,10 @@ How to use it in your own django application ============================================ 0. Get the source from the subversion repository -1. Copy the "template" directory to your django project directory -2. Edit your settings.py: +1. Follow the instructions in the INSTALL file +2. Edit the settings.py of your Django project: - # Add ``myapp.template`` to the ``INSTALLED_APPS`` where "myapp" is the - name of your django project + # Add ``dbtemplates`` to the ``INSTALLED_APPS`` of your django project # Check if ``django.contrib.sites`` and ``django.contrib.admin`` are in ``INSTALLED_APPS`` and add if necessary @@ -26,19 +26,19 @@ How to use it in your own django application 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.flatpages', + 'dbtemplates', 'myapp.blog', - 'myapp.template', ) - # Add ``myapp.template.loaders.database.load_template_source`` to the - ``TEMPLATE_LOADERS`` where "myapp" is the name of your Django project + # Add ``dbtemplates.loader.load_template_source`` to the + ``TEMPLATE_LOADERS`` list in the settings.py of your Django project It should look something like this: TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', - 'myapp.template.loaders.database.load_template_source', + 'dbtemplates.loader.load_template_source', ) 3. Sync your database via shell (hint: "./manage.py syncdb" within project dir) diff --git a/dbtemplates/loader.py b/dbtemplates/loader.py index 91f0e76..f2b4fd4 100644 --- a/dbtemplates/loader.py +++ b/dbtemplates/loader.py @@ -1,8 +1,9 @@ from django.conf import settings from django.template import TemplateDoesNotExist -from django.contrib.dbtemplates.models import Template from django.contrib.sites.models import Site +from dbtemplates.models import Template + try: site = Site.objects.get_current() except: diff --git a/dbtemplates/management.py b/dbtemplates/management.py index 06d2cfd..1dad385 100644 --- a/dbtemplates/management.py +++ b/dbtemplates/management.py @@ -1,14 +1,11 @@ -""" -Creates the default database template objects. -Don't know if it works. -""" +""" Creates the default database template objects. """ from django.dispatch import dispatcher from django.db.models import signals from django.contrib.sites.models import Site -from template.models import Template -from template import models as template_app +from dbtemplates.models import Template +from dbtemplates import models as template_app def create_default_templates(app, created_models, verbosity): try: diff --git a/dbtemplates/models.py b/dbtemplates/models.py index 807c37f..e4b92c2 100644 --- a/dbtemplates/models.py +++ b/dbtemplates/models.py @@ -47,7 +47,7 @@ __test__ = {'API_TESTS':""" [, ] >>> t2.sites.all() [] ->>> from django.contrib.dbtemplates.loader import load_template_source +>>> from dbtemplates.loader import load_template_source >>> loader.template_source_loaders = [load_template_source] >>> loader.get_template("base.html").render(Context({'title':'MainPage'})) 'Welcome at MainPage' diff --git a/dbtemplates/sync_templates.py b/dbtemplates/sync_templates.py index 4a06b9d..447509c 100644 --- a/dbtemplates/sync_templates.py +++ b/dbtemplates/sync_templates.py @@ -1,12 +1,7 @@ -""" -Helper function for syncing templates in TEMPLATES_DIRS with the dbtemplates -contrib app. -""" - from django.conf import settings from django.template import TemplateDoesNotExist -from django.contrib.dbtemplates.models import Template from django.contrib.sites.models import Site +from dbtemplates.models import Template import os import sys @@ -76,5 +71,8 @@ def synctemplates(extension=".html", overwrite=False): for _tried in tried: print _tried +def main(): + synctemplates() + if __name__ == "__main__": - synctemplates() \ No newline at end of file + main() \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d1fc506 --- /dev/null +++ b/setup.py @@ -0,0 +1,18 @@ +from distutils.core import setup + +setup(name='dbtemplates', + version='0.2', + description='Template loader for database stored templates', + author='Jannis Leidel', + author_email='jannis@leidel.info', + url='http://code.google.com/p/django-databasetemplateloader/', + packages=['dbtemplates'], + package_dir={ 'dbtemplates': 'dbtemplates' }, + classifiers=['Development Status :: 4 - Beta', + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Utilities'], + ) \ No newline at end of file