Skip to content

Commit

Permalink
boulder-oracle-sprint: Merged to trunk [4253]
Browse files Browse the repository at this point in the history
  • Loading branch information
Boulder Sprinters committed Dec 28, 2006
1 parent f4aa493 commit 58ba520
Show file tree
Hide file tree
Showing 29 changed files with 950 additions and 1,172 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Expand Up @@ -118,10 +118,12 @@ answer newbie questions, and generally made Django that much better:
Manuzhai
Petar Marić
mark@junklight.com
Yasushi Masuda <whosaysni@gmail.com>
mattycakes@gmail.com
Jason McBrayer <http://www.carcosa.net/jason/>
mccutchen@gmail.com
michael.mcewan@gmail.com
mitakummaa@gmail.com
mmarshall
Eric Moritz <http://eric.themoritzfamily.com/>
Robin Munn <http://www.geekforgod.com/>
Expand Down Expand Up @@ -160,6 +162,7 @@ answer newbie questions, and generally made Django that much better:
Tom Insam
Joe Topjian <http://joe.terrarum.net/geek/code/python/django/>
Karen Tracey <graybark@bellsouth.net>
Makoto Tsuyuki <mtsuyuki@gmail.com>
Amit Upadhyay
Geert Vanderkelen
Milton Waddams
Expand Down
5 changes: 4 additions & 1 deletion django/contrib/admin/templates/admin/base.html
Expand Up @@ -38,7 +38,10 @@
<div id="content" class="{% block coltype %}colM{% endblock %}">
{% block pretitle %}{% endblock %}
{% block content_title %}{% if title %}<h1>{{ title|escape }}</h1>{% endif %}{% endblock %}
{% block content %}{{ content }}{% endblock %}
{% block content %}
{% block object-tools %}{% endblock %}
{{ content }}
{% endblock %}
{% block sidebar %}{% endblock %}
<br class="clear" />
</div>
Expand Down
2 changes: 2 additions & 0 deletions django/contrib/admin/templates/admin/change_form.html
Expand Up @@ -16,11 +16,13 @@
</div>
{% endif %}{% endblock %}
{% block content %}<div id="content-main">
{% block object-tools %}
{% if change %}{% if not is_popup %}
<ul class="object-tools"><li><a href="history/" class="historylink">{% trans "History" %}</a></li>
{% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
</ul>
{% endif %}{% endif %}
{% endblock %}
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% block form_top %}{% endblock %}
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
Expand Down
2 changes: 2 additions & 0 deletions django/contrib/admin/templates/admin/change_list.html
Expand Up @@ -7,9 +7,11 @@
{% block coltype %}flex{% endblock %}
{% block content %}
<div id="content-main">
{% block object-tools %}
{% 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|escape as name %}Add {{ name }}{% endblocktrans %}</a></li></ul>
{% endif %}
{% endblock %}
<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
{% block search %}{% search_form cl %}{% endblock %}
{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/csrf/middleware.py
Expand Up @@ -11,7 +11,7 @@
import re
import itertools

_ERROR_MSG = "<h1>403 Forbidden</h1><p>Cross Site Request Forgery detected. Request aborted.</p>"
_ERROR_MSG = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><body><h1>403 Forbidden</h1><p>Cross Site Request Forgery detected. Request aborted.</p></body></html>'

_POST_FORM_RE = \
re.compile(r'(<form\W[^>]*\bmethod=(\'|"|)POST(\'|"|)\b[^>]*>)', re.IGNORECASE)
Expand Down
5 changes: 4 additions & 1 deletion django/core/handlers/base.py
Expand Up @@ -60,7 +60,10 @@ def get_response(self, request):
if response:
return response

resolver = urlresolvers.RegexURLResolver(r'^/', settings.ROOT_URLCONF)
# Get urlconf from request object, if available. Otherwise use default.
urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)

resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
try:
callback, callback_args, callback_kwargs = resolver.resolve(request.path)

