• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.absolutify函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shared.utils.absolutify函数的典型用法代码示例。如果您正苦于以下问题:Python absolutify函数的具体用法?Python absolutify怎么用?Python absolutify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: banner_create

def banner_create(request):
    form = FacebookBannerInstanceForm(request, request.POST or None)
    if request.method == 'POST':
        if not form.is_valid():
            return JSONResponse(form.errors, status=400)

        banner_instance = form.save()

        # The create form is submitted via an AJAX call. If the user wants to
        # include their profile picture on a banner, we return a 202 Accepted to
        # indicate we are processing the image. If they don't, we just return
        # a 201 Created to signify that the banner instance has been created
        # and it is safe to continue.
        if request.POST['next_action'] == 'share':
            next = absolutify(reverse('facebook.banners.share',
                                      args=[banner_instance.id]))
        else:
            next = absolutify(reverse('facebook.banner_list'))

        if form.cleaned_data['use_profile_image']:
            generate_banner_instance_image.delay(banner_instance.id)

            payload = {
                'check_url': reverse('facebook.banners.create_image_check',
                                     args=[banner_instance.id]),
                'next': next
            }
            return JSONResponse(payload, status=202)  # 202 Accepted
        else:
            # No processing needed.
            banner_instance.processed = True
            banner_instance.save()
            return JSONResponse({'next': next}, status=201)  # 201 Created

    return jingo.render(request, 'facebook/banner_create.html', {'form': form})
开发者ID:drutorBOT,项目名称:affiliates,代码行数:35,代码来源:views.py


示例2: test_cdn

    def test_cdn(self):
        with patch.object(settings, 'CDN_DOMAIN', None):
            url = absolutify('/some/url', cdn=True)
            eq_(url, 'http://badge.mo.com/some/url')

        with patch.object(settings, 'CDN_DOMAIN', 'cdn.badge.mo.com'):
            url = absolutify('/some/url', cdn=True)
            eq_(url, 'http://cdn.badge.mo.com/some/url')
开发者ID:davedash,项目名称:affiliates,代码行数:8,代码来源:test__utils.py


示例3: code

 def code(self):
     """Return the code to embed this banner.."""
     return jingo.env.from_string(BANNER_TEMPLATE).render({
         'url': self.affiliate_link(),
         'img': absolutify(self.image.image.url),
         'alt_text': _locale(self.badge.name, self.image.locale)
     })
开发者ID:LucianU,项目名称:affiliates,代码行数:7,代码来源:models.py


示例4: render

    def render(self):
        """Render the image grid for the banner selector."""
        banner_ids = [int(banner_id) for banner_id, label in self.choices
                      if banner_id != '']
        banners = dict((banner.id, banner) for banner in
                       FacebookBanner.objects.filter(id__in=banner_ids))

        inputs = []
        locale = get_language()
        for radio_input in self:
            # Ignore empty choice.
            # TODO: Could probably use a better workaround.
            if radio_input.choice_value == '':
                continue

            banner = banners[int(radio_input.choice_value)]

            # Construct image tag.
            img = '<img%s>' % flatatt({
                'class': 'banner-choice',
                'src': absolutify(banner.thumbnail_for_locale(locale).url),
                'width': 100,
                'height': 72,
                'alt': banner.alt_text
            })

            # Add attributes to the input tag.
            url = banner.image_for_locale(locale).url
            radio_input.attrs['data-image'] = absolutify(url)

            if 'id' in self.attrs:
                label_for = ' for="%s_%s"' % (radio_input.attrs['id'],
                                              radio_input.index)
            else:
                label_for = ''

            # Bring it all together!
            inputs.append('<label%(label_for)s>\n%(input)s\n%(img)s\n'
                          '</label>' % {
                'label_for': label_for,
                'input': radio_input.tag(),
                'img': img
            })

        return mark_safe(u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>'
                % tag for tag in inputs]))
开发者ID:Hugochazz,项目名称:affiliates,代码行数:46,代码来源:forms.py


示例5: banner_share

