1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

i18n: merged up to [954] from trunk. contains the big load of admin reworking stuff from adrian.

git-svn-id: http://code.djangoproject.com/svn/django/branches/i18n@956 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Georg Bauer 2005-10-19 15:47:26 +00:00
commit 1d08d433f9
106 changed files with 200 additions and 369 deletions

View File

@ -27,22 +27,28 @@ MEDIA_ROOT = ''
# Example: "http://media.lawrence.com" # Example: "http://media.lawrence.com"
MEDIA_URL = '' MEDIA_URL = ''
# 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 = '/media/'
# Make this unique, and don't share it with anybody. # Make this unique, and don't share it with anybody.
SECRET_KEY = '' SECRET_KEY = ''
# List of callables that know how to import templates from various sources. # List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = ( TEMPLATE_LOADERS = (
# 'django.core.template.loaders.app_directories.load_template_source',
'django.core.template.loaders.filesystem.load_template_source', 'django.core.template.loaders.filesystem.load_template_source',
'django.core.template.loaders.app_directories.load_template_source',
# 'django.core.template.loaders.eggs.load_template_source', # 'django.core.template.loaders.eggs.load_template_source',
) )
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
"django.middleware.common.CommonMiddleware", "django.middleware.common.CommonMiddleware",
"django.middleware.sessions.SessionMiddleware",
"django.middleware.doc.XViewMiddleware", "django.middleware.doc.XViewMiddleware",
) )
ROOT_URLCONF = '{{ project_name }}.settings.urls.main' ROOT_URLCONF = '{{ project_name }}.urls'
TEMPLATE_DIRS = ( TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates". # Put strings here, like "/home/html/django_templates".

View File

@ -1,6 +0,0 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^admin/', include('django.conf.urls.admin')),
(r'^r/', include('django.conf.urls.shortcut')),
)

View File

@ -3,4 +3,7 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('', urlpatterns = patterns('',
# Example: # Example:
# (r'^{{ project_name }}/', include('{{ project_name }}.apps.foo.urls.foo')), # (r'^{{ project_name }}/', include('{{ project_name }}.apps.foo.urls.foo')),
# Uncomment this for admin:
# (r'^admin/', include('django.contrib.admin.urls.admin')),
) )

View File

Before

Width:  |  Height:  |  Size: 80 B

After

Width:  |  Height:  |  Size: 80 B

View File

Before

Width:  |  Height:  |  Size: 838 B

After

Width:  |  Height:  |  Size: 838 B

View File

Before

Width:  |  Height:  |  Size: 58 B

After

Width:  |  Height:  |  Size: 58 B

View File

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 199 B

View File

Before

Width:  |  Height:  |  Size: 212 B

After

Width:  |  Height:  |  Size: 212 B

View File

Before

Width:  |  Height:  |  Size: 843 B

After

Width:  |  Height:  |  Size: 843 B

View File

Before

Width:  |  Height:  |  Size: 844 B

After

Width:  |  Height:  |  Size: 844 B

View File

Before

Width:  |  Height:  |  Size: 176 B

After

Width:  |  Height:  |  Size: 176 B

View File

Before

Width:  |  Height:  |  Size: 299 B

After

Width:  |  Height:  |  Size: 299 B

View File

Before

Width:  |  Height:  |  Size: 119 B

After

Width:  |  Height:  |  Size: 119 B

View File

Before

Width:  |  Height:  |  Size: 145 B

After

Width:  |  Height:  |  Size: 145 B

View File

Before

Width:  |  Height:  |  Size: 192 B

After

Width:  |  Height:  |  Size: 192 B

View File

Before

Width:  |  Height:  |  Size: 119 B

After

Width:  |  Height:  |  Size: 119 B

View File

Before

Width:  |  Height:  |  Size: 390 B

After

Width:  |  Height:  |  Size: 390 B

View File

Before

Width:  |  Height:  |  Size: 181 B

After

Width:  |  Height:  |  Size: 181 B

View File

Before

Width:  |  Height:  |  Size: 319 B

After

Width:  |  Height:  |  Size: 319 B

View File

Before

Width:  |  Height:  |  Size: 667 B

After

Width:  |  Height:  |  Size: 667 B

View File

Before

Width:  |  Height:  |  Size: 341 B

After

Width:  |  Height:  |  Size: 341 B

View File

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 116 B

View File

