mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +00:00
[full-history]: Trunk merge from [3421]
git-svn-id: http://code.djangoproject.com/svn/django/branches/full-history@3426 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c1be99e088
commit
b0a11fcdc5
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import getopt
|
|
||||||
|
|
||||||
def compile_messages():
|
def compile_messages():
|
||||||
basedir = None
|
basedir = None
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Need to ensure that the i18n framework is enabled
|
||||||
|
from django.conf import settings
|
||||||
|
settings.configure(USE_I18N = True)
|
||||||
|
|
||||||
from django.utils.translation import templatize
|
from django.utils.translation import templatize
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
@ -7,7 +7,6 @@ a list of all possible variables.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
from django.conf import global_settings
|
from django.conf import global_settings
|
||||||
|
|
||||||
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
|
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
|
||||||
|
@ -62,6 +62,7 @@ LANGUAGES = (
|
|||||||
('sl', gettext_noop('Slovenian')),
|
('sl', gettext_noop('Slovenian')),
|
||||||
('sr', gettext_noop('Serbian')),
|
('sr', gettext_noop('Serbian')),
|
||||||
('sv', gettext_noop('Swedish')),
|
('sv', gettext_noop('Swedish')),
|
||||||
|
('ta', gettext_noop('Tamil')),
|
||||||
('uk', gettext_noop('Ukrainian')),
|
('uk', gettext_noop('Ukrainian')),
|
||||||
('zh-cn', gettext_noop('Simplified Chinese')),
|
('zh-cn', gettext_noop('Simplified Chinese')),
|
||||||
('zh-tw', gettext_noop('Traditional Chinese')),
|
('zh-tw', gettext_noop('Traditional Chinese')),
|
||||||
|
BIN
django/conf/locale/ta/LC_MESSAGES/django.mo
Normal file
BIN
django/conf/locale/ta/LC_MESSAGES/django.mo
Normal file
Binary file not shown.
2111
django/conf/locale/ta/LC_MESSAGES/django.po
Normal file
2111
django/conf/locale/ta/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
@ -123,7 +123,7 @@ class DateFieldFilterSpec(FilterSpec):
|
|||||||
def choices(self, cl):
|
def choices(self, cl):
|
||||||
for title, param_dict in self.links:
|
for title, param_dict in self.links:
|
||||||
yield {'selected': self.date_params == param_dict,
|
yield {'selected': self.date_params == param_dict,
|
||||||
'query_string': cl.get_query_string(param_dict, self.field_generic),
|
'query_string': cl.get_query_string(param_dict, [self.field_generic]),
|
||||||
'display': title}
|
'display': title}
|
||||||
|
|
||||||
FilterSpec.register(lambda f: isinstance(f, models.DateField), DateFieldFilterSpec)
|
FilterSpec.register(lambda f: isinstance(f, models.DateField), DateFieldFilterSpec)
|
||||||
|
@ -42,9 +42,9 @@
|
|||||||
|
|
||||||
/* PAGINATOR */
|
/* PAGINATOR */
|
||||||
.paginator { font-size:11px; padding-top:10px; padding-bottom:10px; line-height:22px; margin:0; border-top:1px solid #ddd; }
|
.paginator { font-size:11px; padding-top:10px; padding-bottom:10px; line-height:22px; margin:0; border-top:1px solid #ddd; }
|
||||||
.paginator a:link, .paginator a:visited { padding:2px 6px; border:solid 1px #ccc; background:white; text-decoration:none; }
|
.paginator a:link, .paginator a:visited { padding:2px 6px; border:solid 1px #ccc; background:white; text-decoration:none; }
|
||||||
.paginator a.showall { padding:0 !important; border:none !important; }
|
.paginator a.showall { padding:0 !important; border:none !important; }
|
||||||
.paginator a.showall:hover { color:#036 !important; background:transparent !important; }
|
.paginator a.showall:hover { color:#036 !important; background:transparent !important; }
|
||||||
.paginator .end { border-width:2px !important; margin-right:6px; }
|
.paginator .end { border-width:2px !important; margin-right:6px; }
|
||||||
.paginator .this-page { padding:2px 6px; font-weight:bold; font-size:13px; vertical-align:top; }
|
.paginator .this-page { padding:2px 6px; font-weight:bold; font-size:13px; vertical-align:top; }
|
||||||
.paginator a:hover { color:white; background:#5b80b2; border-color:#036; }
|
.paginator a:hover { color:white; background:#5b80b2; border-color:#036; }
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
form .form-row p { padding-left:0; font-size:11px; }
|
form .form-row p { padding-left:0; font-size:11px; }
|
||||||
|
|
||||||
/* FORM LABELS */
|
/* FORM LABELS */
|
||||||
form h4 { margin:0 !important; padding:0 !important; border:none !important; }
|
form h4 { margin:0 !important; padding:0 !important; border:none !important; }
|
||||||
label { font-weight:normal !important; color:#666; font-size:12px; }
|
label { font-weight:normal !important; color:#666; font-size:12px; }
|
||||||
label.inline { margin-left:20px; }
|
label.inline { margin-left:20px; }
|
||||||
.required label, label.required { font-weight:bold !important; color:#333 !important; }
|
.required label, label.required { font-weight:bold !important; color:#333 !important; }
|
||||||
|
|
||||||
/* RADIO BUTTONS */
|
/* RADIO BUTTONS */
|
||||||
form ul.radiolist li { list-style-type:none; }
|
form ul.radiolist li { list-style-type:none; }
|
||||||
|
@ -31,7 +31,7 @@ fieldset { margin:0; padding:0; }
|
|||||||
blockquote { font-size:11px; color:#777; margin-left:2px; padding-left:10px; border-left:5px solid #ddd; }
|
blockquote { font-size:11px; color:#777; margin-left:2px; padding-left:10px; border-left:5px solid #ddd; }
|
||||||
code, pre { font-family:"Bitstream Vera Sans Mono", Monaco, "Courier New", Courier, monospace; background:inherit; color:#666; font-size:11px; }
|
code, pre { font-family:"Bitstream Vera Sans Mono", Monaco, "Courier New", Courier, monospace; background:inherit; color:#666; font-size:11px; }
|
||||||
pre.literal-block { margin:10px; background:#eee; padding:6px 8px; }
|
pre.literal-block { margin:10px; background:#eee; padding:6px 8px; }
|
||||||
code strong { color:#930; }
|
code strong { color:#930; }
|
||||||
hr { clear:both; color:#eee; background-color:#eee; height:1px; border:none; margin:0; padding:0; font-size:1px; line-height:1px; }
|
hr { clear:both; color:#eee; background-color:#eee; height:1px; border:none; margin:0; padding:0; font-size:1px; line-height:1px; }
|
||||||
|
|
||||||
/* TEXT STYLES & MODIFIERS */
|
/* TEXT STYLES & MODIFIERS */
|
||||||
@ -81,7 +81,7 @@ table.orderable tbody tr td:first-child { padding-left:14px; background-image:ur
|
|||||||
table.orderable-initalized .order-cell, body>tr>td.order-cell { display:none; }
|
table.orderable-initalized .order-cell, body>tr>td.order-cell { display:none; }
|
||||||
|
|
||||||
/* FORM DEFAULTS */
|
/* FORM DEFAULTS */
|
||||||
input, textarea, select { margin:2px 0; padding:2px 3px; vertical-align:middle; font-family:"Lucida Grande", Verdana, Arial, sans-serif; font-weight:normal; font-size:11px; }
|
input, textarea, select { margin:2px 0; padding:2px 3px; vertical-align:middle; font-family:"Lucida Grande", Verdana, Arial, sans-serif; font-weight:normal; font-size:11px; }
|
||||||
textarea { vertical-align:top !important; }
|
textarea { vertical-align:top !important; }
|
||||||
input[type=text], input[type=password], textarea, select, .vTextField { border:1px solid #ccc; }
|
input[type=text], input[type=password], textarea, select, .vTextField { border:1px solid #ccc; }
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ input[type=submit].default, .submit-row input.default { border:2px solid #5b80b2
|
|||||||
input[type=submit].default:active { background-image:url(../img/admin/default-bg-reverse.gif); background-position:top; }
|
input[type=submit].default:active { background-image:url(../img/admin/default-bg-reverse.gif); background-position:top; }
|
||||||
|
|
||||||
/* MODULES */
|
/* MODULES */
|
||||||
.module { border:1px solid #ccc; margin-bottom:5px; background:white; }
|
.module { border:1px solid #ccc; margin-bottom:5px; background:white; }
|
||||||
.module p, .module ul, .module h3, .module h4, .module dl, .module pre { padding-left:10px; padding-right:10px; }
|
.module p, .module ul, .module h3, .module h4, .module dl, .module pre { padding-left:10px; padding-right:10px; }
|
||||||
.module blockquote { margin-left:12px; }
|
.module blockquote { margin-left:12px; }
|
||||||
.module ul, .module ol { margin-left:1.5em; }
|
.module ul, .module ol { margin-left:1.5em; }
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#header { width:100%; }
|
#header { width:100%; }
|
||||||
#content-main { float:left; width:100%; }
|
#content-main { float:left; width:100%; }
|
||||||
#content-related { float:right; width:18em; position:relative; margin-right:-19em; }
|
#content-related { float:right; width:18em; position:relative; margin-right:-19em; }
|
||||||
#footer { clear:both; padding:10px; }
|
#footer { clear:both; padding:10px; }
|
||||||
|
|
||||||
/* COLUMN TYPES */
|
/* COLUMN TYPES */
|
||||||
.colMS { margin-right:20em !important; }
|
.colMS { margin-right:20em !important; }
|
||||||
@ -16,14 +16,14 @@
|
|||||||
.dashboard #content { width:500px; }
|
.dashboard #content { width:500px; }
|
||||||
|
|
||||||
/* HEADER */
|
/* HEADER */
|
||||||
#header { background:#417690; color:#ffc; overflow:hidden; }
|
#header { background:#417690; color:#ffc; overflow:hidden; }
|
||||||
#header a:link, #header a:visited { color:white; }
|
#header a:link, #header a:visited { color:white; }
|
||||||
#header a:hover { text-decoration:underline; }
|
#header a:hover { text-decoration:underline; }
|
||||||
#branding h1 { padding:0 10px; font-size:18px; margin:8px 0; font-weight:normal; color:#f4f379; }
|
#branding h1 { padding:0 10px; font-size:18px; margin:8px 0; font-weight:normal; color:#f4f379; }
|
||||||
#branding h2 { padding:0 10px; font-size:14px; margin:-8px 0 8px 0; font-weight:normal; color:#ffc; }
|
#branding h2 { padding:0 10px; font-size:14px; margin:-8px 0 8px 0; font-weight:normal; color:#ffc; }
|
||||||
#user-tools { position:absolute; top:0; right:0; padding:1.2em 10px; font-size:11px; text-align:right; }
|
#user-tools { position:absolute; top:0; right:0; padding:1.2em 10px; font-size:11px; text-align:right; }
|
||||||
|
|
||||||
/* SIDEBAR */
|
/* SIDEBAR */
|
||||||
#content-related h3 { font-size:12px; color:#666; margin-bottom:3px; }
|
#content-related h3 { font-size:12px; color:#666; margin-bottom:3px; }
|
||||||
#content-related h4 { font-size:11px; }
|
#content-related h4 { font-size:11px; }
|
||||||
#content-related .module h2 { background:#eee url(../img/admin/nav-bg.gif) bottom left repeat-x; color:#666; }
|
#content-related .module h2 { background:#eee url(../img/admin/nav-bg.gif) bottom left repeat-x; color:#666; }
|
@ -16,7 +16,7 @@ th { text-align: right; }
|
|||||||
|
|
||||||
|
|
||||||
/* layout styles */
|
/* layout styles */
|
||||||
#user-tools { right:auto; left:0; text-align:left; }
|
#user-tools { right:auto; left:0; text-align:left; }
|
||||||
div.breadcrumbs { text-align:right; }
|
div.breadcrumbs { text-align:right; }
|
||||||
#content-main { float:right;}
|
#content-main { float:right;}
|
||||||
#content-related { float:left; margin-left:-19em; margin-right:auto;}
|
#content-related { float:left; margin-left:-19em; margin-right:auto;}
|
||||||
|
@ -3,83 +3,83 @@
|
|||||||
// link when the fieldset is visible.
|
// link when the fieldset is visible.
|
||||||
|
|
||||||
function findForm(node) {
|
function findForm(node) {
|
||||||
// returns the node of the form containing the given node
|
// returns the node of the form containing the given node
|
||||||
if (node.tagName.toLowerCase() != 'form') {
|
if (node.tagName.toLowerCase() != 'form') {
|
||||||
return findForm(node.parentNode);
|
return findForm(node.parentNode);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
var CollapsedFieldsets = {
|
var CollapsedFieldsets = {
|
||||||
collapse_re: /\bcollapse\b/, // Class of fieldsets that should be dealt with.
|
collapse_re: /\bcollapse\b/, // Class of fieldsets that should be dealt with.
|
||||||
collapsed_re: /\bcollapsed\b/, // Class that fieldsets get when they're hidden.
|
collapsed_re: /\bcollapsed\b/, // Class that fieldsets get when they're hidden.
|
||||||
collapsed_class: 'collapsed',
|
collapsed_class: 'collapsed',
|
||||||
init: function() {
|
init: function() {
|
||||||
var fieldsets = document.getElementsByTagName('fieldset');
|
var fieldsets = document.getElementsByTagName('fieldset');
|
||||||
var collapsed_seen = false;
|
var collapsed_seen = false;
|
||||||
for (var i = 0, fs; fs = fieldsets[i]; i++) {
|
for (var i = 0, fs; fs = fieldsets[i]; i++) {
|
||||||
// Collapse this fieldset if it has the correct class, and if it
|
// Collapse this fieldset if it has the correct class, and if it
|
||||||
// doesn't have any errors. (Collapsing shouldn't apply in the case
|
// doesn't have any errors. (Collapsing shouldn't apply in the case
|
||||||
// of error messages.)
|
// of error messages.)
|
||||||
if (fs.className.match(CollapsedFieldsets.collapse_re) && !CollapsedFieldsets.fieldset_has_errors(fs)) {
|
if (fs.className.match(CollapsedFieldsets.collapse_re) && !CollapsedFieldsets.fieldset_has_errors(fs)) {
|
||||||
collapsed_seen = true;
|
collapsed_seen = true;
|
||||||
// Give it an additional class, used by CSS to hide it.
|
// Give it an additional class, used by CSS to hide it.
|
||||||
fs.className += ' ' + CollapsedFieldsets.collapsed_class;
|
fs.className += ' ' + CollapsedFieldsets.collapsed_class;
|
||||||
// (<a id="fieldsetcollapser3" class="collapse-toggle" href="#">Show</a>)
|
// (<a id="fieldsetcollapser3" class="collapse-toggle" href="#">Show</a>)
|
||||||
var collapse_link = document.createElement('a');
|
var collapse_link = document.createElement('a');
|
||||||
collapse_link.className = 'collapse-toggle';
|
collapse_link.className = 'collapse-toggle';
|
||||||
collapse_link.id = 'fieldsetcollapser' + i;
|
collapse_link.id = 'fieldsetcollapser' + i;
|
||||||
collapse_link.onclick = new Function('CollapsedFieldsets.show('+i+'); return false;');
|
collapse_link.onclick = new Function('CollapsedFieldsets.show('+i+'); return false;');
|
||||||
collapse_link.href = '#';
|
collapse_link.href = '#';
|
||||||
collapse_link.innerHTML = gettext('Show');
|
collapse_link.innerHTML = gettext('Show');
|
||||||
var h2 = fs.getElementsByTagName('h2')[0];
|
var h2 = fs.getElementsByTagName('h2')[0];
|
||||||
h2.appendChild(document.createTextNode(' ('));
|
h2.appendChild(document.createTextNode(' ('));
|
||||||
h2.appendChild(collapse_link);
|
h2.appendChild(collapse_link);
|
||||||
h2.appendChild(document.createTextNode(')'));
|
h2.appendChild(document.createTextNode(')'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (collapsed_seen) {
|
if (collapsed_seen) {
|
||||||
// Expand all collapsed fieldsets when form is submitted.
|
// Expand all collapsed fieldsets when form is submitted.
|
||||||
addEvent(findForm(document.getElementsByTagName('fieldset')[0]), 'submit', function() { CollapsedFieldsets.uncollapse_all(); });
|
addEvent(findForm(document.getElementsByTagName('fieldset')[0]), 'submit', function() { CollapsedFieldsets.uncollapse_all(); });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fieldset_has_errors: function(fs) {
|
fieldset_has_errors: function(fs) {
|
||||||
// Returns true if any fields in the fieldset have validation errors.
|
// Returns true if any fields in the fieldset have validation errors.
|
||||||
var divs = fs.getElementsByTagName('div');
|
var divs = fs.getElementsByTagName('div');
|
||||||
for (var i=0; i<divs.length; i++) {
|
for (var i=0; i<divs.length; i++) {
|
||||||
if (divs[i].className.match(/\berror\b/)) {
|
if (divs[i].className.match(/\berror\b/)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
show: function(fieldset_index) {
|
show: function(fieldset_index) {
|
||||||
var fs = document.getElementsByTagName('fieldset')[fieldset_index];
|
var fs = document.getElementsByTagName('fieldset')[fieldset_index];
|
||||||
// Remove the class name that causes the "display: none".
|
// Remove the class name that causes the "display: none".
|
||||||
fs.className = fs.className.replace(CollapsedFieldsets.collapsed_re, '');
|
fs.className = fs.className.replace(CollapsedFieldsets.collapsed_re, '');
|
||||||
// Toggle the "Show" link to a "Hide" link
|
// Toggle the "Show" link to a "Hide" link
|
||||||
var collapse_link = document.getElementById('fieldsetcollapser' + fieldset_index);
|
var collapse_link = document.getElementById('fieldsetcollapser' + fieldset_index);
|
||||||
collapse_link.onclick = new Function('CollapsedFieldsets.hide('+fieldset_index+'); return false;');
|
collapse_link.onclick = new Function('CollapsedFieldsets.hide('+fieldset_index+'); return false;');
|
||||||
collapse_link.innerHTML = gettext('Hide');
|
collapse_link.innerHTML = gettext('Hide');
|
||||||
},
|
},
|
||||||
hide: function(fieldset_index) {
|
hide: function(fieldset_index) {
|
||||||
var fs = document.getElementsByTagName('fieldset')[fieldset_index];
|
var fs = document.getElementsByTagName('fieldset')[fieldset_index];
|
||||||
// Add the class name that causes the "display: none".
|
// Add the class name that causes the "display: none".
|
||||||
fs.className += ' ' + CollapsedFieldsets.collapsed_class;
|
fs.className += ' ' + CollapsedFieldsets.collapsed_class;
|
||||||
// Toggle the "Hide" link to a "Show" link
|
// Toggle the "Hide" link to a "Show" link
|
||||||
var collapse_link = document.getElementById('fieldsetcollapser' + fieldset_index);
|
var collapse_link = document.getElementById('fieldsetcollapser' + fieldset_index);
|
||||||
collapse_link.onclick = new Function('CollapsedFieldsets.show('+fieldset_index+'); return false;');
|
collapse_link.onclick = new Function('CollapsedFieldsets.show('+fieldset_index+'); return false;');
|
||||||
collapse_link.innerHTML = gettext('Show');
|
collapse_link.innerHTML = gettext('Show');
|
||||||
},
|
},
|
||||||
|
|
||||||
uncollapse_all: function() {
|
uncollapse_all: function() {
|
||||||
var fieldsets = document.getElementsByTagName('fieldset');
|
var fieldsets = document.getElementsByTagName('fieldset');
|
||||||
for (var i=0; i<fieldsets.length; i++) {
|
for (var i=0; i<fieldsets.length; i++) {
|
||||||
if (fieldsets[i].className.match(CollapsedFieldsets.collapsed_re)) {
|
if (fieldsets[i].className.match(CollapsedFieldsets.collapsed_re)) {
|
||||||
CollapsedFieldsets.show(i);
|
CollapsedFieldsets.show(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addEvent(window, 'load', CollapsedFieldsets.init);
|
addEvent(window, 'load', CollapsedFieldsets.init);
|
||||||
|
@ -20,13 +20,13 @@
|
|||||||
<div id="branding">
|
<div id="branding">
|
||||||
{% block branding %}{% endblock %}
|
{% block branding %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% if not user.is_anonymous %}{% if user.is_staff %}
|
{% if user.is_authenticated and user.is_staff %}
|
||||||
<div id="user-tools">{% trans 'Welcome,' %} <strong>{% if user.first_name %}{{ user.first_name|escape }}{% else %}{{ user.username }}{% endif %}</strong>. {% block userlinks %}<a href="doc/">{% trans 'Documentation' %}</a> / <a href="password_change/">{% trans 'Change password' %}</a> / <a href="logout/">{% trans 'Log out' %}</a>{% endblock %}</div>
|
<div id="user-tools">{% trans 'Welcome,' %} <strong>{% if user.first_name %}{{ user.first_name|escape }}{% else %}{{ user.username }}{% endif %}</strong>. {% block userlinks %}<a href="doc/">{% trans 'Documentation' %}</a> / <a href="password_change/">{% trans 'Change password' %}</a> / <a href="logout/">{% trans 'Log out' %}</a>{% endblock %}</div>
|
||||||
{% endif %}{% endif %}
|
{% endif %}
|
||||||
{% block nav-global %}{% endblock %}
|
{% block nav-global %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
<!-- END Header -->
|
<!-- END Header -->
|
||||||
{% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans 'Home' %}</a>{% if title %} › {{ title }}{% endif %}</div>{% endblock %}
|
{% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans 'Home' %}</a>{% if title %} › {{ title|escape }}{% endif %}</div>{% endblock %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
@ -36,7 +36,7 @@
|
|||||||
<!-- Content -->
|
<!-- Content -->
|
||||||
<div id="content" class="{% block coltype %}colM{% endblock %}">
|
<div id="content" class="{% block coltype %}colM{% endblock %}">
|
||||||
{% block pretitle %}{% endblock %}
|
{% block pretitle %}{% endblock %}
|
||||||
{% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}{% endblock %}
|
{% block content_title %}{% if title %}<h1>{{ title|escape }}</h1>{% endif %}{% endblock %}
|
||||||
{% block content %}{{ content }}{% endblock %}
|
{% block content %}{{ content }}{% endblock %}
|
||||||
{% block sidebar %}{% endblock %}
|
{% block sidebar %}{% endblock %}
|
||||||
<br class="clear" />
|
<br class="clear" />
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% extends "admin/base.html" %}
|
{% extends "admin/base.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %}
|
{% block title %}{{ title|escape }} | {% trans 'Django site admin' %}{% endblock %}
|
||||||
|
|
||||||
{% block branding %}
|
{% block branding %}
|
||||||
<h1 id="site-name">{% trans 'Django administration' %}</h1>
|
<h1 id="site-name">{% trans 'Django administration' %}</h1>
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
{% block breadcrumbs %}{% if not is_popup %}
|
{% block breadcrumbs %}{% if not is_popup %}
|
||||||
<div class="breadcrumbs">
|
<div class="breadcrumbs">
|
||||||
<a href="../../../">{% trans "Home" %}</a> ›
|
<a href="../../../">{% trans "Home" %}</a> ›
|
||||||
<a href="../">{{ opts.verbose_name_plural|capfirst }}</a> ›
|
<a href="../">{{ opts.verbose_name_plural|capfirst|escape }}</a> ›
|
||||||
{% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18"|escape }}{% endif %}
|
{% if add %}{% trans "Add" %} {{ opts.verbose_name|escape }}{% else %}{{ original|truncatewords:"18"|escape }}{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}{% endblock %}
|
{% endif %}{% endblock %}
|
||||||
{% block content %}<div id="content-main">
|
{% block content %}<div id="content-main">
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
{% block stylesheet %}{% admin_media_prefix %}css/changelists.css{% endblock %}
|
{% block stylesheet %}{% admin_media_prefix %}css/changelists.css{% endblock %}
|
||||||
{% block bodyclass %}change-list{% endblock %}
|
{% block bodyclass %}change-list{% endblock %}
|
||||||
{% block userlinks %}<a href="../../doc/">{% trans 'Documentation' %}</a> / <a href="../../password_change/">{% trans 'Change password' %}</a> / <a href="../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
{% block userlinks %}<a href="../../doc/">{% trans 'Documentation' %}</a> / <a href="../../password_change/">{% trans 'Change password' %}</a> / <a href="../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
||||||
{% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> › {{ cl.opts.verbose_name_plural|capfirst }}</div>{% endblock %}{% endif %}
|
{% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> › {{ cl.opts.verbose_name_plural|capfirst|escape }}</div>{% endblock %}{% endif %}
|
||||||
{% block coltype %}flex{% endblock %}
|
{% block coltype %}flex{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="content-main">
|
<div id="content-main">
|
||||||
{% if has_add_permission %}
|
{% if has_add_permission %}
|
||||||
<ul class="object-tools"><li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a></li></ul>
|
<ul class="object-tools"><li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name|escape as name %}Add {{ name }}{% endblocktrans %}</a></li></ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
|
<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
|
||||||
{% block search %}{% search_form cl %}{% endblock %}
|
{% block search %}{% search_form cl %}{% endblock %}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{% if show %}
|
{% if show %}
|
||||||
<div class="xfull">
|
<div class="xfull">
|
||||||
<ul class="toplinks">
|
<ul class="toplinks">
|
||||||
{% if back %}<li class="date-back"><a href="{{ back.link }}">‹ {{ back.title }}</a></li>{% endif %}
|
{% if back %}<li class="date-back"><a href="{{ back.link }}">‹ {{ back.title|escape }}</a></li>{% endif %}
|
||||||
{% for choice in choices %}
|
{% for choice in choices %}
|
||||||
<li> {% if choice.link %}<a href="{{ choice.link }}">{% endif %}{{ choice.title }}{% if choice.link %}</a>{% endif %}</li>
|
<li> {% if choice.link %}<a href="{{ choice.link }}">{% endif %}{{ choice.title|escape }}{% if choice.link %}</a>{% endif %}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul><br class="clear" />
|
</ul><br class="clear" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,21 +4,21 @@
|
|||||||
{% block breadcrumbs %}
|
{% block breadcrumbs %}
|
||||||
<div class="breadcrumbs">
|
<div class="breadcrumbs">
|
||||||
<a href="../../../../">{% trans "Home" %}</a> ›
|
<a href="../../../../">{% trans "Home" %}</a> ›
|
||||||
<a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> ›
|
<a href="../../">{{ opts.verbose_name_plural|capfirst|escape }}</a> ›
|
||||||
<a href="../">{{ object|striptags|truncatewords:"18" }}</a> ›
|
<a href="../">{{ object|escape|truncatewords:"18" }}</a> ›
|
||||||
{% trans 'Delete' %}
|
{% trans 'Delete' %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if perms_lacking %}
|
{% if perms_lacking %}
|
||||||
<p>{% blocktrans %}Deleting the {{ object_name }} '{{ object }}' would result in deleting related objects, but your account doesn't have permission to delete the following types of objects:{% endblocktrans %}</p>
|
<p>{% blocktrans with object|escape as escaped_object %}Deleting the {{ object_name }} '{{ escaped_object }}' would result in deleting related objects, but your account doesn't have permission to delete the following types of objects:{% endblocktrans %}</p>
|
||||||
<ul>
|
<ul>
|
||||||
{% for obj in perms_lacking %}
|
{% for obj in perms_lacking %}
|
||||||
<li>{{ obj }}</li>
|
<li>{{ obj|escape }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>{% blocktrans %}Are you sure you want to delete the {{ object_name }} "{{ object }}"? All of the following related items will be deleted:{% endblocktrans %}</p>
|
<p>{% blocktrans with object|escape as escaped_object %}Are you sure you want to delete the {{ object_name }} "{{ escaped_object }}"? All of the following related items will be deleted:{% endblocktrans %}</p>
|
||||||
<ul>{{ deleted_objects|unordered_list }}</ul>
|
<ul>{{ deleted_objects|unordered_list }}</ul>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<div>
|
<div>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% load admin_modify %}
|
{% load admin_modify %}
|
||||||
<fieldset class="module aligned">
|
<fieldset class="module aligned">
|
||||||
{% for fcw in bound_related_object.form_field_collection_wrappers %}
|
{% for fcw in bound_related_object.form_field_collection_wrappers %}
|
||||||
<h2>{{ bound_related_object.relation.opts.verbose_name|capfirst }} #{{ forloop.counter }}</h2>
|
<h2>{{ bound_related_object.relation.opts.verbose_name|capfirst|escape }} #{{ forloop.counter }}</h2>
|
||||||
{% if bound_related_object.show_url %}{% if fcw.obj.original %}
|
{% if bound_related_object.show_url %}{% if fcw.obj.original %}
|
||||||
<p><a href="/r/{{ fcw.obj.original.content_type_id }}/{{ fcw.obj.original.id }}/">View on site</a></p>
|
<p><a href="/r/{{ fcw.obj.original.content_type_id }}/{{ fcw.obj.original.id }}/">View on site</a></p>
|
||||||
{% endif %}{% endif %}
|
{% endif %}{% endif %}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{% load admin_modify %}
|
{% load admin_modify %}
|
||||||
<fieldset class="module">
|
<fieldset class="module">
|
||||||
<h2>{{ bound_related_object.relation.opts.verbose_name_plural|capfirst }}</h2><table>
|
<h2>{{ bound_related_object.relation.opts.verbose_name_plural|capfirst|escape }}</h2><table>
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
{% for fw in bound_related_object.field_wrapper_list %}
|
{% for fw in bound_related_object.field_wrapper_list %}
|
||||||
{% if fw.needs_header %}
|
{% if fw.needs_header %}
|
||||||
<th{{ fw.header_class_attribute }}>{{ fw.field.verbose_name|capfirst }}</th>
|
<th{{ fw.header_class_attribute }}>{{ fw.field.verbose_name|capfirst|escape }}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for fcw in bound_related_object.form_field_collection_wrappers %}
|
{% for fcw in bound_related_object.form_field_collection_wrappers %}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<h3>{% blocktrans %} By {{ title }} {% endblocktrans %}</h3>
|
<h3>{% blocktrans with title|escape as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{% for choice in choices %}
|
{% for choice in choices %}
|
||||||
<li{% if choice.selected %} class="selected"{% endif %}>
|
<li{% if choice.selected %} class="selected"{% endif %}>
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
{% for model in app.models %}
|
{% for model in app.models %}
|
||||||
<tr>
|
<tr>
|
||||||
{% if model.perms.change %}
|
{% if model.perms.change %}
|
||||||
<th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
|
<th scope="row"><a href="{{ model.admin_url }}">{{ model.name|escape }}</a></th>
|
||||||
{% else %}
|
{% else %}
|
||||||
<th scope="row">{{ model.name }}</th>
|
<th scope="row">{{ model.name|escape }}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if model.perms.add %}
|
{% if model.perms.add %}
|
||||||
@ -58,7 +58,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<ul class="actionlist">
|
<ul class="actionlist">
|
||||||
{% for entry in admin_log %}
|
{% for entry in admin_log %}
|
||||||
<li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">{% if not entry.is_deletion %}<a href="{{ entry.get_admin_url }}">{% endif %}{{ entry.object_repr|escape }}{% if not entry.is_deletion %}</a>{% endif %}<br /><span class="mini quiet">{{ entry.content_type.name|capfirst }}</span></li>
|
<li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">{% if not entry.is_deletion %}<a href="{{ entry.get_admin_url }}">{% endif %}{{ entry.object_repr|escape }}{% if not entry.is_deletion %}</a>{% endif %}<br /><span class="mini quiet">{{ entry.content_type.name|capfirst|escape }}</span></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% extends "admin/base_site.html" %}
|
{% extends "admin/base_site.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans 'Home' %}</a> › {{ title }}</div>{% endblock %}
|
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans 'Home' %}</a> › {{ title|escape }}</div>{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
@ -13,17 +13,17 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<div id="content-main">
|
<div id="content-main">
|
||||||
<form action="{{ app_path }}" method="post" id="login-form">
|
<form action="{{ app_path }}" method="post" id="login-form">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="id_username">{% trans 'Username:' %}</label> <input type="text" name="username" id="id_username" />
|
<label for="id_username">{% trans 'Username:' %}</label> <input type="text" name="username" id="id_username" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="id_password">{% trans 'Password:' %}</label> <input type="password" name="password" id="id_password" />
|
<label for="id_password">{% trans 'Password:' %}</label> <input type="password" name="password" id="id_password" />
|
||||||
<input type="hidden" name="this_is_the_login_form" value="1" />
|
<input type="hidden" name="this_is_the_login_form" value="1" />
|
||||||
<input type="hidden" name="post_data" value="{{ post_data }}" /> {% comment %}<span class="help">{% trans 'Have you <a href="/password_reset/">forgotten your password</a>?' %}</span>{% endcomment %}
|
<input type="hidden" name="post_data" value="{{ post_data }}" /> {% comment %}<span class="help">{% trans 'Have you <a href="/password_reset/">forgotten your password</a>?' %}</span>{% endcomment %}
|
||||||
</div>
|
</div>
|
||||||
<div class="submit-row">
|
<div class="submit-row">
|
||||||
<label> </label><input type="submit" value="{% trans 'Log in' %}" />
|
<label> </label><input type="submit" value="{% trans 'Log in' %}" />
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block userlinks %}<a href="../../../../doc/">{% trans 'Documentation' %}</a> / <a href="../../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
{% block userlinks %}<a href="../../../../doc/">{% trans 'Documentation' %}</a> / <a href="../../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
||||||
{% block breadcrumbs %}
|
{% block breadcrumbs %}
|
||||||
<div class="breadcrumbs"><a href="../../../../">{% trans 'Home' %}</a> › <a href="../../">{{ module_name }}</a> › <a href="../">{{ object|truncatewords:"18" }}</a> › {% trans 'History' %}</div>
|
<div class="breadcrumbs"><a href="../../../../">{% trans 'Home' %}</a> › <a href="../../">{{ module_name|escape }}</a> › <a href="../">{{ object|escape|truncatewords:"18" }}</a> › {% trans 'History' %}</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
{% paginator_number cl i %}
|
{% paginator_number cl i %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ cl.result_count }} {% ifequal cl.result_count 1 %}{{ cl.opts.verbose_name }}{% else %}{{ cl.opts.verbose_name_plural }}{% endifequal %}
|
{{ cl.result_count }} {% ifequal cl.result_count 1 %}{{ cl.opts.verbose_name|escape }}{% else %}{{ cl.opts.verbose_name_plural|escape }}{% endifequal %}
|
||||||
{% if show_all_url %} <a href="{{ show_all_url }}" class="showall">{% trans 'Show all' %}</a>{% endif %}
|
{% if show_all_url %} <a href="{{ show_all_url }}" class="showall">{% trans 'Show all' %}</a>{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
@ -9,17 +9,17 @@
|
|||||||
<h1>Documentation</h1>
|
<h1>Documentation</h1>
|
||||||
|
|
||||||
<div id="content-main">
|
<div id="content-main">
|
||||||
<h3><a href="tags/">Tags</a></h3>
|
<h3><a href="tags/">Tags</a></h3>
|
||||||
<p>List of all the template tags and their functions.</p>
|
<p>List of all the template tags and their functions.</p>
|
||||||
|
|
||||||
<h3><a href="filters/">Filters</a></h3>
|
<h3><a href="filters/">Filters</a></h3>
|
||||||
<p>Filters are actions which can be applied to variables in a template to alter the output.</p>
|
<p>Filters are actions which can be applied to variables in a template to alter the output.</p>
|
||||||
|
|
||||||
<h3><a href="models/">Models</a></h3>
|
<h3><a href="models/">Models</a></h3>
|
||||||
<p>Models are descriptions of all the objects in the system and their associated fields. Each model has a list of fields which can be accessed as template variables.</p>
|
<p>Models are descriptions of all the objects in the system and their associated fields. Each model has a list of fields which can be accessed as template variables.</p>
|
||||||
|
|
||||||
<h3><a href="views/">Views</a></h3>
|
<h3><a href="views/">Views</a></h3>
|
||||||
<p>Each page on the public site is generated by a view. The view defines which template is used to generate the page and which objects are available to that template.</p>
|
<p>Each page on the public site is generated by a view. The view defines which template is used to generate the page and which objects are available to that template.</p>
|
||||||
|
|
||||||
<h3><a href="bookmarklets/">Bookmarklets</a></h3>
|
<h3><a href="bookmarklets/">Bookmarklets</a></h3>
|
||||||
<p>Tools for your browser to quickly access admin functionality.</p>
|
<p>Tools for your browser to quickly access admin functionality.</p>
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
<h1>Documentation</h1>
|
<h1>Documentation</h1>
|
||||||
|
|
||||||
<div id="content-main">
|
<div id="content-main">
|
||||||
<h3>The admin documentation system requires Python's <a href="http://docutils.sf.net/">docutils</a> library.</h3>
|
<h3>The admin documentation system requires Python's <a href="http://docutils.sf.net/">docutils</a> library.</h3>
|
||||||
|
|
||||||
<p>Please ask your administrators to install <a href="http://docutils.sf.net/">docutils</a>.</p>
|
<p>Please ask your administrators to install <a href="http://docutils.sf.net/">docutils</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -9,13 +9,13 @@
|
|||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../../">Home</a> › <a href="../../">Documentation</a> › <a href="../">Models</a> › {{ name }}</div>{% endblock %}
|
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../../">Home</a> › <a href="../../">Documentation</a> › <a href="../">Models</a> › {{ name|escape }}</div>{% endblock %}
|
||||||
|
|
||||||
{% block title %}Model: {{ name }}{% endblock %}
|
{% block title %}Model: {{ name|escape }}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="content-main">
|
<div id="content-main">
|
||||||
<h1>{{ summary }}</h1>
|
<h1>{{ summary|escape }}</h1>
|
||||||
|
|
||||||
{% if description %}
|
{% if description %}
|
||||||
<p>{% filter escape|linebreaksbr %}{% trans description %}{% endfilter %}</p>
|
<p>{% filter escape|linebreaksbr %}{% trans description %}{% endfilter %}</p>
|
||||||
@ -35,7 +35,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ field.name }}</td>
|
<td>{{ field.name }}</td>
|
||||||
<td>{{ field.data_type }}</td>
|
<td>{{ field.data_type }}</td>
|
||||||
<td>{% if field.verbose %}{{ field.verbose }}{% endif %}{% if field.help_text %} - {{ field.help_text }}{% endif %}</td>
|
<td>{% if field.verbose %}{{ field.verbose|escape }}{% endif %}{% if field.help_text %} - {{ field.help_text|escape }}{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
{% extends "admin/base_site.html" %}
|
{% extends "admin/base_site.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../../">Home</a> › <a href="../../">Documentation</a> › Templates › {{ name }}</div>{% endblock %}
|
{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../../">Home</a> › <a href="../../">Documentation</a> › Templates › {{ name|escape }}</div>{% endblock %}
|
||||||
{% block userlinks %}<a href="../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
{% block userlinks %}<a href="../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../logout/">{% trans 'Log out' %}</a>{% endblock %}
|
||||||
|
|
||||||
{% block title %}Template: {{ name }}{% endblock %}
|
{% block title %}Template: {{ name|escape }}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Template: "{{ name }}"</h1>
|
<h1>Template: "{{ name|escape }}"</h1>
|
||||||
|
|
||||||
{% regroup templates|dictsort:"site_id" by site as templates_by_site %}
|
{% regroup templates|dictsort:"site_id" by site as templates_by_site %}
|
||||||
{% for group in templates_by_site %}
|
{% for group in templates_by_site %}
|
||||||
<h2>Search path for template "{{ name }}" on {{ group.grouper }}:</h2>
|
<h2>Search path for template "{{ name|escape }}" on {{ group.grouper }}:</h2>
|
||||||
<ol>
|
<ol>
|
||||||
{% for template in group.list|dictsort:"order" %}
|
{% for template in group.list|dictsort:"order" %}
|
||||||
<li><code>{{ template.file }}</code>{% if not template.exists %} <em>(does not exist)</em>{% endif %}</li>
|
<li><code>{{ template.file|escape }}</code>{% if not template.exists %} <em>(does not exist)</em>{% endif %}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ol>
|
</ol>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<h1>{{ name }}</h1>
|
<h1>{{ name }}</h1>
|
||||||
|
|
||||||
<h2 class="subhead">{{ summary }}</h2>
|
<h2 class="subhead">{{ summary|escape }}</h2>
|
||||||
|
|
||||||
<p>{{ body }}</p>
|
<p>{{ body }}</p>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% load admin_modify i18n %}{% if bound_field.original_value %}
|
{% load admin_modify i18n %}{% if bound_field.original_value %}
|
||||||
{% trans "Currently:" %} <a href="{{ bound_field.original_url }}" > {{ bound_field.original_value }} </a><br />
|
{% trans "Currently:" %} <a href="{{ bound_field.original_url }}" > {{ bound_field.original_value|escape }} </a><br />
|
||||||
{% trans "Change:" %}{% output_all bound_field.form_fields %}
|
{% trans "Change:" %}{% output_all bound_field.form_fields %}
|
||||||
{% else %} {% output_all bound_field.form_fields %} {% endif %}
|
{% else %} {% output_all bound_field.form_fields %} {% endif %}
|
||||||
|
@ -15,6 +15,6 @@
|
|||||||
{{ bound_field.original_value }}
|
{{ bound_field.original_value }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if bound_field.raw_id_admin %}
|
{% if bound_field.raw_id_admin %}
|
||||||
{% if bound_field.existing_display %} <strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}
|
{% if bound_field.existing_display %} <strong>{{ bound_field.existing_display|truncatewords:"14"|escape }}</strong>{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
{% if add %}{% include "widget/foreign.html" %}{% endif %}
|
{% if add %}{% include "widget/foreign.html" %}{% endif %}
|
||||||
{% if change %}{% if bound_field.existing_display %} <strong>{{ bound_field.existing_display|truncatewords:"14" }}</strong>{% endif %}{% endif %}
|
{% if change %}{% if bound_field.existing_display %} <strong>{{ bound_field.existing_display|truncatewords:"14"|escape }}</strong>{% endif %}{% endif %}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
from django import template
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.admin.views.main import MAX_SHOW_ALL_ALLOWED, ALL_VAR
|
from django.contrib.admin.views.main import ALL_VAR, EMPTY_CHANGELIST_VALUE
|
||||||
from django.contrib.admin.views.main import ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR, SEARCH_VAR
|
from django.contrib.admin.views.main import ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR, SEARCH_VAR
|
||||||
from django.contrib.admin.views.main import IS_POPUP_VAR, EMPTY_CHANGELIST_VALUE
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import dateformat
|
from django.utils import dateformat
|
||||||
@ -119,7 +117,7 @@ def items_for_result(cl, result):
|
|||||||
if callable(attr):
|
if callable(attr):
|
||||||
attr = attr()
|
attr = attr()
|
||||||
result_repr = str(attr)
|
result_repr = str(attr)
|
||||||
except AttributeError, ObjectDoesNotExist:
|
except (AttributeError, ObjectDoesNotExist):
|
||||||
result_repr = EMPTY_CHANGELIST_VALUE
|
result_repr = EMPTY_CHANGELIST_VALUE
|
||||||
else:
|
else:
|
||||||
# Strip HTML tags in the resulting text, except if the
|
# Strip HTML tags in the resulting text, except if the
|
||||||
@ -167,11 +165,12 @@ def items_for_result(cl, result):
|
|||||||
result_repr = ' '
|
result_repr = ' '
|
||||||
# If list_display_links not defined, add the link tag to the first field
|
# If list_display_links not defined, add the link tag to the first field
|
||||||
if (first and not cl.lookup_opts.admin.list_display_links) or field_name in cl.lookup_opts.admin.list_display_links:
|
if (first and not cl.lookup_opts.admin.list_display_links) or field_name in cl.lookup_opts.admin.list_display_links:
|
||||||
|
table_tag = {True:'th', False:'td'}[first]
|
||||||
first = False
|
first = False
|
||||||
url = cl.url_for_result(result)
|
url = cl.url_for_result(result)
|
||||||
result_id = str(getattr(result, pk)) # str() is needed in case of 23L (long ints)
|
result_id = str(getattr(result, pk)) # str() is needed in case of 23L (long ints)
|
||||||
yield ('<th%s><a href="%s"%s>%s</a></th>' % \
|
yield ('<%s%s><a href="%s"%s>%s</a></%s>' % \
|
||||||
(row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr))
|
(table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr, table_tag))
|
||||||
else:
|
else:
|
||||||
yield ('<td%s>%s</td>' % (row_class, result_repr))
|
yield ('<td%s>%s</td>' % (row_class, result_repr))
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
from django import template
|
from django import template
|
||||||
from django.contrib.admin.views.main import AdminBoundField
|
from django.contrib.admin.views.main import AdminBoundField
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
from django.utils.html import escape
|
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.functional import curry
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.fields import Field
|
from django.db.models.fields import Field
|
||||||
from django.db.models.related import BoundRelatedObject
|
from django.db.models.related import BoundRelatedObject
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
import re
|
import re
|
||||||
from email.Parser import HeaderParser
|
from email.Parser import HeaderParser
|
||||||
from email.Errors import HeaderParseError
|
from email.Errors import HeaderParseError
|
||||||
from urlparse import urljoin
|
|
||||||
try:
|
try:
|
||||||
import docutils.core
|
import docutils.core
|
||||||
import docutils.nodes
|
import docutils.nodes
|
||||||
|
@ -46,7 +46,7 @@ def staff_member_required(view_func):
|
|||||||
member, displaying the login page if necessary.
|
member, displaying the login page if necessary.
|
||||||
"""
|
"""
|
||||||
def _checklogin(request, *args, **kwargs):
|
def _checklogin(request, *args, **kwargs):
|
||||||
if not request.user.is_anonymous() and request.user.is_staff:
|
if request.user.is_authenticated() and request.user.is_staff:
|
||||||
# The user is valid. Continue to the admin page.
|
# The user is valid. Continue to the admin page.
|
||||||
if request.POST.has_key('post_data'):
|
if request.POST.has_key('post_data'):
|
||||||
# User must have re-authenticated through a different window
|
# User must have re-authenticated through a different window
|
||||||
|
@ -28,7 +28,7 @@ def bookmarklets(request):
|
|||||||
# Hack! This couples this view to the URL it lives at.
|
# Hack! This couples this view to the URL it lives at.
|
||||||
admin_root = request.path[:-len('doc/bookmarklets/')]
|
admin_root = request.path[:-len('doc/bookmarklets/')]
|
||||||
return render_to_response('admin_doc/bookmarklets.html', {
|
return render_to_response('admin_doc/bookmarklets.html', {
|
||||||
'admin_url': "%s://%s%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', get_host(request), admin_root),
|
'admin_url': "%s://%s%s" % (request.is_secure() and 'https' or 'http', get_host(request), admin_root),
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
bookmarklets = staff_member_required(bookmarklets)
|
bookmarklets = staff_member_required(bookmarklets)
|
||||||
|
|
||||||
|
@ -10,9 +10,6 @@ from django.shortcuts import get_object_or_404, render_to_response
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.query import handle_legacy_orderlist, QuerySet
|
from django.db.models.query import handle_legacy_orderlist, QuerySet
|
||||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||||
from django.template import loader
|
|
||||||
from django.utils import dateformat
|
|
||||||
from django.utils.dates import MONTHS
|
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.text import capfirst, get_text_list
|
from django.utils.text import capfirst, get_text_list
|
||||||
import operator
|
import operator
|
||||||
|
@ -22,7 +22,7 @@ def template_validator(request):
|
|||||||
new_data = request.POST.copy()
|
new_data = request.POST.copy()
|
||||||
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.message_set.create(message='The template is valid.')
|
||||||
return render_to_response('admin/template_validator.html', {
|
return render_to_response('admin/template_validator.html', {
|
||||||
'title': 'Template validator',
|
'title': 'Template validator',
|
||||||
'form': forms.FormWrapper(manipulator, new_data, errors),
|
'form': forms.FormWrapper(manipulator, new_data, errors),
|
||||||
@ -32,7 +32,7 @@ template_validator = staff_member_required(template_validator)
|
|||||||
class TemplateValidator(forms.Manipulator):
|
class TemplateValidator(forms.Manipulator):
|
||||||
def __init__(self, settings_modules):
|
def __init__(self, settings_modules):
|
||||||
self.settings_modules = settings_modules
|
self.settings_modules = settings_modules
|
||||||
site_list = Site.objects.get_in_bulk(settings_modules.keys()).values()
|
site_list = Site.objects.in_bulk(settings_modules.keys()).values()
|
||||||
self.fields = (
|
self.fields = (
|
||||||
forms.SelectField('site', is_required=True, choices=[(s.id, s.name) for s in site_list]),
|
forms.SelectField('site', is_required=True, choices=[(s.id, s.name) for s in site_list]),
|
||||||
forms.LargeTextField('template', is_required=True, rows=25, validator_list=[self.isValidTemplate]),
|
forms.LargeTextField('template', is_required=True, rows=25, validator_list=[self.isValidTemplate]),
|
||||||
|
@ -38,7 +38,7 @@ def authenticate(**credentials):
|
|||||||
if user is None:
|
if user is None:
|
||||||
continue
|
continue
|
||||||
# Annotate the user object with the path of the backend.
|
# Annotate the user object with the path of the backend.
|
||||||
user.backend = str(backend.__class__)
|
user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def login(request, user):
|
def login(request, user):
|
||||||
@ -56,8 +56,14 @@ def logout(request):
|
|||||||
"""
|
"""
|
||||||
Remove the authenticated user's ID from the request.
|
Remove the authenticated user's ID from the request.
|
||||||
"""
|
"""
|
||||||
del request.session[SESSION_KEY]
|
try:
|
||||||
del request.session[BACKEND_SESSION_KEY]
|
del request.session[SESSION_KEY]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
del request.session[BACKEND_SESSION_KEY]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
def get_user(request):
|
def get_user(request):
|
||||||
from django.contrib.auth.models import AnonymousUser
|
from django.contrib.auth.models import AnonymousUser
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from django.contrib.auth.models import User, check_password
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
class ModelBackend:
|
class ModelBackend:
|
||||||
"""
|
"""
|
||||||
|
@ -17,7 +17,7 @@ def user_passes_test(test_func, login_url=LOGIN_URL):
|
|||||||
return _checklogin
|
return _checklogin
|
||||||
return _dec
|
return _dec
|
||||||
|
|
||||||
login_required = user_passes_test(lambda u: not u.is_anonymous())
|
login_required = user_passes_test(lambda u: u.is_authenticated())
|
||||||
login_required.__doc__ = (
|
login_required.__doc__ = (
|
||||||
"""
|
"""
|
||||||
Decorator for views that checks that the user is logged in, redirecting
|
Decorator for views that checks that the user is logged in, redirecting
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from django.core import validators
|
from django.core import validators
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.db import backend, connection, models
|
from django.db import backend, connection, models
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -126,6 +127,11 @@ class User(models.Model):
|
|||||||
"Always returns False. This is a way of comparing User objects to anonymous users."
|
"Always returns False. This is a way of comparing User objects to anonymous users."
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_authenticated(self):
|
||||||
|
"""Always return True. This is a way to tell if the user has been authenticated in templates.
|
||||||
|
"""
|
||||||
|
return True
|
||||||
|
|
||||||
def get_full_name(self):
|
def get_full_name(self):
|
||||||
"Returns the first_name plus the last_name, with a space in between."
|
"Returns the first_name plus the last_name, with a space in between."
|
||||||
full_name = '%s %s' % (self.first_name, self.last_name)
|
full_name = '%s %s' % (self.first_name, self.last_name)
|
||||||
@ -293,3 +299,6 @@ class AnonymousUser(object):
|
|||||||
|
|
||||||
def is_anonymous(self):
|
def is_anonymous(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def is_authenticated(self):
|
||||||
|
return False
|
||||||
|
@ -4,7 +4,7 @@ from django import forms
|
|||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.http import HttpResponse, HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth import LOGIN_URL, REDIRECT_FIELD_NAME
|
from django.contrib.auth import LOGIN_URL, REDIRECT_FIELD_NAME
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.comments.models import Comment, FreeComment
|
from django.contrib.comments.models import Comment, FreeComment
|
||||||
from django.contrib.syndication.feeds import Feed
|
from django.contrib.syndication.feeds import Feed
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
|
|
||||||
class LatestFreeCommentsFeed(Feed):
|
class LatestFreeCommentsFeed(Feed):
|
||||||
@ -37,6 +36,6 @@ class LatestCommentsFeed(LatestFreeCommentsFeed):
|
|||||||
qs = qs.filter(is_removed=False)
|
qs = qs.filter(is_removed=False)
|
||||||
if settings.COMMENTS_BANNED_USERS_GROUP:
|
if settings.COMMENTS_BANNED_USERS_GROUP:
|
||||||
where = ['user_id NOT IN (SELECT user_id FROM auth_users_group WHERE group_id = %s)']
|
where = ['user_id NOT IN (SELECT user_id FROM auth_users_group WHERE group_id = %s)']
|
||||||
params = [COMMENTS_BANNED_USERS_GROUP]
|
params = [settings.COMMENTS_BANNED_USERS_GROUP]
|
||||||
qs = qs.extra(where=where, params=params)
|
qs = qs.extra(where=where, params=params)
|
||||||
return qs
|
return qs
|
||||||
|
@ -51,7 +51,7 @@ class CommentManager(models.Manager):
|
|||||||
extra_kwargs.setdefault('select', {})
|
extra_kwargs.setdefault('select', {})
|
||||||
extra_kwargs['select']['_karma_total_good'] = 'SELECT COUNT(*) FROM comments_karmascore, comments_comment WHERE comments_karmascore.comment_id=comments_comment.id AND score=1'
|
extra_kwargs['select']['_karma_total_good'] = 'SELECT COUNT(*) FROM comments_karmascore, comments_comment WHERE comments_karmascore.comment_id=comments_comment.id AND score=1'
|
||||||
extra_kwargs['select']['_karma_total_bad'] = 'SELECT COUNT(*) FROM comments_karmascore, comments_comment WHERE comments_karmascore.comment_id=comments_comment.id AND score=-1'
|
extra_kwargs['select']['_karma_total_bad'] = 'SELECT COUNT(*) FROM comments_karmascore, comments_comment WHERE comments_karmascore.comment_id=comments_comment.id AND score=-1'
|
||||||
return self.filter(**kwargs).extra(**extra_kwargs)
|
return self.filter(**kwargs).extra(**extra_kwargs)
|
||||||
|
|
||||||
def user_is_moderator(self, user):
|
def user_is_moderator(self, user):
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
{% if display_form %}
|
{% if display_form %}
|
||||||
<form {% if photos_optional or photos_required %}enctype="multipart/form-data" {% endif %}action="/comments/post/" method="post">
|
<form {% if photos_optional or photos_required %}enctype="multipart/form-data" {% endif %}action="/comments/post/" method="post">
|
||||||
|
|
||||||
{% if user.is_anonymous %}
|
{% if user.is_authenticated %}
|
||||||
<p><label for="id_username">{% trans "Username:" %}</label> <input type="text" name="username" id="id_username" /><br />{% trans "Password:" %} <input type="password" name="password" id="id_password" /> (<a href="/accounts/password_reset/">{% trans "Forgotten your password?" %}</a>)</p>
|
|
||||||
{% else %}
|
|
||||||
<p>{% trans "Username:" %} <strong>{{ user.username }}</strong> (<a href="/accounts/logout/">{% trans "Log out" %}</a>)</p>
|
<p>{% trans "Username:" %} <strong>{{ user.username }}</strong> (<a href="/accounts/logout/">{% trans "Log out" %}</a>)</p>
|
||||||
|
{% else %}
|
||||||
|
<p><label for="id_username">{% trans "Username:" %}</label> <input type="text" name="username" id="id_username" /><br />{% trans "Password:" %} <input type="password" name="password" id="id_password" /> (<a href="/accounts/password_reset/">{% trans "Forgotten your password?" %}</a>)</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if ratings_optional or ratings_required %}
|
{% if ratings_optional or ratings_required %}
|
||||||
|
@ -114,7 +114,7 @@ class CommentListNode(template.Node):
|
|||||||
comment_list = get_list_function(**kwargs).order_by(self.ordering + 'submit_date').select_related()
|
comment_list = get_list_function(**kwargs).order_by(self.ordering + 'submit_date').select_related()
|
||||||
|
|
||||||
if not self.free:
|
if not self.free:
|
||||||
if context.has_key('user') and not context['user'].is_anonymous():
|
if context.has_key('user') and context['user'].is_authenticated():
|
||||||
user_id = context['user'].id
|
user_id = context['user'].id
|
||||||
context['user_can_moderate_comments'] = Comment.objects.user_is_moderator(context['user'])
|
context['user_can_moderate_comments'] = Comment.objects.user_is_moderator(context['user'])
|
||||||
else:
|
else:
|
||||||
|
@ -5,7 +5,7 @@ from django.http import Http404
|
|||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.contrib.comments.models import Comment, FreeComment, PHOTOS_REQUIRED, PHOTOS_OPTIONAL, RATINGS_REQUIRED, RATINGS_OPTIONAL, IS_PUBLIC
|
from django.contrib.comments.models import Comment, FreeComment, RATINGS_REQUIRED, RATINGS_OPTIONAL, IS_PUBLIC
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.auth.forms import AuthenticationForm
|
from django.contrib.auth.forms import AuthenticationForm
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
@ -63,7 +63,7 @@ class PublicCommentManipulator(AuthenticationForm):
|
|||||||
validator_list=get_validator_list(8),
|
validator_list=get_validator_list(8),
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
if not user.is_anonymous():
|
if user.is_authenticated():
|
||||||
self["username"].is_required = False
|
self["username"].is_required = False
|
||||||
self["username"].validator_list = []
|
self["username"].validator_list = []
|
||||||
self["password"].is_required = False
|
self["password"].is_required = False
|
||||||
|
@ -15,7 +15,7 @@ def vote(request, comment_id, vote):
|
|||||||
rating = {'up': 1, 'down': -1}.get(vote, False)
|
rating = {'up': 1, 'down': -1}.get(vote, False)
|
||||||
if not rating:
|
if not rating:
|
||||||
raise Http404, "Invalid vote"
|
raise Http404, "Invalid vote"
|
||||||
if request.user.is_anonymous():
|
if not request.user.is_authenticated():
|
||||||
raise Http404, _("Anonymous users cannot vote")
|
raise Http404, _("Anonymous users cannot vote")
|
||||||
try:
|
try:
|
||||||
comment = Comment.objects.get(pk=comment_id)
|
comment = Comment.objects.get(pk=comment_id)
|
||||||
|
@ -22,7 +22,7 @@ def flatpage(request, url):
|
|||||||
f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=settings.SITE_ID)
|
f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=settings.SITE_ID)
|
||||||
# If registration is required for accessing this page, and the user isn't
|
# If registration is required for accessing this page, and the user isn't
|
||||||
# logged in, redirect to the login page.
|
# logged in, redirect to the login page.
|
||||||
if f.registration_required and request.user.is_anonymous():
|
if f.registration_required and not request.user.is_authenticated():
|
||||||
from django.contrib.auth.views import redirect_to_login
|
from django.contrib.auth.views import redirect_to_login
|
||||||
return redirect_to_login(request.path)
|
return redirect_to_login(request.path)
|
||||||
if f.template_name:
|
if f.template_name:
|
||||||
|
@ -32,11 +32,21 @@ class SessionManager(models.Manager):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
class Session(models.Model):
|
class Session(models.Model):
|
||||||
"""Django provides full support for anonymous sessions. The session framework lets you store and retrieve arbitrary data on a per-site-visitor basis. It stores data on the server side and abstracts the sending and receiving of cookies. Cookies contain a session ID -- not the data itself.
|
"""
|
||||||
|
Django provides full support for anonymous sessions. The session
|
||||||
|
framework lets you store and retrieve arbitrary data on a
|
||||||
|
per-site-visitor basis. It stores data on the server side and
|
||||||
|
abstracts the sending and receiving of cookies. Cookies contain a
|
||||||
|
session ID -- not the data itself.
|
||||||
|
|
||||||
The Django sessions framework is entirely cookie-based. It does not fall back to putting session IDs in URLs. This is an intentional design decision. Not only does that behavior make URLs ugly, it makes your site vulnerable to session-ID theft via the "Referer" header.
|
The Django sessions framework is entirely cookie-based. It does
|
||||||
|
not fall back to putting session IDs in URLs. This is an intentional
|
||||||
|
design decision. Not only does that behavior make URLs ugly, it makes
|
||||||
|
your site vulnerable to session-ID theft via the "Referer" header.
|
||||||
|
|
||||||
For complete documentation on using Sessions in your code, consult the sessions documentation that is shipped with Django (also available on the Django website).
|
For complete documentation on using Sessions in your code, consult
|
||||||
|
the sessions documentation that is shipped with Django (also available
|
||||||
|
on the Django website).
|
||||||
"""
|
"""
|
||||||
session_key = models.CharField(_('session key'), maxlength=40, primary_key=True)
|
session_key = models.CharField(_('session key'), maxlength=40, primary_key=True)
|
||||||
session_data = models.TextField(_('session data'))
|
session_data = models.TextField(_('session data'))
|
||||||
|
@ -73,7 +73,7 @@ class Feed(object):
|
|||||||
link = link,
|
link = link,
|
||||||
description = self.__get_dynamic_attr('description', obj),
|
description = self.__get_dynamic_attr('description', obj),
|
||||||
language = settings.LANGUAGE_CODE.decode(),
|
language = settings.LANGUAGE_CODE.decode(),
|
||||||
feed_url = add_domain(current_site, self.feed_url),
|
feed_url = add_domain(current_site, self.__get_dynamic_attr('feed_url', obj)),
|
||||||
author_name = self.__get_dynamic_attr('author_name', obj),
|
author_name = self.__get_dynamic_attr('author_name', obj),
|
||||||
author_link = self.__get_dynamic_attr('author_link', obj),
|
author_link = self.__get_dynamic_attr('author_link', obj),
|
||||||
author_email = self.__get_dynamic_attr('author_email', obj),
|
author_email = self.__get_dynamic_attr('author_email', obj),
|
||||||
|
2
django/core/cache/backends/db.py
vendored
2
django/core/cache/backends/db.py
vendored
@ -1,7 +1,7 @@
|
|||||||
"Database cache backend."
|
"Database cache backend."
|
||||||
|
|
||||||
from django.core.cache.backends.base import BaseCache
|
from django.core.cache.backends.base import BaseCache
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction, DatabaseError
|
||||||
import base64, time
|
import base64, time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
try:
|
try:
|
||||||
|
4
django/core/cache/backends/locmem.py
vendored
4
django/core/cache/backends/locmem.py
vendored
@ -3,10 +3,6 @@
|
|||||||
from django.core.cache.backends.simple import CacheClass as SimpleCacheClass
|
from django.core.cache.backends.simple import CacheClass as SimpleCacheClass
|
||||||
from django.utils.synch import RWLock
|
from django.utils.synch import RWLock
|
||||||
import copy, time
|
import copy, time
|
||||||
try:
|
|
||||||
import cPickle as pickle
|
|
||||||
except ImportError:
|
|
||||||
import pickle
|
|
||||||
|
|
||||||
class CacheClass(SimpleCacheClass):
|
class CacheClass(SimpleCacheClass):
|
||||||
def __init__(self, host, params):
|
def __init__(self, host, params):
|
||||||
|
@ -119,7 +119,6 @@ class BaseHandler(object):
|
|||||||
Returns an HttpResponse that displays a PUBLIC error message for a
|
Returns an HttpResponse that displays a PUBLIC error message for a
|
||||||
fundamental error.
|
fundamental error.
|
||||||
"""
|
"""
|
||||||
from django.core import urlresolvers
|
|
||||||
callback, param_dict = resolver.resolve500()
|
callback, param_dict = resolver.resolve500()
|
||||||
return callback(request, **param_dict)
|
return callback(request, **param_dict)
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ class ModPythonRequest(http.HttpRequest):
|
|||||||
def get_full_path(self):
|
def get_full_path(self):
|
||||||
return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '')
|
return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '')
|
||||||
|
|
||||||
|
def is_secure(self):
|
||||||
|
return self._req.subprocess_env.has_key('HTTPS') and self._req.subprocess_env['HTTPS'] == 'on'
|
||||||
|
|
||||||
def _load_post_and_files(self):
|
def _load_post_and_files(self):
|
||||||
"Populates self._post and self._files"
|
"Populates self._post and self._files"
|
||||||
if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'):
|
if self._req.headers_in.has_key('content-type') and self._req.headers_in['content-type'].startswith('multipart'):
|
||||||
@ -145,7 +148,6 @@ class ModPythonHandler(BaseHandler):
|
|||||||
|
|
||||||
def populate_apache_request(http_response, mod_python_req):
|
def populate_apache_request(http_response, mod_python_req):
|
||||||
"Populates the mod_python request object with an HttpResponse"
|
"Populates the mod_python request object with an HttpResponse"
|
||||||
from django.conf import settings
|
|
||||||
mod_python_req.content_type = http_response['Content-Type']
|
mod_python_req.content_type = http_response['Content-Type']
|
||||||
for key, value in http_response.headers.items():
|
for key, value in http_response.headers.items():
|
||||||
if key != 'Content-Type':
|
if key != 'Content-Type':
|
||||||
|
@ -58,14 +58,16 @@ class WSGIRequest(http.HttpRequest):
|
|||||||
self.method = environ['REQUEST_METHOD'].upper()
|
self.method = environ['REQUEST_METHOD'].upper()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
from pprint import pformat
|
return '<WSGIRequest\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \
|
||||||
return '<DjangoRequest\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' % \
|
|
||||||
(pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
|
(pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
|
||||||
pformat(self.META))
|
pformat(self.META))
|
||||||
|
|
||||||
def get_full_path(self):
|
def get_full_path(self):
|
||||||
return '%s%s' % (self.path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '')
|
return '%s%s' % (self.path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '')
|
||||||
|
|
||||||
|
def is_secure(self):
|
||||||
|
return self.environ.has_key('HTTPS') and self.environ['HTTPS'] == 'on'
|
||||||
|
|
||||||
def _load_post_and_files(self):
|
def _load_post_and_files(self):
|
||||||
# Populates self._post and self._files
|
# Populates self._post and self._files
|
||||||
if self.method == 'POST':
|
if self.method == 'POST':
|
||||||
|
@ -45,8 +45,8 @@ def disable_termcolors():
|
|||||||
global style
|
global style
|
||||||
style = dummy()
|
style = dummy()
|
||||||
|
|
||||||
# Disable terminal coloring on Windows or if somebody's piping the output.
|
# Disable terminal coloring on Windows, Pocket PC, or if somebody's piping the output.
|
||||||
if sys.platform == 'win32' or not sys.stdout.isatty():
|
if sys.platform == 'win32' or sys.platform == 'Pocket PC' or not sys.stdout.isatty():
|
||||||
disable_termcolors()
|
disable_termcolors()
|
||||||
|
|
||||||
def _is_valid_dir_name(s):
|
def _is_valid_dir_name(s):
|
||||||
@ -95,44 +95,39 @@ def get_sql_create(app):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get installed models, so we generate REFERENCES right
|
# Get installed models, so we generate REFERENCES right
|
||||||
installed_models = _get_installed_models(_get_table_list())
|
|
||||||
|
|
||||||
final_output = []
|
final_output = []
|
||||||
models_output = set(installed_models)
|
known_models = set(_get_installed_models(_get_table_list()))
|
||||||
pending_references = {}
|
pending_references = {}
|
||||||
|
|
||||||
app_models = models.get_models(app)
|
app_models = models.get_models(app)
|
||||||
|
|
||||||
for klass in app_models:
|
for model in app_models:
|
||||||
output, references = _get_sql_model_create(klass, models_output)
|
output, references = _get_sql_model_create(model, known_models)
|
||||||
final_output.extend(output)
|
final_output.extend(output)
|
||||||
for refto, refs in references.items():
|
for refto, refs in references.items():
|
||||||
try:
|
pending_references.setdefault(refto,[]).extend(refs)
|
||||||
pending_references[refto].extend(refs)
|
final_output.extend(_get_sql_for_pending_references(model, pending_references))
|
||||||
except KeyError:
|
|
||||||
pending_references[refto] = refs
|
|
||||||
final_output.extend(_get_sql_for_pending_references(klass, pending_references))
|
|
||||||
# Keep track of the fact that we've created the table for this model.
|
# Keep track of the fact that we've created the table for this model.
|
||||||
models_output.add(klass)
|
known_models.add(model)
|
||||||
|
|
||||||
# Create the many-to-many join tables.
|
# Create the many-to-many join tables.
|
||||||
for klass in app_models:
|
for model in app_models:
|
||||||
final_output.extend(_get_many_to_many_sql_for_model(klass))
|
final_output.extend(_get_many_to_many_sql_for_model(model))
|
||||||
|
|
||||||
# Handle references to tables that are from other apps
|
# Handle references to tables that are from other apps
|
||||||
# but don't exist physically
|
# but don't exist physically
|
||||||
not_installed_models = set(pending_references.keys())
|
not_installed_models = set(pending_references.keys())
|
||||||
if not_installed_models:
|
if not_installed_models:
|
||||||
final_output.append('-- The following references should be added but depend on non-existant tables:')
|
final_output.append('-- The following references should be added but depend on non-existant tables:')
|
||||||
for klass in not_installed_models:
|
for model in not_installed_models:
|
||||||
final_output.extend(['-- ' + sql for sql in
|
final_output.extend(['-- ' + sql for sql in
|
||||||
_get_sql_for_pending_references(klass, pending_references)])
|
_get_sql_for_pending_references(model, pending_references)])
|
||||||
|
|
||||||
return final_output
|
return final_output
|
||||||
get_sql_create.help_doc = "Prints the CREATE TABLE SQL statements for the given app name(s)."
|
get_sql_create.help_doc = "Prints the CREATE TABLE SQL statements for the given app name(s)."
|
||||||
get_sql_create.args = APP_ARGS
|
get_sql_create.args = APP_ARGS
|
||||||
|
|
||||||
def _get_sql_model_create(klass, models_already_seen=set()):
|
def _get_sql_model_create(model, known_models=set()):
|
||||||
"""
|
"""
|
||||||
Get the SQL required to create a single model.
|
Get the SQL required to create a single model.
|
||||||
|
|
||||||
@ -141,7 +136,7 @@ def _get_sql_model_create(klass, models_already_seen=set()):
|
|||||||
from django.db import backend, get_creation_module, models
|
from django.db import backend, get_creation_module, models
|
||||||
data_types = get_creation_module().DATA_TYPES
|
data_types = get_creation_module().DATA_TYPES
|
||||||
|
|
||||||
opts = klass._meta
|
opts = model._meta
|
||||||
final_output = []
|
final_output = []
|
||||||
table_output = []
|
table_output = []
|
||||||
pending_references = {}
|
pending_references = {}
|
||||||
@ -163,7 +158,7 @@ def _get_sql_model_create(klass, models_already_seen=set()):
|
|||||||
if f.primary_key:
|
if f.primary_key:
|
||||||
field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
|
field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
|
||||||
if f.rel:
|
if f.rel:
|
||||||
if f.rel.to in models_already_seen:
|
if f.rel.to in known_models:
|
||||||
field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \
|
field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \
|
||||||
style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)) + ' (' + \
|
style.SQL_TABLE(backend.quote_name(f.rel.to._meta.db_table)) + ' (' + \
|
||||||
style.SQL_FIELD(backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')'
|
style.SQL_FIELD(backend.quote_name(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')'
|
||||||
@ -171,7 +166,7 @@ def _get_sql_model_create(klass, models_already_seen=set()):
|
|||||||
else:
|
else:
|
||||||
# We haven't yet created the table to which this field
|
# We haven't yet created the table to which this field
|
||||||
# is related, so save it for later.
|
# is related, so save it for later.
|
||||||
pr = pending_references.setdefault(f.rel.to, []).append((klass, f))
|
pr = pending_references.setdefault(f.rel.to, []).append((model, f))
|
||||||
table_output.append(' '.join(field_output))
|
table_output.append(' '.join(field_output))
|
||||||
if opts.order_with_respect_to:
|
if opts.order_with_respect_to:
|
||||||
table_output.append(style.SQL_FIELD(backend.quote_name('_order')) + ' ' + \
|
table_output.append(style.SQL_FIELD(backend.quote_name('_order')) + ' ' + \
|
||||||
@ -189,7 +184,7 @@ def _get_sql_model_create(klass, models_already_seen=set()):
|
|||||||
|
|
||||||
return final_output, pending_references
|
return final_output, pending_references
|
||||||
|
|
||||||
def _get_sql_for_pending_references(klass, pending_references):
|
def _get_sql_for_pending_references(model, pending_references):
|
||||||
"""
|
"""
|
||||||
Get any ALTER TABLE statements to add constraints after the fact.
|
Get any ALTER TABLE statements to add constraints after the fact.
|
||||||
"""
|
"""
|
||||||
@ -197,29 +192,35 @@ def _get_sql_for_pending_references(klass, pending_references):
|
|||||||
data_types = get_creation_module().DATA_TYPES
|
data_types = get_creation_module().DATA_TYPES
|
||||||
|
|
||||||
final_output = []
|
final_output = []
|
||||||
|
reference_names = {}
|
||||||
if backend.supports_constraints:
|
if backend.supports_constraints:
|
||||||
opts = klass._meta
|
opts = model._meta
|
||||||
if klass in pending_references:
|
if model in pending_references:
|
||||||
for rel_class, f in pending_references[klass]:
|
for rel_class, f in pending_references[model]:
|
||||||
rel_opts = rel_class._meta
|
rel_opts = rel_class._meta
|
||||||
r_table = rel_opts.db_table
|
r_table = rel_opts.db_table
|
||||||
r_col = f.column
|
r_col = f.column
|
||||||
table = opts.db_table
|
table = opts.db_table
|
||||||
col = opts.get_field(f.rel.field_name).column
|
col = opts.get_field(f.rel.field_name).column
|
||||||
|
r_name = '%s_referencing_%s_%s' % (r_col, table, col)
|
||||||
|
if r_name in reference_names:
|
||||||
|
reference_names[r_name] += 1
|
||||||
|
r_name += '_%s' % reference_names[r_name]
|
||||||
|
else:
|
||||||
|
reference_names[r_name] = 0
|
||||||
final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
|
final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \
|
||||||
(backend.quote_name(r_table),
|
(backend.quote_name(r_table), r_name,
|
||||||
backend.quote_name('%s_referencing_%s_%s' % (r_col, table, col)),
|
|
||||||
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
|
backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col)))
|
||||||
del pending_references[klass]
|
del pending_references[model]
|
||||||
return final_output
|
return final_output
|
||||||
|
|
||||||
def _get_many_to_many_sql_for_model(klass):
|
def _get_many_to_many_sql_for_model(model):
|
||||||
from django.db import backend, get_creation_module
|
from django.db import backend, get_creation_module
|
||||||
from django.db.models import GenericRel
|
from django.db.models import GenericRel
|
||||||
|
|
||||||
data_types = get_creation_module().DATA_TYPES
|
data_types = get_creation_module().DATA_TYPES
|
||||||
|
|
||||||
opts = klass._meta
|
opts = model._meta
|
||||||
final_output = []
|
final_output = []
|
||||||
for f in opts.many_to_many:
|
for f in opts.many_to_many:
|
||||||
if not isinstance(f.rel, GenericRel):
|
if not isinstance(f.rel, GenericRel):
|
||||||
@ -273,37 +274,37 @@ def get_sql_delete(app):
|
|||||||
|
|
||||||
references_to_delete = {}
|
references_to_delete = {}
|
||||||
app_models = models.get_models(app)
|
app_models = models.get_models(app)
|
||||||
for klass in app_models:
|
for model in app_models:
|
||||||
if cursor and klass._meta.db_table in table_names:
|
if cursor and model._meta.db_table in table_names:
|
||||||
# The table exists, so it needs to be dropped
|
# The table exists, so it needs to be dropped
|
||||||
opts = klass._meta
|
opts = model._meta
|
||||||
for f in opts.fields:
|
for f in opts.fields:
|
||||||
if f.rel and f.rel.to not in to_delete:
|
if f.rel and f.rel.to not in to_delete:
|
||||||
references_to_delete.setdefault(f.rel.to, []).append( (klass, f) )
|
references_to_delete.setdefault(f.rel.to, []).append( (model, f) )
|
||||||
|
|
||||||
to_delete.add(klass)
|
to_delete.add(model)
|
||||||
|
|
||||||
for klass in app_models:
|
for model in app_models:
|
||||||
if cursor and klass._meta.db_table in table_names:
|
if cursor and model._meta.db_table in table_names:
|
||||||
# Drop the table now
|
# Drop the table now
|
||||||
output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'),
|
output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'),
|
||||||
style.SQL_TABLE(backend.quote_name(klass._meta.db_table))))
|
style.SQL_TABLE(backend.quote_name(model._meta.db_table))))
|
||||||
if backend.supports_constraints and references_to_delete.has_key(klass):
|
if backend.supports_constraints and references_to_delete.has_key(model):
|
||||||
for rel_class, f in references_to_delete[klass]:
|
for rel_class, f in references_to_delete[model]:
|
||||||
table = rel_class._meta.db_table
|
table = rel_class._meta.db_table
|
||||||
col = f.column
|
col = f.column
|
||||||
r_table = klass._meta.db_table
|
r_table = model._meta.db_table
|
||||||
r_col = klass._meta.get_field(f.rel.field_name).column
|
r_col = model._meta.get_field(f.rel.field_name).column
|
||||||
output.append('%s %s %s %s;' % \
|
output.append('%s %s %s %s;' % \
|
||||||
(style.SQL_KEYWORD('ALTER TABLE'),
|
(style.SQL_KEYWORD('ALTER TABLE'),
|
||||||
style.SQL_TABLE(backend.quote_name(table)),
|
style.SQL_TABLE(backend.quote_name(table)),
|
||||||
style.SQL_KEYWORD(backend.get_drop_foreignkey_sql()),
|
style.SQL_KEYWORD(backend.get_drop_foreignkey_sql()),
|
||||||
style.SQL_FIELD(backend.quote_name("%s_referencing_%s_%s" % (col, r_table, r_col)))))
|
style.SQL_FIELD(backend.quote_name("%s_referencing_%s_%s" % (col, r_table, r_col)))))
|
||||||
del references_to_delete[klass]
|
del references_to_delete[model]
|
||||||
|
|
||||||
# Output DROP TABLE statements for many-to-many tables.
|
# Output DROP TABLE statements for many-to-many tables.
|
||||||
for klass in app_models:
|
for model in app_models:
|
||||||
opts = klass._meta
|
opts = model._meta
|
||||||
for f in opts.many_to_many:
|
for f in opts.many_to_many:
|
||||||
if cursor and f.m2m_db_table() in table_names:
|
if cursor and f.m2m_db_table() in table_names:
|
||||||
output.append("%s %s;" % (style.SQL_KEYWORD('DROP TABLE'),
|
output.append("%s %s;" % (style.SQL_KEYWORD('DROP TABLE'),
|
||||||
@ -360,8 +361,8 @@ def get_sql_initial_data(app):
|
|||||||
app_models = get_models(app)
|
app_models = get_models(app)
|
||||||
app_dir = os.path.normpath(os.path.join(os.path.dirname(app.__file__), 'sql'))
|
app_dir = os.path.normpath(os.path.join(os.path.dirname(app.__file__), 'sql'))
|
||||||
|
|
||||||
for klass in app_models:
|
for model in app_models:
|
||||||
output.extend(get_sql_initial_data_for_model(klass))
|
output.extend(get_sql_initial_data_for_model(model))
|
||||||
|
|
||||||
return output
|
return output
|
||||||
get_sql_initial_data.help_doc = "Prints the initial INSERT SQL statements for the given app name(s)."
|
get_sql_initial_data.help_doc = "Prints the initial INSERT SQL statements for the given app name(s)."
|
||||||
@ -371,18 +372,18 @@ def get_sql_sequence_reset(app):
|
|||||||
"Returns a list of the SQL statements to reset PostgreSQL sequences for the given app."
|
"Returns a list of the SQL statements to reset PostgreSQL sequences for the given app."
|
||||||
from django.db import backend, models
|
from django.db import backend, models
|
||||||
output = []
|
output = []
|
||||||
for klass in models.get_models(app):
|
for model in models.get_models(app):
|
||||||
for f in klass._meta.fields:
|
for f in model._meta.fields:
|
||||||
if isinstance(f, models.AutoField):
|
if isinstance(f, models.AutoField):
|
||||||
output.append("%s setval('%s', (%s max(%s) %s %s));" % \
|
output.append("%s setval('%s', (%s max(%s) %s %s));" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_FIELD('%s_%s_seq' % (klass._meta.db_table, f.column)),
|
style.SQL_FIELD('%s_%s_seq' % (model._meta.db_table, f.column)),
|
||||||
style.SQL_KEYWORD('SELECT'),
|
style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_FIELD(backend.quote_name(f.column)),
|
style.SQL_FIELD(backend.quote_name(f.column)),
|
||||||
style.SQL_KEYWORD('FROM'),
|
style.SQL_KEYWORD('FROM'),
|
||||||
style.SQL_TABLE(backend.quote_name(klass._meta.db_table))))
|
style.SQL_TABLE(backend.quote_name(model._meta.db_table))))
|
||||||
break # Only one AutoField is allowed per model, so don't bother continuing.
|
break # Only one AutoField is allowed per model, so don't bother continuing.
|
||||||
for f in klass._meta.many_to_many:
|
for f in model._meta.many_to_many:
|
||||||
output.append("%s setval('%s', (%s max(%s) %s %s));" % \
|
output.append("%s setval('%s', (%s max(%s) %s %s));" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_FIELD('%s_id_seq' % f.m2m_db_table()),
|
style.SQL_FIELD('%s_id_seq' % f.m2m_db_table()),
|
||||||
@ -399,15 +400,15 @@ def get_sql_indexes(app):
|
|||||||
from django.db import backend, models
|
from django.db import backend, models
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
for klass in models.get_models(app):
|
for model in models.get_models(app):
|
||||||
for f in klass._meta.fields:
|
for f in model._meta.fields:
|
||||||
if f.db_index:
|
if f.db_index:
|
||||||
unique = f.unique and 'UNIQUE ' or ''
|
unique = f.unique and 'UNIQUE ' or ''
|
||||||
output.append(
|
output.append(
|
||||||
style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \
|
style.SQL_KEYWORD('CREATE %sINDEX' % unique) + ' ' + \
|
||||||
style.SQL_TABLE('%s_%s' % (klass._meta.db_table, f.column)) + ' ' + \
|
style.SQL_TABLE('%s_%s' % (model._meta.db_table, f.column)) + ' ' + \
|
||||||
style.SQL_KEYWORD('ON') + ' ' + \
|
style.SQL_KEYWORD('ON') + ' ' + \
|
||||||
style.SQL_TABLE(backend.quote_name(klass._meta.db_table)) + ' ' + \
|
style.SQL_TABLE(backend.quote_name(model._meta.db_table)) + ' ' + \
|
||||||
"(%s);" % style.SQL_FIELD(backend.quote_name(f.column))
|
"(%s);" % style.SQL_FIELD(backend.quote_name(f.column))
|
||||||
)
|
)
|
||||||
return output
|
return output
|
||||||
@ -517,14 +518,14 @@ def get_admin_index(app):
|
|||||||
app_label = app_models[0]._meta.app_label
|
app_label = app_models[0]._meta.app_label
|
||||||
output.append('{%% if perms.%s %%}' % app_label)
|
output.append('{%% if perms.%s %%}' % app_label)
|
||||||
output.append('<div class="module"><h2>%s</h2><table>' % app_label.title())
|
output.append('<div class="module"><h2>%s</h2><table>' % app_label.title())
|
||||||
for klass in app_models:
|
for model in app_models:
|
||||||
if klass._meta.admin:
|
if model._meta.admin:
|
||||||
output.append(MODULE_TEMPLATE % {
|
output.append(MODULE_TEMPLATE % {
|
||||||
'app': app_label,
|
'app': app_label,
|
||||||
'mod': klass._meta.module_name,
|
'mod': model._meta.module_name,
|
||||||
'name': capfirst(klass._meta.verbose_name_plural),
|
'name': capfirst(model._meta.verbose_name_plural),
|
||||||
'addperm': klass._meta.get_add_permission(),
|
'addperm': model._meta.get_add_permission(),
|
||||||
'changeperm': klass._meta.get_change_permission(),
|
'changeperm': model._meta.get_change_permission(),
|
||||||
})
|
})
|
||||||
output.append('</table></div>')
|
output.append('</table></div>')
|
||||||
output.append('{% endif %}')
|
output.append('{% endif %}')
|
||||||
@ -592,7 +593,6 @@ install.args = APP_ARGS
|
|||||||
def reset(app):
|
def reset(app):
|
||||||
"Executes the equivalent of 'get_sql_reset' in the current database."
|
"Executes the equivalent of 'get_sql_reset' in the current database."
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
from cStringIO import StringIO
|
|
||||||
app_name = app.__name__.split('.')[-2]
|
app_name = app.__name__.split('.')[-2]
|
||||||
|
|
||||||
disable_termcolors()
|
disable_termcolors()
|
||||||
@ -692,7 +692,6 @@ startapp.args = "[appname]"
|
|||||||
def inspectdb():
|
def inspectdb():
|
||||||
"Generator that introspects the tables in the given database name and returns a Django model, one line at a time."
|
"Generator that introspects the tables in the given database name and returns a Django model, one line at a time."
|
||||||
from django.db import connection, get_introspection_module
|
from django.db import connection, get_introspection_module
|
||||||
from django.conf import settings
|
|
||||||
import keyword
|
import keyword
|
||||||
|
|
||||||
introspection_module = get_introspection_module()
|
introspection_module = get_introspection_module()
|
||||||
@ -1024,7 +1023,7 @@ def _check_for_validation_errors(app=None):
|
|||||||
sys.stderr.write(s.read())
|
sys.stderr.write(s.read())
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def runserver(addr, port):
|
def runserver(addr, port, use_reloader=True):
|
||||||
"Starts a lightweight Web server for development."
|
"Starts a lightweight Web server for development."
|
||||||
from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
|
from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
|
||||||
from django.core.handlers.wsgi import WSGIHandler
|
from django.core.handlers.wsgi import WSGIHandler
|
||||||
@ -1058,9 +1057,12 @@ def runserver(addr, port):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
from django.utils import autoreload
|
if use_reloader:
|
||||||
autoreload.main(inner_run)
|
from django.utils import autoreload
|
||||||
runserver.args = '[optional port number, or ipaddr:port]'
|
autoreload.main(inner_run)
|
||||||
|
else:
|
||||||
|
inner_run()
|
||||||
|
runserver.args = '[--noreload] [optional port number, or ipaddr:port]'
|
||||||
|
|
||||||
def createcachetable(tablename):
|
def createcachetable(tablename):
|
||||||
"Creates the table needed to use the SQL cache backend"
|
"Creates the table needed to use the SQL cache backend"
|
||||||
@ -1209,6 +1211,8 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
|
|||||||
help='Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".')
|
help='Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".')
|
||||||
parser.add_option('--plain', action='store_true', dest='plain',
|
parser.add_option('--plain', action='store_true', dest='plain',
|
||||||
help='Tells Django to use plain Python, not IPython, for "shell" command.')
|
help='Tells Django to use plain Python, not IPython, for "shell" command.')
|
||||||
|
parser.add_option('--noreload', action='store_false', dest='use_reloader', default=True,
|
||||||
|
help='Tells Django to NOT use the auto-reloader when running the development server.')
|
||||||
options, args = parser.parse_args(argv[1:])
|
options, args = parser.parse_args(argv[1:])
|
||||||
|
|
||||||
# Take care of options.
|
# Take care of options.
|
||||||
@ -1264,7 +1268,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
|
|||||||
addr, port = args[1].split(':')
|
addr, port = args[1].split(':')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
addr, port = '', args[1]
|
addr, port = '', args[1]
|
||||||
action_mapping[action](addr, port)
|
action_mapping[action](addr, port, options.use_reloader)
|
||||||
elif action == 'runfcgi':
|
elif action == 'runfcgi':
|
||||||
action_mapping[action](args[1:])
|
action_mapping[action](args[1:])
|
||||||
else:
|
else:
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from copy import copy
|
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
class InvalidPage(Exception):
|
class InvalidPage(Exception):
|
||||||
|
@ -79,7 +79,7 @@ def Deserializer(object_list, **options):
|
|||||||
elif field.rel and isinstance(field.rel, models.ManyToOneRel):
|
elif field.rel and isinstance(field.rel, models.ManyToOneRel):
|
||||||
try:
|
try:
|
||||||
data[field.name] = field.rel.to._default_manager.get(pk=field_value)
|
data[field.name] = field.rel.to._default_manager.get(pk=field_value)
|
||||||
except RelatedModel.DoesNotExist:
|
except field.rel.to.DoesNotExist:
|
||||||
data[field.name] = None
|
data[field.name] = None
|
||||||
|
|
||||||
# Handle all other fields
|
# Handle all other fields
|
||||||
|
@ -8,7 +8,7 @@ been reviewed for security issues. Don't use it for production use.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
||||||
from types import ListType, StringType, TupleType
|
from types import ListType, StringType
|
||||||
import os, re, sys, time, urllib
|
import os, re, sys, time, urllib
|
||||||
|
|
||||||
__version__ = "0.1"
|
__version__ = "0.1"
|
||||||
|
@ -40,7 +40,7 @@ class MysqlDebugWrapper:
|
|||||||
def executemany(self, sql, param_list):
|
def executemany(self, sql, param_list):
|
||||||
try:
|
try:
|
||||||
return self.cursor.executemany(sql, param_list)
|
return self.cursor.executemany(sql, param_list)
|
||||||
except Database.Warning:
|
except Database.Warning, w:
|
||||||
self.cursor.execute("SHOW WARNINGS")
|
self.cursor.execute("SHOW WARNINGS")
|
||||||
raise Database.Warning, "%s: %s" % (w, self.cursor.fetchall())
|
raise Database.Warning, "%s: %s" % (w, self.cursor.fetchall())
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from django.db import transaction
|
|
||||||
from django.db.backends.mysql.base import quote_name
|
from django.db.backends.mysql.base import quote_name
|
||||||
from MySQLdb import ProgrammingError, OperationalError
|
from MySQLdb import ProgrammingError, OperationalError
|
||||||
from MySQLdb.constants import FIELD_TYPE
|
from MySQLdb.constants import FIELD_TYPE
|
||||||
|
@ -10,7 +10,6 @@ try:
|
|||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
raise ImproperlyConfigured, "Error loading cx_Oracle module: %s" % e
|
raise ImproperlyConfigured, "Error loading cx_Oracle module: %s" % e
|
||||||
import types
|
|
||||||
|
|
||||||
DatabaseError = Database.Error
|
DatabaseError = Database.Error
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from django.db import transaction
|
|
||||||
from django.db.backends.oracle.base import quote_name
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
foreign_key_re = re.compile(r"\sCONSTRAINT `[^`]*` FOREIGN KEY \(`([^`]*)`\) REFERENCES `([^`]*)` \(`([^`]*)`\)")
|
foreign_key_re = re.compile(r"\sCONSTRAINT `[^`]*` FOREIGN KEY \(`([^`]*)`\) REFERENCES `([^`]*)` \(`([^`]*)`\)")
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from django.db import transaction
|
|
||||||
from django.db.backends.postgresql.base import quote_name
|
from django.db.backends.postgresql.base import quote_name
|
||||||
|
|
||||||
def get_table_list(cursor):
|
def get_table_list(cursor):
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from django.db import transaction
|
|
||||||
from django.db.backends.postgresql_psycopg2.base import quote_name
|
from django.db.backends.postgresql_psycopg2.base import quote_name
|
||||||
|
|
||||||
def get_table_list(cursor):
|
def get_table_list(cursor):
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from django.db import transaction
|
|
||||||
from django.db.backends.sqlite3.base import quote_name
|
from django.db.backends.sqlite3.base import quote_name
|
||||||
|
|
||||||
def get_table_list(cursor):
|
def get_table_list(cursor):
|
||||||
|
@ -4,8 +4,7 @@ from django.core import validators
|
|||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db.models.fields import AutoField, ImageField, FieldDoesNotExist
|
from django.db.models.fields import AutoField, ImageField, FieldDoesNotExist
|
||||||
from django.db.models.fields.related import OneToOneRel, ManyToOneRel
|
from django.db.models.fields.related import OneToOneRel, ManyToOneRel
|
||||||
from django.db.models.related import RelatedObject
|
from django.db.models.query import delete_objects
|
||||||
from django.db.models.query import orderlist2sql, delete_objects
|
|
||||||
from django.db.models.options import Options, AdminOptions
|
from django.db.models.options import Options, AdminOptions
|
||||||
from django.db import connection, backend, transaction
|
from django.db import connection, backend, transaction
|
||||||
from django.db.models import signals
|
from django.db.models import signals
|
||||||
|
@ -4,7 +4,7 @@ from django.conf import settings
|
|||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.utils.functional import curry, lazy
|
from django.utils.functional import curry
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.translation import gettext, gettext_lazy
|
from django.utils.translation import gettext, gettext_lazy
|
||||||
import datetime, os, time
|
import datetime, os, time
|
||||||
@ -364,8 +364,8 @@ class BooleanField(Field):
|
|||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
if value in (True, False): return value
|
if value in (True, False): return value
|
||||||
if value is 't': return True
|
if value in ('t', 'True'): return True
|
||||||
if value is 'f': return False
|
if value in ('f', 'False'): return False
|
||||||
raise validators.ValidationError, gettext("This value must be either True or False.")
|
raise validators.ValidationError, gettext("This value must be either True or False.")
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from django.db import backend, connection, transaction
|
from django.db import backend, transaction
|
||||||
from django.db.models import signals, get_model
|
from django.db.models import signals, get_model
|
||||||
from django.db.models.fields import AutoField, Field, IntegerField, get_ul_class
|
from django.db.models.fields import AutoField, Field, IntegerField, get_ul_class
|
||||||
from django.db.models.related import RelatedObject
|
from django.db.models.related import RelatedObject
|
||||||
@ -46,7 +46,7 @@ def manipulator_valid_rel_key(f, self, field_data, all_data):
|
|||||||
"Validates that the value is a valid foreign key"
|
"Validates that the value is a valid foreign key"
|
||||||
klass = f.rel.to
|
klass = f.rel.to
|
||||||
try:
|
try:
|
||||||
klass._default_manager.get(pk=field_data)
|
klass._default_manager.get(**{f.rel.field_name: field_data})
|
||||||
except klass.DoesNotExist:
|
except klass.DoesNotExist:
|
||||||
raise validators.ValidationError, _("Please enter a valid %s.") % f.verbose_name
|
raise validators.ValidationError, _("Please enter a valid %s.") % f.verbose_name
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
from django.utils.functional import curry
|
|
||||||
from django.db import backend, connection
|
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
from django.db.models import signals
|
from django.db.models import signals
|
||||||
from django.db.models.fields import FieldDoesNotExist
|
from django.db.models.fields import FieldDoesNotExist
|
||||||
from django.utils.datastructures import SortedDict
|
|
||||||
|
|
||||||
# Size of each "chunk" for get_iterator calls.
|
# Size of each "chunk" for get_iterator calls.
|
||||||
# Larger values are slightly faster at the expense of more storage space.
|
# Larger values are slightly faster at the expense of more storage space.
|
||||||
|
@ -5,7 +5,7 @@ from django.db.models.fields import FileField, AutoField
|
|||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
from django.db.models import signals
|
from django.db.models import signals
|
||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
from django.utils.datastructures import DotExpandedDict, MultiValueDict
|
from django.utils.datastructures import DotExpandedDict
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
import types
|
import types
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ class AutomaticManipulator(forms.Manipulator):
|
|||||||
|
|
||||||
# Add field for ordering.
|
# Add field for ordering.
|
||||||
if self.change and self.opts.get_ordered_objects():
|
if self.change and self.opts.get_ordered_objects():
|
||||||
self.fields.append(formfields.CommaSeparatedIntegerField(field_name="order_"))
|
self.fields.append(forms.CommaSeparatedIntegerField(field_name="order_"))
|
||||||
|
|
||||||
def save(self, new_data):
|
def save(self, new_data):
|
||||||
# TODO: big cleanup when core fields go -> use recursive manipulators.
|
# TODO: big cleanup when core fields go -> use recursive manipulators.
|
||||||
|
@ -18,7 +18,7 @@ QUERY_TERMS = (
|
|||||||
'exact', 'iexact', 'contains', 'icontains',
|
'exact', 'iexact', 'contains', 'icontains',
|
||||||
'gt', 'gte', 'lt', 'lte', 'in',
|
'gt', 'gte', 'lt', 'lte', 'in',
|
||||||
'startswith', 'istartswith', 'endswith', 'iendswith',
|
'startswith', 'istartswith', 'endswith', 'iendswith',
|
||||||
'range', 'year', 'month', 'day', 'isnull',
|
'range', 'year', 'month', 'day', 'isnull', 'search',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Size of each "chunk" for get_iterator calls.
|
# Size of each "chunk" for get_iterator calls.
|
||||||
|
@ -6,24 +6,24 @@ system.
|
|||||||
|
|
||||||
Module attributes of note:
|
Module attributes of note:
|
||||||
|
|
||||||
Any -- Singleton used to signal either "Any Sender" or
|
Any -- Singleton used to signal either "Any Sender" or
|
||||||
"Any Signal". See documentation of the _Any class.
|
"Any Signal". See documentation of the _Any class.
|
||||||
Anonymous -- Singleton used to signal "Anonymous Sender"
|
Anonymous -- Singleton used to signal "Anonymous Sender"
|
||||||
See documentation of the _Anonymous class.
|
See documentation of the _Anonymous class.
|
||||||
|
|
||||||
Internal attributes:
|
Internal attributes:
|
||||||
WEAKREF_TYPES -- tuple of types/classes which represent
|
WEAKREF_TYPES -- tuple of types/classes which represent
|
||||||
weak references to receivers, and thus must be de-
|
weak references to receivers, and thus must be de-
|
||||||
referenced on retrieval to retrieve the callable
|
referenced on retrieval to retrieve the callable
|
||||||
object
|
object
|
||||||
connections -- { senderkey (id) : { signal : [receivers...]}}
|
connections -- { senderkey (id) : { signal : [receivers...]}}
|
||||||
senders -- { senderkey (id) : weakref(sender) }
|
senders -- { senderkey (id) : weakref(sender) }
|
||||||
used for cleaning up sender references on sender
|
used for cleaning up sender references on sender
|
||||||
deletion
|
deletion
|
||||||
sendersBack -- { receiverkey (id) : [senderkey (id)...] }
|
sendersBack -- { receiverkey (id) : [senderkey (id)...] }
|
||||||
used for cleaning up receiver references on receiver
|
used for cleaning up receiver references on receiver
|
||||||
deletion, (considerably speeds up the cleanup process
|
deletion, (considerably speeds up the cleanup process
|
||||||
vs. the original code.)
|
vs. the original code.)
|
||||||
"""
|
"""
|
||||||
from __future__ import generators
|
from __future__ import generators
|
||||||
import types, weakref
|
import types, weakref
|
||||||
@ -34,44 +34,44 @@ __cvsid__ = "$Id: dispatcher.py,v 1.9 2005/09/17 04:55:57 mcfletch Exp $"
|
|||||||
__version__ = "$Revision: 1.9 $"[11:-2]
|
__version__ = "$Revision: 1.9 $"[11:-2]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
True
|
True
|
||||||
except NameError:
|
except NameError:
|
||||||
True = 1==1
|
True = 1==1
|
||||||
False = 1==0
|
False = 1==0
|
||||||
|
|
||||||
class _Parameter:
|
class _Parameter:
|
||||||
"""Used to represent default parameter values."""
|
"""Used to represent default parameter values."""
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__class__.__name__
|
return self.__class__.__name__
|
||||||
|
|
||||||
class _Any(_Parameter):
|
class _Any(_Parameter):
|
||||||
"""Singleton used to signal either "Any Sender" or "Any Signal"
|
"""Singleton used to signal either "Any Sender" or "Any Signal"
|
||||||
|
|
||||||
The Any object can be used with connect, disconnect,
|
The Any object can be used with connect, disconnect,
|
||||||
send, or sendExact to signal that the parameter given
|
send, or sendExact to signal that the parameter given
|
||||||
Any should react to all senders/signals, not just
|
Any should react to all senders/signals, not just
|
||||||
a particular sender/signal.
|
a particular sender/signal.
|
||||||
"""
|
"""
|
||||||
Any = _Any()
|
Any = _Any()
|
||||||
|
|
||||||
class _Anonymous(_Parameter):
|
class _Anonymous(_Parameter):
|
||||||
"""Singleton used to signal "Anonymous Sender"
|
"""Singleton used to signal "Anonymous Sender"
|
||||||
|
|
||||||
The Anonymous object is used to signal that the sender
|
The Anonymous object is used to signal that the sender
|
||||||
of a message is not specified (as distinct from being
|
of a message is not specified (as distinct from being
|
||||||
"any sender"). Registering callbacks for Anonymous
|
"any sender"). Registering callbacks for Anonymous
|
||||||
will only receive messages sent without senders. Sending
|
will only receive messages sent without senders. Sending
|
||||||
with anonymous will only send messages to those receivers
|
with anonymous will only send messages to those receivers
|
||||||
registered for Any or Anonymous.
|
registered for Any or Anonymous.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
The default sender for connect is Any, while the
|
The default sender for connect is Any, while the
|
||||||
default sender for send is Anonymous. This has
|
default sender for send is Anonymous. This has
|
||||||
the effect that if you do not specify any senders
|
the effect that if you do not specify any senders
|
||||||
in either function then all messages are routed
|
in either function then all messages are routed
|
||||||
as though there was a single sender (Anonymous)
|
as though there was a single sender (Anonymous)
|
||||||
being used everywhere.
|
being used everywhere.
|
||||||
"""
|
"""
|
||||||
Anonymous = _Anonymous()
|
Anonymous = _Anonymous()
|
||||||
|
|
||||||
WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref)
|
WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref)
|
||||||
@ -82,416 +82,416 @@ sendersBack = {}
|
|||||||
|
|
||||||
|
|
||||||
def connect(receiver, signal=Any, sender=Any, weak=True):
|
def connect(receiver, signal=Any, sender=Any, weak=True):
|
||||||
"""Connect receiver to sender for signal
|
"""Connect receiver to sender for signal
|
||||||
|
|
||||||
receiver -- a callable Python object which is to receive
|
receiver -- a callable Python object which is to receive
|
||||||
messages/signals/events. Receivers must be hashable
|
messages/signals/events. Receivers must be hashable
|
||||||
objects.
|
objects.
|
||||||
|
|
||||||
if weak is True, then receiver must be weak-referencable
|
if weak is True, then receiver must be weak-referencable
|
||||||
(more precisely saferef.safeRef() must be able to create
|
(more precisely saferef.safeRef() must be able to create
|
||||||
a reference to the receiver).
|
a reference to the receiver).
|
||||||
|
|
||||||
Receivers are fairly flexible in their specification,
|
Receivers are fairly flexible in their specification,
|
||||||
as the machinery in the robustApply module takes care
|
as the machinery in the robustApply module takes care
|
||||||
of most of the details regarding figuring out appropriate
|
of most of the details regarding figuring out appropriate
|
||||||
subsets of the sent arguments to apply to a given
|
subsets of the sent arguments to apply to a given
|
||||||
receiver.
|
receiver.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
if receiver is itself a weak reference (a callable),
|
if receiver is itself a weak reference (a callable),
|
||||||
it will be de-referenced by the system's machinery,
|
it will be de-referenced by the system's machinery,
|
||||||
so *generally* weak references are not suitable as
|
so *generally* weak references are not suitable as
|
||||||
receivers, though some use might be found for the
|
receivers, though some use might be found for the
|
||||||
facility whereby a higher-level library passes in
|
facility whereby a higher-level library passes in
|
||||||
pre-weakrefed receiver references.
|
pre-weakrefed receiver references.
|
||||||
|
|
||||||
signal -- the signal to which the receiver should respond
|
signal -- the signal to which the receiver should respond
|
||||||
|
|
||||||
if Any, receiver will receive any signal from the
|
if Any, receiver will receive any signal from the
|
||||||
indicated sender (which might also be Any, but is not
|
indicated sender (which might also be Any, but is not
|
||||||
necessarily Any).
|
necessarily Any).
|
||||||
|
|
||||||
Otherwise must be a hashable Python object other than
|
Otherwise must be a hashable Python object other than
|
||||||
None (DispatcherError raised on None).
|
None (DispatcherError raised on None).
|
||||||
|
|
||||||
sender -- the sender to which the receiver should respond
|
sender -- the sender to which the receiver should respond
|
||||||
|
|
||||||
if Any, receiver will receive the indicated signals
|
if Any, receiver will receive the indicated signals
|
||||||
from any sender.
|
from any sender.
|
||||||
|
|
||||||
if Anonymous, receiver will only receive indicated
|
if Anonymous, receiver will only receive indicated
|
||||||
signals from send/sendExact which do not specify a
|
signals from send/sendExact which do not specify a
|
||||||
sender, or specify Anonymous explicitly as the sender.
|
sender, or specify Anonymous explicitly as the sender.
|
||||||
|
|
||||||
Otherwise can be any python object.
|
Otherwise can be any python object.
|
||||||
|
|
||||||
weak -- whether to use weak references to the receiver
|
weak -- whether to use weak references to the receiver
|
||||||
By default, the module will attempt to use weak
|
By default, the module will attempt to use weak
|
||||||
references to the receiver objects. If this parameter
|
references to the receiver objects. If this parameter
|
||||||
is false, then strong references will be used.
|
is false, then strong references will be used.
|
||||||
|
|
||||||
returns None, may raise DispatcherTypeError
|
returns None, may raise DispatcherTypeError
|
||||||
"""
|
"""
|
||||||
if signal is None:
|
if signal is None:
|
||||||
raise errors.DispatcherTypeError(
|
raise errors.DispatcherTypeError(
|
||||||
'Signal cannot be None (receiver=%r sender=%r)'%( receiver,sender)
|
'Signal cannot be None (receiver=%r sender=%r)'%( receiver,sender)
|
||||||
)
|
)
|
||||||
if weak:
|
if weak:
|
||||||
receiver = saferef.safeRef(receiver, onDelete=_removeReceiver)
|
receiver = saferef.safeRef(receiver, onDelete=_removeReceiver)
|
||||||
senderkey = id(sender)
|
senderkey = id(sender)
|
||||||
if connections.has_key(senderkey):
|
if connections.has_key(senderkey):
|
||||||
signals = connections[senderkey]
|
signals = connections[senderkey]
|
||||||
else:
|
else:
|
||||||
connections[senderkey] = signals = {}
|
connections[senderkey] = signals = {}
|
||||||
# Keep track of senders for cleanup.
|
# Keep track of senders for cleanup.
|
||||||
# Is Anonymous something we want to clean up?
|
# Is Anonymous something we want to clean up?
|
||||||
if sender not in (None, Anonymous, Any):
|
if sender not in (None, Anonymous, Any):
|
||||||
def remove(object, senderkey=senderkey):
|
def remove(object, senderkey=senderkey):
|
||||||
_removeSender(senderkey=senderkey)
|
_removeSender(senderkey=senderkey)
|
||||||
# Skip objects that can not be weakly referenced, which means
|
# Skip objects that can not be weakly referenced, which means
|
||||||
# they won't be automatically cleaned up, but that's too bad.
|
# they won't be automatically cleaned up, but that's too bad.
|
||||||
try:
|
try:
|
||||||
weakSender = weakref.ref(sender, remove)
|
weakSender = weakref.ref(sender, remove)
|
||||||
senders[senderkey] = weakSender
|
senders[senderkey] = weakSender
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
receiverID = id(receiver)
|
receiverID = id(receiver)
|
||||||
# get current set, remove any current references to
|
# get current set, remove any current references to
|
||||||
# this receiver in the set, including back-references
|
# this receiver in the set, including back-references
|
||||||
if signals.has_key(signal):
|
if signals.has_key(signal):
|
||||||
receivers = signals[signal]
|
receivers = signals[signal]
|
||||||
_removeOldBackRefs(senderkey, signal, receiver, receivers)
|
_removeOldBackRefs(senderkey, signal, receiver, receivers)
|
||||||
else:
|
else:
|
||||||
receivers = signals[signal] = []
|
receivers = signals[signal] = []
|
||||||
try:
|
try:
|
||||||
current = sendersBack.get( receiverID )
|
current = sendersBack.get( receiverID )
|
||||||
if current is None:
|
if current is None:
|
||||||
sendersBack[ receiverID ] = current = []
|
sendersBack[ receiverID ] = current = []
|
||||||
if senderkey not in current:
|
if senderkey not in current:
|
||||||
current.append(senderkey)
|
current.append(senderkey)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
receivers.append(receiver)
|
receivers.append(receiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def disconnect(receiver, signal=Any, sender=Any, weak=True):
|
def disconnect(receiver, signal=Any, sender=Any, weak=True):
|
||||||
"""Disconnect receiver from sender for signal
|
"""Disconnect receiver from sender for signal
|
||||||
|
|
||||||
receiver -- the registered receiver to disconnect
|
receiver -- the registered receiver to disconnect
|
||||||
signal -- the registered signal to disconnect
|
signal -- the registered signal to disconnect
|
||||||
sender -- the registered sender to disconnect
|
sender -- the registered sender to disconnect
|
||||||
weak -- the weakref state to disconnect
|
weak -- the weakref state to disconnect
|
||||||
|
|
||||||
disconnect reverses the process of connect,
|
disconnect reverses the process of connect,
|
||||||
the semantics for the individual elements are
|
the semantics for the individual elements are
|
||||||
logically equivalent to a tuple of
|
logically equivalent to a tuple of
|
||||||
(receiver, signal, sender, weak) used as a key
|
(receiver, signal, sender, weak) used as a key
|
||||||
to be deleted from the internal routing tables.
|
to be deleted from the internal routing tables.
|
||||||
(The actual process is slightly more complex
|
(The actual process is slightly more complex
|
||||||
but the semantics are basically the same).
|
but the semantics are basically the same).
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
Using disconnect is not required to cleanup
|
Using disconnect is not required to cleanup
|
||||||
routing when an object is deleted, the framework
|
routing when an object is deleted, the framework
|
||||||
will remove routes for deleted objects
|
will remove routes for deleted objects
|
||||||
automatically. It's only necessary to disconnect
|
automatically. It's only necessary to disconnect
|
||||||
if you want to stop routing to a live object.
|
if you want to stop routing to a live object.
|
||||||
|
|
||||||
returns None, may raise DispatcherTypeError or
|
returns None, may raise DispatcherTypeError or
|
||||||
DispatcherKeyError
|
DispatcherKeyError
|
||||||
"""
|
"""
|
||||||
if signal is None:
|
if signal is None:
|
||||||
raise errors.DispatcherTypeError(
|
raise errors.DispatcherTypeError(
|
||||||
'Signal cannot be None (receiver=%r sender=%r)'%( receiver,sender)
|
'Signal cannot be None (receiver=%r sender=%r)'%( receiver,sender)
|
||||||
)
|
)
|
||||||
if weak: receiver = saferef.safeRef(receiver)
|
if weak: receiver = saferef.safeRef(receiver)
|
||||||
senderkey = id(sender)
|
senderkey = id(sender)
|
||||||
try:
|
try:
|
||||||
signals = connections[senderkey]
|
signals = connections[senderkey]
|
||||||
receivers = signals[signal]
|
receivers = signals[signal]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise errors.DispatcherKeyError(
|
raise errors.DispatcherKeyError(
|
||||||
"""No receivers found for signal %r from sender %r""" %(
|
"""No receivers found for signal %r from sender %r""" %(
|
||||||
signal,
|
signal,
|
||||||
sender
|
sender
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
# also removes from receivers
|
# also removes from receivers
|
||||||
_removeOldBackRefs(senderkey, signal, receiver, receivers)
|
_removeOldBackRefs(senderkey, signal, receiver, receivers)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise errors.DispatcherKeyError(
|
raise errors.DispatcherKeyError(
|
||||||
"""No connection to receiver %s for signal %s from sender %s""" %(
|
"""No connection to receiver %s for signal %s from sender %s""" %(
|
||||||
receiver,
|
receiver,
|
||||||
signal,
|
signal,
|
||||||
sender
|
sender
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
_cleanupConnections(senderkey, signal)
|
_cleanupConnections(senderkey, signal)
|
||||||
|
|
||||||
def getReceivers( sender = Any, signal = Any ):
|
def getReceivers( sender = Any, signal = Any ):
|
||||||
"""Get list of receivers from global tables
|
"""Get list of receivers from global tables
|
||||||
|
|
||||||
This utility function allows you to retrieve the
|
This utility function allows you to retrieve the
|
||||||
raw list of receivers from the connections table
|
raw list of receivers from the connections table
|
||||||
for the given sender and signal pair.
|
for the given sender and signal pair.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
there is no guarantee that this is the actual list
|
there is no guarantee that this is the actual list
|
||||||
stored in the connections table, so the value
|
stored in the connections table, so the value
|
||||||
should be treated as a simple iterable/truth value
|
should be treated as a simple iterable/truth value
|
||||||
rather than, for instance a list to which you
|
rather than, for instance a list to which you
|
||||||
might append new records.
|
might append new records.
|
||||||
|
|
||||||
Normally you would use liveReceivers( getReceivers( ...))
|
Normally you would use liveReceivers( getReceivers( ...))
|
||||||
to retrieve the actual receiver objects as an iterable
|
to retrieve the actual receiver objects as an iterable
|
||||||
object.
|
object.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return connections[id(sender)][signal]
|
return connections[id(sender)][signal]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def liveReceivers(receivers):
|
def liveReceivers(receivers):
|
||||||
"""Filter sequence of receivers to get resolved, live receivers
|
"""Filter sequence of receivers to get resolved, live receivers
|
||||||
|
|
||||||
This is a generator which will iterate over
|
This is a generator which will iterate over
|
||||||
the passed sequence, checking for weak references
|
the passed sequence, checking for weak references
|
||||||
and resolving them, then returning all live
|
and resolving them, then returning all live
|
||||||
receivers.
|
receivers.
|
||||||
"""
|
"""
|
||||||
for receiver in receivers:
|
for receiver in receivers:
|
||||||
if isinstance( receiver, WEAKREF_TYPES):
|
if isinstance( receiver, WEAKREF_TYPES):
|
||||||
# Dereference the weak reference.
|
# Dereference the weak reference.
|
||||||
receiver = receiver()
|
receiver = receiver()
|
||||||
if receiver is not None:
|
if receiver is not None:
|
||||||
yield receiver
|
yield receiver
|
||||||
else:
|
else:
|
||||||
yield receiver
|
yield receiver
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getAllReceivers( sender = Any, signal = Any ):
|
def getAllReceivers( sender = Any, signal = Any ):
|
||||||
"""Get list of all receivers from global tables
|
"""Get list of all receivers from global tables
|
||||||
|
|
||||||
This gets all receivers which should receive
|
This gets all receivers which should receive
|
||||||
the given signal from sender, each receiver should
|
the given signal from sender, each receiver should
|
||||||
be produced only once by the resulting generator
|
be produced only once by the resulting generator
|
||||||
"""
|
"""
|
||||||
receivers = {}
|
receivers = {}
|
||||||
for set in (
|
for set in (
|
||||||
# Get receivers that receive *this* signal from *this* sender.
|
# Get receivers that receive *this* signal from *this* sender.
|
||||||
getReceivers( sender, signal ),
|
getReceivers( sender, signal ),
|
||||||
# Add receivers that receive *any* signal from *this* sender.
|
# Add receivers that receive *any* signal from *this* sender.
|
||||||
getReceivers( sender, Any ),
|
getReceivers( sender, Any ),
|
||||||
# Add receivers that receive *this* signal from *any* sender.
|
# Add receivers that receive *this* signal from *any* sender.
|
||||||
getReceivers( Any, signal ),
|
getReceivers( Any, signal ),
|
||||||
# Add receivers that receive *any* signal from *any* sender.
|
# Add receivers that receive *any* signal from *any* sender.
|
||||||
getReceivers( Any, Any ),
|
getReceivers( Any, Any ),
|
||||||
):
|
):
|
||||||
for receiver in set:
|
for receiver in set:
|
||||||
if receiver: # filter out dead instance-method weakrefs
|
if receiver: # filter out dead instance-method weakrefs
|
||||||
try:
|
try:
|
||||||
if not receivers.has_key( receiver ):
|
if not receivers.has_key( receiver ):
|
||||||
receivers[receiver] = 1
|
receivers[receiver] = 1
|
||||||
yield receiver
|
yield receiver
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# dead weakrefs raise TypeError on hash...
|
# dead weakrefs raise TypeError on hash...
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def send(signal=Any, sender=Anonymous, *arguments, **named):
|
def send(signal=Any, sender=Anonymous, *arguments, **named):
|
||||||
"""Send signal from sender to all connected receivers.
|
"""Send signal from sender to all connected receivers.
|
||||||
|
|
||||||
signal -- (hashable) signal value, see connect for details
|
signal -- (hashable) signal value, see connect for details
|
||||||
|
|
||||||
sender -- the sender of the signal
|
sender -- the sender of the signal
|
||||||
|
|
||||||
if Any, only receivers registered for Any will receive
|
if Any, only receivers registered for Any will receive
|
||||||
the message.
|
the message.
|
||||||
|
|
||||||
if Anonymous, only receivers registered to receive
|
if Anonymous, only receivers registered to receive
|
||||||
messages from Anonymous or Any will receive the message
|
messages from Anonymous or Any will receive the message
|
||||||
|
|
||||||
Otherwise can be any python object (normally one
|
Otherwise can be any python object (normally one
|
||||||
registered with a connect if you actually want
|
registered with a connect if you actually want
|
||||||
something to occur).
|
something to occur).
|
||||||
|
|
||||||
arguments -- positional arguments which will be passed to
|
arguments -- positional arguments which will be passed to
|
||||||
*all* receivers. Note that this may raise TypeErrors
|
*all* receivers. Note that this may raise TypeErrors
|
||||||
if the receivers do not allow the particular arguments.
|
if the receivers do not allow the particular arguments.
|
||||||
Note also that arguments are applied before named
|
Note also that arguments are applied before named
|
||||||
arguments, so they should be used with care.
|
arguments, so they should be used with care.
|
||||||
|
|
||||||
named -- named arguments which will be filtered according
|
named -- named arguments which will be filtered according
|
||||||
to the parameters of the receivers to only provide those
|
to the parameters of the receivers to only provide those
|
||||||
acceptable to the receiver.
|
acceptable to the receiver.
|
||||||
|
|
||||||
Return a list of tuple pairs [(receiver, response), ... ]
|
Return a list of tuple pairs [(receiver, response), ... ]
|
||||||
|
|
||||||
if any receiver raises an error, the error propagates back
|
if any receiver raises an error, the error propagates back
|
||||||
through send, terminating the dispatch loop, so it is quite
|
through send, terminating the dispatch loop, so it is quite
|
||||||
possible to not have all receivers called if a raises an
|
possible to not have all receivers called if a raises an
|
||||||
error.
|
error.
|
||||||
"""
|
"""
|
||||||
# Call each receiver with whatever arguments it can accept.
|
# Call each receiver with whatever arguments it can accept.
|
||||||
# Return a list of tuple pairs [(receiver, response), ... ].
|
# Return a list of tuple pairs [(receiver, response), ... ].
|
||||||
responses = []
|
responses = []
|
||||||
for receiver in liveReceivers(getAllReceivers(sender, signal)):
|
for receiver in liveReceivers(getAllReceivers(sender, signal)):
|
||||||
response = robustapply.robustApply(
|
response = robustapply.robustApply(
|
||||||
receiver,
|
receiver,
|
||||||
signal=signal,
|
signal=signal,
|
||||||
sender=sender,
|
sender=sender,
|
||||||
*arguments,
|
*arguments,
|
||||||
**named
|
**named
|
||||||
)
|
)
|
||||||
responses.append((receiver, response))
|
responses.append((receiver, response))
|
||||||
return responses
|
return responses
|
||||||
def sendExact( signal=Any, sender=Anonymous, *arguments, **named ):
|
def sendExact( signal=Any, sender=Anonymous, *arguments, **named ):
|
||||||
"""Send signal only to those receivers registered for exact message
|
"""Send signal only to those receivers registered for exact message
|
||||||
|
|
||||||
sendExact allows for avoiding Any/Anonymous registered
|
sendExact allows for avoiding Any/Anonymous registered
|
||||||
handlers, sending only to those receivers explicitly
|
handlers, sending only to those receivers explicitly
|
||||||
registered for a particular signal on a particular
|
registered for a particular signal on a particular
|
||||||
sender.
|
sender.
|
||||||
"""
|
"""
|
||||||
responses = []
|
responses = []
|
||||||
for receiver in liveReceivers(getReceivers(sender, signal)):
|
for receiver in liveReceivers(getReceivers(sender, signal)):
|
||||||
response = robustapply.robustApply(
|
response = robustapply.robustApply(
|
||||||
receiver,
|
receiver,
|
||||||
signal=signal,
|
signal=signal,
|
||||||
sender=sender,
|
sender=sender,
|
||||||
*arguments,
|
*arguments,
|
||||||
**named
|
**named
|
||||||
)
|
)
|
||||||
responses.append((receiver, response))
|
responses.append((receiver, response))
|
||||||
return responses
|
return responses
|
||||||
|
|
||||||
|
|
||||||
def _removeReceiver(receiver):
|
def _removeReceiver(receiver):
|
||||||
"""Remove receiver from connections."""
|
"""Remove receiver from connections."""
|
||||||
if not sendersBack:
|
if not sendersBack:
|
||||||
# During module cleanup the mapping will be replaced with None
|
# During module cleanup the mapping will be replaced with None
|
||||||
return False
|
return False
|
||||||
backKey = id(receiver)
|
backKey = id(receiver)
|
||||||
for senderkey in sendersBack.get(backKey,()):
|
for senderkey in sendersBack.get(backKey,()):
|
||||||
try:
|
try:
|
||||||
signals = connections[senderkey].keys()
|
signals = connections[senderkey].keys()
|
||||||
except KeyError,err:
|
except KeyError,err:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for signal in signals:
|
for signal in signals:
|
||||||
try:
|
try:
|
||||||
receivers = connections[senderkey][signal]
|
receivers = connections[senderkey][signal]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
receivers.remove( receiver )
|
receivers.remove( receiver )
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
pass
|
pass
|
||||||
_cleanupConnections(senderkey, signal)
|
_cleanupConnections(senderkey, signal)
|
||||||
try:
|
try:
|
||||||
del sendersBack[ backKey ]
|
del sendersBack[ backKey ]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _cleanupConnections(senderkey, signal):
|
def _cleanupConnections(senderkey, signal):
|
||||||
"""Delete any empty signals for senderkey. Delete senderkey if empty."""
|
"""Delete any empty signals for senderkey. Delete senderkey if empty."""
|
||||||
try:
|
try:
|
||||||
receivers = connections[senderkey][signal]
|
receivers = connections[senderkey][signal]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if not receivers:
|
if not receivers:
|
||||||
# No more connected receivers. Therefore, remove the signal.
|
# No more connected receivers. Therefore, remove the signal.
|
||||||
try:
|
try:
|
||||||
signals = connections[senderkey]
|
signals = connections[senderkey]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
del signals[signal]
|
del signals[signal]
|
||||||
if not signals:
|
if not signals:
|
||||||
# No more signal connections. Therefore, remove the sender.
|
# No more signal connections. Therefore, remove the sender.
|
||||||
_removeSender(senderkey)
|
_removeSender(senderkey)
|
||||||
|
|
||||||
def _removeSender(senderkey):
|
def _removeSender(senderkey):
|
||||||
"""Remove senderkey from connections."""
|
"""Remove senderkey from connections."""
|
||||||
_removeBackrefs(senderkey)
|
_removeBackrefs(senderkey)
|
||||||
try:
|
try:
|
||||||
del connections[senderkey]
|
del connections[senderkey]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
# Senderkey will only be in senders dictionary if sender
|
# Senderkey will only be in senders dictionary if sender
|
||||||
# could be weakly referenced.
|
# could be weakly referenced.
|
||||||
try:
|
try:
|
||||||
del senders[senderkey]
|
del senders[senderkey]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _removeBackrefs( senderkey):
|
def _removeBackrefs( senderkey):
|
||||||
"""Remove all back-references to this senderkey"""
|
"""Remove all back-references to this senderkey"""
|
||||||
try:
|
try:
|
||||||
signals = connections[senderkey]
|
signals = connections[senderkey]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
signals = None
|
signals = None
|
||||||
else:
|
else:
|
||||||
items = signals.items()
|
items = signals.items()
|
||||||
def allReceivers( ):
|
def allReceivers( ):
|
||||||
for signal,set in items:
|
for signal,set in items:
|
||||||
for item in set:
|
for item in set:
|
||||||
yield item
|
yield item
|
||||||
for receiver in allReceivers():
|
for receiver in allReceivers():
|
||||||
_killBackref( receiver, senderkey )
|
_killBackref( receiver, senderkey )
|
||||||
|
|
||||||
def _removeOldBackRefs(senderkey, signal, receiver, receivers):
|
def _removeOldBackRefs(senderkey, signal, receiver, receivers):
|
||||||
"""Kill old sendersBack references from receiver
|
"""Kill old sendersBack references from receiver
|
||||||
|
|
||||||
This guards against multiple registration of the same
|
This guards against multiple registration of the same
|
||||||
receiver for a given signal and sender leaking memory
|
receiver for a given signal and sender leaking memory
|
||||||
as old back reference records build up.
|
as old back reference records build up.
|
||||||
|
|
||||||
Also removes old receiver instance from receivers
|
Also removes old receiver instance from receivers
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
index = receivers.index(receiver)
|
index = receivers.index(receiver)
|
||||||
# need to scan back references here and remove senderkey
|
# need to scan back references here and remove senderkey
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
oldReceiver = receivers[index]
|
oldReceiver = receivers[index]
|
||||||
del receivers[index]
|
del receivers[index]
|
||||||
found = 0
|
found = 0
|
||||||
signals = connections.get(signal)
|
signals = connections.get(signal)
|
||||||
if signals is not None:
|
if signals is not None:
|
||||||
for sig,recs in connections.get(signal,{}).iteritems():
|
for sig,recs in connections.get(signal,{}).iteritems():
|
||||||
if sig != signal:
|
if sig != signal:
|
||||||
for rec in recs:
|
for rec in recs:
|
||||||
if rec is oldReceiver:
|
if rec is oldReceiver:
|
||||||
found = 1
|
found = 1
|
||||||
break
|
break
|
||||||
if not found:
|
if not found:
|
||||||
_killBackref( oldReceiver, senderkey )
|
_killBackref( oldReceiver, senderkey )
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _killBackref( receiver, senderkey ):
|
def _killBackref( receiver, senderkey ):
|
||||||
"""Do the actual removal of back reference from receiver to senderkey"""
|
"""Do the actual removal of back reference from receiver to senderkey"""
|
||||||
receiverkey = id(receiver)
|
receiverkey = id(receiver)
|
||||||
set = sendersBack.get( receiverkey, () )
|
set = sendersBack.get( receiverkey, () )
|
||||||
while senderkey in set:
|
while senderkey in set:
|
||||||
try:
|
try:
|
||||||
set.remove( senderkey )
|
set.remove( senderkey )
|
||||||
except:
|
except:
|
||||||
break
|
break
|
||||||
if not set:
|
if not set:
|
||||||
try:
|
try:
|
||||||
del sendersBack[ receiverkey ]
|
del sendersBack[ receiverkey ]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
return True
|
return True
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
class DispatcherError(Exception):
|
class DispatcherError(Exception):
|
||||||
"""Base class for all Dispatcher errors"""
|
"""Base class for all Dispatcher errors"""
|
||||||
class DispatcherKeyError(KeyError, DispatcherError):
|
class DispatcherKeyError(KeyError, DispatcherError):
|
||||||
"""Error raised when unknown (sender,signal) set specified"""
|
"""Error raised when unknown (sender,signal) set specified"""
|
||||||
class DispatcherTypeError(TypeError, DispatcherError):
|
class DispatcherTypeError(TypeError, DispatcherError):
|
||||||
"""Error raised when inappropriate signal-type specified (None)"""
|
"""Error raised when inappropriate signal-type specified (None)"""
|
||||||
|
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
PyDispatcher License
|
PyDispatcher License
|
||||||
|
|
||||||
Copyright (c) 2001-2003, Patrick K. O'Brien and Contributors
|
Copyright (c) 2001-2003, Patrick K. O'Brien and Contributors
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
are met:
|
are met:
|
||||||
|
|
||||||
Redistributions of source code must retain the above copyright
|
Redistributions of source code must retain the above copyright
|
||||||
notice, this list of conditions and the following disclaimer.
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
Redistributions in binary form must reproduce the above
|
Redistributions in binary form must reproduce the above
|
||||||
copyright notice, this list of conditions and the following
|
copyright notice, this list of conditions and the following
|
||||||
disclaimer in the documentation and/or other materials
|
disclaimer in the documentation and/or other materials
|
||||||
provided with the distribution.
|
provided with the distribution.
|
||||||
|
|
||||||
The name of Patrick K. O'Brien, or the name of any Contributor,
|
The name of Patrick K. O'Brien, or the name of any Contributor,
|
||||||
may not be used to endorse or promote products derived from this
|
may not be used to endorse or promote products derived from this
|
||||||
software without specific prior written permission.
|
software without specific prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
@ -3,55 +3,55 @@ from django.dispatch.dispatcher import Any, Anonymous, liveReceivers, getAllRece
|
|||||||
from django.dispatch.robustapply import robustApply
|
from django.dispatch.robustapply import robustApply
|
||||||
|
|
||||||
def sendRobust(
|
def sendRobust(
|
||||||
signal=Any,
|
signal=Any,
|
||||||
sender=Anonymous,
|
sender=Anonymous,
|
||||||
*arguments, **named
|
*arguments, **named
|
||||||
):
|
):
|
||||||
"""Send signal from sender to all connected receivers catching errors
|
"""Send signal from sender to all connected receivers catching errors
|
||||||
|
|
||||||
signal -- (hashable) signal value, see connect for details
|
signal -- (hashable) signal value, see connect for details
|
||||||
|
|
||||||
sender -- the sender of the signal
|
sender -- the sender of the signal
|
||||||
|
|
||||||
if Any, only receivers registered for Any will receive
|
if Any, only receivers registered for Any will receive
|
||||||
the message.
|
the message.
|
||||||
|
|
||||||
if Anonymous, only receivers registered to receive
|
if Anonymous, only receivers registered to receive
|
||||||
messages from Anonymous or Any will receive the message
|
messages from Anonymous or Any will receive the message
|
||||||
|
|
||||||
Otherwise can be any python object (normally one
|
Otherwise can be any python object (normally one
|
||||||
registered with a connect if you actually want
|
registered with a connect if you actually want
|
||||||
something to occur).
|
something to occur).
|
||||||
|
|
||||||
arguments -- positional arguments which will be passed to
|
arguments -- positional arguments which will be passed to
|
||||||
*all* receivers. Note that this may raise TypeErrors
|
*all* receivers. Note that this may raise TypeErrors
|
||||||
if the receivers do not allow the particular arguments.
|
if the receivers do not allow the particular arguments.
|
||||||
Note also that arguments are applied before named
|
Note also that arguments are applied before named
|
||||||
arguments, so they should be used with care.
|
arguments, so they should be used with care.
|
||||||
|
|
||||||
named -- named arguments which will be filtered according
|
named -- named arguments which will be filtered according
|
||||||
to the parameters of the receivers to only provide those
|
to the parameters of the receivers to only provide those
|
||||||
acceptable to the receiver.
|
acceptable to the receiver.
|
||||||
|
|
||||||
Return a list of tuple pairs [(receiver, response), ... ]
|
Return a list of tuple pairs [(receiver, response), ... ]
|
||||||
|
|
||||||
if any receiver raises an error (specifically any subclass of Exception),
|
if any receiver raises an error (specifically any subclass of Exception),
|
||||||
the error instance is returned as the result for that receiver.
|
the error instance is returned as the result for that receiver.
|
||||||
"""
|
"""
|
||||||
# Call each receiver with whatever arguments it can accept.
|
# Call each receiver with whatever arguments it can accept.
|
||||||
# Return a list of tuple pairs [(receiver, response), ... ].
|
# Return a list of tuple pairs [(receiver, response), ... ].
|
||||||
responses = []
|
responses = []
|
||||||
for receiver in liveReceivers(getAllReceivers(sender, signal)):
|
for receiver in liveReceivers(getAllReceivers(sender, signal)):
|
||||||
try:
|
try:
|
||||||
response = robustApply(
|
response = robustApply(
|
||||||
receiver,
|
receiver,
|
||||||
signal=signal,
|
signal=signal,
|
||||||
sender=sender,
|
sender=sender,
|
||||||
*arguments,
|
*arguments,
|
||||||
**named
|
**named
|
||||||
)
|
)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
responses.append((receiver, err))
|
responses.append((receiver, err))
|
||||||
else:
|
else:
|
||||||
responses.append((receiver, response))
|
responses.append((receiver, response))
|
||||||
return responses
|
return responses
|
||||||
|
@ -7,43 +7,41 @@ those which are acceptable.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def function( receiver ):
|
def function( receiver ):
|
||||||
"""Get function-like callable object for given receiver
|
"""Get function-like callable object for given receiver
|
||||||
|
|
||||||
returns (function_or_method, codeObject, fromMethod)
|
returns (function_or_method, codeObject, fromMethod)
|
||||||
|
|
||||||
If fromMethod is true, then the callable already
|
If fromMethod is true, then the callable already
|
||||||
has its first argument bound
|
has its first argument bound
|
||||||
"""
|
"""
|
||||||
if hasattr(receiver, '__call__'):
|
if hasattr(receiver, '__call__'):
|
||||||
# receiver is a class instance; assume it is callable.
|
# receiver is a class instance; assume it is callable.
|
||||||
# Reassign receiver to the actual method that will be called.
|
# Reassign receiver to the actual method that will be called.
|
||||||
if hasattr( receiver.__call__, 'im_func') or hasattr( receiver.__call__, 'im_code'):
|
if hasattr( receiver.__call__, 'im_func') or hasattr( receiver.__call__, 'im_code'):
|
||||||
receiver = receiver.__call__
|
receiver = receiver.__call__
|
||||||
if hasattr( receiver, 'im_func' ):
|
if hasattr( receiver, 'im_func' ):
|
||||||
# an instance-method...
|
# an instance-method...
|
||||||
return receiver, receiver.im_func.func_code, 1
|
return receiver, receiver.im_func.func_code, 1
|
||||||
elif not hasattr( receiver, 'func_code'):
|
elif not hasattr( receiver, 'func_code'):
|
||||||
raise ValueError('unknown reciever type %s %s'%(receiver, type(receiver)))
|
raise ValueError('unknown reciever type %s %s'%(receiver, type(receiver)))
|
||||||
return receiver, receiver.func_code, 0
|
return receiver, receiver.func_code, 0
|
||||||
|
|
||||||
def robustApply(receiver, *arguments, **named):
|
def robustApply(receiver, *arguments, **named):
|
||||||
"""Call receiver with arguments and an appropriate subset of named
|
"""Call receiver with arguments and an appropriate subset of named
|
||||||
"""
|
"""
|
||||||
receiver, codeObject, startIndex = function( receiver )
|
receiver, codeObject, startIndex = function( receiver )
|
||||||
acceptable = codeObject.co_varnames[startIndex+len(arguments):codeObject.co_argcount]
|
acceptable = codeObject.co_varnames[startIndex+len(arguments):codeObject.co_argcount]
|
||||||
for name in codeObject.co_varnames[startIndex:startIndex+len(arguments)]:
|
for name in codeObject.co_varnames[startIndex:startIndex+len(arguments)]:
|
||||||
if named.has_key( name ):
|
if named.has_key( name ):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"""Argument %r specified both positionally and as a keyword for calling %r"""% (
|
"""Argument %r specified both positionally and as a keyword for calling %r"""% (
|
||||||
name, receiver,
|
name, receiver,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if not (codeObject.co_flags & 8):
|
if not (codeObject.co_flags & 8):
|
||||||
# fc does not have a **kwds type parameter, therefore
|
# fc does not have a **kwds type parameter, therefore
|
||||||
# remove unacceptable arguments.
|
# remove unacceptable arguments.
|
||||||
for arg in named.keys():
|
for arg in named.keys():
|
||||||
if arg not in acceptable:
|
if arg not in acceptable:
|
||||||
del named[arg]
|
del named[arg]
|
||||||
return receiver(*arguments, **named)
|
return receiver(*arguments, **named)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,164 +2,164 @@
|
|||||||
import weakref, traceback
|
import weakref, traceback
|
||||||
|
|
||||||
def safeRef(target, onDelete = None):
|
def safeRef(target, onDelete = None):
|
||||||
"""Return a *safe* weak reference to a callable target
|
"""Return a *safe* weak reference to a callable target
|
||||||
|
|
||||||
target -- the object to be weakly referenced, if it's a
|
target -- the object to be weakly referenced, if it's a
|
||||||
bound method reference, will create a BoundMethodWeakref,
|
bound method reference, will create a BoundMethodWeakref,
|
||||||
otherwise creates a simple weakref.
|
otherwise creates a simple weakref.
|
||||||
onDelete -- if provided, will have a hard reference stored
|
onDelete -- if provided, will have a hard reference stored
|
||||||
to the callable to be called after the safe reference
|
to the callable to be called after the safe reference
|
||||||
goes out of scope with the reference object, (either a
|
goes out of scope with the reference object, (either a
|
||||||
weakref or a BoundMethodWeakref) as argument.
|
weakref or a BoundMethodWeakref) as argument.
|
||||||
"""
|
"""
|
||||||
if hasattr(target, 'im_self'):
|
if hasattr(target, 'im_self'):
|
||||||
if target.im_self is not None:
|
if target.im_self is not None:
|
||||||
# Turn a bound method into a BoundMethodWeakref instance.
|
# Turn a bound method into a BoundMethodWeakref instance.
|
||||||
# Keep track of these instances for lookup by disconnect().
|
# Keep track of these instances for lookup by disconnect().
|
||||||
assert hasattr(target, 'im_func'), """safeRef target %r has im_self, but no im_func, don't know how to create reference"""%( target,)
|
assert hasattr(target, 'im_func'), """safeRef target %r has im_self, but no im_func, don't know how to create reference"""%( target,)
|
||||||
reference = BoundMethodWeakref(
|
reference = BoundMethodWeakref(
|
||||||
target=target,
|
target=target,
|
||||||
onDelete=onDelete
|
onDelete=onDelete
|
||||||
)
|
)
|
||||||
return reference
|
return reference
|
||||||
if callable(onDelete):
|
if callable(onDelete):
|
||||||
return weakref.ref(target, onDelete)
|
return weakref.ref(target, onDelete)
|
||||||
else:
|
else:
|
||||||
return weakref.ref( target )
|
return weakref.ref( target )
|
||||||
|
|
||||||
class BoundMethodWeakref(object):
|
class BoundMethodWeakref(object):
|
||||||
"""'Safe' and reusable weak references to instance methods
|
"""'Safe' and reusable weak references to instance methods
|
||||||
|
|
||||||
BoundMethodWeakref objects provide a mechanism for
|
BoundMethodWeakref objects provide a mechanism for
|
||||||
referencing a bound method without requiring that the
|
referencing a bound method without requiring that the
|
||||||
method object itself (which is normally a transient
|
method object itself (which is normally a transient
|
||||||
object) is kept alive. Instead, the BoundMethodWeakref
|
object) is kept alive. Instead, the BoundMethodWeakref
|
||||||
object keeps weak references to both the object and the
|
object keeps weak references to both the object and the
|
||||||
function which together define the instance method.
|
function which together define the instance method.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
key -- the identity key for the reference, calculated
|
key -- the identity key for the reference, calculated
|
||||||
by the class's calculateKey method applied to the
|
by the class's calculateKey method applied to the
|
||||||
target instance method
|
target instance method
|
||||||
deletionMethods -- sequence of callable objects taking
|
deletionMethods -- sequence of callable objects taking
|
||||||
single argument, a reference to this object which
|
single argument, a reference to this object which
|
||||||
will be called when *either* the target object or
|
will be called when *either* the target object or
|
||||||
target function is garbage collected (i.e. when
|
target function is garbage collected (i.e. when
|
||||||
this object becomes invalid). These are specified
|
this object becomes invalid). These are specified
|
||||||
as the onDelete parameters of safeRef calls.
|
as the onDelete parameters of safeRef calls.
|
||||||
weakSelf -- weak reference to the target object
|
weakSelf -- weak reference to the target object
|
||||||
weakFunc -- weak reference to the target function
|
weakFunc -- weak reference to the target function
|
||||||
|
|
||||||
Class Attributes:
|
Class Attributes:
|
||||||
_allInstances -- class attribute pointing to all live
|
_allInstances -- class attribute pointing to all live
|
||||||
BoundMethodWeakref objects indexed by the class's
|
BoundMethodWeakref objects indexed by the class's
|
||||||
calculateKey(target) method applied to the target
|
calculateKey(target) method applied to the target
|
||||||
objects. This weak value dictionary is used to
|
objects. This weak value dictionary is used to
|
||||||
short-circuit creation so that multiple references
|
short-circuit creation so that multiple references
|
||||||
to the same (object, function) pair produce the
|
to the same (object, function) pair produce the
|
||||||
same BoundMethodWeakref instance.
|
same BoundMethodWeakref instance.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
_allInstances = weakref.WeakValueDictionary()
|
_allInstances = weakref.WeakValueDictionary()
|
||||||
def __new__( cls, target, onDelete=None, *arguments,**named ):
|
def __new__( cls, target, onDelete=None, *arguments,**named ):
|
||||||
"""Create new instance or return current instance
|
"""Create new instance or return current instance
|
||||||
|
|
||||||
Basically this method of construction allows us to
|
Basically this method of construction allows us to
|
||||||
short-circuit creation of references to already-
|
short-circuit creation of references to already-
|
||||||
referenced instance methods. The key corresponding
|
referenced instance methods. The key corresponding
|
||||||
to the target is calculated, and if there is already
|
to the target is calculated, and if there is already
|
||||||
an existing reference, that is returned, with its
|
an existing reference, that is returned, with its
|
||||||
deletionMethods attribute updated. Otherwise the
|
deletionMethods attribute updated. Otherwise the
|
||||||
new instance is created and registered in the table
|
new instance is created and registered in the table
|
||||||
of already-referenced methods.
|
of already-referenced methods.
|
||||||
"""
|
"""
|
||||||
key = cls.calculateKey(target)
|
key = cls.calculateKey(target)
|
||||||
current =cls._allInstances.get(key)
|
current =cls._allInstances.get(key)
|
||||||
if current is not None:
|
if current is not None:
|
||||||
current.deletionMethods.append( onDelete)
|
current.deletionMethods.append( onDelete)
|
||||||
return current
|
return current
|
||||||
else:
|
else:
|
||||||
base = super( BoundMethodWeakref, cls).__new__( cls )
|
base = super( BoundMethodWeakref, cls).__new__( cls )
|
||||||
cls._allInstances[key] = base
|
cls._allInstances[key] = base
|
||||||
base.__init__( target, onDelete, *arguments,**named)
|
base.__init__( target, onDelete, *arguments,**named)
|
||||||
return base
|
return base
|
||||||
def __init__(self, target, onDelete=None):
|
def __init__(self, target, onDelete=None):
|
||||||
"""Return a weak-reference-like instance for a bound method
|
"""Return a weak-reference-like instance for a bound method
|
||||||
|
|
||||||
target -- the instance-method target for the weak
|
target -- the instance-method target for the weak
|
||||||
reference, must have im_self and im_func attributes
|
reference, must have im_self and im_func attributes
|
||||||
and be reconstructable via:
|
and be reconstructable via:
|
||||||
target.im_func.__get__( target.im_self )
|
target.im_func.__get__( target.im_self )
|
||||||
which is true of built-in instance methods.
|
which is true of built-in instance methods.
|
||||||
onDelete -- optional callback which will be called
|
onDelete -- optional callback which will be called
|
||||||
when this weak reference ceases to be valid
|
when this weak reference ceases to be valid
|
||||||
(i.e. either the object or the function is garbage
|
(i.e. either the object or the function is garbage
|
||||||
collected). Should take a single argument,
|
collected). Should take a single argument,
|
||||||
which will be passed a pointer to this object.
|
which will be passed a pointer to this object.
|
||||||
"""
|
"""
|
||||||
def remove(weak, self=self):
|
def remove(weak, self=self):
|
||||||
"""Set self.isDead to true when method or instance is destroyed"""
|
"""Set self.isDead to true when method or instance is destroyed"""
|
||||||
methods = self.deletionMethods[:]
|
methods = self.deletionMethods[:]
|
||||||
del self.deletionMethods[:]
|
del self.deletionMethods[:]
|
||||||
try:
|
try:
|
||||||
del self.__class__._allInstances[ self.key ]
|
del self.__class__._allInstances[ self.key ]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
for function in methods:
|
for function in methods:
|
||||||
try:
|
try:
|
||||||
if callable( function ):
|
if callable( function ):
|
||||||
function( self )
|
function( self )
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
try:
|
try:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
except AttributeError, err:
|
except AttributeError, err:
|
||||||
print '''Exception during saferef %s cleanup function %s: %s'''%(
|
print '''Exception during saferef %s cleanup function %s: %s'''%(
|
||||||
self, function, e
|
self, function, e
|
||||||
)
|
)
|
||||||
self.deletionMethods = [onDelete]
|
self.deletionMethods = [onDelete]
|
||||||
self.key = self.calculateKey( target )
|
self.key = self.calculateKey( target )
|
||||||
self.weakSelf = weakref.ref(target.im_self, remove)
|
self.weakSelf = weakref.ref(target.im_self, remove)
|
||||||
self.weakFunc = weakref.ref(target.im_func, remove)
|
self.weakFunc = weakref.ref(target.im_func, remove)
|
||||||
self.selfName = str(target.im_self)
|
self.selfName = str(target.im_self)
|
||||||
self.funcName = str(target.im_func.__name__)
|
self.funcName = str(target.im_func.__name__)
|
||||||
def calculateKey( cls, target ):
|
def calculateKey( cls, target ):
|
||||||
"""Calculate the reference key for this reference
|
"""Calculate the reference key for this reference
|
||||||
|
|
||||||
Currently this is a two-tuple of the id()'s of the
|
Currently this is a two-tuple of the id()'s of the
|
||||||
target object and the target function respectively.
|
target object and the target function respectively.
|
||||||
"""
|
"""
|
||||||
return (id(target.im_self),id(target.im_func))
|
return (id(target.im_self),id(target.im_func))
|
||||||
calculateKey = classmethod( calculateKey )
|
calculateKey = classmethod( calculateKey )
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Give a friendly representation of the object"""
|
"""Give a friendly representation of the object"""
|
||||||
return """%s( %s.%s )"""%(
|
return """%s( %s.%s )"""%(
|
||||||
self.__class__.__name__,
|
self.__class__.__name__,
|
||||||
self.selfName,
|
self.selfName,
|
||||||
self.funcName,
|
self.funcName,
|
||||||
)
|
)
|
||||||
__repr__ = __str__
|
__repr__ = __str__
|
||||||
def __nonzero__( self ):
|
def __nonzero__( self ):
|
||||||
"""Whether we are still a valid reference"""
|
"""Whether we are still a valid reference"""
|
||||||
return self() is not None
|
return self() is not None
|
||||||
def __cmp__( self, other ):
|
def __cmp__( self, other ):
|
||||||
"""Compare with another reference"""
|
"""Compare with another reference"""
|
||||||
if not isinstance (other,self.__class__):
|
if not isinstance (other,self.__class__):
|
||||||
return cmp( self.__class__, type(other) )
|
return cmp( self.__class__, type(other) )
|
||||||
return cmp( self.key, other.key)
|
return cmp( self.key, other.key)
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
"""Return a strong reference to the bound method
|
"""Return a strong reference to the bound method
|
||||||
|
|
||||||
If the target cannot be retrieved, then will
|
If the target cannot be retrieved, then will
|
||||||
return None, otherwise returns a bound instance
|
return None, otherwise returns a bound instance
|
||||||
method for our object and function.
|
method for our object and function.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
You may call this method any number of times,
|
You may call this method any number of times,
|
||||||
as it does not invalidate the reference.
|
as it does not invalidate the reference.
|
||||||
"""
|
"""
|
||||||
target = self.weakSelf()
|
target = self.weakSelf()
|
||||||
if target is not None:
|
if target is not None:
|
||||||
function = self.weakFunc()
|
function = self.weakFunc()
|
||||||
if function is not None:
|
if function is not None:
|
||||||
return function.__get__(target)
|
return function.__get__(target)
|
||||||
return None
|
return None
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
from Cookie import SimpleCookie
|
from Cookie import SimpleCookie
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from urllib import urlencode, quote
|
from urllib import urlencode, quote
|
||||||
@ -38,6 +39,9 @@ class HttpRequest(object):
|
|||||||
def get_full_path(self):
|
def get_full_path(self):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def is_secure(self):
|
||||||
|
return os.environ.get("HTTPS") == "on"
|
||||||
|
|
||||||
def parse_file_upload(header_dict, post_data):
|
def parse_file_upload(header_dict, post_data):
|
||||||
"Returns a tuple of (POST MultiValueDict, FILES MultiValueDict)"
|
"Returns a tuple of (POST MultiValueDict, FILES MultiValueDict)"
|
||||||
import email, email.Message
|
import email, email.Message
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers
|
from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers
|
||||||
from django.http import HttpResponseNotModified
|
|
||||||
|
|
||||||
class CacheMiddleware(object):
|
class CacheMiddleware(object):
|
||||||
"""
|
"""
|
||||||
@ -10,6 +9,11 @@ class CacheMiddleware(object):
|
|||||||
|
|
||||||
Only parameter-less GET or HEAD-requests with status code 200 are cached.
|
Only parameter-less GET or HEAD-requests with status code 200 are cached.
|
||||||
|
|
||||||
|
If CACHE_MIDDLEWARE_ANONYMOUS_ONLY is set to True, only anonymous requests
|
||||||
|
(i.e., those node made by a logged-in user) will be cached. This is a
|
||||||
|
simple and effective way of avoiding the caching of the Django admin (and
|
||||||
|
any other user-specific content).
|
||||||
|
|
||||||
This middleware expects that a HEAD request is answered with a response
|
This middleware expects that a HEAD request is answered with a response
|
||||||
exactly like the corresponding GET request.
|
exactly like the corresponding GET request.
|
||||||
|
|
||||||
@ -23,13 +27,17 @@ class CacheMiddleware(object):
|
|||||||
This middleware also sets ETag, Last-Modified, Expires and Cache-Control
|
This middleware also sets ETag, Last-Modified, Expires and Cache-Control
|
||||||
headers on the response object.
|
headers on the response object.
|
||||||
"""
|
"""
|
||||||
def __init__(self, cache_timeout=None, key_prefix=None):
|
def __init__(self, cache_timeout=None, key_prefix=None, cache_anonymous_only=None):
|
||||||
self.cache_timeout = cache_timeout
|
self.cache_timeout = cache_timeout
|
||||||
if cache_timeout is None:
|
if cache_timeout is None:
|
||||||
self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
|
self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
|
||||||
self.key_prefix = key_prefix
|
self.key_prefix = key_prefix
|
||||||
if key_prefix is None:
|
if key_prefix is None:
|
||||||
self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
|
self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
|
||||||
|
if cache_anonymous_only is None:
|
||||||
|
self.cache_anonymous_only = getattr(settings, 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY', False)
|
||||||
|
else:
|
||||||
|
self.cache_anonymous_only = cache_anonymous_only
|
||||||
|
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
"Checks whether the page is already cached and returns the cached version if available."
|
"Checks whether the page is already cached and returns the cached version if available."
|
||||||
@ -37,6 +45,10 @@ class CacheMiddleware(object):
|
|||||||
request._cache_update_cache = False
|
request._cache_update_cache = False
|
||||||
return None # Don't bother checking the cache.
|
return None # Don't bother checking the cache.
|
||||||
|
|
||||||
|
if self.cache_anonymous_only and request.user.is_authenticated():
|
||||||
|
request._cache_update_cache = False
|
||||||
|
return None # Don't cache requests from authenticated users.
|
||||||
|
|
||||||
cache_key = get_cache_key(request, self.key_prefix)
|
cache_key = get_cache_key(request, self.key_prefix)
|
||||||
if cache_key is None:
|
if cache_key is None:
|
||||||
request._cache_update_cache = True
|
request._cache_update_cache = True
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django import http
|
from django import http
|
||||||
from django.core.mail import mail_managers
|
from django.core.mail import mail_managers
|
||||||
import md5, os
|
import md5
|
||||||
|
|
||||||
class CommonMiddleware(object):
|
class CommonMiddleware(object):
|
||||||
"""
|
"""
|
||||||
@ -44,7 +44,7 @@ class CommonMiddleware(object):
|
|||||||
if new_url != old_url:
|
if new_url != old_url:
|
||||||
# Redirect
|
# Redirect
|
||||||
if new_url[0]:
|
if new_url[0]:
|
||||||
newurl = "%s://%s%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', new_url[0], new_url[1])
|
newurl = "%s://%s%s" % (request.is_secure() and 'https' or 'http', new_url[0], new_url[1])
|
||||||
else:
|
else:
|
||||||
newurl = new_url[1]
|
newurl = new_url[1]
|
||||||
if request.GET:
|
if request.GET:
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from django.conf import settings
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
class TransactionMiddleware(object):
|
class TransactionMiddleware(object):
|
||||||
|
@ -708,9 +708,9 @@ class DebugNodeList(NodeList):
|
|||||||
if not hasattr(e, 'source'):
|
if not hasattr(e, 'source'):
|
||||||
e.source = node.source
|
e.source = node.source
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception, e:
|
||||||
from sys import exc_info
|
from sys import exc_info
|
||||||
wrapped = TemplateSyntaxError('Caught an exception while rendering.')
|
wrapped = TemplateSyntaxError('Caught an exception while rendering: %s' % e)
|
||||||
wrapped.source = node.source
|
wrapped.source = node.source
|
||||||
wrapped.exc_info = exc_info()
|
wrapped.exc_info = exc_info()
|
||||||
raise wrapped
|
raise wrapped
|
||||||
@ -817,7 +817,7 @@ class Library(object):
|
|||||||
self.filters[name] = filter_func
|
self.filters[name] = filter_func
|
||||||
return filter_func
|
return filter_func
|
||||||
else:
|
else:
|
||||||
raise InvalidTemplateLibrary, "Unsupported arguments to Library.filter: (%r, %r, %r)", (name, compile_function, has_arg)
|
raise InvalidTemplateLibrary, "Unsupported arguments to Library.filter: (%r, %r)", (name, filter_func)
|
||||||
|
|
||||||
def filter_function(self, func):
|
def filter_function(self, func):
|
||||||
self.filters[func.__name__] = func
|
self.filters[func.__name__] = func
|
||||||
|
@ -133,7 +133,7 @@ def wordwrap(value, arg):
|
|||||||
"""
|
"""
|
||||||
Wraps words at specified line length
|
Wraps words at specified line length
|
||||||
|
|
||||||
Argument: number of words to wrap the text at.
|
Argument: number of characters to wrap the text at.
|
||||||
"""
|
"""
|
||||||
from django.utils.text import wrap
|
from django.utils.text import wrap
|
||||||
return wrap(str(value), int(arg))
|
return wrap(str(value), int(arg))
|
||||||
@ -438,7 +438,7 @@ def pluralize(value, arg='s'):
|
|||||||
the comma is used for the singular case.
|
the comma is used for the singular case.
|
||||||
"""
|
"""
|
||||||
if not ',' in arg:
|
if not ',' in arg:
|
||||||
arg = ',' + arg
|
arg = ',' + arg
|
||||||
bits = arg.split(',')
|
bits = arg.split(',')
|
||||||
if len(bits) > 2:
|
if len(bits) > 2:
|
||||||
return ''
|
return ''
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
# installed, because pkg_resources is necessary to read eggs.
|
# installed, because pkg_resources is necessary to read eggs.
|
||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.template import Origin, StringOrigin, Template, Context, TemplateDoesNotExist, add_to_builtins
|
from django.template import Origin, Template, Context, TemplateDoesNotExist, add_to_builtins
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
template_source_loaders = None
|
template_source_loaders = None
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from django.template import TemplateSyntaxError, TemplateDoesNotExist, resolve_variable
|
from django.template import TemplateSyntaxError, TemplateDoesNotExist, resolve_variable
|
||||||
from django.template import Library, Context, Node
|
from django.template import Library, Node
|
||||||
from django.template.loader import get_template, get_template_from_string, find_template_source
|
from django.template.loader import get_template, get_template_from_string, find_template_source
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
from django.template import Node, NodeList, Template, Context, resolve_variable
|
from django.template import Node, resolve_variable
|
||||||
from django.template import TemplateSyntaxError, TokenParser, Library
|
from django.template import TemplateSyntaxError, TokenParser, Library
|
||||||
from django.template import TOKEN_BLOCK, TOKEN_TEXT, TOKEN_VAR
|
from django.template import TOKEN_TEXT, TOKEN_VAR
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
import re, sys
|
|
||||||
|
|
||||||
register = Library()
|
register = Library()
|
||||||
|
|
||||||
@ -228,7 +227,7 @@ def do_block_translate(parser, token):
|
|||||||
break
|
break
|
||||||
if countervar and counter:
|
if countervar and counter:
|
||||||
if token.contents.strip() != 'plural':
|
if token.contents.strip() != 'plural':
|
||||||
raise TemplateSyntaxError, "'blocktrans' doesn't allow other block tags inside it" % tag
|
raise TemplateSyntaxError, "'blocktrans' doesn't allow other block tags inside it"
|
||||||
while parser.tokens:
|
while parser.tokens:
|
||||||
token = parser.next_token()
|
token = parser.next_token()
|
||||||
if token.token_type in (TOKEN_VAR, TOKEN_TEXT):
|
if token.token_type in (TOKEN_VAR, TOKEN_TEXT):
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
termcolors.py
|
termcolors.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import types
|
|
||||||
|
|
||||||
color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white')
|
color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white')
|
||||||
foreground = dict([(color_names[x], '3%s' % x) for x in range(8)])
|
foreground = dict([(color_names[x], '3%s' % x) for x in range(8)])
|
||||||
background = dict([(color_names[x], '4%s' % x) for x in range(8)])
|
background = dict([(color_names[x], '4%s' % x) for x in range(8)])
|
||||||
|
@ -17,3 +17,11 @@ get_language = lambda: settings.LANGUAGE_CODE
|
|||||||
get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
|
get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
|
||||||
get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, settings.TIME_FORMAT)
|
get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, settings.TIME_FORMAT)
|
||||||
get_partial_date_formats = lambda: (settings.YEAR_MONTH_FORMAT, settings.MONTH_DAY_FORMAT)
|
get_partial_date_formats = lambda: (settings.YEAR_MONTH_FORMAT, settings.MONTH_DAY_FORMAT)
|
||||||
|
check_for_language = lambda x: True
|
||||||
|
|
||||||
|
def to_locale(language):
|
||||||
|
p = language.find('-')
|
||||||
|
if p >= 0:
|
||||||
|
return language[:p].lower()+'_'+language[p+1:].upper()
|
||||||
|
else:
|
||||||
|
return language.lower()
|
||||||
|
@ -3,8 +3,6 @@ from django.template import Template, Context, TemplateDoesNotExist
|
|||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.http import HttpResponseServerError, HttpResponseNotFound
|
from django.http import HttpResponseServerError, HttpResponseNotFound
|
||||||
import os, re
|
import os, re
|
||||||
from itertools import count, izip
|
|
||||||
from os.path import dirname, join as pathjoin
|
|
||||||
|
|
||||||
HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD')
|
HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD')
|
||||||
|
|
||||||
@ -124,7 +122,7 @@ def technical_500_response(request, exc_type, exc_value, tb):
|
|||||||
'frames': frames,
|
'frames': frames,
|
||||||
'lastframe': frames[-1],
|
'lastframe': frames[-1],
|
||||||
'request': request,
|
'request': request,
|
||||||
'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http",
|
'request_protocol': request.is_secure() and "https" or "http",
|
||||||
'settings': get_safe_settings(),
|
'settings': get_safe_settings(),
|
||||||
'template_info': template_info,
|
'template_info': template_info,
|
||||||
'template_does_not_exist': template_does_not_exist,
|
'template_does_not_exist': template_does_not_exist,
|
||||||
@ -149,7 +147,7 @@ def technical_404_response(request, exception):
|
|||||||
'urlpatterns': tried,
|
'urlpatterns': tried,
|
||||||
'reason': str(exception),
|
'reason': str(exception),
|
||||||
'request': request,
|
'request': request,
|
||||||
'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http",
|
'request_protocol': request.is_secure() and "https" or "http",
|
||||||
'settings': get_safe_settings(),
|
'settings': get_safe_settings(),
|
||||||
})
|
})
|
||||||
return HttpResponseNotFound(t.render(c), mimetype='text/html')
|
return HttpResponseNotFound(t.render(c), mimetype='text/html')
|
||||||
|
@ -10,7 +10,6 @@ example, as that is unique across a Django project.
|
|||||||
Additionally, all headers from the response's Vary header will be taken into
|
Additionally, all headers from the response's Vary header will be taken into
|
||||||
account on caching -- just like the middleware does.
|
account on caching -- just like the middleware does.
|
||||||
"""
|
"""
|
||||||
import re
|
|
||||||
|
|
||||||
from django.utils.decorators import decorator_from_middleware
|
from django.utils.decorators import decorator_from_middleware
|
||||||
from django.utils.cache import patch_cache_control, add_never_cache_headers
|
from django.utils.cache import patch_cache_control, add_never_cache_headers
|
||||||
|
@ -4,7 +4,6 @@ from django import forms
|
|||||||
from django.db.models import FileField
|
from django.db.models import FileField
|
||||||
from django.contrib.auth.views import redirect_to_login
|
from django.contrib.auth.views import redirect_to_login
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.core.paginator import ObjectPaginator, InvalidPage
|
|
||||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||||
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
|
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
|
||||||
|
|
||||||
@ -20,7 +19,7 @@ def create_object(request, model, template_name=None,
|
|||||||
the form wrapper for the object
|
the form wrapper for the object
|
||||||
"""
|
"""
|
||||||
if extra_context is None: extra_context = {}
|
if extra_context is None: extra_context = {}
|
||||||
if login_required and request.user.is_anonymous():
|
if login_required and not request.user.is_authenticated():
|
||||||
return redirect_to_login(request.path)
|
return redirect_to_login(request.path)
|
||||||
|
|
||||||
manipulator = model.AddManipulator(follow=follow)
|
manipulator = model.AddManipulator(follow=follow)
|
||||||
@ -39,7 +38,7 @@ def create_object(request, model, template_name=None,
|
|||||||
# No errors -- this means we can save the data!
|
# No errors -- this means we can save the data!
|
||||||
new_object = manipulator.save(new_data)
|
new_object = manipulator.save(new_data)
|
||||||
|
|
||||||
if not request.user.is_anonymous():
|
if request.user.is_authenticated():
|
||||||
request.user.message_set.create(message="The %s was created successfully." % model._meta.verbose_name)
|
request.user.message_set.create(message="The %s was created successfully." % model._meta.verbose_name)
|
||||||
|
|
||||||
# Redirect to the new object: first by trying post_save_redirect,
|
# Redirect to the new object: first by trying post_save_redirect,
|
||||||
@ -86,7 +85,7 @@ def update_object(request, model, object_id=None, slug=None,
|
|||||||
the original object being edited
|
the original object being edited
|
||||||
"""
|
"""
|
||||||
if extra_context is None: extra_context = {}
|
if extra_context is None: extra_context = {}
|
||||||
if login_required and request.user.is_anonymous():
|
if login_required and not request.user.is_authenticated():
|
||||||
return redirect_to_login(request.path)
|
return redirect_to_login(request.path)
|
||||||
|
|
||||||
# Look up the object to be edited
|
# Look up the object to be edited
|
||||||
@ -113,7 +112,7 @@ def update_object(request, model, object_id=None, slug=None,
|
|||||||
if not errors:
|
if not errors:
|
||||||
object = manipulator.save(new_data)
|
object = manipulator.save(new_data)
|
||||||
|
|
||||||
if not request.user.is_anonymous():
|
if request.user.is_authenticated():
|
||||||
request.user.message_set.create(message="The %s was updated successfully." % model._meta.verbose_name)
|
request.user.message_set.create(message="The %s was updated successfully." % model._meta.verbose_name)
|
||||||
|
|
||||||
# Do a post-after-redirect so that reload works, etc.
|
# Do a post-after-redirect so that reload works, etc.
|
||||||
@ -162,7 +161,7 @@ def delete_object(request, model, post_delete_redirect,
|
|||||||
the original object being deleted
|
the original object being deleted
|
||||||
"""
|
"""
|
||||||
if extra_context is None: extra_context = {}
|
if extra_context is None: extra_context = {}
|
||||||
if login_required and request.user.is_anonymous():
|
if login_required and not request.user.is_authenticated():
|
||||||
return redirect_to_login(request.path)
|
return redirect_to_login(request.path)
|
||||||
|
|
||||||
# Look up the object to be edited
|
# Look up the object to be edited
|
||||||
@ -180,7 +179,7 @@ def delete_object(request, model, post_delete_redirect,
|
|||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
object.delete()
|
object.delete()
|
||||||
if not request.user.is_anonymous():
|
if request.user.is_authenticated():
|
||||||
request.user.message_set.create(message="The %s was deleted." % model._meta.verbose_name)
|
request.user.message_set.create(message="The %s was deleted." % model._meta.verbose_name)
|
||||||
return HttpResponseRedirect(post_delete_redirect)
|
return HttpResponseRedirect(post_delete_redirect)
|
||||||
else:
|
else:
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from django.template import loader
|
from django.template import loader
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified
|
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified
|
||||||
from django.template import Template, Context, TemplateDoesNotExist
|
from django.template import Template, Context, TemplateDoesNotExist
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
@ -118,8 +118,8 @@ additional class on the ``a`` for that tool. These are ``.addlink`` and
|
|||||||
Example from a changelist page::
|
Example from a changelist page::
|
||||||
|
|
||||||
<ul class="object-tools">
|
<ul class="object-tools">
|
||||||
<li><a href="/stories/add/" class="addlink">Add redirect</a></li>
|
<li><a href="/stories/add/" class="addlink">Add redirect</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
.. image:: http://media.djangoproject.com/img/doc/admincss/objecttools_01.gif
|
.. image:: http://media.djangoproject.com/img/doc/admincss/objecttools_01.gif
|
||||||
:alt: Object tools on a changelist page
|
:alt: Object tools on a changelist page
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user