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

Python views.Meta类代码示例

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

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



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

示例1: test_get_full_url_without_schema

 def test_get_full_url_without_schema(self):
     meta.settings.SITE_PROTOCOL = 'https'
     m = Meta()
     self.assertEqual(
         m.get_full_url('//foo.com/foo/bar'),
         'https://foo.com/foo/bar'
     )
开发者ID:intip,项目名称:django-meta,代码行数:7,代码来源:test_meta.py


示例2: test_get_full_url_with_absolute_path

 def test_get_full_url_with_absolute_path(self):
     meta.settings.SITE_PROTOCOL = 'https'
     meta.settings.SITE_DOMAIN = 'foo.com'
     m = Meta()
     self.assertEqual(
         m.get_full_url('/foo/bar'),
         'https://foo.com/foo/bar'
     )
开发者ID:Work4Labs,项目名称:django-meta,代码行数:8,代码来源:test_meta.py


示例3: test_get_full_url_with_domain_and_protocol

 def test_get_full_url_with_domain_and_protocol(self):
     meta.settings.SITE_PROTOCOL = 'https'
     meta.settings.SITE_DOMAIN = 'foo.com'
     m = Meta()
     self.assertEqual(
         m.get_full_url('foo/bar'),
         'https://foo.com/foo/bar'
     )
开发者ID:Work4Labs,项目名称:django-meta,代码行数:8,代码来源:test_meta.py


示例4: test_get_full_url_without_site_id_with_request_will_not_raise

 def test_get_full_url_without_site_id_with_request_will_not_raise(self):
     settings.USE_SITES = True
     settings.SITE_PROTOCOL = 'http'
     factory = RequestFactory()
     request = factory.get('/')
     Site.objects.create(domain=request.get_host())
     m = Meta(request=request)
     self.assertEqual(
         m.get_full_url('foo/bar'),
         'http://testserver/foo/bar'
     )
开发者ID:nephila,项目名称:django-meta,代码行数:11,代码来源:test_meta.py


示例5: test_get_full_url_without_domain_will_raise

 def test_get_full_url_without_domain_will_raise(self):
     meta.settings.SITE_PROTOCOL = 'http'
     m = Meta()
     with self.assertRaises(ImproperlyConfigured):
         m.get_full_url('foo/bar')
开发者ID:Work4Labs,项目名称:django-meta,代码行数:5,代码来源:test_meta.py


示例6: test_get_full_url_without_protocol_will_raise

 def test_get_full_url_without_protocol_will_raise(self):
     m = Meta()
     with self.assertRaises(ImproperlyConfigured):
         m.get_full_url('foo/bar')
开发者ID:Work4Labs,项目名称:django-meta,代码行数:4,代码来源:test_meta.py


示例7: test_get_full_url_with_full_url

 def test_get_full_url_with_full_url(self):
     m = Meta()
     self.assertEqual(
         m.get_full_url('http://example.com/foo'),
         'http://example.com/foo'
     )
开发者ID:Work4Labs,项目名称:django-meta,代码行数:6,代码来源:test_meta.py


示例8: test_get_full_url_with_None

 def test_get_full_url_with_None(self):
     m = Meta()
     self.assertEqual(m.get_full_url(None), None)
开发者ID:Work4Labs,项目名称:django-meta,代码行数:3,代码来源:test_meta.py


示例9: get_page_meta