def banner_share(request, instance_id):
    banner_instance = get_object_or_404(FacebookBannerInstance, id=instance_id,
                                        user=request.user)
    protocol = 'https' if request.is_secure() else 'http'
    next = absolutify(reverse('facebook.post_banner_share'),
                              protocol=protocol)
    return jingo.render(request, 'facebook/banner_share.html',
                        {'banner_instance': banner_instance, 'next': next})
开发者ID:drutorBOT,项目名称:affiliates,代码行数:8,代码来源:views.py


示例6: load_app

def load_app(request):
    """
    Create or authenticate the Facebook user and direct them to the correct
    area of the app upon their entry.
    """
    signed_request = request.POST.get('signed_request', None)
    if signed_request is None:
        # App wasn't loaded within a canvas, redirect to the home page.
        return redirect('home')

    decoded_request = decode_signed_request(signed_request,
                                            settings.FACEBOOK_APP_SECRET)
    if decoded_request is None:
        return redirect('home')

    # If user is using Safari, we need to apply the cookie workaround.
    useragent = request.META.get('HTTP_USER_AGENT', '')
    using_safari = 'Safari' in useragent and not 'Chrome' in useragent
    workaround_applied = SAFARI_WORKAROUND_KEY in request.COOKIES
    if using_safari and not workaround_applied:
        return fb_redirect(request,
                           absolutify(reverse('facebook.safari_workaround')),
                           top_window=True)

    user, created = (FacebookUser.objects.
            get_or_create_user_from_decoded_request(decoded_request))
    if user is None:
        # User has yet to authorize the app, redirect to the pre-auth promo.
        return fb_redirect(request,
                           absolutify(reverse('facebook.pre_auth_promo')))

    # Attach country data to the user object. This can only be retrieved from
    # the decoded request, so we add it here and login saves it.
    user.country = decoded_request['user'].get('country', user.country)

    # User has been authed, let's log them in.
    login(request, user)

    return fb_redirect(request, absolutify(reverse('facebook.banner_list')))
开发者ID:drutorBOT,项目名称:affiliates,代码行数:39,代码来源:views.py


示例7: test_no_safari_workaround

    def test_no_safari_workaround(self, fb_redirect, update_user_info):
        """
        If the user is not using Safari, do not redirect to the workaround.
        """
        with self.activate('en-US'):
            workaround_url = absolutify(reverse('facebook.safari_workaround'))

        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=1)
        response = self.load_app(payload,
                                 HTTP_USER_AGENT='Safari/5.04 Chrome/7.5')

        eq_(response, fb_redirect.return_value)
        ok_(fb_redirect.call_args[0][1] != workaround_url)
开发者ID:disegnovitruviano,项目名称:affiliates,代码行数:14,代码来源:test_views.py


示例8: size_color_to_image_map

    def size_color_to_image_map(self):
        """
        Return a dictionary that maps sizes and colors to these banner images.
        """
        banner_images = {}
        for img in self:
            if img.size not in banner_images:
                banner_images[img.size] = {}

            banner_images[img.size][img.localized('color')] = {
                'image_url': absolutify(img.image.url, cdn=True),
                'pk': img.pk
            }

        return banner_images
开发者ID:davedash,项目名称:affiliates,代码行数:15,代码来源:models.py


示例9: browserid_home

def browserid_home(request):
    """Display the home page with a BrowserID login."""
    register_form = BrowserIDRegisterForm(request.POST or None)
    if request.method == 'POST':
        # Attempting to register
        response = browserid_register(request, register_form)
        if response is not None:
            return response

    params = {'browserid_verify': reverse('browserid.verify'),
              'register_form': register_form,
              'share_url': absolutify('/', protocol='https'),
              'tweet_text': urlquote_plus(TWEET_TEXT),
              'browserid_no_assertion': BROWSERID_NO_ASSERTION,
              'browserid_verify_fail': BROWSERID_VERIFY_FAIL}
    return render(request, 'shared/home/browserid.html', params)
开发者ID:disegnovitruviano,项目名称:affiliates,代码行数:16,代码来源:views.py


