Files
zulip/zephyr/lib/mention.py
Kevin Mehall dce1f7f729 Parse @-mentions in bugdown and style them.
* This makes bugdown.convert take a `message` parameter. Properties
    for parsed mentions are added to the message object by the `Pattern`
    for use in do_send_messages.

  * Refactor repeated markdown rendering code into `Message` model methods.

(imported from commit 4f0ed5570104c0210f984b6de21e9048e2b53fa0)
2013-07-02 18:20:26 -04:00

26 lines
642 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'(?:\B@(?:\*\*([^\*]+)\*\*)|@(\w+))'
find_mentions_re = re.compile(find_mentions)
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)