Before

Width:  |  Height:  |  Size: 186 B

After

Width:  |  Height:  |  Size: 186 B

View File

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 273 B

View File

Before

Width:  |  Height:  |  Size: 606 B

After

Width:  |  Height:  |  Size: 606 B

View File

Before

Width:  |  Height:  |  Size: 358 B

After

Width:  |  Height:  |  Size: 358 B

View File

Before

Width:  |  Height:  |  Size: 398 B

After

Width:  |  Height:  |  Size: 398 B

View File

Before

Width:  |  Height:  |  Size: 355 B

After

Width:  |  Height:  |  Size: 355 B

View File

Before

Width:  |  Height:  |  Size: 552 B

After

Width:  |  Height:  |  Size: 552 B

View File

Before

Width:  |  Height:  |  Size: 612 B

After

Width:  |  Height:  |  Size: 612 B

View File

Before

Width:  |  Height:  |  Size: 401 B

After

Width:  |  Height:  |  Size: 401 B

View File

Before

Width:  |  Height:  |  Size: 197 B

After

Width:  |  Height:  |  Size: 197 B

View File

Before

Width:  |  Height:  |  Size: 203 B

After

Width:  |  Height:  |  Size: 203 B

View File

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 198 B

View File

Before

Width:  |  Height:  |  Size: 200 B

After

Width:  |  Height:  |  Size: 200 B

View File

Before

Width:  |  Height:  |  Size: 932 B

After

Width:  |  Height:  |  Size: 932 B

View File

Before

Width:  |  Height:  |  Size: 336 B

After

Width:  |  Height:  |  Size: 336 B

View File

Before

Width:  |  Height:  |  Size: 351 B

After

Width:  |  Height:  |  Size: 351 B

View File

Before

Width:  |  Height:  |  Size: 354 B

After

Width:  |  Height:  |  Size: 354 B

View File

@ -0,0 +1 @@
__all__ = ['admin']

View File

