Initial import of eatslugs code...
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Wed, 2 Sep 2009 12:39:26 +0000 (13:39 +0100)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Wed, 2 Sep 2009 12:39:26 +0000 (13:39 +0100)
23 files changed:
.gitignore [new file with mode: 0644]
eatslugs/__init__.py [new file with mode: 0644]
eatslugs/generic/__init__.py [new file with mode: 0644]
eatslugs/generic/context_processors.py [new file with mode: 0644]
eatslugs/generic/docutils_xhtml11.py [new file with mode: 0644]
eatslugs/generic/helpers.py [new file with mode: 0644]
eatslugs/generic/templatetags/__init__.py [new file with mode: 0644]
eatslugs/generic/templatetags/thumbnail.py [new file with mode: 0644]
eatslugs/generic/templatetags/xhtml11rst.py [new file with mode: 0644]
eatslugs/generic/views.py [new file with mode: 0644]
eatslugs/manage.py [new file with mode: 0755]
eatslugs/recipes/__init__.py [new file with mode: 0644]
eatslugs/recipes/admin.py [new file with mode: 0644]
eatslugs/recipes/models.py [new file with mode: 0644]
eatslugs/recipes/views.py [new file with mode: 0644]
eatslugs/settings.py [new file with mode: 0644]
eatslugs/urls.py [new file with mode: 0644]
media/img/sandwich.png [new file with mode: 0644]
media/img/slug.png [new file with mode: 0644]
media/style/main.css [new file with mode: 0644]
templates/404.html [new file with mode: 0644]
templates/base.html [new file with mode: 0644]
templates/main_index.html [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..8c4ffb7
--- /dev/null
@@ -0,0 +1,3 @@
+eatslugs.db
+*.pyc
+*.pyo
diff --git a/eatslugs/__init__.py b/eatslugs/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/eatslugs/generic/__init__.py b/eatslugs/generic/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/eatslugs/generic/context_processors.py b/eatslugs/generic/context_processors.py
new file mode 100644 (file)
index 0000000..d7ab9e0
--- /dev/null
@@ -0,0 +1,6 @@
+from django.conf import settings
+
+def media(request):
+    return {
+        'MEDIA_URL': settings.MEDIA_URL,
+    }
diff --git a/eatslugs/generic/docutils_xhtml11.py b/eatslugs/generic/docutils_xhtml11.py
new file mode 100644 (file)
index 0000000..4b7d9b9
--- /dev/null
@@ -0,0 +1,32 @@
+# Author: Brett Parker <iDunno@sommitrealweird.co.uk>
+
+"""
+HTML1.1 Writer.
+"""
+
+__docformat__ = 'reStructuredText'
+
+import sys
+import os
+import os.path
+import codecs
+import docutils
+from docutils import frontend, nodes, utils, writers
+from docutils.writers import html4css1
+
+class Writer(html4css1.Writer):
+
+    config_section = 'xhtml11 writer'
+    config_section_dependencies = ('writers', 'html4css1 writer')
+
+    def __init__(self):
+        html4css1.Writer.__init__(self)
+        self.translator_class = HTMLTranslator
+
+class HTMLTranslator(html4css1.HTMLTranslator):
+
+    def is_compactable(self, node):
+        return False
+
+    def should_be_compact_paragraph(self, node):
+        return False
diff --git a/eatslugs/generic/helpers.py b/eatslugs/generic/helpers.py
new file mode 100644 (file)
index 0000000..6c85aa1
--- /dev/null
@@ -0,0 +1,100 @@
+from django.conf import settings
+from PIL import Image
+import os, sys
+
+def make_thumbnail(imagefile,width=None,height=None):
+    # first check that the thumbnail image doesn't already exist
+    # and if it does that it's newer than the origional image
+    
+    base_dir = settings.MEDIA_ROOT
+    thumbs_dir = base_dir
+    if not thumbs_dir.endswith("/"):
+        thumbs_dir = "%s/" %(thumbs_dir,)
+        base_dir = "%s/" %(base_dir,)
+    
+    try:
+        thumbs_dir = "%s%s/" %(thumbs_dir, settings.THUMBS_DIRECTORY)
+        thumbsdirectory = settings.THUMBS_DIRECTORY
+    except:
+        thumbs_dir = "%sthumbs/" %(thumbs_dir,)
+        thumbsdirectory = "thumbs"
+
+    if width != None:
+        try:
+            thumb = os.stat("%sw%d/%s" % (thumbs_dir, width, imagefile))
+            pic = os.stat("%s%s" % (base_dir, imagefile))
+            if thumb.st_ctime < pic.st_ctime:
+                # regenerate the icon
+                img = Image.open("%s%s" %(base_dir, imagefile))
+                (curwidth,curheight) = img.size
+
+                newwidth = width
+                newheight = int((newwidth * curheight) / curwidth)
+
+                newimg = img.resize((newwidth, newheight))
+                newimg.save("%sw%d/%s" %(thumbs_dir, width, imagefile))
+                
+                return "%s%s/w%d/%s" %(settings.MEDIA_URL, thumbsdirectory, width, imagefile)
+            else:
+                # we have a winner!
+                return "%s%s/w%d/%s" %(settings.MEDIA_URL, thumbsdirectory, width, imagefile)
+        except:
+            # well, there's not one there. feh. sucks.
+            try:
+                directory_to_create = imagefile[:imagefile.rindex(os.sep)]
+                img = Image.open("%s%s" %(base_dir, imagefile))
+                if not os.path.isdir("%sw%d/%s" %(thumbs_dir, width, directory_to_create)):
+                    os.makedirs("%sw%d/%s" %(thumbs_dir, width, directory_to_create))
+                (curwidth,curheight) = img.size
+
+                newwidth = width
+                newheight = int((newwidth * curheight) / curwidth)
+
+                newimg = img.resize((newwidth, newheight))
+                newimg.save("%sw%d/%s" %(thumbs_dir, width, imagefile))
+                
+                return "%s%s/w%d/%s" %(settings.MEDIA_URL, thumbsdirectory, width, imagefile)
+            except Exception, e:
+                sys.stderr.write("Got exception: %s" %(e,))
+
+    elif height != None:
+        try:
+            thumb = os.stat("%sh%d/%s" % (thumbs_dir, height, imagefile))
+            pic = os.stat("%s%s" % (base_dir, imagefile))
+            if thumb.st_ctime < pic.st_ctime:
+                # regenerate the icon
+                img = Image.open("%s%s" %(base_dir, imagefile))
+                (curwidth,curheight) = img.size
+
+                newheight = height
+                newheight = int((newheight * curwidth) / curheight)
+
+                newimg = img.resize((newwidth, newheight))
+                newimg.save("%sh%d/%s" %(thumbs_dir, height, imagefile))
+                
+                return "%s%s/h%d/%s" %(settings.MEDIA_URL, thumbsdirectory, height, imagefile)
+            else:
+                # we have a winner!
+                return "%s%s/h%d/%s" %(settings.MEDIA_URL, thumbsdirectory, height, imagefile)
+        except:
+            # well, there's not one there. feh. sucks.
+            try:
+                directory_to_create = imagefile[:imagefile.rindex(os.sep)]
+                img = Image.open("%s%s" %(base_dir, imagefile))
+                os.makedirs("%sh%h/%s" %(thumbs_dir, height, directory_to_create))
+                (curwidth,curheight) = img.size
+
+                newheight = height
+                newwidth = int((newheight * curwidth) / curheight)
+
+                newimg = img.resize((newwidth, newheight))
+                newimg.save("%sh%d/%s" %(thumbs_dir, height, imagefile))
+                
+                return "%s%s/h%d/%s" %(settings.MEDIA_URL, thumbsdirectory, height, imagefile)
+            except:
+                pass
+
+    # if everything fails, we'll return the origional image URL
+    # this is for simpilicity
+    return "%s%s" %(settings.MEDIA_URL, imagefile)
+
diff --git a/eatslugs/generic/templatetags/__init__.py b/eatslugs/generic/templatetags/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/eatslugs/generic/templatetags/thumbnail.py b/eatslugs/generic/templatetags/thumbnail.py
new file mode 100644 (file)
index 0000000..4e20cef
--- /dev/null
@@ -0,0 +1,37 @@
+from django import template
+from django.conf import settings
+from generic import helpers
+import sys
+
+register = template.Library()
+
+def thumbnail(image_url, args=''):
+    options = {}
+
+    if ',' not in args:
+        args = "%s," %(args,)
+
+    for arg in args.split(','):
+        arg = arg.strip()
+        try:
+            (kw,val) = arg.split('=', 1)
+            try:
+                options[kw] = int(val)
+            except:
+                pass
+        except:
+            pass
+
+    if options.has_key("height") or options.has_key("width"):
+        if options.has_key("width") and options.has_key("height"):
+            return helpers.make_thumbnail(image_url[len(settings.MEDIA_URL):], width=options["width"], height=options["height"])
+        elif options.has_key("width"):
+            return helpers.make_thumbnail(image_url[len(settings.MEDIA_URL):], width=options["width"])
+        else:
+            return helpers.make_thumbnail(image_url[len(settings.MEDIA_URL):], height=options["height"])
+    else:
+        pass
+
+    return "%s" %(image_url)
+
+register.filter(thumbnail)
diff --git a/eatslugs/generic/templatetags/xhtml11rst.py b/eatslugs/generic/templatetags/xhtml11rst.py
new file mode 100644 (file)
index 0000000..3bc212a
--- /dev/null
@@ -0,0 +1,22 @@
+from django import template
+from django.conf import settings
+from django.utils.encoding import smart_str, force_unicode
+from django.utils.safestring import mark_safe
+from generic import docutils_xhtml11
+
+register = template.Library()
+
+def restructuredtext(value):
+    try:
+        from docutils.core import publish_parts
+    except ImportError:
+        if settings.DEBUG:
+            raise template.TemplateSyntaxError, "Error in {% restructuredtext %} filter: The Python docutils library isn't installed."
+        return force_unicode(value)
+    else:
+        docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})
+        parts = publish_parts(source=smart_str(value), writer=docutils_xhtml11.Writer(), settings_overrides=docutils_settings)
+        return mark_safe(force_unicode(parts["fragment"]))
+restructuredtext.is_safe = True
+
+register.filter(restructuredtext)
diff --git a/eatslugs/generic/views.py b/eatslugs/generic/views.py
new file mode 100644 (file)
index 0000000..63d9ea1
--- /dev/null
@@ -0,0 +1,14 @@
+from settings import MEDIA_URL
+from django.http import HttpResponseNotFound
+from django.template import RequestContext, loader 
+
+
+def render_404(request, template_name='404.html'):
+    t = loader.get_template(template_name)
+    return HttpResponseNotFound( \
+        t.render(RequestContext(request,
+            {
+                'request_path': request.path,
+                'media_url'   : MEDIA_URL,
+            }
+        )))
diff --git a/eatslugs/manage.py b/eatslugs/manage.py
new file mode 100755 (executable)
index 0000000..bcdd55e
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)
diff --git a/eatslugs/recipes/__init__.py b/eatslugs/recipes/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/eatslugs/recipes/admin.py b/eatslugs/recipes/admin.py
new file mode 100644 (file)
index 0000000..7cecf88
--- /dev/null
@@ -0,0 +1,7 @@
+from django.contrib import admin
+from models import Drink, Recipe, Combination
+
+admin.site.register(Drink)
+admin.site.register(Recipe)
+admin.site.register(Combination)
+
diff --git a/eatslugs/recipes/models.py b/eatslugs/recipes/models.py
new file mode 100644 (file)
index 0000000..dda8c98
--- /dev/null
@@ -0,0 +1,16 @@
+from django.db import models
+
+# Create your models here.
+
+class Recipe(models.Model):
+    name = models.CharField(max_length=250)
+    ingrediants = models.TextField()
+    description = models.TextField()
+
+class Drink(models.Model):
+    name = models.CharField(max_length=250)
+    description = models.TextField()
+
+class Combination(models.Model):
+    recipe = models.ForeignKey('Recipe')
+    drink = models.ForeignKey('Drink')
diff --git a/eatslugs/recipes/views.py b/eatslugs/recipes/views.py
new file mode 100644 (file)
index 0000000..60f00ef
--- /dev/null
@@ -0,0 +1 @@
+# Create your views here.
diff --git a/eatslugs/settings.py b/eatslugs/settings.py
new file mode 100644 (file)
index 0000000..27227aa
--- /dev/null
@@ -0,0 +1,83 @@
+# Django settings for eatslugs project.
+
+# Rather than editing settings here, add them to the localsettings.py file
+# which will be included at the end of the run and replace anything in here.
+
+import os
+topdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    ('Brett Parker', 'iDunno@sommitrealweird.co.uk'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'sqlite3'
+DATABASE_NAME = os.path.join(topdir, 'eatslugs.db')
+DATABASE_USER = ''
+DATABASE_PASSWORD = ''
+DATABASE_HOST = ''
+DATABASE_PORT = ''
+
+TIME_ZONE = 'Europe/London'
+
+LANGUAGE_CODE = 'en-gb'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+MEDIA_ROOT = os.path.join(topdir, 'media') + os.sep
+MEDIA_URL = '/media/'
+
+ADMIN_MEDIA_PREFIX = '/admin-media/'
+
+import random
+import string
+key_chars = "%s%s%s" %(string.letters, string.digits, '+-()_#~')
+SECRET_KEY = "".join([random.choice(key_chars) for a in range(0,50)])
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.load_template_source',
+    'django.template.loaders.app_directories.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+)
+
+ROOT_URLCONF = 'urls'
+
+TEMPLATE_DIRS = (
+    os.path.join(topdir, 'templates')
+)
+
+INSTALLED_APPS = (
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'recipes',
+)
+
+TEMPLATE_CONTEXT_PROCESSORS = (
+    'django.core.context_processors.auth',
+    'django.core.context_processors.debug',
+    'django.core.context_processors.i18n',
+    'generic.context_processors.media',
+)
+
+try:
+    from localsettings import *
+except:
+    pass
+
diff --git a/eatslugs/urls.py b/eatslugs/urls.py
new file mode 100644 (file)
index 0000000..8597968
--- /dev/null
@@ -0,0 +1,16 @@
+from django.conf.urls.defaults import *
+from django.views.generic.simple import direct_to_template
+from django.views.static import serve
+from django.conf import settings
+
+# Uncomment the next two lines to enable the admin:
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    # Example:
+    # (r'^recipes/', include('recipes.urls')),
+    (r'^$', direct_to_template, {"template": 'main_index.html'},),
+    (r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT, 'show_indexes': False}),
+    (r'^admin/(.*)', admin.site.root),
+)
diff --git a/media/img/sandwich.png b/media/img/sandwich.png
new file mode 100644 (file)
index 0000000..104498c
Binary files /dev/null and b/media/img/sandwich.png differ
diff --git a/media/img/slug.png b/media/img/slug.png
new file mode 100644 (file)
index 0000000..8b35464
Binary files /dev/null and b/media/img/slug.png differ
diff --git a/media/style/main.css b/media/style/main.css
new file mode 100644 (file)
index 0000000..23e7920
--- /dev/null
@@ -0,0 +1,31 @@
+body {
+    background: white;
+    color: black;
+    font-family: arial, helvetica, sans-serif;
+}
+
+#page {
+    position: relative;
+    width: 98%;
+}
+
+#websitetitle img.logoleft {
+    float: left;
+}
+
+#websitetitle img.logoright {
+    float: right;
+}
+
+#websitetitle p.title {
+    font-size: 240%;
+    vertical-align: middle;
+    text-align: center;
+    padding-left: 1em;
+    padding-right: 1em;
+}
+
+#content {
+    clear: both;
+    width: 100%;
+}
diff --git a/templates/404.html b/templates/404.html
new file mode 100644 (file)
index 0000000..ab274be
--- /dev/null
@@ -0,0 +1,6 @@
+{% extends "base.html" %}
+
+{% block title %}Not Found{% endblock %}
+{% block content %}
+    <p>Sorry, couldn't find what you were looking for. Oops.</p>
+{% endblock %}
diff --git a/templates/base.html b/templates/base.html
new file mode 100644 (file)
index 0000000..7afbb33
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+    <head>
+        <title>{% block title %}{% if title %}{{ title }}{% else %}EATSLUGS{% endif %}{% endblock %}</title>
+        <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}style/main.css" />
+        {% block extrahead %}{% endblock %}
+    </head>
+    <body>
+        <div id="page">
+            <div id="websitetitle">
+                <img src="{{ MEDIA_URL }}img/sandwich.png" alt="A Yummy Sandwich" class="logoleft" /><img src="{{ MEDIA_URL }}img/slug.png" alt="A Slug... no, really." class="logoright" /><p class="title">East Anglian Sandwich, Toasty and Luncheon Users Group Symposium</p>
+            </div>
+            <div id="content">
+                {% block content %}
+                {% endblock %}
+            </div>
+        </div>
+    </body>
+</html>
diff --git a/templates/main_index.html b/templates/main_index.html
new file mode 100644 (file)
index 0000000..6d92f33
--- /dev/null
@@ -0,0 +1,8 @@
+{% extends "base.html" %}
+
+{% block content %}
+    <h1>Welcome to the EATSLUGS website</h1>
+    <p>
+        This will be a collection of random sandwich and drink combinations come up with by our resident experts (or just generally by us lot being insane...) - we hope you will like them.
+    </p>
+{% endblock %}