mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
Add a truncate_name method to shorten DB identifiers for Oracle
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@3972 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
23246ebd09
commit
6ab11188d5
@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import md5
|
||||
from time import time
|
||||
|
||||
class CursorDebugWrapper(object):
|
||||
@ -92,6 +93,16 @@ def typecast_boolean(s):
|
||||
def rev_typecast_boolean(obj, d):
|
||||
return obj and '1' or '0'
|
||||
|
||||
def truncate_name(name, length=None):
|
||||
"""Shortens a string to a repeatable mangled version with the given length.
|
||||
"""
|
||||
if length is None or len(name) <= length:
|
||||
return name
|
||||
|
||||
hash = md5.md5(name).hexdigest()[:4]
|
||||
|
||||
return '%s%s' % (name[:length-4], hash)
|
||||
|
||||
##################################################################################
|
||||
# Helper functions for dictfetch* for databases that don't natively support them #
|
||||
##################################################################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user