Skip to content

Commit db51d9a

Browse files
committed
examples/hammertime: a simple yet comprehensive example
1 parent a0afda6 commit db51d9a

File tree

14 files changed

+223
-0
lines changed

14 files changed

+223
-0
lines changed

examples/hammertime/__init__.py

Whitespace-only changes.

examples/hammertime/anvil/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

examples/hammertime/anvil/tests.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
This file demonstrates two different styles of tests (one doctest and one
3+
unittest). These will both pass when you run "manage.py test".
4+
5+
Replace these with more appropriate tests for your application.
6+
"""
7+
8+
from django.test import TestCase
9+
10+
class SimpleTest(TestCase):
11+
def test_basic_addition(self):
12+
"""
13+
Tests that 1 + 1 always equals 2.
14+
"""
15+
self.failUnlessEqual(1 + 1, 2)
16+
17+
__test__ = {"doctest": """
18+
Another way to test that 1 + 1 is equal to 2.
19+
20+
>>> 1 + 1 == 2
21+
True
22+
"""}
23+

examples/hammertime/anvil/urls.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.conf.urls.defaults import *
2+
from django.views.generic.simple import direct_to_template
3+
4+
from anvil.views import protected_resource
5+
6+
urlpatterns = patterns('',
7+
url(r'^$', direct_to_template, {'template':'index.html'}, name="index_page"),
8+
url(r'^protected/$', protected_resource, name="protected_page"),
9+
10+
url(r'^accounts/login/$', 'django.contrib.auth.views.login', name="login_page"),
11+
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', name="logout_page")
12+
)

examples/hammertime/anvil/views.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Create your views here.
2+
3+
from django.shortcuts import render_to_response
4+
from django.contrib.auth.decorators import login_required
5+
from django.template import RequestContext
6+
7+
@login_required
8+
def protected_resource(request):
9+
return render_to_response("protected.html", context_instance=RequestContext(request, {}))
10+

examples/hammertime/manage.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/python
2+
from django.core.management import execute_manager
3+
try:
4+
import settings # Assumed to be in the same directory.
5+
except ImportError:
6+
import sys
7+
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__)
8+
sys.exit(1)
9+
10+
if __name__ == "__main__":
11+
execute_manager(settings)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Django settings for hammertime project.
2+
import os
3+
4+
DEBUG = True
5+
TEMPLATE_DEBUG = DEBUG
6+
7+
ADMINS = (
8+
# ('Your Name', 'your_email@domain.com'),
9+
)
10+
11+
MANAGERS = ADMINS
12+
13+
DATABASE_ENGINE = '' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
14+
DATABASE_NAME = '' # Or path to database file if using sqlite3.
15+
DATABASE_USER = '' # Not used with sqlite3.
16+
DATABASE_PASSWORD = '' # Not used with sqlite3.
17+
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
18+
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
19+
20+
# Local time zone for this installation. Choices can be found here:
21+
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
22+
# although not all choices may be available on all operating systems.
23+
# If running in a Windows environment this must be set to the same as your
24+
# system time zone.
25+
TIME_ZONE = 'Europe/Helsinki'
26+
27+
# Language code for this installation. All choices can be found here:
28+
# http://www.i18nguy.com/unicode/language-identifiers.html
29+
LANGUAGE_CODE = 'en-us'
30+
31+
SITE_ID = 1
32+
33+
# If you set this to False, Django will make some optimizations so as not
34+
# to load the internationalization machinery.
35+
USE_I18N = True
36+
37+
# Absolute path to the directory that holds media.
38+
# Example: "/home/media/media.lawrence.com/"
39+
MEDIA_ROOT = ''
40+
41+
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
42+
# trailing slash if there is a path component (optional in other cases).
43+
# Examples: "http://media.lawrence.com", "http://example.com/media/"
44+
MEDIA_URL = ''
45+
46+
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
47+
# trailing slash.
48+
# Examples: "http://foo.com/media/", "/media/".
49+
ADMIN_MEDIA_PREFIX = '/media/'
50+
51+
# Make this unique, and don't share it with anybody.
52+
SECRET_KEY = 'salainen'
53+
54+
# List of callables that know how to import templates from various sources.
55+
TEMPLATE_LOADERS = (
56+
'django.template.loaders.filesystem.load_template_source',
57+
'django.template.loaders.app_directories.load_template_source',
58+
# 'django.template.loaders.eggs.load_template_source',
59+
)
60+
61+
MIDDLEWARE_CLASSES = (
62+
'django.middleware.common.CommonMiddleware',
63+
'django.contrib.sessions.middleware.SessionMiddleware',
64+
'django.contrib.auth.middleware.AuthenticationMiddleware',
65+
)
66+
67+
ROOT_URLCONF = 'urls'
68+
69+
TEMPLATE_DIRS = (
70+
os.path.abspath(os.path.join(os.path.dirname(__file__), "templates"))
71+
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
72+
# Always use forward slashes, even on Windows.
73+
# Don't forget to use absolute paths, not relative paths.
74+
)
75+
76+
INSTALLED_APPS = (
77+
'django.contrib.auth',
78+
'django.contrib.contenttypes',
79+
'django.contrib.sessions',
80+
'django.contrib.sites',
81+
)
82+
83+
LOGIN_URL = '/hammertime/accounts/login'
84+
85+
AUTHENTICATION_BACKENDS = (
86+
('django.contrib.auth.backends.ModelBackend'),
87+
('phpbb.auth.backends.PhpbbBackend'),
88+
)
89+
90+
PHPBB_AUTH_DB_MODULE = "psycopg2"
91+
PHPBB_AUTH_DB_PARAMS = {
92+
"user": "",
93+
"password": "",
94+
"database": "",
95+
}
96+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<head>
3+
<title>Hammertime!</title>
4+
</head>
5+
<body>
6+
<h1>Hammertime!</h1>
7+
{% block content %}
8+
<p>Content goes here.</p>
9+
{% endblock content %}
10+
</body>
11+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "base.html" %}
2+
{% block content %}
3+
<ul>
4+
<li><a href="{% url login_page %}">Log in</a></li>
5+
<li><a href="{% url protected_page %}">Access protected resource</a></li>
6+
<li><a href="{% url logout_page %}">Log out</a></li>
7+
</ul>
8+
{% endblock content %}

0 commit comments

Comments
 (0)