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


Python ThreadLocal.get_current_request方法代码示例

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


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

示例1: get_ols_url

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
def get_ols_url():
    req = ThreadLocal.get_current_request()
    protocol = req.META['wsgi.url_scheme']
    r = req.build_absolute_uri()
    ols_url = protocol + '://' + ThreadLocal.get_current_request().META['HTTP_HOST'] + reverse(
        'copo:ajax_search_ontology')

    return ols_url
开发者ID:ISA-tools,项目名称:COPO,代码行数:10,代码来源:html_tags.py

示例2: __init__

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
 def __init__(self, sub_id):
     self.BASE_URL = FIGSHARE_API_URLS['base_url']
     request = ThreadLocal.get_current_request()
     self.TOKEN = Figshare().get_token_for_user(request.user.id)['token']
     self.HEADERS = {'Authorization': 'token ' + self.TOKEN}
     self.MEDIA_ROOT = settings.MEDIA_ROOT
     self.transfer_token = RemoteDataFile().create_transfer(sub_id)['_id']
开发者ID:ISA-tools,项目名称:COPO,代码行数:9,代码来源:figshareSubmission.py

示例3: get_absolute_url

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
    def get_absolute_url(self):
        """
        absolute url (without domain/host part)
        TODO: Should be used a cache here?
        """
        if not self.url_name:
            return "" # menu section

        url = self.get_url()
        if url is None: # can't resolve url, message was created.
            return "#resolve-error" # XXX: return something else?

        request = ThreadLocal.get_current_request()
        get_data = {}
        if self.get_pagetree and hasattr(request.PYLUCID, "pagetree"):
            get_data["pagetree"] = request.PYLUCID.pagetree.pk
        if self.get_pagemeta and hasattr(request.PYLUCID, "pagemeta"):
            get_data["pagemeta"] = request.PYLUCID.pagemeta.pk
        if self.get_page:
            if hasattr(request.PYLUCID, "pagecontent"):
                get_data["pagecontent"] = request.PYLUCID.pagecontent.pk
            elif hasattr(request.PYLUCID, "pluginpage"):
                get_data["pluginpage"] = request.PYLUCID.pluginpage.pk

        if get_data:
            # FIXME: There must be a better was to to this.
            # TODO: escape it.
            url += "?" + "&".join(["%s=%s" % (key, value) for key, value in get_data.items()])

        return url
开发者ID:BIGGANI,项目名称:PyLucid,代码行数:32,代码来源:models.py

示例4: _setup_tag_filter

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
    def _setup_tag_filter(self):
        """
        prepare the tag queryset filter
        """
        def get_data(field_name):
            return self.initial.get(field_name, None) or self.data.get(field_name, None)

        language = get_data("language")
        if not language:
            # Use current language for tag queryset filter
            request = ThreadLocal.get_current_request()
            language = request.PYLUCID.current_language

        pagetree_id = get_data("pagetree")
        if pagetree_id:
            pagetree = PageTree.objects.only("site").get(id=pagetree_id)
            site = pagetree.site
        else:
            # Use current site for tag queryset filter
            site = settings.SITE_ID

        # change the tag queryset filter:
        self.fields["tags"].widget.tag_queryset_filters = {
            "language": language,
            "pagetree__site": site,
        }
开发者ID:BIGGANI,项目名称:PyLucid,代码行数:28,代码来源:pagemeta.py

示例5: generate_copo_sample_form

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
def generate_copo_sample_form(source_id=None, sample_id=None):
    profile_id = ThreadLocal.get_current_request().session['profile_id']

    # if there are sources in the profile, create a dropdown showing the sources and a box to create a new one
    # if there are no sources in the profile, create the new source form
    output = ''
    if ProfileInfo(profile_id).source_count() > 0:
        # get sources
        sources = Source(profile_id).get_all_sources()

        output += "<div id='source_select'>"
        output += generate_copo_source_dropdown(sources)
        output += generate_copo_source_add_button()
        output += "</div>"
        output += "<div id='new_source_div'>"
        output += generate_copo_source_form_html()
        output += "</div>"
    else:
        output += "<div id='new_source_div'>"
        output += generate_copo_source_form_html()
        output += "</div>"

    output += generate_copo_sample_form_html()

    return output
