# HG changeset patch # User Mads Kiilerich # Date 1602368386 -7200 # Node ID a765b2961eda92e78e451e4dcb2567c72a39ce68 # Parent 6fbbbd9a627a98c065a3996143a3c260384e7dd4 lib: move extract_mentioned_users out of utils2 Avoid model.db reference to keep utils2.py independent of Kallithea classes. diff -r 6fbbbd9a627a -r a765b2961eda kallithea/lib/utils.py --- a/kallithea/lib/utils.py Mon Oct 12 11:26:49 2020 +0200 +++ b/kallithea/lib/utils.py Sun Oct 11 00:19:46 2020 +0200 @@ -40,7 +40,7 @@ import kallithea.config.conf from kallithea.lib.exceptions import InvalidCloneUriException -from kallithea.lib.utils2 import ascii_bytes, aslist, get_current_authuser, safe_bytes, safe_str +from kallithea.lib.utils2 import ascii_bytes, aslist, extract_mentioned_usernames, get_current_authuser, safe_bytes, safe_str from kallithea.lib.vcs.backends.git.repository import GitRepository from kallithea.lib.vcs.backends.hg.repository import MercurialRepository from kallithea.lib.vcs.conf import settings @@ -591,3 +591,13 @@ settings.GIT_EXECUTABLE_PATH, output) return ver + + +def extract_mentioned_users(text): + """ Returns set of actual database Users @mentioned in given text. """ + result = set() + for name in extract_mentioned_usernames(text): + user = User.get_by_username(name, case_insensitive=True) + if user is not None and not user.is_default_user: + result.add(user) + return result diff -r 6fbbbd9a627a -r a765b2961eda kallithea/lib/utils2.py --- a/kallithea/lib/utils2.py Mon Oct 12 11:26:49 2020 +0200 +++ b/kallithea/lib/utils2.py Sun Oct 11 00:19:46 2020 +0200 @@ -378,17 +378,6 @@ return MENTIONS_REGEX.findall(text) -def extract_mentioned_users(text): - """ Returns set of actual database Users @mentioned in given text. """ - from kallithea.model.db import User - result = set() - for name in extract_mentioned_usernames(text): - user = User.get_by_username(name, case_insensitive=True) - if user is not None and not user.is_default_user: - result.add(user) - return result - - class AttributeDict(dict): def __getattr__(self, attr): return self.get(attr, None) diff -r 6fbbbd9a627a -r a765b2961eda kallithea/model/comment.py --- a/kallithea/model/comment.py Mon Oct 12 11:26:49 2020 +0200 +++ b/kallithea/model/comment.py Sun Oct 11 00:19:46 2020 +0200 @@ -31,7 +31,7 @@ from tg.i18n import ugettext as _ from kallithea.lib import helpers as h -from kallithea.lib.utils2 import extract_mentioned_users +from kallithea.lib.utils import extract_mentioned_users from kallithea.model.db import ChangesetComment, PullRequest, Repository, User from kallithea.model.meta import Session from kallithea.model.notification import NotificationModel diff -r 6fbbbd9a627a -r a765b2961eda kallithea/model/pull_request.py --- a/kallithea/model/pull_request.py Mon Oct 12 11:26:49 2020 +0200 +++ b/kallithea/model/pull_request.py Sun Oct 11 00:19:46 2020 +0200 @@ -34,7 +34,8 @@ from kallithea.lib import helpers as h from kallithea.lib.hooks import log_create_pullrequest -from kallithea.lib.utils2 import ascii_bytes, extract_mentioned_users +from kallithea.lib.utils import extract_mentioned_users +from kallithea.lib.utils2 import ascii_bytes from kallithea.model.db import ChangesetStatus, PullRequest, PullRequestReviewer, User from kallithea.model.meta import Session from kallithea.model.notification import NotificationModel