Mercurial > kallithea
changeset 8677:a765b2961eda
lib: move extract_mentioned_users out of utils2
Avoid model.db reference to keep utils2.py independent of Kallithea classes.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 11 Oct 2020 00:19:46 +0200 |
parents | 6fbbbd9a627a |
children | 16a359ce1801 |
files | kallithea/lib/utils.py kallithea/lib/utils2.py kallithea/model/comment.py kallithea/model/pull_request.py |
diffstat | 4 files changed, 14 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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)
--- 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
--- 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