Files
zulip/zephyr/lib/mention.py
Kevin Mehall 9d8765ac24 Don't compile an unused copy of the find_mentions regex.
(imported from commit 67e4cd89a5ed038e0e5a7459d5f88aa8d04b21d7)
2013-07-15 13:26:44 -04:00

25 lines
609 B
Python

import re
from django.db.models import F, Q
import zephyr.models
# Match multi-word string between @** ** or match any one-word
# sequences after @
find_mentions = r'(?<![^\s\'\"\(,:<])@(?:\*\*([^\*]+)\*\*|(\w+))'
wildcards = ['all', 'everyone']
def find_user_for_mention(mention, realm):
if mention in wildcards:
return (True, None)
try:
user = zephyr.models.UserProfile.objects.filter(
Q(full_name__iexact=mention) | Q(short_name__iexact=mention),
realm=realm
)[0]
except IndexError:
user = None
return (False, user)