Removed automatic creation of 404.html and 500.html templates and added a new management command for those cases called "create_error_templates". Also made reverted move to Bitbucket.

git-svn-id: https://django-dbtemplates.googlecode.com/svn/trunk@84 cfb8ba98-e953-0410-9cff-959ffddf5974

committer: leidel <leidel@cfb8ba98-e953-0410-9cff-959ffddf5974>

--HG--
extra : convert_revision : b03959a7322a1acd040dad721d80d7bbd680f16d
This commit is contained in:
leidel 2008-11-28 13:06:34 +00:00
parent 84dc3e0bcc
commit c9277e9c84
6 changed files with 73 additions and 58 deletions

View file

@ -1,2 +1,2 @@
VERSION = (0, 5, 3, 'pre')
VERSION = (0, 5, 3)
__version__ = '.'.join(map(str, VERSION))

View file

@ -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 %}
<h2>{% trans 'Page not found' %}</h2>
<p>{% trans "We're sorry, but the requested page could not be found." %}</p>
{% 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 %}
<h1>{% trans 'Server Error <em>(500)</em>' %}</h1>
<p>{% trans "There's been an error." %}</p>
{% endblock %}
"""
template500.save()
template500.sites.add(site)
signals.post_syncdb.connect(create_default_templates, sender=template_app)

View file

@ -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 %}
<h2>{% trans 'Page not found' %}</h2>
<p>{% trans "We're sorry, but the requested page could not be found." %}</p>
{% endblock %}
""",
500: """
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<h1>{% trans 'Server Error <em>(500)</em>' %}</h1>
<p>{% trans "There's been an error." %}</p>
{% 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

View file

@ -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")

View file

@ -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

View file

@ -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',