示例10: test_no_profile_image

    def test_no_profile_image(self):
        """
        If the user did not check `use_profile_image`, create the banner
        instance and return a 201 Created.
        """
        banner = FacebookBannerLocaleFactory.create(locale='en-us').banner
        response = self.banner_create(banner=banner.id, text='asdf',
                                      next_action='', use_profile_image=False)
        ok_(FacebookBannerInstance.objects.filter(banner=banner, user=self.user)
            .exists())

        eq_(response.status_code, 201)
        response_data = json.loads(response.content)
        with self.activate('en-US'):
            eq_(response_data['next'],
                absolutify(reverse('facebook.banner_list')))
开发者ID:disegnovitruviano,项目名称:affiliates,代码行数:16,代码来源:test_views.py


示例11: home

def home(request, register_form=None, login_form=None):
    """Display the home page."""
    # Redirect logged-in users
    if request.user.is_authenticated():
        return redirect('badges.new.step1')

    if register_form is None:
        register_form = RegisterForm()
    if login_form is None:
        login_form = LoginForm()

    params = {'register_form': register_form,
              'login_form': login_form,
              'share_url': absolutify('/'),
              'tweet_text': urlquote_plus(TWEET_TEXT)}
    return jingo.render(request, 'badges/home.html', params)
开发者ID:davedash,项目名称:affiliates,代码行数:16,代码来源:views.py


示例12: test_safari_workaround_done

    def test_safari_workaround_done(self, fb_redirect, update_user_info):
        """
        If the user is using Safari and hasthe workaround cookie, do not send
        them to the workaround page.
        """
        with self.activate('en-US'):
            workaround_url = absolutify(reverse('facebook.safari_workaround'))

        fb_redirect.return_value = HttpResponse('blah')
        payload = create_payload(user_id=1)
        self.client.cookies[SAFARI_WORKAROUND_KEY] = '1'
        response = self.load_app(payload, HTTP_USER_AGENT='Safari/5.04')
        del self.client.cookies[SAFARI_WORKAROUND_KEY]

        # Ensure that the redirect URL is NOT the safari workaround url
        eq_(response, fb_redirect.return_value)
        ok_(fb_redirect.call_args[0][1] != workaround_url)
开发者ID:disegnovitruviano,项目名称:affiliates,代码行数:17,代码来源:test_views.py


示例13: test_save_and_share

    def test_save_and_share(self):
        """
        If the user clicks the `Save and Share` button, the `next` link should
        point to the share page for the new banner instance.
        """
        banner = FacebookBannerLocaleFactory.create(locale='en-us').banner
        response = self.banner_create(banner=banner.id, text='asdf',
                                      next_action='share',
                                      use_profile_image=False)
        instance = FacebookBannerInstance.objects.get(banner=banner,
                                                      user=self.user)

        response_data = json.loads(response.content)
        with self.activate('en-US'):
            eq_(response_data['next'],
                absolutify(reverse('facebook.banners.share',
                           args=[instance.id])))
开发者ID:disegnovitruviano,项目名称:affiliates,代码行数:17,代码来源:test_views.py


示例14: load_app

def load_app(request):
    """
    Create or authenticate the Facebook user and direct them to the correct
    area of the app upon their entry.
    """
    # Temporary measure to handle when Facebook does a GET to the main URL when
    # a logged-out user views the app. In the future we should show a promo
    # page instead.
    if request.method != "POST":
        return request_authorization(request)

    signed_request = request.POST.get("signed_request", None)
    if signed_request is None:
        # App wasn't loaded within a canvas, redirect to the home page.
        return redirect("home")

    decoded_request = decode_signed_request(signed_request, settings.FACEBOOK_APP_SECRET)
    if decoded_request is None:
        return redirect("home")

    # If user is using Safari, we need to apply the cookie workaround.
    useragent = request.META.get("HTTP_USER_AGENT", "")
    using_safari = "Safari" in useragent and not "Chrome" in useragent
    workaround_applied = SAFARI_WORKAROUND_KEY in request.COOKIES
    if using_safari and not workaround_applied:
        return fb_redirect(request, absolutify(reverse("facebook.safari_workaround")))

    user, created = FacebookUser.objects.get_or_create_user_from_decoded_request(decoded_request)
    if user is None:
        # User has yet to authorize the app, offer authorization.
        return request_authorization(request)

    # Attach country data to the user object. This can only be retrieved from
    # the decoded request, so we add it here and login saves it.
    user.country = decoded_request["user"].get("country", user.country)

    # User has been authed, let's log them in.
    login(request, user)

    # Normally the FacebookAuthenticationMiddleware activates the locale for
    # the user, but since it does not run for this view, we need to activate it
    # manually.
    activate_locale(request, user.locale)

    return banner_list(request)
