- username = appeal[1:]
- profile_url = None
-
- try:
- user = User.objects.get(username__iexact=username)
- profile_url = user.get_absolute_url()
- except User.DoesNotExist:
- """If we don't find the user from the first time, the interesting part
- begins. We look through all the authors (looking through question,
- comments, answers, and if it matches some of the -- we link him."""
-
- # We should find the root of the node tree (question) the current node belongs to.
- if node.node_type == "question":
- question = node
- elif node.node_type == "answer":
- question = node.question
- elif node.node_type == "comment":
- if not node.question:
- question = node
- else:
- question = node.question
+ username = appeal.group(0)[1:]
+
+ matches = []
+
+ for user in active_users:
+ if user.username.lower().startswith(username.lower()):
+ matches.append(user)
+
+ if len(matches) == 1:
+ replacements.append(
+ (find_best_match_in_name(content, username, matches[0].username, appeal.start(0) + 1), matches[0])
+ )
+ elif len(matches) == 0:
+ matches = User.objects.filter(username__istartswith=username)