Skip to content

Commit 38420a5

Browse files
committed
Use get_user_model and QuerySet filter in mention.py
1 parent 78ee6fe commit 38420a5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

martor/extensions/mention.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import markdown
2-
from django.contrib.auth.models import User
2+
from django.contrib.auth import get_user_model
33
from ..settings import (
44
MARTOR_ENABLE_CONFIGS,
55
MARTOR_MARKDOWN_BASE_MENTION_URL
@@ -23,10 +23,11 @@ class MentionPattern(markdown.inlinepatterns.Pattern):
2323

2424
def handleMatch(self, m):
2525
username = self.unescape(m.group(2))
26+
user_check = get_user_model().objects.filter(username=username, is_active=True)
2627

2728
"""Makesure `username` is registered and actived."""
2829
if MARTOR_ENABLE_CONFIGS['mention'] == 'true':
29-
if username in [u.username for u in User.objects.exclude(is_active=False)]:
30+
if user_check.exists():
3031
url = '{0}{1}/'.format(MARTOR_MARKDOWN_BASE_MENTION_URL, username)
3132
el = markdown.util.etree.Element('a')
3233
el.set('href', url)

0 commit comments

Comments
 (0)