diff --git a/dbtemplates/__init__.py b/dbtemplates/__init__.py index a9fe19f..3c9dcb6 100644 --- a/dbtemplates/__init__.py +++ b/dbtemplates/__init__.py @@ -1,2 +1,2 @@ -VERSION = (0, 5, 3, 'pre') +VERSION = (0, 5, 3) __version__ = '.'.join(map(str, VERSION)) \ No newline at end of file diff --git a/dbtemplates/management/__init__.py b/dbtemplates/management/__init__.py index d9fb6a6..e69de29 100644 --- a/dbtemplates/management/__init__.py +++ b/dbtemplates/management/__init__.py @@ -1,47 +0,0 @@ -from django.db.models import signals -from django.contrib.sites.models import Site - -from dbtemplates.models import Template -from dbtemplates import models as template_app - -def create_default_templates(app, created_models, verbosity, **kwargs): - """Creates the default database template objects.""" - try: - site = Site.objects.get_current() - except Site.DoesNotExist: - site = None - - if site is not None: - if Template in created_models: - if verbosity >= 2: - print "Creating default database templates for error 404 and 500" - - template404, created404 = Template.objects.get_or_create( - name="404.html") - if created404: - template404.content=""" -{% extends "base.html" %} -{% load i18n %} -{% block content %} -
{% trans "We're sorry, but the requested page could not be found." %}
-{% endblock %} -""" - template404.save() - template404.sites.add(site) - - template500, created500 = Template.objects.get_or_create( - name="500.html") - if created500: - template500.content=""" -{% extends "base.html" %} -{% load i18n %} -{% block content %} -{% trans "There's been an error." %}
-{% endblock %} -""" - template500.save() - template500.sites.add(site) - -signals.post_syncdb.connect(create_default_templates, sender=template_app) diff --git a/dbtemplates/management/commands/create_error_templates.py b/dbtemplates/management/commands/create_error_templates.py new file mode 100644 index 0000000..3d11e79 --- /dev/null +++ b/dbtemplates/management/commands/create_error_templates.py @@ -0,0 +1,49 @@ +from optparse import make_option + +from django.core.management.base import CommandError, NoArgsCommand +from django.contrib.sites.models import Site + +from dbtemplates.models import Template + +TEMPLATES = { + 404: """ +{% extends "base.html" %} +{% load i18n %} +{% block content %} +{% trans "We're sorry, but the requested page could not be found." %}
+{% endblock %} +""", + 500: """ +{% extends "base.html" %} +{% load i18n %} +{% block content %} +{% trans "There's been an error." %}
+{% endblock %} +""", +} + +class Command(NoArgsCommand): + help = "Creates the 404.html and 500.html error templates as database template objects." + option_list = NoArgsCommand.option_list + ( + make_option("-f", "--force", action="store_true", dest="force", + default=False, help="overwrite existing database templates") + ) + def handle_noargs(self, **options): + force = options.get('force') + try: + site = Site.objects.get_current() + except Site.DoesNotExist: + raise CommandError("Please make sure to have the sites contrib " + "app installed and setup with a site object") + for error_code in (404, 500): + template, created = Template.objects.get_or_create( + name="%s.html" % error_code) + if created or (not created and force): + template.content = TEMPLATES.get(error_code, '') + template.save() + template.sites.add(site) + print "Created database template for %s errors." % error_code + else: + print "A template for %s errors already exists." % error_code diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index 09f6f0e..c6a2aff 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -1,5 +1,4 @@ import os -import re from optparse import make_option from django.conf import settings @@ -28,9 +27,6 @@ class Command(NoArgsCommand): try: site = Site.objects.get_current() except: - site = None - - if site is None: raise CommandError("Please make sure to have the sites contrib " "app installed and setup with a site object") diff --git a/docs/overview.txt b/docs/overview.txt index d20a98b..3eba369 100644 --- a/docs/overview.txt +++ b/docs/overview.txt @@ -18,7 +18,7 @@ of the templates saved in the database. Setup ===== -1. Get the source from the `Mercurial repository`_ or install it from the +1. Get the source from the `Git repository`_ or install it from the Python Package Index by running ``easy_install django-dbtemplates`` or ``pip django-dbtemplates``. 2. Follow the instructions in the INSTALL file @@ -56,7 +56,7 @@ Setup 4. Sync your database ``python manage.py syncdb`` 5. Restart your Django server -.. _Mercurial repository: http://bitbucket.org/jezdez/django-dbtemplates/ +.. _Git repository: http://github.com/jezdez/django-dbtemplates/ Usage ===== @@ -187,7 +187,7 @@ follwing three reuqired methods: Please see also the `source of the default backends`_ to see how it works. -.. _source of the default backends: http://www.bitbucket.org/jezdez/django-dbtemplates/src/tip/dbtemplates/cache.py +.. _source of the default backends: http://github.com/jezdez/django-dbtemplates/tree/master/dbtemplates/cache.py Versionizing your templates =========================== @@ -214,9 +214,26 @@ Short installation howto .. _django-reversion: http://code.google.com/p/django-reversion/ .. _django-reversion's documentation: http://code.google.com/p/django-reversion/wiki/GettingStarted +Management commands +=================== + +``dbtemplates`` comes with two `management commands`_ to be used with ``django-admin.py`` or ``manage.py``: + +* ``sync_templates`` + + Enables you to sync your already existing file systems templates with the + database. It will guide you through the whole process. + +* ``create_error_templates`` + + Tries to add the two templates ``404.html`` and ``500.html`` that are used + by Django when a error occurs. + +.. _management commands: http://docs.djangoproject.com/en/dev/ref/django-admin/ + Support ======= Please leave your questions and messages on the designated site: -http://www.bitbucket.org/jezdez/django-dbtemplates/issues/ +http://code.google.com/p/django-dbtemplates/source/list diff --git a/setup.py b/setup.py index 681ea55..dfe427a 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +7,8 @@ setup( long_description=open('docs/overview.txt').read(), author='Jannis Leidel', author_email='jannis@leidel.info', - url='http://www.bitbucket.org/jezdez/django-dbtemplates/wiki/', - download_url='http://www.bitbucket.org/jezdez/django-dbtemplates/get/v0.5.2.gz', + url='http://github.com/jezdez/django-dbtemplates/wikis/', + download_url='http://github.com/jezdez/django-dbtemplates/tarball/0.5.3', packages=[ 'dbtemplates', 'dbtemplates.management',