Commits

Mathieu Agopian  committed 35c1a1e

(scratch) Project created

  • Participants

Comments (0)

Files changed (22)

+syntax: glob
+scratch.db      # sqlite database
+creds.py        # credentials that must be kept secret!
+To use, simply:
+
+1. clone
+2. pip install -r pip_requirements (django trunk and sphinx for doc contributions)
+3. enjoy
+
+The scratch.db is the sqlite db is an "empty" database with an admin created (admin:admin).

File __init__.py

Empty file added.
+#!/usr/bin/env python
+from django.core.management import execute_manager
+import imp
+try:
+    imp.find_module('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" % __file__)
+    sys.exit(1)
+
+import settings
+
+if __name__ == "__main__":
+    execute_manager(settings)

File mysql_settings.py

+"""Mysql settings
+
+Create a symbolic link to settings.py to use.
+
+"""
+
+from sqlite_settings import *
+from creds import MY_CREDS
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': 'scratch',
+        'USER': MY_CREDS['user'],
+        'PASSWORD': MY_CREDS['pass'],
+    },
+    'other': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': os.path.join(PROJECT_ROOT, 'scratch_test.db'),
+    },
+}

File pip-requirements.txt

+-e git+https://github.com/django/django.git#egg=django
+sphinx

File postgresql_settings.py

+"""Postgresql settings
+
+Create a symbolic link to settings.py to use.
+
+"""
+
+from sqlite_settings import *
+from creds import PG_CREDS
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.postgresql_psycopg2',
+        'NAME': 'scratch',
+        'USER': PG_CREDS['user'],
+        'PASSWORD': PG_CREDS['pass'],
+    },
+    'other': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': os.path.join(PROJECT_ROOT, 'scratch_test.db'),
+    },
+}

File scratch.db.save

Binary file added.
+sqlite_settings.py

File sqlite_settings.py

+# Django settings for scratch project.
+
+import os
+
+PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
+PROJECT_NAME = os.path.basename(PROJECT_ROOT)
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    ('to be defined', 'to_be@defined.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': os.path.join(PROJECT_ROOT, 'scratch.db'),
+    },
+    'other': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': os.path.join(PROJECT_ROOT, 'scratch_test.db'),
+    },
+}
+
+SITE_ID = 1
+
+MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media/')
+MEDIA_URL = '/media/'
+
+STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static/')
+STATIC_URL = '/static/'
+
+ADMIN_MEDIA_PREFIX = '/static/admin/'
+
+SECRET_KEY = 'some secret key'
+
+ROOT_URLCONF = '%s.urls' % PROJECT_NAME
+
+TEMPLATE_DIRS = (
+    os.path.join(PROJECT_ROOT, 'templates'),
+)
+
+INSTALLED_APPS = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+    'django.contrib.admin',
+    'django.contrib.admindocs',
+    'testapp',
+)
+

File templates/404.html

+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset=utf-8 />
+  <title>Missing</title>
+</head>
+<body>
+  <h1>You lost it.</h1>
+</body>
+</html>

File templates/500.html

+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset=utf-8 />
+  <title>Broke</title>
+</head>
+<body>
+  <h1>You broke it.</h1>
+</body>
+</html>

File templates/base.html

+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8" />
+    <title>Scratch website {% block title %}{% endblock title %}</title>
+    {% block css %}{% endblock css %}
+    {% block extrahead %}{% endblock extrahead %}
+</head>
+
+<body>
+    {% block content %}{% endblock content %}
+
+    {% block js %}{% endblock js %}
+</body>
+</html>
+

File templates/form_include.html

+{% if form.errors %}
+<p class="error">Please correct the following errors:</p>
+{% endif %}
+
+{% for field in form %}
+    <div class="form-row{% if field.field.required %} required{% endif %}{% if field.errors %} error{% endif %}">
+        {{ field.errors }}
+        {{ field.label_tag }} {{ field }}
+        {% if field.help_text %}<p class="help">{{ field.help_text }}</p>{% endif %}
+    </div>
+{% endfor %}
+

File templates/testapp/index.html

+{% extends "base.html" %}
+
+{% block content %}Some random text here.{% endblock content %}
+

File testapp/__init__.py

Empty file added.

File testapp/admin.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from django.contrib import admin
+from testapp.models import Foo
+
+
+admin.site.register(Foo)

File testapp/models.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from django.db import models
+
+
+class Foo(models.Model):
+    name = models.CharField(max_length=50)
+
+    class Meta:
+        ordering = ['name']
+
+    def __unicode__(self):
+        return self.name

File testapp/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.assertEqual(1 + 1, 2)

File testapp/urls.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from django.conf.urls.defaults import patterns, url
+from django.views.generic.simple import direct_to_template
+
+
+urlpatterns = patterns('',
+    url(r'^$',
+        direct_to_template,
+        {'template': 'testapp/index.html'},
+        name='home'),
+)

File testapp/views.py

+# Create your views here.
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from django.conf.urls.defaults import patterns, include, url
+from django.contrib import admin
+from django.views.generic.simple import direct_to_template
+
+
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    url(r'^$',
+        direct_to_template, {'template': 'testapp/index.html'}, name='home'),
+    url(r'^scratch/',
+        include('testapp.urls', namespace='testapp', app_name='testapp')),
+
+    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+    url(r'^admin/', include(admin.site.urls)),
+)