core: use consistent import for get_current_request

This commit is contained in:
RhodeCode Admin 2024-12-10 07:36:38 +01:00
parent 2433f3fbfc
commit 107b31a78f
14 changed files with 20 additions and 17 deletions

View file

@ -56,7 +56,7 @@ _exc_store = None
def maybe_send_exc_email(exc_id, exc_type_name, send_email):
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
import rhodecode as app
request = get_current_request()
@ -185,7 +185,7 @@ def get_detailed_tb(exc_info):
def get_request_metadata(request=None) -> dict:
request_metadata = {}
if not request:
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
request = get_current_request()

View file

@ -51,6 +51,7 @@ from pygments.formatters.html import HtmlFormatter
from pygments.lexers import (
get_lexer_by_name, get_lexer_for_filename, get_lexer_for_mimetype)
from tempita import looper
from webhelpers2.html import literal, HTML, escape
from webhelpers2.html._autolink import _auto_link_urls
@ -76,6 +77,7 @@ from webhelpers2.number import format_byte_size
from rhodecode import ConfigGet
from rhodecode.lib._vendor.webhelpers_backports import raw_select
from rhodecode.lib.pyramid_utils import get_current_request
from rhodecode.lib.action_parser import action_parser
from rhodecode.lib.html_filters import sanitize_html
from rhodecode.lib.pagination import Page, RepoPage, SqlPage

View file

@ -38,7 +38,7 @@ COLORS = {
def _inject_req_id(record, with_prefix=True):
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
dummy = '00000000-0000-0000-0000-000000000000'
req_id = None
@ -50,10 +50,11 @@ def _inject_req_id(record, with_prefix=True):
else:
req_id = (req_id or dummy)
record.req_id = req_id
return record
def _add_log_to_debug_bucket(formatted_record):
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
req = get_current_request()
if req:
req.req_id_bucket.append(formatted_record)
@ -129,7 +130,7 @@ class ExceptionAwareFormatter(logging.Formatter):
class RequestTrackingFormatter(ExceptionAwareFormatter):
def format(self, record):
_inject_req_id(record)
record = _inject_req_id(record)
def_record = logging.Formatter.format(self, record)
_add_log_to_debug_bucket(def_record)
return def_record

View file

@ -47,5 +47,5 @@ def get_current_request():
if not pyramid_req:
# maybe we're in celery context and need to get the PYRAMID_REQUEST
from rhodecode.lib.celerylib.loader import celery_app
pyramid_req = celery_app.conf['PYRAMID_REQUEST']
pyramid_req = celery_app.conf.get('PYRAMID_REQUEST')
return pyramid_req

View file

@ -49,7 +49,7 @@ from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.exc import IntegrityError # pragma: no cover
from sqlalchemy.dialects.mysql import LONGTEXT
from zope.cachedescriptors.property import Lazy as LazyProperty
from pyramid.threadlocal import get_current_request
from webhelpers2.text import remove_formatting
from rhodecode import ConfigGet
@ -71,6 +71,7 @@ from rhodecode.lib.ext_json import json, str_json
from rhodecode.lib.caching_query import FromCache
from rhodecode.lib.exceptions import (
ArtifactMetadataDuplicate, ArtifactMetadataBadValueType)
from rhodecode.lib.pyramid_utils import get_current_request
from rhodecode.model.meta import Base, Session
URL_SEP = '/'

View file

@ -46,7 +46,7 @@ import formencode
from pkg_resources import resource_filename
from formencode import All, Pipe
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
from rhodecode import BACKENDS
from rhodecode.lib import helpers

View file

@ -26,7 +26,7 @@ import logging
import traceback
import shutil
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
from rhodecode.lib.utils2 import (
unique_id, safe_int, safe_str, time_to_datetime, AttributeDict)

View file

@ -31,7 +31,7 @@ import urllib.error
import collections
import dataclasses as dataclasses
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
from rhodecode.lib.vcs.nodes import FileNode
from rhodecode.translation import lazy_ugettext

View file

@ -24,7 +24,6 @@ import logging
import traceback
import datetime
from pyramid.threadlocal import get_current_request
from sqlalchemy.orm import aliased
from zope.cachedescriptors.property import Lazy as LazyProperty
@ -35,6 +34,7 @@ from rhodecode.lib.exceptions import AttachedForksError, AttachedPullRequestsErr
from rhodecode.lib import hooks_base
from rhodecode.lib.str_utils import safe_bytes
from rhodecode.lib.user_log_filter import user_log_filter
from rhodecode.lib.pyramid_utils import get_current_request
from rhodecode.lib.utils import make_db_config
from rhodecode.lib.utils2 import (
safe_str, remove_prefix, obfuscate_url_pw,

View file

@ -719,7 +719,7 @@ class RepoGroupModel(BaseModel):
def get_repo_groups_as_dict(self, repo_group_list=None, admin=False,
super_user_actions=False):
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
_render = get_current_request().get_partial_renderer(
'rhodecode:templates/data_table/_dt_elements.mako')
c = _render.get_call_context()

View file

@ -23,8 +23,7 @@ import time
import functools
from collections import namedtuple
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
from rhodecode.lib import rc_cache
from rhodecode.lib.hash_utils import sha1_safe
from rhodecode.lib.html_filters import sanitize_html

View file

@ -25,10 +25,10 @@ import traceback
import datetime
import ipaddress
from pyramid.threadlocal import get_current_request
from sqlalchemy.exc import DatabaseError
from rhodecode import events
from rhodecode.lib.pyramid_utils import get_current_request
from rhodecode.lib.user_log_filter import user_log_filter
from rhodecode.lib.utils2 import (
get_current_rhodecode_user, action_logger_generic,

View file

@ -48,7 +48,7 @@ def add_renderer_globals(event):
# TODO: When executed in pyramid view context the request is not available
# in the event. Find a better solution to get the request.
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
request = event['request'] or get_current_request()
# Add Pyramid translation as '_' to context

View file

@ -43,7 +43,7 @@ class _LazyString(object):
self._request = kw.pop('request', None)
def _get_request(self):
from pyramid.threadlocal import get_current_request
from rhodecode.lib.pyramid_utils import get_current_request
return self._request or get_current_request()
def eval(self):