开发者ID:bensternthal,项目名称:affiliates,代码行数:45,代码来源:views.py


示例15: home

def home(request, register_form=None, login_form=None):
    """Display the home page."""
    # Redirect logged-in users
    if request.user.is_authenticated():
        return redirect('badges.new.step1')

    # en-US users see the BrowserID view instead
    if get_language() in settings.BROWSERID_LOCALES:
        return browserid_home(request)

    if register_form is None:
        register_form = RegisterForm()
    if login_form is None:
        login_form = LoginForm()

    params = {'register_form': register_form,
              'login_form': login_form,
              'share_url': absolutify('/', protocol='https'),
              'tweet_text': urlquote_plus(TWEET_TEXT)}
    return render(request, 'shared/home/normal.html', params)
开发者ID:disegnovitruviano,项目名称:affiliates,代码行数:20,代码来源:views.py


示例16: test_use_profile_image

    def test_use_profile_image(self, delay):
        """
        If the user checked `use_profile_image`, create a banner instance,
        trigger the celery task and return a 202 Accepted.
        """
        banner = FacebookBannerLocaleFactory.create(locale='en-us').banner
        response = self.banner_create(banner=banner.id, text='asdf',
                                      next_action='', use_profile_image=True)

        # Asserts that banner instance exists.
        instance = FacebookBannerInstance.objects.get(banner=banner,
                                                      user=self.user)
        delay.assert_called_with(instance.id)

        # Assert response contians the expected links.
        eq_(response.status_code, 202)
        response_data = json.loads(response.content)
        with self.activate('en-US'):
            eq_(response_data['next'],
                absolutify(reverse('facebook.banner_list')))
            eq_(response_data['check_url'],
                reverse('facebook.banners.create_image_check',
                        args=[instance.id]))
开发者ID:disegnovitruviano,项目名称:affiliates,代码行数:23,代码来源:test_views.py


示例17: render

 def render(self):
     return jingo.env.from_string(BANNER_TEMPLATE).render({
         'url': self.affiliate_link(),
         'img': absolutify(self.image.image.url)
     })
开发者ID:davedash,项目名称:affiliates,代码行数:5,代码来源:models.py


示例18: link

 def link(self):
     return absolutify(reverse('facebook.banners.link', args=[self.id]))
开发者ID:disegnovitruviano,项目名称:affiliates,代码行数:2,代码来源:models.py


示例19: banner_share

def banner_share(request, instance_id):
    banner_instance = get_object_or_404(FacebookBannerInstance, id=instance_id, user=request.user)
    protocol = "https" if request.is_secure() else "http"
    next = absolutify(reverse("facebook.post_banner_share"), protocol=protocol)
    return jingo.render(request, "facebook/banner_share.html", {"banner_instance": banner_instance, "next": next})
开发者ID:bensternthal,项目名称:affiliates,代码行数:5,代码来源:views.py


示例20: invite

def invite(request):
    protocol = "https" if request.is_secure() else "http"
    next = absolutify(reverse("facebook.post_invite"), protocol=protocol)
    return jingo.render(request, "facebook/invite.html", {"next": next})
开发者ID:bensternthal,项目名称:affiliates,代码行数:4,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shared_functions.CommonCloudFunctions类代码示例发布时间:2022-05-27
下一篇:
Python ttypes.SharedStruct类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap