X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/bdb70243eb9189c92189c05afad9599ab1453946..dcacc3b4c2ba2f550806a2d22b183f6fac4f63ff:/forum/utils/userlinking.py diff --git a/forum/utils/userlinking.py b/forum/utils/userlinking.py index fd7a66d..741a950 100644 --- a/forum/utils/userlinking.py +++ b/forum/utils/userlinking.py @@ -1,44 +1,84 @@ +# -*- coding: utf-8 -*- + import re +from django.utils.encoding import smart_unicode from forum.models.user import User +def find_best_match_in_name(content, uname, fullname, start_index): + uname = smart_unicode(uname) + fullname = smart_unicode(fullname) + + end_index = start_index + len(fullname) + + while end_index > start_index: + if content[start_index : end_index].lower() == fullname.lower(): + return content[start_index : end_index] + + while len(fullname) and fullname[-1] != ' ': + fullname = fullname[:-1] + + fullname = fullname.rstrip() + end_index = start_index + len(fullname) + + return uname + +APPEAL_PATTERN = re.compile(r'(?%s' % (profile_url, appeal) - content = content.replace(appeal, auto_link) + auto_link = '%s' % (profile_url, to_replace) + content = content.replace(to_replace, auto_link) - return content \ No newline at end of file + return content