def get_page_meta(page, language):
    """
    Retrieves all the meta information for the page in the given language

    :param page: a Page instance
    :param lang: a language code

    :return: Meta instance
    :type: object
    """
    from django.core.cache import cache
    from meta.views import Meta
    from .models import PageMeta, TitleMeta

    try:
        meta_key = get_cache_key(page, language)
    except AttributeError:
        return None
    meta = cache.get(meta_key)
    if not meta:
        meta = Meta()
        title = page.get_title_obj(language)

        meta.title = page.get_page_title(language)
        if not meta.title:
            meta.title = page.get_title(language)

        if title.meta_description:
            meta.description = title.meta_description.strip()
        try:
            titlemeta = title.titlemeta
            if titlemeta.description:
                meta.description = titlemeta.description.strip()
            if titlemeta.keywords:
                meta.keywords = titlemeta.keywords.strip().split(',')
            meta.locale = titlemeta.locale
            meta.og_description = titlemeta.og_description.strip()
            if not meta.og_description:
                meta.og_description = meta.description
            meta.twitter_description = titlemeta.twitter_description.strip()
            if not meta.twitter_description:
                meta.twitter_description = meta.description
            meta.gplus_description = titlemeta.gplus_description.strip()
            if not meta.gplus_description:
                meta.gplus_description = meta.description
            if titlemeta.image:
                meta.image = title.titlemeta.image.url
        except (TitleMeta.DoesNotExist, AttributeError):
            if meta.description:
                meta.og_description = meta.description
                meta.twitter_description = meta.description
                meta.gplus_description = meta.description
            # Skipping title-level metas
            pass
        try:
            pagemeta = page.pagemeta
            meta.object_type = pagemeta.og_type
            meta.og_type = pagemeta.og_type
            meta.og_app_id = pagemeta.og_app_id
            meta.og_profile_id = pagemeta.og_author_fbid
            meta.twitter_type = pagemeta.twitter_type
            meta.twitter_site = pagemeta.twitter_site
            meta.twitter_author = pagemeta.twitter_author
            meta.gplus_type = pagemeta.gplus_type
            meta.gplus_author = pagemeta.gplus_author
            if not meta.gplus_author.startswith('http'):
                if not meta.gplus_author.startswith('/'):
                    meta.gplus_author = 'https://plus.google.com/{0}'.format(meta.gplus_author)
                else:
                    meta.gplus_author = 'https://plus.google.com{0}'.format(meta.gplus_author)
            if page.publication_date:
                meta.published_time = page.publication_date.isoformat()
            if page.changed_date:
                meta.modified_time = page.changed_date.isoformat()
            if page.publication_end_date:
                meta.expiration_time = page.publication_end_date.isoformat()
            if meta.og_type == 'article':
                meta.og_publisher = pagemeta.og_publisher
                if pagemeta.og_author_url:
                    meta.og_author_url = pagemeta.og_author_url
                try:
                    from djangocms_page_tags.utils import get_title_tags, get_page_tags
                    tags = list(get_title_tags(page, language))
                    tags += list(get_page_tags(page))
                    meta.tag = ','.join([tag.name for tag in tags])
                except ImportError:
                    # djangocms-page-tags not available
                    pass
            if not meta.image and pagemeta.image:
                meta.image = pagemeta.image.url
        except PageMeta.DoesNotExist:
            # Skipping page-level metas
            pass
        meta.url = page.get_absolute_url(language)
    return meta
开发者ID:skirsdeda,项目名称:djangocms-page-meta,代码行数:95,代码来源:utils.py


示例10: get_page_meta

def get_page_meta(page, language):
    """
    Retrieves all the meta information for the page in the given language

    :param page: a Page instance
    :param lang: a language code

    :return: Meta instance
    :type: object
    """
    from django.core.cache import cache
    from meta.views import Meta
    from .models import PageMeta, TitleMeta

    meta_key = get_cache_key(page, language)
    meta = cache.get(meta_key)
    if not meta:
        meta = Meta()
        title = page.get_title_obj(language)

        meta.title = page.get_title(language)

        try:
            titlemeta = title.titlemeta
            meta.description = titlemeta.description.strip()
            meta.keywords = titlemeta.keywords.strip().split(",")
            meta.locale = titlemeta.locale
            if titlemeta.image:
                meta.image = title.titlemeta.image.url
        except TitleMeta.DoesNotExist:
            # Skipping title-level metas
            pass
        try:
            pagemeta = page.pagemeta
            meta.object_type = pagemeta.og_type
            meta.og_type = pagemeta.og_type
            meta.og_app_id = pagemeta.og_app_id
            meta.og_profile_id = pagemeta.og_author_fbid
            meta.twitter_type = pagemeta.twitter_type
            meta.twitter_site = pagemeta.twitter_site
            meta.twitter_author = pagemeta.twitter_author
            meta.gplus_type = pagemeta.gplus_type
            meta.gplus_author = pagemeta.gplus_author
            meta.published_time = page.publication_date.isoformat()
            meta.modified_time = page.changed_date.isoformat()
            if page.publication_end_date:
                meta.expiration_time = page.publication_end_date.isoformat()
            if meta.og_type == 'article':
                meta.og_publisher = pagemeta.og_publisher
                if pagemeta.og_author_url:
                    meta.og_author_url = pagemeta.og_author_url
                elif pagemeta.og_author:
                    meta.og_author = {
                        'first_name': pagemeta.og_author.first_name,
                        'last_name': pagemeta.og_author.last_name
                    }

                try:
                    from djangocms_page_meta.utils import get_title_tags, get_page_meta
                    tags = get_title_tags(page, language)
                    tags += get_page_meta(page, language)
                    meta.tag = ",".join(tags)
                except ImportError:
                    # djangocms-page-meta not available
                    pass
            if not meta.image and pagemeta.image:
                meta.image = pagemeta.image.url
        except PageMeta.DoesNotExist:
            # Skipping page-level metas
            pass
        if not meta.description and page.get_meta_description(language):
            meta.description = page.get_meta_description(language).strip()
        meta.url = page.get_absolute_url(language)
    return meta
开发者ID:synasius,项目名称:djangocms-page-meta,代码行数:74,代码来源:utils.py


示例11: test_get_full_url_with_absolute_path

 def test_get_full_url_with_absolute_path(self):
     meta.settings.SITE_PROTOCOL = "https"
     meta.settings.SITE_DOMAIN = "foo.com"
     m = Meta()
     self.assertEqual(m.get_full_url("/foo/bar"), "https://foo.com/foo/bar")
开发者ID:sergei-maertens,项目名称:django-meta,代码行数:5,代码来源:test_meta.py


