当前位置: 首页>>代码示例>>Python>>正文


Python threadlocal.get_current_request方法代码示例

本文整理汇总了Python中pyramid.threadlocal.get_current_request方法的典型用法代码示例。如果您正苦于以下问题:Python threadlocal.get_current_request方法的具体用法?Python threadlocal.get_current_request怎么用?Python threadlocal.get_current_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.threadlocal的用法示例。


在下文中一共展示了threadlocal.get_current_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: memoize

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def memoize(self, func):

        def memogetter(*args, **kwargs):
            inst = args[0]
            cache = getattr(inst, self.propname, _marker)
            if cache is _marker:
                setattr(inst, self.propname, dict())
                cache = getattr(inst, self.propname)

            # XXX this could be potentially big, a custom key should
            # be used if the arguments are expected to be big

            request_id = getattr(get_current_request(), 'request_id', None)
            if request_id:
                kwargs['request_id'] = request_id

            key = (func.__module__, func.__name__, args, tuple(sorted(kwargs.items())))
            val = cache.get(key, _marker)
            if val is _marker:
                val = func(*args, **kwargs)
                cache[key] = val
                setattr(inst, self.propname, cache)
            return val
        return memogetter 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:26,代码来源:memoize.py

示例2: request_memoize

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def request_memoize(self, func):

        def memogetter(*args, **kwargs):
            request = get_current_request()
            cache = getattr(request, self.propname, _marker)
            if cache is _marker:
                setattr(request, self.propname, dict())
                cache = getattr(request, self.propname)

            # XXX this could be potentially big, a custom key should
            # be used if the arguments are expected to be big
            key = (func.__module__, func.__name__, args, tuple(sorted(kwargs.items())))
            val = cache.get(key, _marker)
            if val is _marker:
                val = func(*args, **kwargs)
                cache[key] = val
                setattr(request, self.propname, cache)
            return val
        return memogetter 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:21,代码来源:memoize.py

示例3: review_imgs_site_evolve

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def review_imgs_site_evolve(root, registry):
    from lac.utilities.data_manager import evolve_article_images
    from lac.views.filter import find_entities
    from lac.content.interface import IBaseReview

    reviews = find_entities(interfaces=[IBaseReview])
    request = get_current_request()
    for review in reviews:
        article = review.article
        source = getattr(review, 'source_data', {}).get('site', None)
        if article and source in SOURCE_SITES:
            try:
                root_url = request.resource_url(review)
                resolved, newarticle = evolve_article_images(
                    review, article, SOURCE_SITES.get(source), root_url)
            except Exception:
                log.warning(review.title+" images not resolved")
                continue

            if resolved:
                review.article = newarticle
                review.reindex()
                log.info(review.title)

    log.info('Review imgs evolved.') 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:27,代码来源:__init__.py

示例4: get_content_data

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def get_content_data(self, request=None):
        if request is None:
            request = get_current_request()

        result = {'url': '',
                  'type': 'none'}
        if self.picture:
            result = {'url': self.picture.url,
                      'filename': self.picture.filename}
            if self.picture.mimetype.startswith('application/pdf'):
                result['type'] = 'pdf'
            else:
                #application/quarkxpress, application/x-quark-express
                result['type'] = 'xpress'

        return result 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:18,代码来源:periodic_advertising.py

示例5: admin_breadcrumbs

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def admin_breadcrumbs(jinja_ctx, context, **kw):
    """Render admin interface top breadcrumbs bar."""

    if not context:
        return ""

    request = jinja_ctx.get('request') or get_current_request()
    current_view_name = jinja_ctx.get("current_view_name")
    current_view_url = request.url
    crumbs = get_breadcrumbs(context, request, root_iface=IAdmin, current_view_name=current_view_name, current_view_url=current_view_url)

    assert crumbs, "Could not get breadcrumbs for {}".format(context)

    if len(crumbs) == 1:
        return ""

    return render("templates/admin/breadcrumbs.html", dict(context=context, breadcrumbs=crumbs), request=request) 
开发者ID:websauna,项目名称:websauna,代码行数:19,代码来源:filters.py

示例6: language_priors

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def language_priors(self, translation_service):
        from .auth import User, UserLanguagePreferenceCollection
        priors = super(Post, self).language_priors(translation_service)
        creator = self.creator or AgentProfile.get(self.creator_id)
        if creator and isinstance(creator, User):
            # probably a language that the user knows
            try:
                prefs = UserLanguagePreferenceCollection(creator.id)
                known_languages = prefs.known_languages()
            except AssertionError:  # user without prefs
                from pyramid.threadlocal import get_current_request
                request = get_current_request()
                if request:
                    known_languages = [request.locale_name]
                else:
                    return priors
                known_languages = []
            known_languages = {translation_service.asKnownLocale(loc)
                               for loc in known_languages}
            priors = {k: v * (1 if k in known_languages else 0.7)
                      for (k, v) in priors.items()}
            for lang in known_languages:
                if lang not in priors:
                    priors[lang] = 1
        return priors 
开发者ID:conversence,项目名称:idealoom,代码行数:27,代码来源:post.py

