Author: leidel
Date: Fri Nov 28 05:06:34 2008
New Revision: 84

Added:
    trunk/dbtemplates/management/commands/create_error_templates.py
Modified:
    trunk/dbtemplates/__init__.py
    trunk/dbtemplates/management/__init__.py
    trunk/dbtemplates/management/commands/sync_templates.py
    trunk/docs/overview.txt
    trunk/setup.py

Log:
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.

Modified: trunk/dbtemplates/__init__.py
==============================================================================
--- trunk/dbtemplates/__init__.py       (original)
+++ trunk/dbtemplates/__init__.py       Fri Nov 28 05:06:34 2008
@@ -1,2 +1,2 @@
-VERSION = (0, 5, 3, 'pre')
+VERSION = (0, 5, 3)
  __version__ = '.'.join(map(str, VERSION))

Modified: trunk/dbtemplates/management/__init__.py
==============================================================================
--- trunk/dbtemplates/management/__init__.py    (original)
+++ trunk/dbtemplates/management/__init__.py    Fri Nov 28 05:06:34 2008
@@ -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)

Added: trunk/dbtemplates/management/commands/create_error_templates.py
==============================================================================
--- (empty file)
+++ trunk/dbtemplates/management/commands/create_error_templates.py     Fri Nov 
 
28 05:06:34 2008
@@ -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

Modified: trunk/dbtemplates/management/commands/sync_templates.py
==============================================================================
--- trunk/dbtemplates/management/commands/sync_templates.py     (original)
+++ trunk/dbtemplates/management/commands/sync_templates.py     Fri Nov 28  
05:06:34 2008
@@ -1,5 +1,4 @@
  import os
-import re
  from optparse import make_option

  from django.conf import settings
@@ -28,9 +27,6 @@
          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")


Modified: trunk/docs/overview.txt
==============================================================================
--- trunk/docs/overview.txt     (original)
+++ trunk/docs/overview.txt     Fri Nov 28 05:06:34 2008
@@ -18,7 +18,7 @@
  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 @@
  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 @@

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

Modified: trunk/setup.py
==============================================================================
--- trunk/setup.py      (original)
+++ trunk/setup.py      Fri Nov 28 05:06:34 2008
@@ -7,8 +7,8 @@
      long_description=open('docs/overview.txt').read(),
      author='Jannis Leidel',
      author_email='[EMAIL PROTECTED]',
-    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',

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to