Commits

Ilkka Hakkari  committed 3ccdde3

Changed some directory locations. Added apptemplates template loader. Process management with supervisord.

  • Participants
  • Parent commits 6eefce1

Comments (0)

Files changed (13)

File buildout.cfg

 [buildout]
 extensions = buildout-versions
 parts = django
-develop = 
+develop =
   src/foo
-eggs = 
+  src/apptemplates
+eggs =
   django-foo
+  django-apptemplates
   django-debug-toolbar
   coverage
   django-nose
 newest = false
 
 [versions]
-django = 1.3.1
+django = 1.4
 
 [django]
 recipe = djangorecipe

File production.cfg

 [buildout]
 extensions = buildout-versions
 parts = python
-develop = 
+develop =
   src/foo
-eggs = 
+  src/apptemplates
+eggs =
   django-foo
+  django-apptemplates
+  django
   gunicorn
-#  django-sentry
+  django-supervisor
+  psycopg2
+  raven
 #  South
 
 versions = versions
 newest = false
 
 [versions]
-django = 1.3.1
+django = 1.4
+psycopg2 = 2.0.13
+raven = 1.5.0
 
 [python]
 recipe = zc.recipe.egg

File project/assets/media/.keep

Empty file removed.

File project/assets/static/.keep

Empty file removed.

File project/assets/templates/.keep

Empty file removed.

File project/media/.keep

Empty file added.

File project/settings.py

 # ID 1 is reserved for development/testing site
 SITE_ID = 1
 
-DATABASES = { 
+DATABASES = {
   'default': {
     'ENGINE': 'django.db.backends.sqlite3',
     'NAME': os.path.join(BASEDIR, 'database.db'),
   }
 }
 
-TIME_ZONE = 'America/Chicago'
+TIME_ZONE = 'Europe/Helsinki'
 
-LANGUAGE_CODE = 'en-us'
+LANGUAGE_CODE = 'fi-fi'
 
 STATICFILES_DIRS = (
-  os.path.join(BASEDIR, 'assets', 'static'),
+  os.path.join(BASEDIR, 'static'),
   )
 
 STATIC_ROOT = os.path.join(BASEDIR, 'staticroot')
 STATIC_URL = '/static/'
-  
+
 # Absolute path to the directory that holds media.
 # Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = os.path.join(BASEDIR, 'assets', 'media')
+MEDIA_ROOT = os.path.join(BASEDIR, 'media')
 
 # 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).
 ADMIN_MEDIA_PREFIX = '/static/admin/'
 
 # Don't share this with anybody.
-SECRET_KEY = 'we*b7u7vr5*y7z4vt$j@fb4c@6bt2x4)uy*1%0ya_dj-2-^_%d'
+SECRET_KEY = ''
 
 MIDDLEWARE_CLASSES = (
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.doc.XViewMiddleware',
 )
 
 ROOT_URLCONF = 'project.urls'
 
 TEMPLATE_LOADERS = (
+    'apptemplates.Loader'
     'django.template.loaders.filesystem.Loader',
     'django.template.loaders.app_directories.Loader',
+    'django.template.loaders.eggs.Loader',
 )
 
 TEMPLATE_DIRS = (
 )
 
 INSTALLED_APPS = (
+    'foo',
+
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.staticfiles',
     'django.contrib.messages',
     'django.contrib.admin',
-
-    'foo',
 )
 

File project/static/.keep

Empty file added.

File project/templates/.keep

Empty file added.

File scripts/backup.sh.in

-#!/bin/sh
-
-d="${buildout:directory}"
-b="${backup:directory}"
-bf="${backup:directory}/${backup:filename}"
-c=`pwd`
-s="${backup:settings}"
-
-cd $d
-bin/django dumpdata --settings=$s --indent 2 > $bf
-cd $b
-hg addremove
-hg ci -m "cron"
-cd $c
-

File src/apptemplates/apptemplates.py

+"""
+Django template loader that allows you to load a template from a
+specific application. This allows you to both extend and override
+a template at the same time. The default Django loaders require you
+to copy the entire template you want to override, even if you only
+want to override one small block.
+
+Template usage example::
+
+    {% extends "admin:admin/base.html" %}
+
+Settings::
+
+    TEMPLATE_LOADERS = (
+        'django.template.loaders.filesystem.Loader',
+        'django.template.loaders.app_directories.Loader',
+        'apptemplates.Loader',
+    )
+
+Based on: http://djangosnippets.org/snippets/1376/
+"""
+
+from os.path import dirname, join, abspath
+
+from django.conf import settings
+from django.utils.importlib import import_module
+from django.template.loaders.filesystem import Loader as FilesystemLoader
+
+_cache = {}
+
+def get_app_template_dir(app_name):
+    """Get the template directory for an application
+
+    We do not use django.db.models.get_app, because this will fail if an
+    app does not have any models.
+
+    Returns a full path, or None if the app was not found.
+    """
+    if app_name in _cache:
+        return _cache[app_name]
+    template_dir = None
+    for app in settings.INSTALLED_APPS:
+        if app.split('.')[-1] == app_name:
+            # Do not hide import errors; these should never happen at this point
+            # anyway
+            mod = import_module(app)
+            template_dir = join(abspath(dirname(mod.__file__)), 'templates')
+            break
+    _cache[app_name] = template_dir
+    return template_dir
+
+
+class Loader(FilesystemLoader):
+    is_usable = True
+
+    def get_template_sources(self, template_name, template_dirs=None):
+        """
+        Returns the absolute paths to "template_name" in the specified app.
+        If the name does not contain an app name (no colon), an empty list
+        is returned.
+        The parent FilesystemLoader.load_template_source() will take care
+        of the actual loading for us.
+        """
+        if not ':' in template_name:
+            return []
+        app_name, template_name = template_name.split(":", 1)
+        template_dir = get_app_template_dir(app_name)
+        if template_dir:
+            return [join(template_dir, template_name)]
+        else:
+            return []
+

File src/apptemplates/setup.py

+
+from setuptools import setup, find_packages
+
+setup(
+    name = "django-apptemplates",
+    version = "1.0",
+    url = 'http://example.com/django-foo',
+    license = 'HALTU',
+    description = "apptemplates",
+    author = 'Ilkka Hakkari <ilkka@haltu.fi>',
+    packages = find_packages(),
+    install_requires = [
+      ],
+)
+

File supervisord.conf

+[program:django]
+{% if settings.DEBUG %}
+command={{ PYTHON }} {{ PROJECT_DIR }}/bin/django runserver --settings={{ environ.DJANGO_SETTINGS_MODULE }} 127.0.0.1:{{ PORT }}
+{% else %}
+command={{ PYTHON }} {{ PROJECT_DIR }}/bin/gunicorn_django -n time -b 127.0.0.1:{{ PORT }} {{ environ.DJANGO_SETTINGS_MODULE }}
+{% endif %}
+numprocs=1
+autorestart=unexpected
+directory={{ PROJECT_DIR }}
+redirect_stderr=false
+stdout_logfile=/var/log/supervisor/time/time.out
+stdout_logfile_maxbytes=25MB
+stdout_logfile_backups=10
+stderr_logfile=/var/log/supervisor/time/time.err
+stderr_logfile_maxbytes=25MB
+stderr_logfile_backups=10
+