示例7: getCurrent

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def getCurrent(cls, req=None):
        from pyramid.threadlocal import get_current_request
        from pyramid.security import Everyone
        # Very very hackish, but this call is costly and frequent.
        # Let's cache it in the request. Useful for view_def use.
        if req is None:
            req = get_current_request()
        assert req
        if getattr(req, "lang_prefs", 0) is 0:
            user_id = req.authenticated_userid
            if user_id and user_id != Everyone:
                try:
                    req.lang_prefs = UserLanguagePreferenceCollection(user_id)
                    return req.lang_prefs
                except Exception:
                    capture_exception()
            # use my locale negotiator
            locale = req.locale_name
            req.lang_prefs = LanguagePreferenceCollectionWithDefault(locale)
        return req.lang_prefs 
开发者ID:conversence,项目名称:idealoom,代码行数:22,代码来源:auth.py

示例8: ravenCaptureArguments

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def ravenCaptureArguments(self, level=None, **extra):
        request = get_current_request()
        data = {
            'level': level,
            'user': {
                'id': d.get_userid(),
                'ip_address': d.get_address(),
            },
            'request': {
                'url': request.environ['PATH_INFO'],
                'method': request.environ['REQUEST_METHOD'],
                'data': request.POST,
                'query_string': request.environ['QUERY_STRING'],
                'headers': http.get_headers(request.environ),
                'env': request.environ,
            },
        }

        return {
            'data': data,
            'extra': dict(
                extra,
                session=getattr(request, 'weasyl_session', None),
            ),
        } 
开发者ID:Weasyl,项目名称:weasyl,代码行数:27,代码来源:middleware.py

示例9: get_template_values

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def get_template_values(self, field, cstruct, kw):
        """ Inserts the job status and preview status into template values
        """
        values = super(PhraseFinderWidget, self).\
            get_template_values(field, cstruct, kw)

        values['job_status'] = 'preview_not_available'

        req = get_current_request()

        # TODO: can we refactor this so that we compute the pipeline hash
        # in the pipeline building function?
        pstruct = req.create_corpus_pipeline_struct.copy()
        pstruct['step_id'] = field.schema.name
        phash_id = component_phash_id(
            file_name=pstruct['file_name'],
            text_column=pstruct['text_column'],
            pipeline=get_pipeline_for_component(pstruct)
        )
        values['phash_id'] = phash_id

        logger.info("Phrase widget: need phrase model id %s", phash_id)

        # Calculate the initial "panel status" to assign a status color to this
        # widget
        base_path = corpus_base_path(pstruct['file_name'])
        cpath = os.path.join(base_path, '%s.phras' % phash_id)

        for f in os.listdir(base_path):
            if f.startswith(cpath):    # it's an ngram model
                logger.info("Phrase widget: found a phrase model at %s", cpath)
                values['job_status'] = 'preview_available'
                return values

        # look for a job created for this model
        job = get_assigned_job(phash_id)
        if job is not None:
            values['job_status'] = 'preview_' + job.get_status()

        return values 
开发者ID:eea,项目名称:eea.corpus,代码行数:42,代码来源:widget.py

示例10: get_current_user

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def get_current_user(args):
    request = get_current_request()
    return request.user 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:5,代码来源:schema.py

示例11: resolve_next_date

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def resolve_next_date(self, args, info):
    """Return first date in the start_end interval.
    """
    request = get_current_request()
    start, end = getattr(request, 'start_end', (None, None))
    dates = occurences_start(self._root, 'dates', from_=start, until=end)
    return dates[0].date() if dates else None 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:9,代码来源:schema.py

示例12: resolve_state

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def resolve_state(self, args, info):
        request = get_current_request()
        state = get_states_mapping(
            request.user, self,
            getattr(self, 'state_or_none', [None])[0])
        return request.localizer.translate(state) 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:8,代码来源:schema.py

示例13: resolve_url

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def resolve_url(self, args, info):
        return get_current_request().resource_url(self._root, '@@index') 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:4,代码来源:schema.py

示例14: __init__

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def __init__(self, origin, object_type):
        super(ResolverLazyList, self).__init__(origin, state=None)
        objectmap = find_objectmap(get_current_request().root)
        self.resolver = objectmap.object_for
        self.object_type = object_type 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:7,代码来源:schema.py

示例15: mailer_send

# 需要导入模块: from pyramid import threadlocal [as 别名]
# 或者: from pyramid.threadlocal import get_current_request [as 别名]
def mailer_send(subject="!",
                sender=None,
                recipients=[],
                body=None,
                html=None,
                attachments=[]):
    try:
        request = get_current_request()
        if sender is None:
            sender = request.registry.settings['lac.admin_email']

        mailer = get_mailer(request)
        message = Message(subject=subject,
                          sender=sender,
                          recipients=recipients,
                          body=body,
                          html=html)
        for attachment in attachments:
            attachment = Attachment(attachment.title,
                                    attachment.mimetype,
                                    attachment)
            message.attach(attachment)

        if transaction.get().status == Status.COMMITTED:
            mailer.send_immediately(message)
        else:
            mailer.send(message)

    except Exception:
        pass 
开发者ID:ecreall,项目名称:lagendacommun,代码行数:32,代码来源:__init__.py


注:本文中的pyramid.threadlocal.get_current_request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。