diff options
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/db/__init__.py | 8 | ||||
| -rw-r--r-- | django/core/db/backends/ado_mssql.py | 4 | ||||
| -rw-r--r-- | django/core/db/backends/mysql.py | 11 | ||||
| -rw-r--r-- | django/core/db/backends/postgresql.py | 5 | ||||
| -rw-r--r-- | django/core/db/backends/sqlite3.py | 5 | ||||
| -rw-r--r-- | django/core/template/defaultfilters.py | 5 | ||||
| -rw-r--r-- | django/core/template/defaulttags.py | 13 |
7 files changed, 38 insertions, 13 deletions
diff --git a/django/core/db/__init__.py b/django/core/db/__init__.py index c4f06e4c6e..6636d4f176 100644 --- a/django/core/db/__init__.py +++ b/django/core/db/__init__.py @@ -1,16 +1,11 @@ """ This is the core database connection. -All CMS code assumes database SELECT statements cast the resulting values as such: +All Django code assumes database SELECT statements cast the resulting values as such: * booleans are mapped to Python booleans * dates are mapped to Python datetime.date objects * times are mapped to Python datetime.time objects * timestamps are mapped to Python datetime.datetime objects - -Right now, we're handling this by using psycopg's custom typecast definitions. -If we move to a different database module, we should ensure that it either -performs the appropriate typecasting out of the box, or that it has hooks that -let us do that. """ from django.conf.settings import DATABASE_ENGINE @@ -41,6 +36,7 @@ get_limit_offset_sql = dbmod.get_limit_offset_sql get_random_function_sql = dbmod.get_random_function_sql get_table_list = dbmod.get_table_list get_relations = dbmod.get_relations +quote_name = dbmod.quote_name OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING DATA_TYPES = dbmod.DATA_TYPES DATA_TYPES_REVERSE = dbmod.DATA_TYPES_REVERSE diff --git a/django/core/db/backends/ado_mssql.py b/django/core/db/backends/ado_mssql.py index 9ea0d5456d..a673c4812e 100644 --- a/django/core/db/backends/ado_mssql.py +++ b/django/core/db/backends/ado_mssql.py @@ -110,6 +110,10 @@ def get_table_list(cursor): def get_relations(cursor, table_name): raise NotImplementedError +def quote_name(name): + # TODO: Figure out how MS-SQL quotes database identifiers. + return name + OPERATOR_MAPPING = { 'exact': '=', 'iexact': 'LIKE', diff --git a/django/core/db/backends/mysql.py b/django/core/db/backends/mysql.py index 4399b6a6a0..e7ede84a12 100644 --- a/django/core/db/backends/mysql.py +++ b/django/core/db/backends/mysql.py @@ -122,18 +122,23 @@ def get_table_list(cursor): def get_relations(cursor, table_name): raise NotImplementedError +def quote_name(name): + if name.startswith("`") and name.endswith("`"): + return name # Quoting once is enough. + return "`%s`" % name + OPERATOR_MAPPING = { 'exact': '=', 'iexact': 'LIKE', - 'contains': 'LIKE', + 'contains': 'LIKE BINARY', 'icontains': 'LIKE', 'ne': '!=', 'gt': '>', 'gte': '>=', 'lt': '<', 'lte': '<=', - 'startswith': 'LIKE', - 'endswith': 'LIKE', + 'startswith': 'LIKE BINARY', + 'endswith': 'LIKE BINARY', 'istartswith': 'LIKE', 'iendswith': 'LIKE', } diff --git a/django/core/db/backends/postgresql.py b/django/core/db/backends/postgresql.py index c922fd42f6..a1de11e3df 100644 --- a/django/core/db/backends/postgresql.py +++ b/django/core/db/backends/postgresql.py @@ -116,6 +116,11 @@ def get_relations(cursor, table_name): continue return relations +def quote_name(name): + if name.startswith('"') and name.endswith('"'): + return name # Quoting once is enough. + return '"%s"' % name + # Register these custom typecasts, because Django expects dates/times to be # in Python's native (standard-library) datetime/time format, whereas psycopg # use mx.DateTime by default. diff --git a/django/core/db/backends/sqlite3.py b/django/core/db/backends/sqlite3.py index ea05302a61..3fde8c77e1 100644 --- a/django/core/db/backends/sqlite3.py +++ b/django/core/db/backends/sqlite3.py @@ -124,6 +124,11 @@ def get_table_list(cursor): def get_relations(cursor, table_name): raise NotImplementedError +def quote_name(name): + if name.startswith('"') and name.endswith('"'): + return name # Quoting once is enough. + return '"%s"' % name + # Operators and fields ######################################################## OPERATOR_MAPPING = { diff --git a/django/core/template/defaultfilters.py b/django/core/template/defaultfilters.py index 2604caf7f9..3a25add5e1 100644 --- a/django/core/template/defaultfilters.py +++ b/django/core/template/defaultfilters.py @@ -27,7 +27,10 @@ def floatformat(text, _): Displays a floating point number as 34.2 (with one decimal place) -- but only if there's a point to be displayed """ - f = float(text) + try: + f = float(text) + except ValueError: + return '' m = f - int(f) if m: return '%.1f' % f diff --git a/django/core/template/defaulttags.py b/django/core/template/defaulttags.py index bea4857dec..d7c53fe947 100644 --- a/django/core/template/defaulttags.py +++ b/django/core/template/defaulttags.py @@ -214,8 +214,12 @@ class SsiNode(Node): self.filepath, self.parsed = filepath, parsed def render(self, context): + from django.conf.settings import DEBUG if not include_is_allowed(self.filepath): - return '' # Fail silently for invalid includes. + if DEBUG: + return "[Didn't have permission to include file]" + else: + return '' # Fail silently for invalid includes. try: fp = open(self.filepath, 'r') output = fp.read() @@ -226,8 +230,11 @@ class SsiNode(Node): try: t = Template(output) return t.render(context) - except TemplateSyntaxError: - return '' # Fail silently for invalid included templates. + except (TemplateSyntaxError, e): + if DEBUG: + return "[Included template had syntax error: %s]" % e + else: + return '' # Fail silently for invalid included templates. return output class LoadNode(Node): |
