From daa467d79ec7b40e376294eabc51222a67690181 Mon Sep 17 00:00:00 2001 From: Joseph Kocherhans Date: Thu, 17 Jan 2008 18:12:24 +0000 Subject: newforms-admin: Merged from trunk up to [7021]. git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7022 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/oracle/base.py | 23 ++++++++++++++++++----- django/db/models/fields/__init__.py | 6 +++++- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'django/db') diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index cd830413fc..70f5688d1a 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -413,6 +413,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): return self.connection is not None def _cursor(self, settings): + cursor = None if not self._valid_connection(): if len(settings.DATABASE_HOST.strip()) == 0: settings.DATABASE_HOST = 'localhost' @@ -422,16 +423,25 @@ class DatabaseWrapper(BaseDatabaseWrapper): else: conn_string = "%s/%s@%s" % (settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME) self.connection = Database.connect(conn_string, **self.options) + cursor = FormatStylePlaceholderCursor(self.connection) + # Set oracle date to ansi date format. This only needs to execute + # once when we create a new connection. + cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD' " + "NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") try: self.oracle_version = int(self.connection.version.split('.')[0]) except ValueError: pass - cursor = FormatStylePlaceholderCursor(self.connection) + try: + self.connection.stmtcachesize = 20 + except: + # Django docs specify cx_Oracle version 4.3.1 or higher, but + # stmtcachesize is available only in 4.3.2 and up. + pass + if not cursor: + cursor = FormatStylePlaceholderCursor(self.connection) # Default arraysize of 1 is highly sub-optimal. cursor.arraysize = 100 - # Set oracle date to ansi date format. - cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'") - cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") return cursor class FormatStylePlaceholderCursor(Database.Cursor): @@ -506,7 +516,10 @@ class FormatStylePlaceholderCursor(Database.Cursor): return Database.Cursor.executemany(self, query, new_param_list) def fetchone(self): - return to_unicode(Database.Cursor.fetchone(self)) + row = Database.Cursor.fetchone(self) + if row is None: + return row + return tuple([to_unicode(e) for e in row]) def fetchmany(self, size=None): if size is None: diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 0ea4eae6e7..a41217fef0 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -795,13 +795,17 @@ class FileField(Field): return os.path.normpath(f) def save_form_data(self, instance, data): - if data: + from django.newforms.fields import UploadedFile + if data and isinstance(data, UploadedFile): getattr(instance, "save_%s_file" % self.name)(data.filename, data.content, save=False) def formfield(self, **kwargs): defaults = {'form_class': forms.FileField} # If a file has been provided previously, then the form doesn't require # that a new file is provided this time. + # The code to mark the form field as not required is used by + # form_for_instance, but can probably be removed once form_for_instance + # is gone. ModelForm uses a different method to check for an existing file. if 'initial' in kwargs: defaults['required'] = False defaults.update(kwargs) -- cgit v1.3