initial code for www.sommitrealweird.co.uk
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Wed, 30 Jan 2008 12:44:18 +0000 (12:44 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Wed, 30 Jan 2008 12:44:18 +0000 (12:44 +0000)
19 files changed:
.gitignore [new file with mode: 0644]
media/img/background.png [new file with mode: 0644]
media/img/menu-back.png [new file with mode: 0644]
media/style/main.css [new file with mode: 0644]
sommitrealweird/__init__.py [new file with mode: 0644]
sommitrealweird/content/__init__.py [new file with mode: 0644]
sommitrealweird/content/content_val.py [new file with mode: 0644]
sommitrealweird/content/models.py [new file with mode: 0644]
sommitrealweird/content/templates/html.html [new file with mode: 0644]
sommitrealweird/content/templates/rst.html [new file with mode: 0644]
sommitrealweird/content/views.py [new file with mode: 0644]
sommitrealweird/generic/__init__.py [new file with mode: 0644]
sommitrealweird/generic/views.py [new file with mode: 0644]
sommitrealweird/manage.py [new file with mode: 0755]
sommitrealweird/settings.py [new file with mode: 0644]
sommitrealweird/urls.py [new file with mode: 0644]
templates/404.html [new file with mode: 0644]
templates/500.html [new file with mode: 0644]
templates/base.html [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..686a99c
--- /dev/null
@@ -0,0 +1,2 @@
+*.py[oc]
+/sommitrealweird.db
diff --git a/media/img/background.png b/media/img/background.png
new file mode 100644 (file)
index 0000000..73ac3f8
Binary files /dev/null and b/media/img/background.png differ
diff --git a/media/img/menu-back.png b/media/img/menu-back.png
new file mode 100644 (file)
index 0000000..d4e5ff1
Binary files /dev/null and b/media/img/menu-back.png differ
diff --git a/media/style/main.css b/media/style/main.css
new file mode 100644 (file)
index 0000000..515979f
--- /dev/null
@@ -0,0 +1,88 @@
+body {
+    font-family: freesans, georgia, arial, helvetica, sans-serif;
+    background: white;
+    color: black;
+}
+
+body #page {
+    background: url(../img/background.png) white no-repeat;
+    width: 90%;
+    text-align: center;
+    margin-left: auto;
+    margin-right: auto;
+    font-size: 100%;
+    border: thin solid #000000;
+}
+
+body #page #headerbar {
+    position: relative;
+    width: 100%;
+    margin: 0;
+    padding: 0;
+    min-height: 160px;
+}
+
+body #page #headerbar #websitetitle {
+    color: #721263;
+    text-align: right;
+    padding-top: 0.3em;
+    padding-bottom: 0.3em;
+    padding-right: 0.3em;
+    font-weight: bold;
+}
+
+body #page #headerbar #websitetitle h1 {
+    font-size: 250%;
+}
+
+body #page #headerbar #menu {
+    font-size: 90%;
+    margin-top: 1em;
+    margin-right: 0;
+    text-align: right;
+    width: 100%;
+    border-top: thin solid #bababa;
+    border-bottom: thin solid #bababa;
+    background: url(../img/menu-back.png);
+    padding-top: 0.3em;
+    padding-bottom: 0.3em;
+    bottom: 0;
+    position: absolute;
+}
+
+body #page #headerbar #menu ul {
+    display: inline;
+}
+
+body #page #headerbar #menu ul li {
+    display: inline;
+    padding-left: 1em;
+    padding-right: 1em;
+    margin: 0;
+    color: #9a9a9a;
+    font-weight: bold;
+}
+
+body #page #headerbar #menu ul li:hover {
+    color: #ffffff;
+}
+
+body #page #content {
+    font-family: arial, helvetica, sans-serif;
+    text-align: left;
+    margin-left: 0.8em;
+    margin-right: 0.3em;
+}
+
+body #page #content h1 {
+    margin-left: -0.3em;
+}
+
+body #page #footer {
+    width: 100%;
+    font-size: 70%;
+    text-align: center;
+    margin: 0;
+    padding: 0.1em;
+}
+
diff --git a/sommitrealweird/__init__.py b/sommitrealweird/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sommitrealweird/content/__init__.py b/sommitrealweird/content/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sommitrealweird/content/content_val.py b/sommitrealweird/content/content_val.py
new file mode 100644 (file)
index 0000000..a7ba582
--- /dev/null
@@ -0,0 +1,17 @@
+from django.core import validators
+
+def is_unique_name(slug, all_data):
+    from content.models import Document, Folder
+    if all_data["folder"] != '' and all_data["id"] == '':
+        folder_id = int(all_data["folder"])
+        try:
+            doc = Document.object.get(folder__exact=folder_id, slug__exact=slug)
+            raise validators.ValidationError(u'There is already a document with that name')
+        except:
+            pass
+
+        try:
+            folder = Folder.object.get(slug__exact=slug, parent__exact=folder_id)
+            raise validators.ValidationError(u'There is already a folder with that name')
+        except:
+            pass
diff --git a/sommitrealweird/content/models.py b/sommitrealweird/content/models.py
new file mode 100644 (file)
index 0000000..6487830
--- /dev/null
@@ -0,0 +1,50 @@
+from django.db import models
+from content.content_val import is_unique_name
+
+FORMAT_CHOICES = (
+        ('rst', 'reStructuredText'),
+        ('html', 'HTML'),
+    )
+
+class Document(models.Model):
+    title = models.CharField(maxlength=150)
+    islive = models.BooleanField()
+    folder = models.ForeignKey('Folder', null=True, blank=True)
+    format = models.CharField(maxlength=10, choices=FORMAT_CHOICES)
+    slug = models.SlugField(prepopulate_from=("title",), validator_list=[is_unique_name,])
+    content = models.TextField()
+
+    def __str__(self):
+        return self.__unicode__()
+
+    def __unicode__(self):
+        return u'%s (%s)' %(self.title, self.slug)
+
+    def save(self):
+        super(Document, self).save()
+        # now check if we just set our selves to be live
+        if self.islive:
+            if self.folder:
+                otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__exact=self.folder).exclude(pk=self.id)
+            else:
+                otherdocs = Document.objects.filter(slug__exact=self.slug, islive__exact=True, folder__isnull=True).exclude(pk=self.id)
+            for doc in otherdocs:
+                doc.islive = False
+                doc.save()
+
+    class Admin:
+        pass
+
+class Folder(models.Model):
+    title = models.CharField(maxlength=150)
+    slug = models.SlugField(prepopulate_from=("title",))
+    parent = models.ForeignKey('self', null=True, blank=True)
+
+    def __str__(self):
+        return self.__unicode__()
+
+    def __unicode__(self):
+        return u'%s' %(self.title)
+
+    class Admin:
+        pass
diff --git a/sommitrealweird/content/templates/html.html b/sommitrealweird/content/templates/html.html
new file mode 100644 (file)
index 0000000..9388e68
--- /dev/null
@@ -0,0 +1,7 @@
+{% extends "base.html" %}
+{% load markup %}
+
+{% block content %}
+<h1> {{ title }}</h1>
+{{ content }}
+{% endblock %}
diff --git a/sommitrealweird/content/templates/rst.html b/sommitrealweird/content/templates/rst.html
new file mode 100644 (file)
index 0000000..defd079
--- /dev/null
@@ -0,0 +1,7 @@
+{% extends "base.html" %}
+{% load markup %}
+
+{% block content %}
+<h1> {{ title }}</h1>
+{{ content|restructuredtext }}
+{% endblock %}
diff --git a/sommitrealweird/content/views.py b/sommitrealweird/content/views.py
new file mode 100644 (file)
index 0000000..e4b49da
--- /dev/null
@@ -0,0 +1,55 @@
+from content.models import Document, Folder
+from django.http import Http404, HttpResponse
+from django.template import RequestContext, loader
+from settings import MEDIA_URL
+
+def document_view(request, slug=None, folders=None):
+    if folders == None and slug == None:
+        raise Http404()
+
+    folder = None
+
+    if folders != None:
+        folders = folders.split('/')
+        resfolder = None
+        for folder in folders:
+            try:
+                if resfolder:
+                    resfolder = Folder.objects.get(slug__exact=folder, parent__exact=resfolder)
+                else:
+                    resfolder = Folder.objects.get(slug__exact=folder, parent__isnull=True)
+                resfolder = resfolder.id
+            except:
+                raise Http404
+        try:
+            folder = Folder.objects.get(pk=resfolder)
+        except:
+            raise Http404
+
+    if folder != None:
+        try:
+            doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__exact=folder)
+        except:
+            try:
+                folder = Folder.objects.get(slug__exact=slug, parent__exact=folder)
+                doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
+            except:
+                raise Http404
+    else:
+        try:
+            doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__isnull=True)
+        except:
+            try:
+                folder = Folder.objects.get(slug__exact=slug, parent__isnull=True)
+                doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
+            except:
+                raise Http404
+    template_name = "%s.html" %(doc.format,)
+    t = loader.get_template(template_name)
+    c = RequestContext(request,
+        {
+            "content"   : doc.content,
+            "title"     : doc.title,
+            "media_url" : MEDIA_URL,
+        })
+    return HttpResponse(t.render(c))
diff --git a/sommitrealweird/generic/__init__.py b/sommitrealweird/generic/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sommitrealweird/generic/views.py b/sommitrealweird/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/sommitrealweird/manage.py b/sommitrealweird/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/sommitrealweird/settings.py b/sommitrealweird/settings.py
new file mode 100644 (file)
index 0000000..280a04e
--- /dev/null
@@ -0,0 +1,86 @@
+# Django settings for sommitrealweird project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+    ('Brett Parker', 'iDunno@sommitrealweird.co.uk'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
+DATABASE_NAME = '/home/brettp/dev/sommitrealweird/sommitrealweird.db'             # Or path to database file if using sqlite3.
+DATABASE_USER = ''             # Not used with sqlite3.
+DATABASE_PASSWORD = ''         # Not used with sqlite3.
+DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+
+# Local time zone for this installation. Choices can be found here:
+# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
+# although not all variations may be possible on all operating systems.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'Europe/London'
+
+# Language code for this installation. All choices can be found here:
+# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
+# http://blogs.law.harvard.edu/tech/stories/storyReader$15
+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
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = '/home/brettp/dev/sommitrealweird/media/'
+
+# URL that handles the media served from MEDIA_ROOT.
+# Example: "http://media.lawrence.com"
+MEDIA_URL = '/media/'
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/admin-media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '$!roq-b5snvjxi4dr2y7(l(@$@k+2%aub&)s__0)k#r&c(8(4x'
+
+# 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',
+#     'django.template.loaders.eggs.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.middleware.doc.XViewMiddleware',
+)
+
+ROOT_URLCONF = 'urls'
+
+TEMPLATE_DIRS = (
+    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+    "/home/brettp/dev/sommitrealweird/templates",
+)
+
+INSTALLED_APPS = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'django.contrib.admin',
+    'django.contrib.markup',
+    'content',
+    'generic',
+)
diff --git a/sommitrealweird/urls.py b/sommitrealweird/urls.py
new file mode 100644 (file)
index 0000000..75c6a63
--- /dev/null
@@ -0,0 +1,17 @@
+from django.conf.urls.defaults import *
+from settings import MEDIA_ROOT, MEDIA_URL
+
+handler404 = 'generic.views.render_404'
+
+urlpatterns = patterns('',
+    # Example:
+    # (r'^sommitrealweird/', include('sommitrealweird.foo.urls')),
+
+    # Uncomment this for admin:
+    (r'^$', 'content.views.document_view', {'slug': 'index'}),
+    (r'^admin/', include('django.contrib.admin.urls')),
+    (r'^content/(?P<slug>[^/]+)/$', 'content.views.document_view'),
+    (r'^content/(?P<folders>.*)/(?P<slug>[^/]+)/$', 'content.views.document_view'),
+    (r'^content/$', 'content.views.document_view', {'slug': 'index'}),
+    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT, 'show_indexes': True}),
+)
diff --git a/templates/404.html b/templates/404.html
new file mode 100644 (file)
index 0000000..327f8b9
--- /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/500.html b/templates/500.html
new file mode 100644 (file)
index 0000000..3e62319
--- /dev/null
@@ -0,0 +1,11 @@
+{% extends "base.html" %}
+
+{% block title %}Not Found{% endblock %}
+{% block cmsnavigation %}
+       <ul>
+               <li><a href="/cms/">Home</a></li>
+       </ul>
+{% 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..b471f8d
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+    <head>
+        <title>{% block title %}{{ title }}{% endblock %}</title>
+        <link rel="stylesheet" type="text/css" href="{{ media_url }}style/main.css" />
+    </head>
+    <body>
+        <div id="page">
+            <div id="headerbar">
+                <div id="websitetitle">
+                    <h1>SommitRealWeird</h1>
+                </div>
+                <div id="menu">
+                    {% block meny %}
+                    <ul>
+                        <li>Home</li>
+                        <li>Development</li>
+                        <li>Links</li>
+                        <li>People</li>
+                        <li>CSS Examples</li>
+                        <li>Photos</li>
+                        <li>Blog</li>
+                    </ul>
+                    {% endblock %}
+                </div>
+            </div>
+            <div id="content">
+                {% block content %}
+                {{ content }}
+                {% endblock %}
+            </div>
+            <div id="footer">
+                <p>Copyright &copy; 2008 - <a href="mailto:iDunno@sommitrealweird.co.uk">Brett Parker</a></p>
+            </div>
+        </div>
+    </body>
+</html>