@ -0,0 +1,48 @@
from django.core import meta
from django.models import auth, core
class LogEntry(meta.Model):
action_time = meta.DateTimeField(auto_now=True)
user = meta.ForeignKey(auth.User)
content_type = meta.ForeignKey(core.ContentType, blank=True, null=True)
object_id = meta.TextField(blank=True, null=True)
object_repr = meta.CharField(maxlength=200)
action_flag = meta.PositiveSmallIntegerField()
change_message = meta.TextField(blank=True)
class META:
module_name = 'log'
verbose_name_plural = 'log entries'
db_table = 'django_admin_log'
ordering = ('-action_time',)
module_constants = {
'ADDITION': 1,
'CHANGE': 2,
'DELETION': 3,
}
def __repr__(self):
return str(self.action_time)
def is_addition(self):
return self.action_flag == ADDITION
def is_change(self):
return self.action_flag == CHANGE
def is_deletion(self):
return self.action_flag == DELETION
def get_edited_object(self):
"Returns the edited object represented by this log entry"
return self.get_content_type().get_object_for_this_type(pk=self.object_id)
def get_admin_url(self):
"""
Returns the admin URL to edit the object represented by this log entry.
This is relative to the Django admin index page.
"""
return "%s/%s/%s/" % (self.get_content_type().package, self.get_content_type().python_module_name, self.object_id)
def _module_log_action(user_id, content_type_id, object_id, object_repr, action_flag, change_message=''):
e = LogEntry(None, None, user_id, content_type_id, object_id, object_repr[:200], action_flag, change_message)
e.save()

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block title %}{{ _('Page not found') }}{% endblock %} {% block title %}{{ _('Page not found') }}{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; Server error</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; Server error</div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base" %} {% extends "admin/base" %}
{% block title %}{{ title }} | {{ _('Django site admin') }}{% endblock %} {% block title %}{{ title }} | {{ _('Django site admin') }}{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block content %} {% block content %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block coltype %}colMS{% endblock %} {% block coltype %}colMS{% endblock %}
{% block bodyclass %}dashboard{% endblock %} {% block bodyclass %}dashboard{% endblock %}
@ -49,7 +49,7 @@
<div class="module" id="recent-actions-module"> <div class="module" id="recent-actions-module">
<h2>{{ _('Recent Actions') }}</h2> <h2>{{ _('Recent Actions') }}</h2>
<h3>{{ _('My Actions') }}</h3> <h3>{{ _('My Actions') }}</h3>
{% load auth.log %} {% load log %}
{% get_admin_log 10 as admin_log for_user user %} {% get_admin_log 10 as admin_log for_user user %}
{% if not admin_log %} {% if not admin_log %}
<p>{{ _('None available') }}</p> <p>{{ _('None available') }}</p>

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}{% endblock %} {% block breadcrumbs %}{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %} {% block breadcrumbs %}
<div class="breadcrumbs"><a href="../../../../">{{ _('Home') }}</a> &rsaquo; <a href="../../">{{ module_name }}</a> &rsaquo; <a href="../">{{ object|truncatewords:"18" }}</a> &rsaquo; {{ _('History') }}</div> <div class="breadcrumbs"><a href="../../../../">{{ _('Home') }}</a> &rsaquo; <a href="../../">{{ module_name }}</a> &rsaquo; <a href="../">{{ object|truncatewords:"18" }}</a> &rsaquo; {{ _('History') }}</div>

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block content %} {% block content %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">Home</a> &rsaquo; <a href="../">Documentation</a> &rsaquo; Bookmarklets</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">Home</a> &rsaquo; <a href="../">Documentation</a> &rsaquo; Bookmarklets</div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">Home</a> &rsaquo; Documentation</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../">Home</a> &rsaquo; Documentation</div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">Home</a> &rsaquo; Documentation</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../">Home</a> &rsaquo; Documentation</div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block extrahead %} {% block extrahead %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block coltype %}colSM{% endblock %} {% block coltype %}colSM{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../../">Home</a> &rsaquo; <a href="../../">Documentation</a> &rsaquo; Templates &rsaquo; {{ name }}</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../../../">Home</a> &rsaquo; <a href="../../">Documentation</a> &rsaquo; Templates &rsaquo; {{ name }}</div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block coltype %}colSM{% endblock %} {% block coltype %}colSM{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block coltype %}colSM{% endblock %} {% block coltype %}colSM{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../../">Home</a> &rsaquo; <a href="../../">Documentation</a> &rsaquo; <a href="../">Views</a> &rsaquo; {{ name }}</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../../../">Home</a> &rsaquo; <a href="../../">Documentation</a> &rsaquo; <a href="../">Views</a> &rsaquo; {{ name }}</div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block coltype %}colSM{% endblock %} {% block coltype %}colSM{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a></div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a></div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a> &rsaquo; {{ _('Password change') }}</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a> &rsaquo; {{ _('Password change') }}</div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a> &rsaquo; {{ _('Password change') }}</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a> &rsaquo; {{ _('Password change') }}</div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a> &rsaquo; {{ _('Password reset') }}</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a> &rsaquo; {{ _('Password reset') }}</div>{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_site" %} {% extends "admin/base_site" %}
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a> &rsaquo; {{ _('Password reset') }}</div>{% endblock %} {% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{{ _('Home') }}</a> &rsaquo; {{ _('Password reset') }}</div>{% endblock %}

View File

@ -1,4 +1,4 @@
from django.models.auth import log from django.models.admin import log
from django.core import template from django.core import template
class AdminLogNode(template.Node): class AdminLogNode(template.Node):

View File

@ -6,7 +6,7 @@ from django.core.template import loader
from django.core.exceptions import Http404, ObjectDoesNotExist, PermissionDenied from django.core.exceptions import Http404, ObjectDoesNotExist, PermissionDenied
from django.core.extensions import DjangoContext as Context from django.core.extensions import DjangoContext as Context
from django.core.extensions import get_object_or_404, render_to_response from django.core.extensions import get_object_or_404, render_to_response
from django.models.auth import log from django.models.admin import log
from django.utils.html import strip_tags from django.utils.html import strip_tags
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
from django.utils.text import capfirst, get_text_list from django.utils.text import capfirst, get_text_list
@ -49,7 +49,7 @@ def get_query_string(original_params, new_params={}, remove=[]):
return '?' + '&amp;'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20') return '?' + '&amp;'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20')
def index(request): def index(request):
return render_to_response('index', {'title': 'Site administration'}, context_instance=Context(request)) return render_to_response('admin/index', {'title': 'Site administration'}, context_instance=Context(request))
index = staff_member_required(index) index = staff_member_required(index)
def change_list(request, app_label, module_name): def change_list(request, app_label, module_name):
@ -266,7 +266,7 @@ def change_list(request, app_label, module_name):
else: else:
pass # Invalid argument to "list_filter" pass # Invalid argument to "list_filter"
raw_template = ['{% extends "base_site" %}\n'] raw_template = ['{% extends "admin/base_site" %}\n']
raw_template.append('{% block bodyclass %}change-list{% endblock %}\n') raw_template.append('{% block bodyclass %}change-list{% endblock %}\n')
if not is_popup: if not is_popup:
raw_template.append('{%% block breadcrumbs %%}<div class="breadcrumbs"><a href="../../">Home</a> &rsaquo; %s</div>{%% endblock %%}\n' % capfirst(opts.verbose_name_plural)) raw_template.append('{%% block breadcrumbs %%}<div class="breadcrumbs"><a href="../../">Home</a> &rsaquo; %s</div>{%% endblock %%}\n' % capfirst(opts.verbose_name_plural))
@ -538,7 +538,7 @@ def _get_template(opts, app_label, add=False, change=False, show_delete=False, f
admin_field_objs = opts.admin.get_field_objs(opts) admin_field_objs = opts.admin.get_field_objs(opts)
ordered_objects = opts.get_ordered_objects()[:] ordered_objects = opts.get_ordered_objects()[:]
auto_populated_fields = [f for f in opts.fields if f.prepopulate_from] auto_populated_fields = [f for f in opts.fields if f.prepopulate_from]
t = ['{% extends "base_site" %}\n'] t = ['{% extends "admin/base_site" %}\n']
t.append('{% block extrahead %}') t.append('{% block extrahead %}')
# Put in any necessary JavaScript imports. # Put in any necessary JavaScript imports.
@ -1087,7 +1087,7 @@ def delete_stage(request, app_label, module_name, object_id):
log.log_action(request.user.id, opts.get_content_type_id(), object_id, obj_repr, log.DELETION) log.log_action(request.user.id, opts.get_content_type_id(), object_id, obj_repr, log.DELETION)
request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr)) request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr))
return HttpResponseRedirect("../../") return HttpResponseRedirect("../../")
return render_to_response('delete_confirmation_generic', { return render_to_response('admin/delete_confirmation', {
"title": "Are you sure?", "title": "Are you sure?",
"object_name": opts.verbose_name, "object_name": opts.verbose_name,
"object": obj, "object": obj,
@ -1102,7 +1102,7 @@ def history(request, app_label, module_name, object_id):
order_by=("action_time",), select_related=True) order_by=("action_time",), select_related=True)
# If no history was found, see whether this object even exists. # If no history was found, see whether this object even exists.
obj = get_object_or_404(mod, pk=object_id) obj = get_object_or_404(mod, pk=object_id)
return render_to_response('admin_object_history', { return render_to_response('admin/object_history', {
'title': 'Change history: %r' % obj, 'title': 'Change history: %r' % obj,
'action_list': action_list, 'action_list': action_list,
'module_name': capfirst(opts.verbose_name_plural), 'module_name': capfirst(opts.verbose_name_plural),

View File

@ -23,7 +23,7 @@ def template_validator(request):
errors = manipulator.get_validation_errors(new_data) errors = manipulator.get_validation_errors(new_data)
if not errors: if not errors:
request.user.add_message('The template is valid.') request.user.add_message('The template is valid.')
return render_to_response('template_validator', { return render_to_response('admin/template_validator', {
'title': 'Template validator', 'title': 'Template validator',
'form': formfields.FormWrapper(manipulator, new_data, errors), 'form': formfields.FormWrapper(manipulator, new_data, errors),
}, context_instance=DjangoContext(request)) }, context_instance=DjangoContext(request))

View File

@ -102,8 +102,10 @@ def get_limit_offset_sql(limit, offset=None):
return sql return sql
def get_random_function_sql(): def get_random_function_sql():
# TODO: This is a guess. Make sure this is correct. return "RAND()"
return "RANDOM()"
def get_table_list(cursor):
raise NotImplementedError
def get_relations(cursor, table_name): def get_relations(cursor, table_name):
raise NotImplementedError raise NotImplementedError
@ -151,3 +153,5 @@ DATA_TYPES = {
'URLField': 'varchar(200)', 'URLField': 'varchar(200)',
'USStateField': 'varchar(2)', 'USStateField': 'varchar(2)',
} }
DATA_TYPES_REVERSE = {}

View File

@ -74,7 +74,7 @@ class BaseHandler:
response = middleware_method(request, e) response = middleware_method(request, e)
if response: if response:
return response return response
raise e raise
# Complain if the view returned None (a common error). # Complain if the view returned None (a common error).
if response is None: if response is None:

View File

@ -17,7 +17,6 @@ APP_ARGS = '[modelmodule ...]'
# Use django.__path__[0] because we don't know which directory django into # Use django.__path__[0] because we don't know which directory django into
# which has been installed. # which has been installed.
PROJECT_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf', '%s_template') PROJECT_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf', '%s_template')
ADMIN_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf', 'admin_templates')
def _get_packages_insert(app_label): def _get_packages_insert(app_label):
return "INSERT INTO packages (label, name) VALUES ('%s', '%s');" % (app_label, app_label) return "INSERT INTO packages (label, name) VALUES ('%s', '%s');" % (app_label, app_label)
@ -142,7 +141,7 @@ def get_sql_delete(mod):
if cursor is not None: if cursor is not None:
cursor.execute("SELECT id FROM content_types WHERE package = %s", [app_label]) cursor.execute("SELECT id FROM content_types WHERE package = %s", [app_label])
for row in cursor.fetchall(): for row in cursor.fetchall():
output.append("DELETE FROM auth_admin_log WHERE content_type_id = %s;" % row[0]) output.append("DELETE FROM django_admin_log WHERE content_type_id = %s;" % row[0])
# Close database connection explicitly, in case this output is being piped # Close database connection explicitly, in case this output is being piped
# directly into a database client, to avoid locking issues. # directly into a database client, to avoid locking issues.
@ -378,16 +377,8 @@ def startproject(project_name, directory):
"Creates a Django project for the given project_name in the given directory." "Creates a Django project for the given project_name in the given directory."
from random import choice from random import choice
_start_helper('project', project_name, directory) _start_helper('project', project_name, directory)
# Populate TEMPLATE_DIRS for the admin templates, based on where Django is
# installed.
admin_settings_file = os.path.join(directory, project_name, 'settings', 'admin.py')
settings_contents = open(admin_settings_file, 'r').read()
fp = open(admin_settings_file, 'w')
settings_contents = re.sub(r'(?s)\b(TEMPLATE_DIRS\s*=\s*\()(.*?)\)', "\\1\n r%r,\\2)" % ADMIN_TEMPLATE_DIR, settings_contents)
fp.write(settings_contents)
fp.close()
# Create a random SECRET_KEY hash, and put it in the main settings. # Create a random SECRET_KEY hash, and put it in the main settings.
main_settings_file = os.path.join(directory, project_name, 'settings', 'main.py') main_settings_file = os.path.join(directory, project_name, 'settings.py')
settings_contents = open(main_settings_file, 'r').read() settings_contents = open(main_settings_file, 'r').read()
fp = open(main_settings_file, 'w') fp = open(main_settings_file, 'w')
secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])

View File

@ -602,7 +602,7 @@ class AdminMediaHandler:
from django.conf import settings from django.conf import settings
import django import django
self.application = application self.application = application
self.media_dir = django.__path__[0] + '/conf/admin_media' self.media_dir = django.__path__[0] + '/contrib/admin/media'
self.media_url = settings.ADMIN_MEDIA_PREFIX self.media_url = settings.ADMIN_MEDIA_PREFIX
def __call__(self, environ, start_response): def __call__(self, environ, start_response):

View File

@ -1,126 +0,0 @@
from django.utils import httpwrappers
from django.core.extensions import DjangoContext
from django.core.extensions import render_to_response
from django.models.auth import users
from django.views.registration import passwords
from django.views.auth.login import logout
import base64, md5
import cPickle as pickle
from django.conf.settings import SECRET_KEY
ERROR_MESSAGE = "Please enter a correct username and password. Note that both fields are case-sensitive."
class AdminUserRequired:
"""
Admin middleware. If this is enabled, access to the site will be granted only
to valid users with the "is_staff" flag set.
"""
def process_view(self, request, view_func, param_dict):
"""
Make sure the user is logged in and is a valid admin user before
allowing any access.
Done at the view point because we need to know if we're running the
password reset function.
"""
# If this is the password reset view, we don't want to require login
# Otherwise the password reset would need its own entry in the httpd
# conf, which is a little uglier than this. Same goes for the logout
# view.
if view_func in (passwords.password_reset, passwords.password_reset_done, logout):
return
assert hasattr(request, 'session'), "The admin requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.middleware.sessions.SessionMiddleware' before %r." % self.__class__.__name__
# Check for a logged in, valid user
if self.user_is_valid(request.user):
return
# If this isn't already the login page, display it
if not request.POST.has_key('this_is_the_login_form'):
if request.POST:
message = "Please log in again, because your session has expired. "\
"Don't worry: Your submission has been saved."
else:
message = ""
return self.display_login_form(request, message)
# Check that the user accepts cookies.
if not request.session.test_cookie_worked():
message = "Looks like your browser isn't configured to accept cookies. Please enable cookies, reload this page, and try again."
return self.display_login_form(request, message)
# Check the password
username = request.POST.get('username', '')
try:
user = users.get_object(username__exact=username)
except users.UserDoesNotExist:
message = ERROR_MESSAGE
if '@' in username:
# Mistakenly entered e-mail address instead of username? Look it up.
try:
user = users.get_object(email__exact=username)
except users.UserDoesNotExist:
message = "Usernames cannot contain the '@' character."
else:
message = "Your e-mail address is not your username. Try '%s' instead." % user.username
return self.display_login_form(request, message)
# The user data is correct; log in the user in and continue
else:
if self.authenticate_user(user, request.POST.get('password', '')):
request.session[users.SESSION_KEY] = user.id
if request.POST.has_key('post_data'):
post_data = decode_post_data(request.POST['post_data'])
if post_data and not post_data.has_key('this_is_the_login_form'):
# overwrite request.POST with the saved post_data, and continue
request.POST = post_data
request.user = user
return
else:
request.session.delete_test_cookie()
return httpwrappers.HttpResponseRedirect(request.path)
else:
return self.display_login_form(request, ERROR_MESSAGE)
def display_login_form(self, request, error_message=''):
request.session.set_test_cookie()
if request.POST and request.POST.has_key('post_data'):
# User has failed login BUT has previously saved 'post_data'
post_data = request.POST['post_data']
elif request.POST:
# User's session must have expired; save their post data
post_data = encode_post_data(request.POST)
else:
post_data = encode_post_data({})
return render_to_response(self.get_login_template_name(), {
'title': 'Log in',
'app_path': request.path,
'post_data': post_data,
'error_message': error_message
}, context_instance=DjangoContext(request))
def authenticate_user(self, user, password):
return user.check_password(password) and user.is_staff
def user_is_valid(self, user):
return not user.is_anonymous() and user.is_staff
def get_login_template_name(self):
return "login"
def encode_post_data(post_data):
pickled = pickle.dumps(post_data)
pickled_md5 = md5.new(pickled + SECRET_KEY).hexdigest()
return base64.encodestring(pickled + pickled_md5)
def decode_post_data(encoded_data):
encoded_data = base64.decodestring(encoded_data)
pickled, tamper_check = encoded_data[:-32], encoded_data[-32:]
if md5.new(pickled + SECRET_KEY).hexdigest() != tamper_check:
from django.core.exceptions import SuspiciousOperation
raise SuspiciousOperation, "User may have tampered with session cookie."
return pickle.loads(pickled)

View File

@ -52,7 +52,7 @@ class CacheMiddleware:
def process_response(self, request, response): def process_response(self, request, response):
"Sets the cache, if needed." "Sets the cache, if needed."
if not request._cache_update_cache: if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache:
# We don't need to update the cache, just return. # We don't need to update the cache, just return.
return response return response
if not request.META['REQUEST_METHOD'] == 'GET': if not request.META['REQUEST_METHOD'] == 'GET':

View File

@ -183,54 +183,3 @@ class Message(meta.Model):
def __repr__(self): def __repr__(self):
return self.message return self.message
class META:
verbose_name = _('Message')
verbose_name_plural = _('Messages')
class LogEntry(meta.Model):
action_time = meta.DateTimeField(_('action time'), auto_now=True)
user = meta.ForeignKey(User)
content_type = meta.ForeignKey(core.ContentType, blank=True, null=True) # TODO: content_type_id name?
object_id = meta.TextField(_('object id'), blank=True, null=True)
object_repr = meta.CharField(_('object repr'), maxlength=200)
action_flag = meta.PositiveSmallIntegerField(_('action flag'))
change_message = meta.TextField(blank=True)
class META:
module_name = 'log'
verbose_name = _('log entry')
verbose_name_plural = _('log entries')
db_table = 'auth_admin_log'
ordering = ('-action_time',)
module_constants = {
'ADDITION': 1,
'CHANGE': 2,
'DELETION': 3,
}
def __repr__(self):
return str(self.action_time)
def is_addition(self):
return self.action_flag == ADDITION
def is_change(self):
return self.action_flag == CHANGE
def is_deletion(self):
return self.action_flag == DELETION
def get_edited_object(self):
"Returns the edited object represented by this log entry"
return self.get_content_type().get_object_for_this_type(pk=self.object_id)
def get_admin_url(self):
"""
Returns the admin URL to edit the object represented by this log entry.
This is relative to the Django admin index page.
"""
return "%s/%s/%s/" % (self.get_content_type().package, self.get_content_type().python_module_name, self.object_id)
def _module_log_action(user_id, content_type_id, object_id, object_repr, action_flag, change_message=''):
e = LogEntry(None, None, user_id, content_type_id, object_id, object_repr[:200], action_flag, change_message)
e.save()

View File

@ -192,10 +192,10 @@ Available options
Example usage:: Example usage::
django-admin.py init --settings='myproject.settings.main' django-admin.py init --settings=myproject.settings
Explicitly specifies the settings module to use. The settings module should be Explicitly specifies the settings module to use. The settings module should be
in Python path syntax, e.g. "myproject.settings.main". If this isn't provided, in Python path syntax, e.g. "myproject.settings". If this isn't provided,
``django-admin.py`` will use the DJANGO_SETTINGS_MODULE environment variable. ``django-admin.py`` will use the DJANGO_SETTINGS_MODULE environment variable.
--pythonpath --pythonpath

View File

@ -348,8 +348,7 @@ things:
* Set the ``SESSION_COOKIE_DOMAIN`` setting in your admin config file * Set the ``SESSION_COOKIE_DOMAIN`` setting in your admin config file
to match your domain. For example, if you're going to to match your domain. For example, if you're going to
"http://www.mysite.com/admin/" in your browser, in "http://www.mysite.com/admin/" in your browser, in
"myproject.settings.admin" you should set ``SESSION_COOKIE_DOMAIN = "myproject.settings" you should set ``SESSION_COOKIE_DOMAIN = 'www.mysite.com'``.
'www.mysite.com'``.
* Some browsers (Firefox?) don't like to accept cookies from domains that * Some browsers (Firefox?) don't like to accept cookies from domains that
don't have dots in them. If you're running the admin site on "localhost" don't have dots in them. If you're running the admin site on "localhost"

View File

@ -27,30 +27,15 @@ name. For example, here's the default ``MIDDLEWARE_CLASSES`` created by
"django.middleware.doc.XViewMiddleware", "django.middleware.doc.XViewMiddleware",
) )
The default admin site has the following ``MIDDLEWARE_CLASSES`` set::
MIDDLEWARE_CLASSES = (
"django.middleware.sessions.SessionMiddleware",
"django.middleware.admin.AdminUserRequired",
"django.middleware.common.CommonMiddleware",
)
Django applies middleware in the order it's defined in ``MIDDLEWARE_CLASSES``. Django applies middleware in the order it's defined in ``MIDDLEWARE_CLASSES``.
For a regular (i.e., non-admin) Django installation, no middleware is required, A Django installation doesn't require any middleware -- e.g.,
but it's strongly suggested that you use ``CommonMiddleware``. For a Django ``MIDDLEWARE_CLASSES`` can be empty, if you'd like -- but it's strongly
admin site, ``SessionMiddleware`` and ``AdminUserRequired`` (in that order) are suggested that you use ``CommonMiddleware``.
required.
Available middleware Available middleware
==================== ====================
django.middleware.admin.AdminUserRequired
-----------------------------------------
Limits site access to valid users with the ``is_staff`` flag set. This is
required by Django's admin, and this middleware requires ``SessionMiddleware``.
django.middleware.cache.CacheMiddleware django.middleware.cache.CacheMiddleware
--------------------------------------- ---------------------------------------

Some files were not shown because too many files have changed in this diff Show More