Expand Down
2 changes: 2 additions & 0 deletions django/db/backends/oracle/creation.py
Expand Up @@ -81,6 +81,8 @@ def destroy_test_db(settings, connection, backend, old_database_name, verbosity=
settings.DATABASE_NAME = old_database_name
#settings.DATABASE_USER = 'old_user'
#settings.DATABASE_PASSWORD = 'old_password'
settings.DATABASE_USER = 'mboersma'
settings.DATABASE_PASSWORD = 'password'

cursor = connection.cursor()
time.sleep(1) # To avoid "database is being accessed by other users" errors.
Expand Down
35 changes: 34 additions & 1 deletion django/db/backends/postgresql/base.py
Expand Up @@ -20,6 +20,38 @@
# Import copy of _thread_local.py from Python 2.4
from django.utils._threading_local import local

def smart_basestring(s, charset):
if isinstance(s, unicode):
return s.encode(charset)
return s

class UnicodeCursorWrapper(object):
"""
A thin wrapper around psycopg cursors that allows them to accept Unicode
strings as params.
This is necessary because psycopg doesn't apply any DB quoting to
parameters that are Unicode strings. If a param is Unicode, this will
convert it to a bytestring using DEFAULT_CHARSET before passing it to
psycopg.
"""
def __init__(self, cursor, charset):
self.cursor = cursor
self.charset = charset

def execute(self, sql, params=()):
return self.cursor.execute(sql, [smart_basestring(p, self.charset) for p in params])

def executemany(self, sql, param_list):
new_param_list = [[smart_basestring(p, self.charset) for p in params] for params in param_list]
return self.cursor.executemany(sql, new_param_list)

def __getattr__(self, attr):
if self.__dict__.has_key(attr):
return self.__dict__[attr]
else:
return getattr(self.cursor, attr)

class DatabaseWrapper(local):
def __init__(self, **kwargs):
self.connection = None
Expand All @@ -45,6 +77,7 @@ def cursor(self):
self.connection.set_isolation_level(1) # make transactions transparent to all cursors
cursor = self.connection.cursor()
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
cursor = UnicodeCursorWrapper(cursor, settings.DEFAULT_CHARSET)
if settings.DEBUG:
return util.CursorDebugWrapper(cursor, self)
return cursor
Expand Down Expand Up @@ -131,7 +164,7 @@ def get_autoinc_sql(table):
try:
Database.register_type(Database.new_type((1082,), "DATE", util.typecast_date))
except AttributeError:
raise Exception, "You appear to be using psycopg version 2, which isn't supported yet, because it's still in beta. Use psycopg version 1 instead: http://initd.org/projects/psycopg1"
raise Exception, "You appear to be using psycopg version 2. Set your DATABASE_ENGINE to 'postgresql_psycopg2' instead of 'postgresql'."
Database.register_type(Database.new_type((1083,1266), "TIME", util.typecast_time))
Database.register_type(Database.new_type((1114,1184), "TIMESTAMP", util.typecast_timestamp))
Database.register_type(Database.new_type((16,), "BOOLEAN", util.typecast_boolean))
Expand Down
38 changes: 35 additions & 3 deletions django/db/models/fields/__init__.py
Expand Up @@ -337,11 +337,15 @@ def _get_choices(self):
return self._choices
choices = property(_get_choices)

def formfield(self):
def formfield(self, initial=None):
"Returns a django.newforms.Field instance for this database Field."
from django.newforms import CharField
# TODO: This is just a temporary default during development.
return CharField(label=capfirst(self.verbose_name))
return forms.CharField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial)

def value_from_object(self, obj):
"Returns the value of this field in the given model instance."
return getattr(obj, self.attname)

class AutoField(Field):
empty_strings_allowed = False
Expand Down Expand Up @@ -379,6 +383,9 @@ def contribute_to_class(self, cls, name):
super(AutoField, self).contribute_to_class(cls, name)
cls._meta.has_auto_field = True

def formfield(self, initial=None):
return None

class BooleanField(Field):
def __init__(self, *args, **kwargs):
kwargs['blank'] = True
Expand All @@ -393,6 +400,9 @@ def to_python(self, value):
def get_manipulator_field_objs(self):
return [oldforms.CheckboxField]

def formfield(self, initial=None):
return forms.BooleanField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial)

class CharField(Field):
def get_manipulator_field_objs(self):
return [oldforms.TextField]
Expand All @@ -407,6 +417,9 @@ def to_python(self, value):
raise validators.ValidationError, gettext_lazy("This field cannot be null.")
return str(value)

def formfield(self, initial=None):
return forms.CharField(max_length=self.maxlength, required=not self.blank, label=capfirst(self.verbose_name), initial=initial)

# TODO: Maybe move this into contrib, because it's specialized.
class CommaSeparatedIntegerField(CharField):
def get_manipulator_field_objs(self):
Expand Down Expand Up @@ -480,10 +493,13 @@ def get_db_prep_save(self, value):
def get_manipulator_field_objs(self):
return [oldforms.DateField]

def flatten_data(self, follow, obj = None):
def flatten_data(self, follow, obj=None):
val = self._get_val_from_obj(obj)
return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')}

def formfield(self, initial=None):
return forms.DateField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial)

class DateTimeField(DateField):
def to_python(self, value):
if isinstance(value, datetime.datetime):
Expand Down Expand Up @@ -553,6 +569,9 @@ def flatten_data(self,follow, obj = None):
return {date_field: (val is not None and val.strftime("%Y-%m-%d") or ''),
time_field: (val is not None and val.strftime("%H:%M:%S") or '')}

def formfield(self, initial=None):
return forms.DateTimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial)

class EmailField(CharField):
def __init__(self, *args, **kwargs):
kwargs['maxlength'] = 75
Expand All @@ -567,6 +586,9 @@ def get_manipulator_field_objs(self):
def validate(self, field_data, all_data):
validators.isValidEmail(field_data, all_data)

def formfield(self, initial=None):
return forms.EmailField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial)

class FileField(Field):
def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs):
self.upload_to = upload_to
Expand Down Expand Up @@ -699,6 +721,9 @@ class IntegerField(Field):
def get_manipulator_field_objs(self):
return [oldforms.IntegerField]

def formfield(self, initial=None):
return forms.IntegerField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial)

class IPAddressField(Field):
def __init__(self, *args, **kwargs):
kwargs['maxlength'] = 15
Expand Down Expand Up @@ -799,15 +824,22 @@ def flatten_data(self,follow, obj = None):
val = self._get_val_from_obj(obj)
return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')}

def formfield(self, initial=None):
return forms.TimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial)

class URLField(Field):
def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
if verify_exists:
kwargs.setdefault('validator_list', []).append(validators.isExistingURL)
self.verify_exists = verify_exists
Field.__init__(self, verbose_name, name, **kwargs)

def get_manipulator_field_objs(self):
return [oldforms.URLField]

def formfield(self, initial=None):
return forms.URLField(required=not self.blank, verify_exists=self.verify_exists, label=capfirst(self.verbose_name), initial=initial)

class USStateField(Field):
def get_manipulator_field_objs(self):
return [oldforms.USStateField]
Expand Down

0 comments on commit 58ba520

Please sign in to comment.