Created
May 28, 2015 16:31
-
-
Save mattdeboard/182e2726ca27cc38dad8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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