Skip to content

Commit

Permalink
newforms-admin: Merged to [6050]
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6051 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Sep 5, 2007
1 parent bd01c6e commit 976acdc
Show file tree
Hide file tree
Showing 28 changed files with 431 additions and 176 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -260,6 +260,7 @@ answer newbie questions, and generally made Django that much better:
Vasiliy Stavenko <stavenko@gmail.com>
Thomas Steinacher <http://www.eggdrop.ch/>
nowell strite
Thomas Stromberg <tstromberg@google.com>
Sundance
SuperJared
Radek Švarz <http://www.svarz.cz/translate/>
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/csrf/middleware.py
Expand Up @@ -40,7 +40,7 @@ class CsrfMiddleware(object):
"""

def process_request(self, request):
if request.POST:
if request.method == 'POST':
try:
session_id = request.COOKIES[settings.SESSION_COOKIE_NAME]
except KeyError:
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/localflavor/it/it_province.py
Expand Up @@ -45,7 +45,7 @@
('IM', 'Imperia'),
('IS', 'Isernia'),
('SP', 'La Spezia'),
('AQ', u'L’Acquila'),
('AQ', u'L’Aquila'),
('LT', 'Latina'),
('LE', 'Lecce'),
('LC', 'Lecco'),
Expand Down
16 changes: 14 additions & 2 deletions django/core/management/base.py
@@ -1,6 +1,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.core.management.color import color_style
import sys
import os

class CommandError(Exception):
pass
Expand Down Expand Up @@ -44,7 +45,7 @@ def execute(self, *args, **options):
sys.stderr.write(self.style.ERROR(str('Error: %s\n' % e)))
sys.exit(1)

def validate(self, app=None):
def validate(self, app=None, display_num_errors=False):
"""
Validates the given app, raising CommandError for any errors.
Expand All @@ -61,6 +62,8 @@ def validate(self, app=None):
s.seek(0)
error_text = s.read()
raise CommandError("One or more models did not validate:\n%s" % error_text)
if display_num_errors:
print "%s error%s found" % (num_errors, num_errors != 1 and 's' or '')

def handle(self, *args, **options):
raise NotImplementedError()
Expand Down Expand Up @@ -119,7 +122,6 @@ def handle_noargs(self, **options):

def copy_helper(style, app_or_project, name, directory, other_name=''):
import django
import os
import re
import shutil
other = {'project': 'app', 'app': 'project'}[app_or_project]
Expand Down Expand Up @@ -155,5 +157,15 @@ def copy_helper(style, app_or_project, name, directory, other_name=''):
fp_new.close()
try:
shutil.copymode(path_old, path_new)
_make_writeable(path_new)
except OSError:
sys.stderr.write(style.NOTICE("Notice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.\n" % path_new))

def _make_writeable(filename):
"Makes sure that the file is writeable. Useful if our source is read-only."
import stat
if not os.access(filename, os.W_OK):
st = os.stat(filename)
new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR
os.chmod(filename, new_permissions)

2 changes: 1 addition & 1 deletion django/core/management/color.py
Expand Up @@ -7,7 +7,7 @@

def color_style():
"Returns a Style object with the Django color scheme."
if sys.platform == 'win32' or sys.platform == 'Pocket PC' or not sys.stdout.isatty():
if sys.platform == 'win32' or sys.platform == 'Pocket PC' or sys.platform.startswith('java') or not sys.stdout.isatty():
return no_style()
class dummy: pass
style = dummy()
Expand Down
2 changes: 1 addition & 1 deletion django/core/management/commands/runserver.py
Expand Up @@ -37,7 +37,7 @@ def handle(self, addrport='', *args, **options):
def inner_run():
from django.conf import settings
print "Validating models..."
self.validate()
self.validate(display_num_errors=True)
print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
print "Development server is running at http://%s:%s/" % (addr, port)
print "Quit the server with %s." % quit_command
Expand Down
5 changes: 0 additions & 5 deletions django/core/management/commands/startproject.py
Expand Up @@ -28,11 +28,6 @@ def handle_label(self, project_name, **options):
# Create a random SECRET_KEY hash, and put it in the main settings.
main_settings_file = os.path.join(directory, project_name, 'settings.py')
settings_contents = open(main_settings_file, 'r').read()

# If settings.py was copied from a read-only source, make it writeable.
if not os.access(main_settings_file, os.W_OK):
os.chmod(main_settings_file, 0600)

fp = open(main_settings_file, 'w')
secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
settings_contents = re.sub(r"(?<=SECRET_KEY = ')'", secret_key + "'", settings_contents)
Expand Down
2 changes: 1 addition & 1 deletion django/core/management/commands/validate.py
Expand Up @@ -6,4 +6,4 @@ class Command(NoArgsCommand):
requires_model_validation = False

def handle_noargs(self, **options):
self.validate()
self.validate(display_num_errors=True)
6 changes: 5 additions & 1 deletion django/db/backends/sqlite3/base.py
@@ -1,5 +1,9 @@
"""
SQLite3 backend for django. Requires pysqlite2 (http://pysqlite.org/).
SQLite3 backend for django.
Python 2.3 and 2.4 require pysqlite2 (http://pysqlite.org/).
Python 2.5 and later use the sqlite3 module in the standard library.
"""

from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
Expand Down
65 changes: 56 additions & 9 deletions django/template/defaultfilters.py
Expand Up @@ -355,8 +355,8 @@ def unordered_list(value):
Recursively takes a self-nested list and returns an HTML unordered list --
WITHOUT opening and closing <ul> tags.
The list is assumed to be in the proper format. For example, if ``var`` contains
``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``,
The list is assumed to be in the proper format. For example, if ``var``
contains: ``['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]``,
then ``{{ var|unordered_list }}`` would return::
<li>States
Expand All @@ -371,14 +371,61 @@ def unordered_list(value):
</ul>
</li>
"""
def _helper(value, tabs):
def convert_old_style_list(list_):
"""
Converts old style lists to the new easier to understand format.
The old list format looked like:
['Item 1', [['Item 1.1', []], ['Item 1.2', []]]
And it is converted to:
['Item 1', ['Item 1.1', 'Item 1.2]]
"""
if not isinstance(list_, (tuple, list)) or len(list_) != 2:
return list_, False
first_item, second_item = list_
if second_item == []:
return [first_item], True
old_style_list = True
new_second_item = []
for sublist in second_item:
item, old_style_list = convert_old_style_list(sublist)
if not old_style_list:
break
new_second_item.extend(item)
if old_style_list:
second_item = new_second_item
return [first_item, second_item], old_style_list
def _helper(list_, tabs=1):
indent = u'\t' * tabs
if value[1]:
return u'%s<li>%s\n%s<ul>\n%s\n%s</ul>\n%s</li>' % (indent, force_unicode(value[0]), indent,
u'\n'.join([_helper(v, tabs+1) for v in value[1]]), indent, indent)
else:
return u'%s<li>%s</li>' % (indent, force_unicode(value[0]))
return _helper(value, 1)
output = []

list_length = len(list_)
i = 0
while i < list_length:
title = list_[i]
sublist = ''
sublist_item = None
if isinstance(title, (list, tuple)):
sublist_item = title
title = ''
elif i < list_length - 1:
next_item = list_[i+1]
if next_item and isinstance(next_item, (list, tuple)):
# The next item is a sub-list.
sublist_item = next_item
# We've processed the next item now too.
i += 1
if sublist_item:
sublist = _helper(sublist_item, tabs+1)
sublist = '\n%s<ul>\n%s\n%s</ul>\n%s' % (indent, sublist,
indent, indent)
output.append('%s<li>%s%s</li>' % (indent, force_unicode(title),
sublist))
i += 1
return '\n'.join(output)
value, converted = convert_old_style_list(value)
return _helper(value)

###################
# INTEGERS #
Expand Down
25 changes: 20 additions & 5 deletions django/test/client.py
Expand Up @@ -11,6 +11,7 @@
from django.core.signals import got_request_exception
from django.dispatch import dispatcher
from django.http import SimpleCookie, HttpRequest
from django.template import TemplateDoesNotExist
from django.test import signals
from django.utils.functional import curry
from django.utils.encoding import smart_str
Expand Down Expand Up @@ -165,7 +166,25 @@ def request(self, **request):
# Capture exceptions created by the handler
dispatcher.connect(self.store_exc_info, signal=got_request_exception)

response = self.handler(environ)
try:
response = self.handler(environ)
except TemplateDoesNotExist, e:
# If the view raises an exception, Django will attempt to show
# the 500.html template. If that template is not available,
# we should ignore the error in favor of re-raising the
# underlying exception that caused the 500 error. Any other
# template found to be missing during view error handling
# should be reported as-is.
if e.args != ('500.html',):
raise

# Look for a signalled exception and reraise it
if self.exc_info:
raise self.exc_info[1], None, self.exc_info[2]

# Save the client and request that stimulated the response
response.client = self
response.request = request

# Add any rendered template detail to the response
# If there was only one template rendered (the most likely case),
Expand All @@ -179,10 +198,6 @@ def request(self, **request):
else:
setattr(response, detail, None)

# Look for a signalled exception and reraise it
if self.exc_info:
raise self.exc_info[1], None, self.exc_info[2]

# Update persistent cookie data
if response.cookies:
self.cookies.update(response.cookies)
Expand Down

0 comments on commit 976acdc

Please sign in to comment.