示例12: test_get_full_url_with_domain_and_protocol

 def test_get_full_url_with_domain_and_protocol(self):
     meta.settings.SITE_PROTOCOL = "https"
     meta.settings.SITE_DOMAIN = "foo.com"
     m = Meta()
     self.assertEqual(m.get_full_url("foo/bar"), "https://foo.com/foo/bar")
开发者ID:sergei-maertens,项目名称:django-meta,代码行数:5,代码来源:test_meta.py


示例13: get_page_meta

def get_page_meta(page, language):
    """
    Retrieves all the meta information for the page in the given language

    :param page: a Page instance
    :param lang: a language code

    :return: Meta instance
    :type: object
    """
    from django.core.cache import cache
    from meta.views import Meta
    from .models import PageMeta, TitleMeta

    try:
        meta_key = get_cache_key(page, language)
    except AttributeError:
        return None
    gplus_server = 'https://plus.google.com'
    meta = cache.get(meta_key)
    if not meta:
        meta = Meta()
        title = page.get_title_obj(language)
        meta.extra_custom_props = []

        meta.title = page.get_page_title(language)
        if not meta.title:
            meta.title = page.get_title(language)

        if title.meta_description:
            meta.description = title.meta_description.strip()
        try:
            titlemeta = title.titlemeta
            if titlemeta.description:
                meta.description = titlemeta.description.strip()
            if titlemeta.keywords:
                meta.keywords = titlemeta.keywords.strip().split(',')
            meta.locale = titlemeta.locale
            meta.og_description = titlemeta.og_description.strip()
            if not meta.og_description:
                meta.og_description = meta.description
            meta.twitter_description = titlemeta.twitter_description.strip()
            if not meta.twitter_description:
                meta.twitter_description = meta.description
            meta.gplus_description = titlemeta.gplus_description.strip()
            if not meta.gplus_description:
                meta.gplus_description = meta.description
            if titlemeta.image:
                meta.image = title.titlemeta.image.canonical_url or title.titlemeta.image.url
            for item in titlemeta.extra.all():
                attribute = item.attribute
                if not attribute:
                    attribute = item.DEFAULT_ATTRIBUTE
                meta.extra_custom_props.append((attribute, item.name, item.value))
        except (TitleMeta.DoesNotExist, AttributeError):
            # Skipping title-level metas
            if meta.description:
                meta.og_description = meta.description
                meta.twitter_description = meta.description
                meta.gplus_description = meta.description
        defaults = {
            'object_type': meta_settings.FB_TYPE,
            'og_type': meta_settings.FB_TYPE,
            'og_app_id': meta_settings.FB_APPID,
            'fb_pages': meta_settings.FB_PAGES,
            'og_profile_id': meta_settings.FB_PROFILE_ID,
            'og_publisher': meta_settings.FB_PUBLISHER,
            'og_author_url': meta_settings.FB_AUTHOR_URL,
            'twitter_type': meta_settings.TWITTER_TYPE,
            'twitter_site': meta_settings.TWITTER_SITE,
            'twitter_author': meta_settings.TWITTER_AUTHOR,
            'gplus_type': meta_settings.GPLUS_TYPE,
            'gplus_author': meta_settings.GPLUS_AUTHOR,
        }
        try:
            pagemeta = page.pagemeta
            meta.object_type = pagemeta.og_type
            meta.og_type = pagemeta.og_type
            meta.og_app_id = pagemeta.og_app_id
            meta.fb_pages = pagemeta.fb_pages
            meta.og_profile_id = pagemeta.og_author_fbid
            meta.twitter_type = pagemeta.twitter_type
            meta.twitter_site = pagemeta.twitter_site
            meta.twitter_author = pagemeta.twitter_author
            meta.gplus_type = pagemeta.gplus_type
            meta.gplus_author = pagemeta.gplus_author
            if meta.og_type == 'article':
                meta.og_publisher = pagemeta.og_publisher
                meta.og_author_url = pagemeta.og_author_url
                try:
                    from djangocms_page_tags.utils import get_title_tags, get_page_tags
                    tags = list(get_title_tags(page, language))
                    tags += list(get_page_tags(page))
                    meta.tag = ','.join([tag.name for tag in tags])
                except ImportError:
                    # djangocms-page-tags not available
                    pass
            if not meta.image and pagemeta.image:
                meta.image = pagemeta.image.canonical_url or pagemeta.image.url
            for item in pagemeta.extra.all():
#.........这里部分代码省略.........
开发者ID:nephila,项目名称:djangocms-page-meta,代码行数:101,代码来源:utils.py


示例14: test_get_full_url_without_site_id_will_raise

 def test_get_full_url_without_site_id_will_raise(self):
     settings.USE_SITES = True
     settings.SITE_PROTOCOL = 'http'
     m = Meta()
     with self.assertRaises(ImproperlyConfigured):
         m.get_full_url('foo/bar')
开发者ID:nephila,项目名称:django-meta,代码行数:6,代码来源:test_meta.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python views.MetadataMixin类代码示例发布时间:2022-05-27
下一篇:
Python view.log函数代码示例发布时间: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