开发者ID:alexgarciac,项目名称:COPO,代码行数:27,代码来源:html_tags.py

示例6: done

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
    def done(self, form_list, **kwargs):
        invoice = None

        from django_tools.middlewares import ThreadLocal

        user = ThreadLocal.get_current_user().username
        klient = Klient.objects.get(nazwa=user)

        for form in form_list:
            if isinstance(form, ZamowienieForm):
                invoiceData = form.cleaned_data
                invoiceData.update({
                    'klient': klient
                })
                invoice = Zamowienie(**invoiceData)
                invoice.save()
            elif isinstance(form, BaseFormSet):
                for posForm in form.forms:
                    if isinstance(posForm, PozycjaZamowieniaForm):
                        positionData = posForm.cleaned_data
                        positionData.update({
                            'zamowienie': invoice
                        })
                        position = PozycjaZamowienia(**positionData)
                        position.save()
                    else:
                        posForm.save()

        self.storage.reset()

        return render_to_response('wizard/stepDone.html',
                                  {'zamowienie': invoice,
                                   'pozycje': PozycjaZamowienia.objects.filter(zamowienie_id=invoice.pk)},
                                  context_instance=RequestContext(ThreadLocal.get_current_request()))
开发者ID:kornicameister,项目名称:InvoiceManager,代码行数:36,代码来源:forms.py

示例7: get_permissions

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
    def get_permissions(self):
        """
        returns the access permissions for this menu entry.
        TODO: Should be cache this?
        """
        if not self.url_name: # a menu section
            # TODO: Check if at least one sub entry is accessible.
            return (False, (), False)

        url = self.get_url()
        if url is None: # can't resolve url, message was created.
            return (True, (), True) # view can only superusers use

        # Get the view function for this url_name
        view_func, func_args, func_kwargs = urlresolvers.resolve(url)

        # get the rights from pylucid_project.apps.pylucid.decorators.check_permissions
        try:
            access_permissions = view_func.access_permissions
        except AttributeError, err:
            # If no permissions available, fallback to superuser only
            request = ThreadLocal.get_current_request()
            if settings.DEBUG or request.user.is_staff:
                messages.error(request, (
                    "The view %s for url %r has no permissions attribute!"
                    " Please use pylucid_project.apps.pylucid.decorators.check_permissions!"
                    ) % (view_func.__name__, self.url_name)
                )
            access_permissions = (True, (), True)
开发者ID:BIGGANI,项目名称:PyLucid,代码行数:31,代码来源:models.py

示例8: get_permalink

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
    def get_permalink(self):
        """
        return a permalink. Use page slug/name/title or nothing as additional text.
        """
        if self.pk in self._permalink_cache:
            #print "PageMeta permalink_cache len: %s, pk: %s" % (len(self._permalink_cache), self.pk)
            return self._permalink_cache[self.pk]

        # Get the system preferences
        request = ThreadLocal.get_current_request()
        sys_pref = request.PYLUCID.preferences
        sys_pref_form = request.PYLUCID.preferences_form

        use_additions = sys_pref.get("permalink_additions", sys_pref_form.PERMALINK_USE_TITLE)

        do_slugify = False
        if use_additions == sys_pref_form.PERMALINK_USE_TITLE:
            # Append the PageMeta title (language dependent)
            addition_txt = self.get_title()
            do_slugify = True
        elif use_additions == sys_pref_form.PERMALINK_USE_NAME:
            addition_txt = self.get_name()
            do_slugify = True
        elif use_additions == sys_pref_form.PERMALINK_USE_SLUG:
            addition_txt = self.pagetree.slug
        else:
            addition_txt = ""

        if do_slugify:
            addition_txt = slugify(addition_txt)

        url = reverse('PyLucid-permalink', kwargs={'page_id': self.pagetree.id, 'url_rest': addition_txt})
        self._permalink_cache[self.pk] = url
        return url
开发者ID:BIGGANI,项目名称:PyLucid,代码行数:36,代码来源:pagemeta.py

示例9: __init__

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
    def __init__(self, *args, **kwargs):
        """
        prepare the tag queryset filter
        """
        super(TagLanguageSitesFilter, self).__init__(*args, **kwargs)

        def get_data(field_name):
            return self.initial.get(field_name, None) or self.data.get(field_name, None)

        language = get_data("language")
        if not language:
            # Use current language for tag queryset filter
            request = ThreadLocal.get_current_request()
            language = request.PYLUCID.current_language

        sites = get_data("sites")
        if not sites:
            # Use current site for tag queryset filter
            sites = [settings.SITE_ID]

        # change the tag queryset filter:
        self.fields["tags"].widget.tag_queryset_filters = {
            "language": language,
            "sites__id__in": sites,
        }
开发者ID:daqing15,项目名称:PyLucid,代码行数:27,代码来源:utils.py

示例10: log_action

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
    def log_action(self, app_label, action, request=None, message=None, long_message=None, data=None):
        if request is None:
            request = ThreadLocal.get_current_request()

        kwargs = {
            "uri": request.build_absolute_uri(),
            "app_label": app_label,
            "action": action,
            "message": message,
            "long_message": long_message,
            "data": data,
        }

        if hasattr(request, "PYLUCID"):
            kwargs["used_language"] = request.PYLUCID.current_language

        for key in META_KEYS:
            value = request.META.get(key)
            if value and len(value) > 255:
                value = "%s..." % value[:252]
            kwargs[key.lower()] = value

        new_entry = self.model(**kwargs)
        new_entry.save()
        return new_entry
开发者ID:daqing15,项目名称:PyLucid,代码行数:27,代码来源:log.py

示例11: _get_callable

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
 def _get_callable(self, obj, attr):
     """ Check if the attr is callable, return its value if it is """
     try:
         _attr = getattr(obj, attr)
         if callable(_attr):
             request = ThreadLocal.get_current_request()
             return _attr(request=request)
     except AttributeError:  # not a model/object attribute or relation does not exist
         pass
     return None
开发者ID:netogallo,项目名称:bluebottle,代码行数:12,代码来源:serializers.py

示例12: do_sample_wizard_components

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
    def do_sample_wizard_components(self):
        self.context['wiz_message'] = d_utils.json_to_pytype(lkup.MESSAGES_LKUPS["sample_wizard_messages"])[
            "properties"]
        self.context['wiz_howtos'] = d_utils.json_to_pytype(lkup.MESSAGES_LKUPS["sample_wizard_howto"])
        self.context['wizard_stages'] = self.wizard_helper.generate_stage_items()

        # get all records: used in the UI for 'cloning' and other purposes
        profile_id = ThreadLocal.get_current_request().session['profile_id']
        self.context["component_records"] = htags.generate_component_records("sample", profile_id)

        return self.context
开发者ID:ISA-tools,项目名称:COPO,代码行数:13,代码来源:broker_requests.py

示例13: get_html

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
 def get_html(self):
     """ return the marker_text as html """
     request = ThreadLocal.get_current_request()
     html = apply_markup(
         raw_content=self.marker_text,
         markup_no=self.markup,
         request=request
     )
     # Needed for JavaScript:
     html = html.strip().replace("\n", "").replace('"', '\"')
     return mark_safe(html)
开发者ID:daqing15,项目名称:PyLucid,代码行数:13,代码来源:models.py

示例14: get_current

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
    def get_current(self, request=None):
        """ return client Language instance, if not available, use get_default_lang_entry() """
        if request == None:
            request = ThreadLocal.get_current_request()

        if request == None:
            # no request available, e.g. loading fixtures
            return self._get_default_language()

        language_list = self.get_languages(request)
        return language_list[0]
开发者ID:pombredanne,项目名称:PyLucid,代码行数:13,代码来源:language.py

示例15: get_current_host

# 需要导入模块: from django_tools.middlewares import ThreadLocal [as 别名]
# 或者: from django_tools.middlewares.ThreadLocal import get_current_request [as 别名]
def get_current_host():
    """
    Get the current hostname with protocol
    E.g. http://localhost:8000 or https://bluebottle.org
    """
    request = ThreadLocal.get_current_request()
    if request.is_secure():
        scheme = 'https'
    else:
        scheme = 'http'
    return '{0}://{1}'.format(scheme, request.get_host())
开发者ID:jfterpstra,项目名称:bluebottle,代码行数:13,代码来源:utils.py


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