當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。