Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
Created May 28, 2015 16:31
Show Gist options
  • Save mattdeboard/182e2726ca27cc38dad8 to your computer and use it in GitHub Desktop.
Save mattdeboard/182e2726ca27cc38dad8 to your computer and use it in GitHub Desktop.
def concat_while(s0, s1):
"""
Concatenate s0 and s1 with a space if the length of that concatenation
is less than or equal to 30 characters. Otherwise it just returns s0.
"""
if len(s0) > 30:
return s0[:30]
new = ' '.join([s0, s1])
if len(new) > 30:
return s0
return new
def truncate_name(name):
"""
Truncate a user's name to ensure that the length constraint on the
first_name and last_name fields on the auth_user table are conformed
to.
"""
if ' ' in name:
name = reduce(concat_while, name.split())
else:
name = name[:30]
return name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment